kamagra how much to take

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 :)

  1. using System;
  2. using Microsoft.SharePoint;
  3.  
  4. namespace examples.SharePoint.Shelter
  5. {
  6. public class List
  7. {
  8. private readonly SPWeb m_oWeb;
  9.  
  10. public List()
  11. {
  12. m_oWeb = null;
  13. }
  14.  
  15. public SPWeb WebSite
  16. {
  17. get { return m_oWeb; }
  18. }
  19.  
  20. public string GetListDirection(Guid oListId)
  21. {
  22. SPList l_oList = m_oWeb.Lists[oListId];
  23. return l_oList.Direction;
  24. }
  25.  
  26. }
  27. }

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:

  1. #if (DEBUG)
  2.  
  3. #endif

So that the class file would instead look like this:

  1. using System;
  2. using Microsoft.SharePoint;
  3.  
  4. namespace examples.SharePoint.Shelter
  5. {
  6. public class List
  7. {
  8. private readonly SPWeb m_oWeb;
  9.  
  10. public List()
  11. {
  12. m_oWeb = null;
  13. }
  14.  
  15. public SPWeb WebSite
  16. {
  17. get { return m_oWeb; }
  18. }
  19. #if (DEBUG)
  20. public string GetListDirection(Guid oListId)
  21. {
  22. SPList l_oList = m_oWeb.Lists[oListId];
  23. return l_oList.Direction;
  24. }
  25.  
  26. #endif
  27.  
  28. }
  29. }

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.

Share

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>