Calendar

<<  mars 2010  >>
lumamejevesadi
22232425262728
1234567
891011121314
15161718192021
22232425262728
2930311234

View posts in large calendar
Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2010

(septembre 3, 2007 14:28)

You probably create regularly new objects. Let's imagine you create a new class like this :

Of course you will use it and you will want in some moments to debug and see the value of your class. By default, here is what the debugger watch will show :

So of course, you know that the ToString method is used for the display and will update your object definition with non-fonctional - and probably not tested - code, to have a nicer debug display.

 

So you are now writing kind of debug code in your production environment. Definitely an error.
So let's remove the ToString method and let's achieve that differently !

And here it is ! Now your application contains only functional code and you can also have a nice debug experience !
Note that you can use the syntax "{name}" where "name" is either a internal member, a property, ... on which Visual Studio will call the ToString() method if necessary.

So to conclude, your application should never contain debug code. You may want to use the "ConditionalAttribute" or the "#if" syntax, but the best is not introduce debug code. And in such a case, the DebuggerDisplayAttribute is probably the solution that will perfectly suits your needs !

    

Powered by BlogEngine.NET 1.2.0.0 | Theme by Pierre-Emmanuel Dautreppe