Neat Commenting Trick With #Debug
I wish I would have known about this trick a long time ago. Jim Sally whom I work with demonstrated to me a really neat commenting trick that I did not know about, that really helps when you are mocking out objects particularly. When you have some arbitrary class file, like this jawdropper :)
-
using System;
-
using Microsoft.SharePoint;
-
-
namespace examples.SharePoint.Shelter
-
{
-
public class List
-
{
-
private readonly SPWeb m_oWeb;
-
-
public List()
-
{
-
m_oWeb = null;
-
}
-
-
public SPWeb WebSite
-
{
-
get { return m_oWeb; }
-
}
-
-
public string GetListDirection(Guid oListId)
-
{
-
SPList l_oList = m_oWeb.Lists[oListId];
-
return l_oList.Direction;
-
}
-
-
}
-
}
There is just that string return that results in the reading direction of an arbitrary SharePoint list object, but what if you wanted to comment out that method, however because you use it for and in development, you want it AUTOMATICALLY commented out when you switch between debug (development) and release (production) build configurations, selected from the Visual Studio IDE. Jim showed me you can just wrap whatever you want with this:
-
#if (DEBUG)
-
-
#endif
So that the class file would instead look like this:
-
using System;
-
using Microsoft.SharePoint;
-
-
namespace examples.SharePoint.Shelter
-
{
-
public class List
-
{
-
private readonly SPWeb m_oWeb;
-
-
public List()
-
{
-
m_oWeb = null;
-
}
-
-
public SPWeb WebSite
-
{
-
get { return m_oWeb; }
-
}
-
#if (DEBUG)
-
public string GetListDirection(Guid oListId)
-
{
-
SPList l_oList = m_oWeb.Lists[oListId];
-
return l_oList.Direction;
-
}
-
-
#endif
-
-
}
-
}
And when you switch the build type configuration, it is automagically commented out. You can define your own, or use the ones that Visual Studio provides for you.
Related posts:
- Return A Document Library GUID In C#
- Get SPList By URL In C#
- Controlling SPField Display
- SharePoint Security Helper Class
- Get Locale From SPWeb URL
2 Comments »
RSS feed for comments on this post. TrackBack URL























Articles & Research
SharePoint Architecture
Research Methodology
Personal/Off-Topic
Article Or Research Filed Under 

[...] I wish I would have known about this trick a long time ago. Jim May whom I work with demonstrated to me a really neat commenting trick that I did not know about, that really helps when you are mocking out objects particularly. When you have some arbitrary Read More……(read more) September 26th 2007 Posted to Uncategorized [...]
Pingback by Blogger Loser » Neat Commenting Trick With #Debug — September 26, 2007 @ 8:54 am
Try using this site for formatting your code…
http://formatmysourcecode.blogspot.com/
Comment by Jim Sally — October 4, 2007 @ 7:11 am