<?xml-stylesheet type="text/xsl" href="/rss.xsl" media="screen"?><rss version="2.0"><channel><title>softlogger Latest Articles ::CSharp</title><link>http://softlogger.com</link><description>softlogger Latest Articles ::CSharp</description><ttl>180</ttl><item><title>Binary vs. Source compatibility</title><link>http://softlogger.com/20314/CSharp/binary-vs-source-compatibility.aspx</link><description>&lt;p&gt;&lt;em&gt;Binary Compatibility&lt;/em&gt; means that when something is updated, you continue to work without needing to even recompile.&amp;nbsp; &lt;/p&gt; &lt;p&gt;&lt;em&gt;Source Compatibility&lt;/em&gt; means that you need to recompile to keep things working, but you don't have to actually change the sources. &lt;/p&gt; &lt;p&gt;One is not a superset of the other. Here are some examples in each combo.&lt;/p&gt; &lt;p&gt;Compatibility generally doesn't just mean that the change is discoverable, but that the change has some significant breaking implication that would cause a reasonably client to need to adjust their behavior. (Of course, you always find afterwards that's some important client did something unexpected and you need to compensate. Hence the heroics of the AppCompat folks). For example, with C# + reflection, any change is discoverable, so any change could technically break a client; but if a client breaks because they're relying on the names of private methods that you changed, they're hard-pressed to complain.&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Yes Binary + Yes Source&lt;/strong&gt;:&lt;/p&gt; &lt;p&gt;Renaming private methods. Changing a method body in a way that continues to behave the same. &lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Yes Binary,&amp;nbsp; Not Source&lt;/strong&gt;:&lt;/p&gt; &lt;p&gt;Adding new method overloads.&amp;nbsp; Since overload resolution is determined at compile time, adding new methods won't affect already-compiled binaries. But if you recompile, it's possible that you may bind to the new overloads.&amp;nbsp; (For example, see &lt;a href="http://blogs.msdn.com/jmstall/archive/2005/03/23/401038.aspx"&gt;float.Equals&lt;/a&gt;)&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Not Binary, Yes Source&lt;/strong&gt;:&lt;/p&gt; &lt;p&gt;In this case, you just need to recompile your sources to keep working. The compiler will respond to the change in a corrective way. For example, consider removing a method overload. At a binary level, the method you're bound to is removed and so things fail. But if you recompile, the compiler may bind to another overload that's semantically equivalent, and so things keep working without you having to change any source.&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Not Binary, Not Source&lt;/strong&gt;:&lt;/p&gt; &lt;p&gt;A real breaking change. This requires clients to update their sources and recompile. For example, removing a method. &lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8141635" width="1" height="1"&gt;&lt;img alt="via softlogger.com" src="http://softlogger.com/postview.aspx?ArticleID=20314"&gt;</description><author>Mike Stalls blog                                                                                    </author><pubDate>2008-03-11T00:00:00</pubDate><category>CSharp</category></item><item><title>Carousel(flying) Movement for Images using .NET DataGrid</title><link>http://softlogger.com/19071/CSharp/carousel-flying-movement-for-images-using-net-datagrid.aspx</link><description>&lt;img src="http://feeds.feedburner.com/~r/Microsoftnet/~4/233798103" height="1" width="1"/&gt;&lt;img alt="via softlogger.com" src="http://softlogger.com/postview.aspx?ArticleID=19071"&gt;</description><author>Dutts DOTNET Support</author><pubDate>2008-02-12T00:00:00</pubDate><category>CSharp</category></item><item><title>Coalesce ?? operator in C# 2.0</title><link>http://softlogger.com/18099/CSharp/coalesce--operator-in-c-2-0.aspx</link><description>&lt;p&gt;Operator &lt;tt&gt;??&lt;/tt&gt;, that was introduced in the .NET 2.0, takes first place in my top used C# idioms list a long time, but unfortunately it is rarely used in projects I’ve participated. Therefore these snippets could be found in production code very often:&lt;/p&gt;
&lt;div class="codecolorer-container c#"&gt;&lt;div class="codecolorer" style="font-family: monospace;"&gt;public &lt;span class="kw4"&gt;string&lt;/span&gt; Caption&lt;br /&gt;
&lt;span class="br0"&gt;{&lt;/span&gt;&lt;br /&gt;
    get &lt;span class="br0"&gt;{&lt;/span&gt; &lt;span class="kw1"&gt;return&lt;/span&gt; ViewState&lt;span class="br0"&gt;[&lt;/span&gt;&lt;span class="st0"&gt;"Caption"&lt;/span&gt;&lt;span class="br0"&gt;]&lt;/span&gt; != &lt;span class="kw2"&gt;null&lt;/span&gt; ? &lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="kw4"&gt;string&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt; ViewState&lt;span class="br0"&gt;[&lt;/span&gt;&lt;span class="st0"&gt;"Caption"&lt;/span&gt;&lt;span class="br0"&gt;]&lt;/span&gt; : &lt;span class="st0"&gt;""&lt;/span&gt;; &lt;span class="br0"&gt;}&lt;/span&gt;&lt;br /&gt;
    set &lt;span class="br0"&gt;{&lt;/span&gt; ViewState&lt;span class="br0"&gt;[&lt;/span&gt;&lt;span class="st0"&gt;"Caption"&lt;/span&gt;&lt;span class="br0"&gt;]&lt;/span&gt; = value; &lt;span class="br0"&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span class="br0"&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Or even:&lt;/p&gt;
&lt;div class="codecolorer-container c#" style="height:280px;"&gt;&lt;div class="codecolorer" style="font-family: monospace;"&gt;public &lt;span class="kw4"&gt;string&lt;/span&gt; VisibleStatistic&lt;br /&gt;
&lt;span class="br0"&gt;{&lt;/span&gt;&lt;br /&gt;
    get&lt;br /&gt;
    &lt;span class="br0"&gt;{&lt;/span&gt;&lt;br /&gt;
        &lt;span class="kw4"&gt;string&lt;/span&gt; retval = &lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="kw4"&gt;string&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt; ViewState&lt;span class="br0"&gt;[&lt;/span&gt;&lt;span class="st0"&gt;"VisibleStatistic"&lt;/span&gt;&lt;span class="br0"&gt;]&lt;/span&gt;;&lt;br /&gt;
        &lt;span class="kw1"&gt;return&lt;/span&gt; retval == &lt;span class="kw2"&gt;null&lt;/span&gt; ? &lt;span class="st0"&gt;""&lt;/span&gt; : retval;&lt;br /&gt;
    &lt;span class="br0"&gt;}&lt;/span&gt;&lt;br /&gt;
    set&lt;br /&gt;
    &lt;span class="br0"&gt;{&lt;/span&gt;&lt;br /&gt;
        ViewState&lt;span class="br0"&gt;[&lt;/span&gt;&lt;span class="st0"&gt;"VisibleStatistic"&lt;/span&gt;&lt;span class="br0"&gt;]&lt;/span&gt; = value;&lt;br /&gt;
    &lt;span class="br0"&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span class="br0"&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
public &lt;span class="kw4"&gt;string&lt;/span&gt; SelectedCategoryName&lt;br /&gt;
&lt;span class="br0"&gt;{&lt;/span&gt;&lt;br /&gt;
    get&lt;br /&gt;
    &lt;span class="br0"&gt;{&lt;/span&gt;&lt;br /&gt;
        object retval = ViewState&lt;span class="br0"&gt;[&lt;/span&gt;&lt;span class="st0"&gt;"SelectedCategoryName"&lt;/span&gt;&lt;span class="br0"&gt;]&lt;/span&gt;;&lt;br /&gt;
        &lt;span class="kw1"&gt;if&lt;/span&gt; &lt;span class="br0"&gt;(&lt;/span&gt;retval != &lt;span class="kw2"&gt;null&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;&lt;br /&gt;
            &lt;span class="kw1"&gt;return&lt;/span&gt; &lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="kw4"&gt;string&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt; retval;&lt;br /&gt;
        &lt;span class="kw1"&gt;return&lt;/span&gt; &lt;span class="kw4"&gt;String&lt;/span&gt;.&lt;span class="me1"&gt;Empty&lt;/span&gt;;&lt;br /&gt;
    &lt;span class="br0"&gt;}&lt;/span&gt;&lt;br /&gt;
    set&lt;br /&gt;
    &lt;span class="br0"&gt;{&lt;/span&gt;&lt;br /&gt;
        ViewState&lt;span class="br0"&gt;[&lt;/span&gt;&lt;span class="st0"&gt;"SelectedCategoryName"&lt;/span&gt;&lt;span class="br0"&gt;]&lt;/span&gt; = value;&lt;br /&gt;
    &lt;span class="br0"&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span class="br0"&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Almost 50% of this could be easily removed, and you will get beautiful and clear code, just right after you will understand what the hell is operator &lt;tt&gt;??&lt;/tt&gt;. Here is information from MSDN:&lt;/p&gt;
&lt;blockquote&gt;&lt;div&gt;The ?? operator returns the left-hand operand if it is not null, or else it returns the right operand.&lt;/div&gt;
&lt;/blockquote&gt;
&lt;p&gt;Easy and clean explanation. Let’s try to rewrite all these examples using this operator:&lt;/p&gt;
&lt;div class="codecolorer-container c#"&gt;&lt;div class="codecolorer" style="font-family: monospace;"&gt;public &lt;span class="kw4"&gt;string&lt;/span&gt; Caption&lt;br /&gt;
&lt;span class="br0"&gt;{&lt;/span&gt;&lt;br /&gt;
    get &lt;span class="br0"&gt;{&lt;/span&gt; &lt;span class="kw1"&gt;return&lt;/span&gt; &lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="kw4"&gt;string&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt; ViewState&lt;span class="br0"&gt;[&lt;/span&gt;&lt;span class="st0"&gt;"Caption"&lt;/span&gt;&lt;span class="br0"&gt;]&lt;/span&gt; ?? &lt;span class="kw4"&gt;String&lt;/span&gt;.&lt;span class="me1"&gt;Empty&lt;/span&gt;; &lt;span class="br0"&gt;}&lt;/span&gt;&lt;br /&gt;
    set &lt;span class="br0"&gt;{&lt;/span&gt; ViewState&lt;span class="br0"&gt;[&lt;/span&gt;&lt;span class="st0"&gt;"Caption"&lt;/span&gt;&lt;span class="br0"&gt;]&lt;/span&gt; = value; &lt;span class="br0"&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span class="br0"&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
public &lt;span class="kw4"&gt;string&lt;/span&gt; VisibleStatistic&lt;br /&gt;
&lt;span class="br0"&gt;{&lt;/span&gt;&lt;br /&gt;
    get &lt;span class="br0"&gt;{&lt;/span&gt; &lt;span class="kw1"&gt;return&lt;/span&gt; &lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="kw4"&gt;string&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt; ViewState&lt;span class="br0"&gt;[&lt;/span&gt;&lt;span class="st0"&gt;"VisibleStatistic"&lt;/span&gt;&lt;span class="br0"&gt;]&lt;/span&gt; ?? &lt;span class="kw4"&gt;String&lt;/span&gt;.&lt;span class="me1"&gt;Empty&lt;/span&gt;; &lt;span class="br0"&gt;}&lt;/span&gt;&lt;br /&gt;
    set &lt;span class="br0"&gt;{&lt;/span&gt; ViewState&lt;span class="br0"&gt;[&lt;/span&gt;&lt;span class="st0"&gt;"VisibleStatistic"&lt;/span&gt;&lt;span class="br0"&gt;]&lt;/span&gt; = value; &lt;span class="br0"&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span class="br0"&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
public &lt;span class="kw4"&gt;string&lt;/span&gt; SelectedCategoryName&lt;br /&gt;
&lt;span class="br0"&gt;{&lt;/span&gt;&lt;br /&gt;
    get &lt;span class="br0"&gt;{&lt;/span&gt; &lt;span class="kw1"&gt;return&lt;/span&gt; &lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="kw4"&gt;string&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt; ViewState&lt;span class="br0"&gt;[&lt;/span&gt;&lt;span class="st0"&gt;"SelectedCategoryName"&lt;/span&gt;&lt;span class="br0"&gt;]&lt;/span&gt; ?? &lt;span class="kw4"&gt;String&lt;/span&gt;.&lt;span class="me1"&gt;Empty&lt;/span&gt;; &lt;span class="br0"&gt;}&lt;/span&gt;&lt;br /&gt;
    set &lt;span class="br0"&gt;{&lt;/span&gt; ViewState&lt;span class="br0"&gt;[&lt;/span&gt;&lt;span class="st0"&gt;"SelectedCategoryName"&lt;/span&gt;&lt;span class="br0"&gt;]&lt;/span&gt; = value; &lt;span class="br0"&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span class="br0"&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;In case of value-types this approach will not work: you will get &lt;tt&gt;NullReferenceException&lt;/tt&gt;. But do not worry — in this case we can use &lt;tt&gt;Nullable&lt;/tt&gt;-types. Before:&lt;/p&gt;
&lt;div class="codecolorer-container c#"&gt;&lt;div class="codecolorer" style="font-family: monospace;"&gt;public &lt;span class="kw4"&gt;int&lt;/span&gt; FirstWidth&lt;br /&gt;
&lt;span class="br0"&gt;{&lt;/span&gt;&lt;br /&gt;
    get &lt;span class="br0"&gt;{&lt;/span&gt; &lt;span class="kw1"&gt;return&lt;/span&gt; ViewState&lt;span class="br0"&gt;[&lt;/span&gt;&lt;span class="st0"&gt;"FirstWidth"&lt;/span&gt;&lt;span class="br0"&gt;]&lt;/span&gt; != &lt;span class="kw2"&gt;null&lt;/span&gt; ? &lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="kw4"&gt;int&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt; ViewState&lt;span class="br0"&gt;[&lt;/span&gt;&lt;span class="st0"&gt;"FirstWidth"&lt;/span&gt;&lt;span class="br0"&gt;]&lt;/span&gt; : &lt;span class="nu0"&gt;0&lt;/span&gt;; &lt;span class="br0"&gt;}&lt;/span&gt;&lt;br /&gt;
    set &lt;span class="br0"&gt;{&lt;/span&gt; ViewState&lt;span class="br0"&gt;[&lt;/span&gt;&lt;span class="st0"&gt;"FirstWidth"&lt;/span&gt;&lt;span class="br0"&gt;]&lt;/span&gt; = value; &lt;span class="br0"&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span class="br0"&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;After:&lt;/p&gt;
&lt;div class="codecolorer-container c#"&gt;&lt;div class="codecolorer" style="font-family: monospace;"&gt;public &lt;span class="kw4"&gt;int&lt;/span&gt; FirstWidth&lt;br /&gt;
&lt;span class="br0"&gt;{&lt;/span&gt;&lt;br /&gt;
    get &lt;span class="br0"&gt;{&lt;/span&gt; &lt;span class="kw1"&gt;return&lt;/span&gt; &lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="kw4"&gt;int&lt;/span&gt;?&lt;span class="br0"&gt;)&lt;/span&gt; ViewState&lt;span class="br0"&gt;[&lt;/span&gt;&lt;span class="st0"&gt;"FirstWidth"&lt;/span&gt;&lt;span class="br0"&gt;]&lt;/span&gt; ?? &lt;span class="nu0"&gt;0&lt;/span&gt;; &lt;span class="br0"&gt;}&lt;/span&gt;&lt;br /&gt;
    set &lt;span class="br0"&gt;{&lt;/span&gt; ViewState&lt;span class="br0"&gt;[&lt;/span&gt;&lt;span class="st0"&gt;"FirstWidth"&lt;/span&gt;&lt;span class="br0"&gt;]&lt;/span&gt; = value; &lt;span class="br0"&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span class="br0"&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;When you are using &lt;tt&gt;??&lt;/tt&gt; operator, expression will be evaluated in the left to right order, so you can use something like this:&lt;/p&gt;
&lt;div class="codecolorer-container c#" style="height:35px;"&gt;&lt;div class="codecolorer" style="font-family: monospace;"&gt;&lt;span class="kw4"&gt;string&lt;/span&gt; name = FirstName ?? LastName ?? &lt;span class="st0"&gt;"Anonymous"&lt;/span&gt;;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Of course, it looks more readably than the:&lt;/p&gt;
&lt;div class="codecolorer-container c#"&gt;&lt;div class="codecolorer" style="font-family: monospace;"&gt;&lt;span class="kw4"&gt;string&lt;/span&gt; name;&lt;br /&gt;
&lt;span class="kw1"&gt;if&lt;/span&gt; &lt;span class="br0"&gt;(&lt;/span&gt;FirstName != &lt;span class="kw2"&gt;null&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;&lt;br /&gt;
    name = FirstName;&lt;br /&gt;
&lt;span class="kw1"&gt;else&lt;/span&gt; &lt;span class="kw1"&gt;if&lt;/span&gt; &lt;span class="br0"&gt;(&lt;/span&gt;LastName != &lt;span class="kw2"&gt;null&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;&lt;br /&gt;
    name = LastName;&lt;br /&gt;
&lt;span class="kw1"&gt;else&lt;/span&gt;&lt;br /&gt;
    name = &lt;span class="st0"&gt;"Anonymous"&lt;/span&gt;;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;And a fortiori than:&lt;/p&gt;
&lt;div class="codecolorer-container c#"&gt;&lt;div class="codecolorer" style="font-family: monospace;"&gt;&lt;span class="kw4"&gt;string&lt;/span&gt; name = FirstName != &lt;span class="kw2"&gt;null&lt;/span&gt;&lt;br /&gt;
        ? FirstName&lt;br /&gt;
        : &lt;span class="br0"&gt;(&lt;/span&gt;LastName != &lt;span class="kw2"&gt;null&lt;/span&gt; ? LastName : &lt;span class="st0"&gt;"Anonymous"&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Add it to your armoury!&lt;/p&gt;
&lt;a href="http://kpumuk.info/tag/.net/" rel="tag"&gt;.net&lt;/a&gt;, &lt;a href="http://kpumuk.info/tag/c%23/" rel="tag"&gt;c#&lt;/a&gt;, &lt;a href="http://kpumuk.info/tag/syntax/" rel="tag"&gt;syntax&lt;/a&gt;, &lt;a href="http://kpumuk.info/tag/tricks/" rel="tag"&gt;tricks&lt;/a&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~f/kpumuk?a=eUdzuid"&gt;&lt;img src="http://feeds.feedburner.com/~f/kpumuk?i=eUdzuid" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/kpumuk?a=2cVdLad"&gt;&lt;img src="http://feeds.feedburner.com/~f/kpumuk?i=2cVdLad" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/kpumuk?a=vci6BEd"&gt;&lt;img src="http://feeds.feedburner.com/~f/kpumuk?i=vci6BEd" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/kpumuk?a=kYi64fD"&gt;&lt;img src="http://feeds.feedburner.com/~f/kpumuk?i=kYi64fD" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/kpumuk/~4/216601394" height="1" width="1"/&gt;&lt;img alt="via softlogger.com" src="http://softlogger.com/postview.aspx?ArticleID=18099"&gt;</description><author>Dmytro Shteflyuks Home</author><pubDate>2008-01-14T00:00:00</pubDate><category>CSharp</category></item><item><title>Using Reflector to search through code and resolve .NET issues</title><link>http://softlogger.com/17746/CSharp/using-reflector-to-search-through-code-and-resolve-net-issues.aspx</link><description>&lt;P&gt;As you already know, i spend my days&amp;nbsp;analyzing dumps for customers, and&amp;nbsp;more often than not&amp;nbsp;I don't have access to the customers code.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;I could probably ask for it but it usually takes a long time&amp;nbsp;and even then I often just get partial code, and sometimes,&amp;nbsp;if the customer has multiple environments or if there has been recent changes, the code I would get may not correspond exactly to what&amp;nbsp;was running in production when the dump was taken. &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm sure many of you are familiar with &lt;A href="http://www.aisto.com/roeder/dotnet/" mce_href="http://www.aisto.com/roeder/dotnet/"&gt;Lutz Roeder's Reflector&lt;/A&gt; already...&amp;nbsp;&amp;nbsp;I just have to say, I just love this tool... it has made my life soo much easier over the years that it's not even funny.&amp;nbsp; I constantly have 2-3 sessions open and in case you are not familiar with some of its features I wanted to show how I use it on a daily bases... &lt;/P&gt;
&lt;P&gt;Before I do though, &lt;A href="http://www.authorstream.com/Presentation/Mentor-6838-reflector-5-NET-Reflector-0-Overview-C-3-support-2-Code-URL-Assembly-Browser-Disassembler-Analyzer-Search-reflector5-ppt-powerpoint/" mce_href="http://www.authorstream.com/Presentation/Mentor-6838-reflector-5-NET-Reflector-0-Overview-C-3-support-2-Code-URL-Assembly-Browser-Disassembler-Analyzer-Search-reflector5-ppt-powerpoint/"&gt;here is a presentation about all the 5.0 features&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Saving the modules &lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;If I have a dump of a process and want to look at the code running inside it I can open it up in windbg and use sos to save the dlls using &lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;!savemodule &amp;lt;base address&amp;gt; &amp;lt;path to save&amp;gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;And I can get the base address by running lmv mmodulename, or just lm to get all start/base addresses for all modules... anyways, it gets pretty tedious to do that for all modules so instead I automate it a bit with windbgs !for_each_module, so the command below, saves out all the dlls/exes loaded in the process in binary form so they will be stored on disk pretty much as an exact replica of the dll loaded in the process... &lt;/P&gt;&lt;PRE class=debug&gt;0:000&amp;gt; !for_each_module !savemodule ${@#Base} f:\blog\modules\${@#ModuleName}.dll
01000000
5 sections in file at 00990000
section 0 - VA=1000, VASize=7f749, FileAddr=400, FileSize=7f800
section 1 - VA=81000, VASize=490, FileAddr=7fc00, FileSize=600
section 2 - VA=82000, VASize=237c, FileAddr=80200, FileSize=2000
section 3 - VA=85000, VASize=3d8, FileAddr=82200, FileSize=400
section 4 - VA=86000, VASize=5404, FileAddr=82600, FileSize=5600
Successfully saved file: f:\blog\modules\oleaut32.dll
01000000
4 sections in file at 00a20000
section 0 - VA=1000, VASize=498f4, FileAddr=400, FileSize=49a00
section 1 - VA=4b000, VASize=1054, FileAddr=49e00, FileSize=c00
section 2 - VA=4d000, VASize=1598, FileAddr=4aa00, FileSize=1600
section 3 - VA=4f000, VASize=26ec, FileAddr=4c000, FileSize=2800
Successfully saved file: f:\blog\modules\shlwapi.dll
00040000
3 sections in file at 00f60000
section 0 - VA=2000, VASize=2954, FileAddr=200, FileSize=2a00
section 1 - VA=6000, VASize=2a8, FileAddr=2c00, FileSize=400
section 2 - VA=8000, VASize=c, FileAddr=3000, FileSize=200
Successfully saved file: f:\blog\modules\y9w_t4cv.dll
00040000
3 sections in file at 00f70000
section 0 - VA=2000, VASize=2954, FileAddr=200, FileSize=2a00
section 1 - VA=6000, VASize=2a8, FileAddr=2c00, FileSize=400
section 2 - VA=8000, VASize=c, FileAddr=3000, FileSize=200
Successfully saved file: f:\blog\modules\ibyunanw.dll
00040000
3 sections in file at 00f80000
section 0 - VA=2000, VASize=2954, FileAddr=200, FileSize=2a00
section 1 - VA=6000, VASize=2a8, FileAddr=2c00, FileSize=400
section 2 - VA=8000, VASize=c, FileAddr=3000, FileSize=200
Successfully saved file: f:\blog\modules\th5r9oei.dll
00040000
3 sections in file at 00f90000
section 0 - VA=2000, VASize=2954, FileAddr=200, FileSize=2a00
section 1 - VA=6000, VASize=2a8, FileAddr=2c00, FileSize=400
section 2 - VA=8000, VASize=c, FileAddr=3000, FileSize=200
Successfully saved file: f:\blog\modules\t0i_pxyo.dll
...
&lt;/PRE&gt;
&lt;P&gt;&lt;STRONG&gt;Opening in reflector&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;In order to get all the code running in the process i just open a new instance of reflector, clean out any previously opened dlls and do file/open, selecting all the modules i just saved.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;Sometimes you need to close out dlls like System.dll System.Xml.dll etc. that have native images and open those directly from the framework directory instead.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Searching in reflector&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Let's say I want to debug the issue described in this &lt;A href="http://blogs.msdn.com/tess/archive/2006/02/15/net-memory-leak-xmlserializing-your-way-to-a-memory-leak.aspx" mce_href="http://blogs.msdn.com/tess/archive/2006/02/15/net-memory-leak-xmlserializing-your-way-to-a-memory-leak.aspx"&gt;post&lt;/A&gt;, where we are leaking dynamic assemblies because we are creating new XmlSerializers, and we want to know where in our code we might be creating these...&lt;/P&gt;
&lt;P&gt;I would use the search function, searching for types to find XmlSerializer&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/tess/WindowsLiveWriter/UsingReflectortosearchthroughc.NETissues_C988/image%7B0%7D%5B6%5D.png" atomicselection="true" mce_href="http://blogs.msdn.com/blogfiles/tess/WindowsLiveWriter/UsingReflectortosearchthroughc.NETissues_C988/image%7B0%7D%5B6%5D.png"&gt;&lt;IMG style="BORDER-RIGHT: 0px; BORDER-TOP: 0px; BORDER-LEFT: 0px; BORDER-BOTTOM: 0px" height=475 src="http://blogs.msdn.com/blogfiles/tess/WindowsLiveWriter/UsingReflectortosearchthroughc.NETissues_C988/image%7B0%7D_thumb%5B4%5D.png" width=1042 border=0 mce_src="http://blogs.msdn.com/blogfiles/tess/WindowsLiveWriter/UsingReflectortosearchthroughc.NETissues_C988/image%7B0%7D_thumb%5B4%5D.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;And then just double click on the XmlSerializer option to explore that class... &lt;/P&gt;
&lt;P&gt;Btw, it has great member search and string/constant search options as well if you need that... &lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Finding out who calls it&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Once we have found the XmlSerializer class we can take one of the methods we are interested in (in this case any of the XmlSerializer constructors that generate dynamic assemblies without caching them) and right-click and choose Analyze...&lt;/P&gt;
&lt;P style="MARGIN: 0in"&gt;&lt;A href="http://blogs.msdn.com/blogfiles/tess/WindowsLiveWriter/UsingReflectortosearchthroughc.NETissues_C988/clip_image001%5B3%5D.png" atomicselection="true" mce_href="http://blogs.msdn.com/blogfiles/tess/WindowsLiveWriter/UsingReflectortosearchthroughc.NETissues_C988/clip_image001%5B3%5D.png"&gt;&lt;IMG style="BORDER-RIGHT: 0px; BORDER-TOP: 0px; BORDER-LEFT: 0px; BORDER-BOTTOM: 0px" height=477 src="http://blogs.msdn.com/blogfiles/tess/WindowsLiveWriter/UsingReflectortosearchthroughc.NETissues_C988/clip_image001_thumb.png" width=1041 border=0 mce_src="http://blogs.msdn.com/blogfiles/tess/WindowsLiveWriter/UsingReflectortosearchthroughc.NETissues_C988/clip_image001_thumb.png"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P lang=sv style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This opens the Analyzer pane where we can expand the Used By node to find out who is calling this method...&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/tess/WindowsLiveWriter/UsingReflectortosearchthroughc.NETissues_C988/image%7B0%7D%5B9%5D.png" atomicselection="true" mce_href="http://blogs.msdn.com/blogfiles/tess/WindowsLiveWriter/UsingReflectortosearchthroughc.NETissues_C988/image%7B0%7D%5B9%5D.png"&gt;&lt;IMG style="BORDER-RIGHT: 0px; BORDER-TOP: 0px; BORDER-LEFT: 0px; BORDER-BOTTOM: 0px" height=483 src="http://blogs.msdn.com/blogfiles/tess/WindowsLiveWriter/UsingReflectortosearchthroughc.NETissues_C988/image%7B0%7D_thumb%5B5%5D.png" width=1036 border=0 mce_src="http://blogs.msdn.com/blogfiles/tess/WindowsLiveWriter/UsingReflectortosearchthroughc.NETissues_C988/image%7B0%7D_thumb%5B5%5D.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;And in this case it tells us that the only method that is using this constructor, in the code loaded in the process, is Lab3_2.Page_Load.&amp;nbsp; And if we right click and choose Go To Member we can even see the code for this in the Disassembler pane so we can see how it calls it.&lt;/P&gt;
&lt;P&gt;And that way we can pinpoint the exact line of code that caused this assembly leak...&lt;/P&gt;
&lt;P&gt;Laters&lt;/P&gt;
&lt;P&gt;Tess&lt;/P&gt;&lt;!-- Begin survey for blog post 61 --&gt;&lt;BR&gt;&lt;BR&gt;
&lt;P&gt;
&lt;SCRIPT language=JavaScript&gt;
&lt;!--


if(window.location=="http://blogs.msdn.com/tess/pages/tess-blog-test-page.aspx#tesssurvey61")
{
    document.write("&lt;b&gt;&lt;a name=\"tesssurvey61\"&gt;Thank you for your response.&lt;/a&gt;&lt;/b&gt;");
}
else
{
    document.write("Did this blog post help you resolve a problem?&lt;br&gt;&lt;br&gt;");
    document.write("&lt;a href=\"http://tess.members.winisp.net/survey/submitsurvey.asp?solvedissue=Yes&amp;blogid=61\"&gt;&lt;b&gt;Yes&lt;/b&gt;&lt;/a&gt; | ");
    document.write("&lt;a href=\"http://tess.members.winisp.net/survey/submitsurvey.asp?solvedissue=No&amp;blogid=61\"&gt;&lt;b&gt;No&lt;/b&gt;&lt;/a&gt;");
}


//--&gt;
&lt;/SCRIPT&gt;
&lt;/P&gt;&lt;BR&gt;&lt;BR&gt;&lt;!-- End survey for blog post 61 --&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=7055656" width="1" height="1"&gt;&lt;img alt="via softlogger.com" src="http://softlogger.com/postview.aspx?ArticleID=17746"&gt;</description><author>If broken it is, fix it you should</author><pubDate>2008-01-10T00:00:00</pubDate><category>CSharp</category></item><item><title>Logging for Libraries</title><link>http://softlogger.com/16634/CSharp/logging-for-libraries.aspx</link><description>&lt;p&gt;
    A pet peeve of mine for a long time has been how many libraries handle logging. There are general two techniques:
&lt;/p&gt;
&lt;ol&gt;
    &lt;li&gt;Don't log&lt;/li&gt;
    &lt;li&gt;Use [commons-logging|log4r|printf|syslog|slf4j]&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
    Both suck.
&lt;/p&gt;
&lt;p&gt;
    In the first case you cannot get info out. In the second case the library is deciding how you will get the info out. The first one is okay for anything that can never go wrong. I'm sure you can think of something in that category. For everything else, you frequently need to see what is going wrong -- or at least figure out why what you are giving it is garbage.
&lt;/p&gt;
&lt;p&gt;
    For a library, then, logging is a &lt;i&gt;feature&lt;/i&gt;. This is where most folks whip out commons-logging, log4perl, or whatever. Bzzzz. You just added a dependency &lt;i&gt;and&lt;/i&gt; dictated that users figure out how to make use of that logging system. The much better way is to expose logging via callbacks and provide concrete instances of the common cases.
&lt;/p&gt;
&lt;p&gt;
    An example might look like:
&lt;/p&gt;
&lt;div class="code"&gt;&lt;code&gt;&lt;/code&gt;&lt;pre&gt;
foo.setLogger(new FooLogger() {
    public void log(int level, String msg) {
        System.err.printf("%s\n",msg);
    }
})
&lt;/pre&gt;&lt;/code&gt;&lt;/div&gt;
&lt;p&gt;
    Which is boring, but you know, covers 98% of the cases where you want logging in a library. To cover the common cases:
&lt;/p&gt;
&lt;div class="code"&gt;&lt;code&gt;&lt;/code&gt;&lt;pre&gt;
foo.setLogger(new PrintStreamLogger(System.err));
    ...
foo.setLogger(new Log4jLogger(Wombat.class));
&lt;/pre&gt;&lt;/code&gt;&lt;/div&gt;
&lt;p&gt;
    This is the runtime-configured-slf4j-per-project approach. It seems kinda gnarly until you use the library and things just magically work they way you want. Any dependency on external logging is specifically selected by users, or they can do their own thing.
&lt;/p&gt;&lt;img alt="via softlogger.com" src="http://softlogger.com/postview.aspx?ArticleID=16634"&gt;</description><author>Waste of Time</author><pubDate>2008-01-05T00:00:00</pubDate><category>CSharp</category></item><item><title>Quirk in the DateTime class</title><link>http://softlogger.com/15250/CSharp/quirk-in-the-datetime-class.aspx</link><description>&lt;p&gt;
I experienced a strange behaviour with the DateTime class and formatting today. For some reason this error only occurs when you format a DateTime in certain cultures like Italian. The error is not present in English, Danish and most other cultures.
&lt;/p&gt;
&lt;p&gt;
It happens when you use the DateTime.ToString and DateTime.ParseExact methods. When you write the following:
&lt;/p&gt;
&lt;p&gt;
&lt;em&gt;String date = DateTime.Now.ToString(&amp;quot;yyyy-MM-dd HH:mm&amp;quot;)&lt;/em&gt;
&lt;/p&gt;
&lt;p&gt;
You would expect the date variable to be formatted like so &lt;em&gt;2008-01-05 11:30&lt;/em&gt;. In Italian it doesn&amp;rsquo;t. Instead it replaces the colon with a period which produces this &lt;em&gt;2008-01-05 11.30&lt;/em&gt;. This might be correctly formatted for the Italian culture, but I explicitly wrote I wanted the colon delimiter in the format string. However, there is a workaround.
&lt;/p&gt;
&lt;p&gt;
All you need is to change the format string into a less obvious one. The following produces the right colon delimited date and time string:
&lt;/p&gt;
&lt;p&gt;
&lt;em&gt;String date = DateTime.Now.ToString(&amp;quot;yyyy-MM-dd HH\\:mm&amp;quot;)&lt;/em&gt;
&lt;/p&gt;
&lt;p&gt;
Strangely enough, you have to escape the colon with two backslashes for it to work. This trick seems to work in all cultures.
&lt;/p&gt;
&lt;img alt="via softlogger.com" src="http://softlogger.com/postview.aspx?ArticleID=15250"&gt;</description><author>.NET slave</author><pubDate>2008-01-05T00:00:00</pubDate><category>CSharp</category></item><item><title>Use SC CONFIG to isolate a Service in its own svchost instance.</title><link>http://softlogger.com/16112/CSharp/use-sc-config-to-isolate-a-service-in-its-own-svchost-instance.aspx</link><description>&lt;p&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="http://blogs.technet.com/ganand/default.aspx"&gt;Digging in&lt;/a&gt; - &lt;a href="http://blogs.technet.com/ganand/archive/2007/12/23/how-to-isolate-a-service-in-its-own-scvhost-exe.aspx"&gt;How to isolate a service in its own scvhost.exe&lt;/a&gt;&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;"This is a very good public link to read about service control manager internals and how to manage services.  &lt;p&gt;&lt;a href="http://download.microsoft.com/download/f/3/9/f3900e1e-a45c-45a4-b716-740e553e1f62/SPTCF_SYS.doc"&gt;http://download.&lt;b&gt;microsoft&lt;/b&gt;.com/download/f/3/9/f3900e1e-a45c-45a4-b716-740e553e1f62/SPTCF_SYS.doc&lt;/a&gt;&amp;nbsp; &lt;p&gt;Description of svchost.exe &lt;a href="http://support.microsoft.com/kb/314056"&gt;http://support.microsoft.com/kb/314056&lt;/a&gt; &lt;p&gt;... &lt;p&gt;&lt;i&gt;&lt;u&gt;&lt;strong&gt;for troubleshooting purposes if we want to isolate any one service running under svchost---we can do that using sc config&amp;nbsp; BITS type= own &lt;/strong&gt;&lt;/u&gt;&lt;/i&gt; &lt;p&gt;&lt;i&gt;&lt;/i&gt; &lt;p&gt;&lt;u&gt;&lt;em&gt;&lt;strong&gt;now as you see BITS&lt;/strong&gt;&lt;/em&gt;&lt;/u&gt;&lt;u&gt;&lt;em&gt;&lt;strong&gt; is running under its own scvhost&amp;nbsp; process&lt;/strong&gt;&lt;/em&gt;&lt;/u&gt;. &lt;p&gt;..."&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;This is like a two for one deal...&lt;/p&gt; &lt;p&gt;First there's a link to the cool Managing System Services document (87 page chapter 13 from what I think is the Windows Server 2003 Resource Kit)&lt;/p&gt; &lt;p&gt;And then there's the tip on how to isolate a Service in a svchost.exe instance. (Say because a SVChost.exe instance is chewing up processor cycles, but that instance is hosting a number of services so it's hard to tell which one is being bad. So you want to isolate each service to its own svchost instance to hunt the evil one...)&lt;/p&gt; &lt;p&gt;Related Past Post XRef:&lt;br&gt;&lt;a href="http://coolthingoftheday.blogspot.com/2007/10/using-tasklist-command-line-utility-to.html"&gt;Using the TaskList command line utility to see what processes are using a DLL (and what process is hosting what Service)&lt;/a&gt;&lt;/p&gt;  &lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~f/coolthingoftheday?a=k7ox1KC"&gt;&lt;img src="http://feeds.feedburner.com/~f/coolthingoftheday?i=k7ox1KC" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/coolthingoftheday?a=AnaBlfC"&gt;&lt;img src="http://feeds.feedburner.com/~f/coolthingoftheday?i=AnaBlfC" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/coolthingoftheday?a=BOGwj5C"&gt;&lt;img src="http://feeds.feedburner.com/~f/coolthingoftheday?i=BOGwj5C" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/coolthingoftheday/~4/205232682" height="1" width="1"/&gt;&lt;img alt="via softlogger.com" src="http://softlogger.com/postview.aspx?ArticleID=16112"&gt;</description><author>Gregs Cool [Insert Clever Name] of the Day</author><pubDate>2008-01-05T00:00:00</pubDate><category>CSharp</category></item><item><title>DataGridviewAutoFilter Sample Updated (Think "Click on a Grid Column Header and select value to filter rows on" sample)</title><link>http://softlogger.com/13585/CSharp/datagridviewautofilter-sample-updated-think-click-on-a-grid-column-header-and-select-value-to-filter-rows-on-sample.aspx</link><description>&lt;p&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="http://blogs.msdn.com/winformsue/default.aspx"&gt;Windows Forms Documentation Updates&lt;/a&gt; - &lt;a href="http://blogs.msdn.com/winformsue/archive/2007/12/05/datagridviewautofilter-sample-updated.aspx"&gt;DataGridviewAutoFilter sample updated&lt;/a&gt;&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;"I've made a few bug-fixes to my &lt;strong&gt;DataGridViewAutoFilter&lt;/strong&gt; sample, which is described in &lt;a href="http://msdn2.microsoft.com/en-us/library/aa480727.aspx"&gt;Building a Drop-Down Filter List for a DataGridView Column Header Cell&lt;/a&gt;. It might be a week or two until the article is updated (as of December 5, 2007), but the new &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=bea5c31b-e07a-46b5-8662-ecd798c0134d&amp;amp;displaylang=en"&gt;sample download&lt;/a&gt; has already been posted. The download contains C# and VB projects, plus the updated article in Word 2003 format.&lt;/p&gt; &lt;p&gt;Here's a summary of the fixes: &lt;p&gt;..."&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;&amp;nbsp;&lt;a href="http://msdn2.microsoft.com"&gt;MSDN&lt;/a&gt; - &lt;a href="http://msdn2.microsoft.com/en-us/library/aa480727.aspx"&gt;Building a Drop-Down Filter List for a DataGridView Column Header Cell&lt;/a&gt; &lt;blockquote&gt; &lt;p&gt;&lt;b&gt;"Summary:&lt;/b&gt; The Microsoft Windows Forms &lt;b&gt;DataGridView&lt;/b&gt; control in Microsoft Visual Studio 2005 provides a grid experience similar to Microsoft Excel, but does not provide the column filtering drop-down lists that Excel provides in its AutoFilter feature. However, the &lt;b&gt;DataGridView&lt;/b&gt; can bind to data sources that provide filtering, such as the ADO.NET &lt;b&gt;DataView&lt;/b&gt;. This article describes how to build a custom &lt;b&gt;DataGridView&lt;/b&gt; column header cell that displays drop-down filter lists, by taking advantage of the filtering capabilities of the data source and the new &lt;b&gt;BindingSource&lt;/b&gt; component. (25 printed pages) &lt;p&gt;...&lt;/p&gt; &lt;p&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="302" alt="Aa480727_dtgrdvwaf01(en-us,MSDN_10)" src="http://lh4.google.com/gduncan411/R1lnVJBKeSI/AAAAAAAAAGk/WjwJeKBAxwA/Aa480727_dtgrdvwaf01%28en-us%2CMSDN_10%29%5B4%5D" width="454" border="0"&gt; &lt;/p&gt; &lt;p&gt;..."&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;This is a feature found in many third party grids, which you can have for free... &lt;/p&gt;  &lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~f/coolthingoftheday?a=VY9I4rC"&gt;&lt;img src="http://feeds.feedburner.com/~f/coolthingoftheday?i=VY9I4rC" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/coolthingoftheday?a=US6e4HC"&gt;&lt;img src="http://feeds.feedburner.com/~f/coolthingoftheday?i=US6e4HC" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/coolthingoftheday?a=EdyPlcC"&gt;&lt;img src="http://feeds.feedburner.com/~f/coolthingoftheday?i=EdyPlcC" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/coolthingoftheday/~4/196682714" height="1" width="1"/&gt;&lt;img alt="via softlogger.com" src="http://softlogger.com/postview.aspx?ArticleID=13585"&gt;</description><author>Gregs Cool [Insert Clever Name] of the Day</author><pubDate>2007-12-10T00:00:00</pubDate><category>CSharp</category></item><item><title>Code snippet for property old style</title><link>http://softlogger.com/13144/CSharp/code-snippet-for-property-old-style.aspx</link><description>When I first realised that the &lt;a href="http://www.danielmoth.com/Blog/2007/08/prop-snippet.html"&gt;prop snippet&lt;/a&gt; now generates &lt;a href="http://www.danielmoth.com/Blog/2007/03/automatic-properties-in-c3.html"&gt;automatic properties in C#&lt;/a&gt; I thought it was cool. The more I write code in VS2008 though I find that when I need to write a property with get/setters that are explicitly implemented, it becomes tedious – I used to rely on &lt;em&gt;prop&lt;/em&gt; in VS2005 too much I guess. This is easily rectified by adding a new &lt;a href="http://msdn2.microsoft.com/en-gb/library/ms165392(VS.90).aspx"&gt;code snippet&lt;/a&gt; of course.&lt;br /&gt;&lt;br /&gt;Creating snippet is so easy it should be illegal :), but to save you the manual work &lt;a href="http://www.danielmoth.com/Blog/propOLD.snippet"&gt;here is the one I created for this purpose (propOld)&lt;/a&gt;. Simply "save as" to your local drive and then from Visual Studio 2008 menu "Tools-&gt;Code Snippet Manager" click the "Import" button; then in a C# file type &lt;em&gt;proOLD&lt;/em&gt; and hit TAB (instead of prop+TAB).&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~f/DanielMoth?a=GAeJH9C"&gt;&lt;img src="http://feeds.feedburner.com/~f/DanielMoth?i=GAeJH9C" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/DanielMoth?a=qBNygNC"&gt;&lt;img src="http://feeds.feedburner.com/~f/DanielMoth?i=qBNygNC" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/DanielMoth?a=wveOAtc"&gt;&lt;img src="http://feeds.feedburner.com/~f/DanielMoth?i=wveOAtc" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/DanielMoth?a=Bnr6TJc"&gt;&lt;img src="http://feeds.feedburner.com/~f/DanielMoth?i=Bnr6TJc" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/DanielMoth?a=QdAq6CC"&gt;&lt;img src="http://feeds.feedburner.com/~f/DanielMoth?i=QdAq6CC" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/DanielMoth?a=E6abJLc"&gt;&lt;img src="http://feeds.feedburner.com/~f/DanielMoth?i=E6abJLc" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/DanielMoth/~4/194890122" height="1" width="1"/&gt;&lt;img alt="via softlogger.com" src="http://softlogger.com/postview.aspx?ArticleID=13144"&gt;</description><author>The Moth</author><pubDate>2007-12-04T00:00:00</pubDate><category>CSharp</category></item><item><title>Display Checkboxes in ASP.NET 2.0 GridView using skins</title><link>http://softlogger.com/13170/CSharp/display-checkboxes-in-asp-net-2-0-gridview-using-skins.aspx</link><description>&lt;p&gt;So, I’ve been struggling for a while with how to style a checkbox to work with a skin file. Basically, what I did was create some gif files that look like checked and unchecked check boxes. I defined them in my SkinFile.skin file as follows:&lt;/p&gt;
&lt;p style="FONT-SIZE: 10pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New"&gt;&lt;span style="COLOR: blue"&gt;&lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;asp&lt;/span&gt;&lt;span style="COLOR: blue"&gt;:&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;ImageButton&lt;/span&gt; &lt;span style="COLOR: red"&gt;SkinID&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=”iconCheckedDisabled”&lt;/span&gt; &lt;span style="COLOR: red"&gt;ImageUrl&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=”Images/iconCheckedDisabled.gif”&lt;/span&gt; &lt;span style="COLOR: red"&gt;runat&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=”server”&lt;/span&gt; &lt;span style="COLOR: red"&gt;ToolTip&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=”Checked Disabled”&lt;/span&gt; &lt;span style="COLOR: blue"&gt;/&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="FONT-SIZE: 10pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New"&gt;&lt;span style="COLOR: blue"&gt;&lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;asp&lt;/span&gt;&lt;span style="COLOR: blue"&gt;:&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;ImageButton&lt;/span&gt; &lt;span style="COLOR: red"&gt;SkinID&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=”iconCheckedEnabled”&lt;/span&gt; &lt;span style="COLOR: red"&gt;ImageUrl&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=”Images/iconCheckedEnabled.gif”&lt;/span&gt; &lt;span style="COLOR: red"&gt;runat&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=”server”&lt;/span&gt; &lt;span style="COLOR: red"&gt;ToolTip&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=”Checked Enabled”&lt;/span&gt; &lt;span style="COLOR: blue"&gt;/&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="FONT-SIZE: 10pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New"&gt;&lt;span style="COLOR: blue"&gt;&lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;asp&lt;/span&gt;&lt;span style="COLOR: blue"&gt;:&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;ImageButton&lt;/span&gt; &lt;span style="COLOR: red"&gt;SkinID&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=”iconUnCheckedDisabled”&lt;/span&gt; &lt;span style="COLOR: red"&gt;ImageUrl&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=”Images/iconUnCheckedDisabled.gif”&lt;/span&gt; &lt;span style="COLOR: red"&gt;runat&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=”server”&lt;/span&gt; &lt;span style="COLOR: red"&gt;ToolTip&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=”Unchecked Disabled”&lt;/span&gt; &lt;span style="COLOR: blue"&gt;/&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="FONT-SIZE: 10pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New"&gt;&lt;span style="COLOR: blue"&gt;&lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;asp&lt;/span&gt;&lt;span style="COLOR: blue"&gt;:&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;ImageButton&lt;/span&gt; &lt;span style="COLOR: red"&gt;SkinID&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=”iconUnCheckedEnabled”&lt;/span&gt; &lt;span style="COLOR: red"&gt;ImageUrl&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=”Images/iconUnCheckedEnabled.gif”&lt;/span&gt; &lt;span style="COLOR: red"&gt;runat&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=”server”&lt;/span&gt; &lt;span style="COLOR: red"&gt;ToolTip&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=”Unchecked Enabled”&lt;/span&gt; &lt;span style="COLOR: blue"&gt;/&gt;&lt;/span&gt;&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;&lt;br /&gt;&lt;/div&gt;
&lt;p style="FONT-SIZE: 10pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New"&gt;The image files look like the following:&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;&lt;br /&gt;&lt;/div&gt;
&lt;p style="FONT-SIZE: 10pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New"&gt;&lt;a href="http://peterkellner.net/wp/wp-content/uploads/2007/11/iconuncheckeddisabled.gif" rel="lightbox" title="iconUncheckedDisabled.gif"&gt;&lt;img src="http://peterkellner.net/wp/wp-content/uploads/2007/11/iconuncheckeddisabled-tn.jpg" title="iconUncheckedDisabled.gif" height="15" width="15" alt="iconUncheckedDisabled.gif" border="0" id="urn:zoundry:jid:iconUncheckedDisabled.gif"/&gt;&lt;/a&gt; &lt;a href="http://peterkellner.net/wp/wp-content/uploads/2007/11/iconcheckeddisabled.gif" rel="lightbox" title="iconCheckedDisabled.gif"&gt;&lt;img src="http://peterkellner.net/wp/wp-content/uploads/2007/11/iconcheckeddisabled-tn.jpg" title="iconCheckedDisabled.gif" height="15" width="15" alt="iconCheckedDisabled.gif" border="0" id="urn:zoundry:jid:iconCheckedDisabled.gif"/&gt;&lt;/a&gt; &lt;a href="http://peterkellner.net/wp/wp-content/uploads/2007/11/iconuncheckedenabled.gif" rel="lightbox" title="iconUncheckedEnabled.gif"&gt;&lt;img src="http://peterkellner.net/wp/wp-content/uploads/2007/11/iconuncheckedenabled-tn.jpg" title="iconUncheckedEnabled.gif" height="15" width="15" alt="iconUncheckedEnabled.gif" border="0" id="urn:zoundry:jid:iconUncheckedEnabled.gif"/&gt;&lt;/a&gt; &lt;a href="http://peterkellner.net/wp/wp-content/uploads/2007/11/iconcheckedenabled.gif" rel="lightbox" title="iconCheckedEnabled.gif"&gt;&lt;img src="http://peterkellner.net/wp/wp-content/uploads/2007/11/iconcheckedenabled-tn.jpg" title="iconCheckedEnabled.gif" height="15" width="15" alt="iconCheckedEnabled.gif" border="0" id="urn:zoundry:jid:iconCheckedEnabled.gif"/&gt;&lt;/a&gt;&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;&lt;br /&gt;&lt;/div&gt;
&lt;p style="FONT-SIZE: 10pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New"&gt;The problem basically is that you can’t dynamically swap skin files easily because they must be set at the preinit phase of event processing. Not at databound events which is where I’d want to do it.&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;&lt;br /&gt;&lt;/div&gt;
&lt;p style="FONT-SIZE: 10pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New"&gt;So, my revelation was that I could just list all the states in a gridview template, then use the visibility attribute to make them show the correct one. That way, the skins are all loaded all the time, just now showing all the time. The GridView Code looks like the following:&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;&lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;asp&lt;/span&gt;&lt;span style="COLOR: blue"&gt;:&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;GridView&lt;/span&gt; &lt;span style="COLOR: red"&gt;ID&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=”GridViewAssigned”&lt;/span&gt; &lt;span style="COLOR: red"&gt;runat&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=”server”&lt;/span&gt; &lt;span style="COLOR: red"&gt;AllowPaging&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=”True”&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;&lt;span style="COLOR: red"&gt;AllowSorting&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=”True”&lt;/span&gt; &lt;span style="COLOR: red"&gt;Caption&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=”Assigned”&lt;/span&gt; &lt;span style="COLOR: red"&gt;AutoGenerateColumns&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=”false”&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;&lt;span style="COLOR: red"&gt;DataSourceID&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=”ObjectDataSourceGroupsAssigned”&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;&lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Columns&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;&lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;asp&lt;/span&gt;&lt;span style="COLOR: blue"&gt;:&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;TemplateField&lt;/span&gt; &lt;span style="COLOR: red"&gt;ShowHeader&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=”False”&lt;/span&gt; &lt;span style="COLOR: blue"&gt;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;&lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;ItemTemplate&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;&lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;asp&lt;/span&gt;&lt;span style="COLOR: blue"&gt;:&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;ImageButton&lt;/span&gt; &lt;span style="COLOR: red"&gt;ID&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=”LinkButtonUnassign”&lt;/span&gt; &lt;span style="COLOR: red"&gt;SkinID&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=”ImageButtonRemove”&lt;/span&gt; &lt;span style="COLOR: red"&gt;runat&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=”server”&lt;/span&gt; &lt;span style="COLOR: red"&gt;BackColor&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=”white”&lt;/span&gt; &lt;span style="COLOR: red"&gt;CausesValidation&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=”False”&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;&lt;span style="COLOR: red"&gt;CommandArgument&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=’&lt;/span&gt;&lt;span style="BACKGROUND: #ffee62"&gt;&lt;%&lt;/span&gt;# Eval(”id”) &lt;span style="BACKGROUND: #ffee62"&gt;%&gt;&lt;/span&gt;&lt;span style="COLOR: blue"&gt;‘&lt;/span&gt; &lt;span style="COLOR: red"&gt;CommandName&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=”Select”&lt;/span&gt; &lt;span style="COLOR: red"&gt;ForeColor&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=”black”&lt;/span&gt; &lt;span style="COLOR: blue"&gt;/&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;&lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;ItemTemplate&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;&lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;asp&lt;/span&gt;&lt;span style="COLOR: blue"&gt;:&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;TemplateField&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;&lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;asp&lt;/span&gt;&lt;span style="COLOR: blue"&gt;:&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;TemplateField&lt;/span&gt; &lt;span style="COLOR: red"&gt;ShowHeader&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=”True”&lt;/span&gt; &lt;span style="COLOR: red"&gt;HeaderText&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=”Assign To New Content By Default”&lt;/span&gt; &lt;span style="COLOR: blue"&gt;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;&lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;ItemTemplate&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;br /&gt;&lt;p style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;&lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;asp&lt;/span&gt;&lt;span style="COLOR: blue"&gt;:&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;ImageButton&lt;/span&gt; &lt;span style="COLOR: red"&gt;ID&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=”LinkButtonToggleDefaultChecked”&lt;/span&gt; &lt;span style="COLOR: red"&gt;SkinID&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=’iconCheckedEnabled’&lt;/span&gt; &lt;span style="COLOR: red"&gt;runat&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=”server”&lt;/span&gt; &lt;span style="COLOR: red"&gt;BackColor&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=”white”&lt;/span&gt; &lt;span style="COLOR: red"&gt;CausesValidation&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=”False”&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;&lt;span style="COLOR: red"&gt;visible&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=’&lt;/span&gt;&lt;span style="BACKGROUND: #ffee62"&gt;&lt;%&lt;/span&gt;# (bool) Eval(”Defaultnewcontent”) &lt;span style="BACKGROUND: #ffee62"&gt;%&gt;&lt;/span&gt;&lt;span style="COLOR: blue"&gt;‘&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;&lt;span style="COLOR: red"&gt;CommandArgument&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=’&lt;/span&gt;&lt;span style="BACKGROUND: #ffee62"&gt;&lt;%&lt;/span&gt;# Eval(”id”) + “;” + Eval(”Approved”) &lt;span style="BACKGROUND: #ffee62"&gt;%&gt;&lt;/span&gt;&lt;span style="COLOR: blue"&gt;‘&lt;/span&gt; &lt;span style="COLOR: red"&gt;CommandName&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=”ToggleDefault”&lt;/span&gt; &lt;span style="COLOR: red"&gt;ForeColor&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=”black”&lt;/span&gt; &lt;span style="COLOR: blue"&gt;/&gt;&lt;/span&gt;&lt;/p&gt;
&lt;br /&gt;&lt;p style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;&lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;asp&lt;/span&gt;&lt;span style="COLOR: blue"&gt;:&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;ImageButton&lt;/span&gt; &lt;span style="COLOR: red"&gt;ID&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=”LinkButtonToggleDefaultUnChecked”&lt;/span&gt; &lt;span style="COLOR: red"&gt;SkinID&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=”iconUnCheckedEnabled”&lt;/span&gt; &lt;span style="COLOR: red"&gt;runat&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=”server”&lt;/span&gt; &lt;span style="COLOR: red"&gt;BackColor&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=”white”&lt;/span&gt; &lt;span style="COLOR: red"&gt;CausesValidation&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=”False”&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;&lt;span style="COLOR: red"&gt;visible&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=’&lt;/span&gt;&lt;span style="BACKGROUND: #ffee62"&gt;&lt;%&lt;/span&gt;# !(bool) Eval(”Approved”) &lt;span style="BACKGROUND: #ffee62"&gt;%&gt;&lt;/span&gt;&lt;span style="COLOR: blue"&gt;‘&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;&lt;span style="COLOR: red"&gt;CommandArgument&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=’&lt;/span&gt;&lt;span style="BACKGROUND: #ffee62"&gt;&lt;%&lt;/span&gt;# Eval(”id”) + “;” + Eval(”Approved”) &lt;span style="BACKGROUND: #ffee62"&gt;%&gt;&lt;/span&gt;&lt;span style="COLOR: blue"&gt;‘&lt;/span&gt; &lt;span style="COLOR: red"&gt;CommandName&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=”ToggleDefault”&lt;/span&gt; &lt;span style="COLOR: red"&gt;ForeColor&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=”black”&lt;/span&gt; &lt;span style="COLOR: blue"&gt;/&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;&lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;ItemTemplate&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;&lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;asp&lt;/span&gt;&lt;span style="COLOR: blue"&gt;:&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;TemplateField&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;&lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;asp&lt;/span&gt;&lt;span style="COLOR: blue"&gt;:&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;BoundField&lt;/span&gt; &lt;span style="COLOR: red"&gt;DataField&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=”Name”&lt;/span&gt; &lt;span style="COLOR: red"&gt;HeaderText&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=”Name”&lt;/span&gt; &lt;span style="COLOR: red"&gt;SortExpression&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=”Name”&lt;/span&gt; &lt;span style="COLOR: blue"&gt;/&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;&lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Columns&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;&lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;asp&lt;/span&gt;&lt;span style="COLOR: blue"&gt;:&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;GridView&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Then, when you finally run it, the gridview looks something like this.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://peterkellner.net/wp/wp-content/uploads/2007/11/gridviewwithskins.jpg" rel="lightbox" title="gridviewWithSKins.jpg"&gt;&lt;img src="http://peterkellner.net/wp/wp-content/uploads/2007/11/gridviewwithskins-tn.jpg" title="gridviewWithSKins.jpg" height="157" width="200" alt="gridviewWithSKins.jpg" border="0" id="urn:zoundry:jid:gridviewWithSKins.jpg"/&gt;&lt;/a&gt;&lt;/p&gt;
Notice no codebehind was necessary for this trick! Good luck and hope this save you some time.&lt;br /&gt;&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;
&lt;img alt="via softlogger.com" src="http://softlogger.com/postview.aspx?ArticleID=13170"&gt;</description><author>peterkellner.net</author><pubDate>2007-11-24T00:00:00</pubDate><category>CSharp</category></item><item><title>C# 3.0 Object Initializers Revisited</title><link>http://softlogger.com/12659/CSharp/c-3-0-object-initializers-revisited.aspx</link><description>&lt;p&gt;A while ago I posted about this &lt;a href="http://community.bartdesmet.net/blogs/bart/archive/2006/12/04/C_2300_-3.0-Feature-Focus-_2D00_-Part-2-_2D00_-Object-Initializers.aspx"&gt;new C# 3.0 feature&lt;/a&gt;. Although the IL code (aargh, yet another of these posts :-)) in that post reveals how object initializers are implemented internally, I wanted to make it slightly more explicit over here to avoid confusion.&lt;/p&gt;  &lt;p&gt;Consider the following C# 3.0 fragment:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font face="Courier New"&gt;&lt;font color="#0000ff"&gt;using&lt;/font&gt; System;&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font face="Courier New"&gt;&lt;font color="#0000ff"&gt;class&lt;/font&gt; Oini        &lt;br /&gt;{        &lt;br /&gt;&amp;#160;&amp;#160; &lt;font color="#0000ff"&gt;public static void &lt;/font&gt;Main()        &lt;br /&gt;&amp;#160;&amp;#160; {        &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#008080"&gt;Customer&lt;/font&gt; c = &lt;font color="#0000ff"&gt;new &lt;/font&gt;&lt;font color="#008080"&gt;Customer&lt;/font&gt;() { Name = &lt;font color="#800000"&gt;&amp;quot;Bart&amp;quot;&lt;/font&gt;, City = &lt;font color="#800000"&gt;&amp;quot;Redmond&amp;quot;&lt;/font&gt;, Age = 24 };        &lt;br /&gt;&amp;#160;&amp;#160; }        &lt;br /&gt;}&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;This is &lt;u&gt;not&lt;/u&gt; equivalent to:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font face="Courier New"&gt;&lt;font color="#0000ff"&gt;using&lt;/font&gt; System;&lt;/font&gt; &lt;/p&gt;    &lt;p&gt;&lt;font face="Courier New"&gt;&lt;font color="#0000ff"&gt;class&lt;/font&gt; Oini        &lt;br /&gt;{        &lt;br /&gt;&amp;#160;&amp;#160; &lt;font color="#0000ff"&gt;public static void &lt;/font&gt;Main()        &lt;br /&gt;&amp;#160;&amp;#160; {        &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#008080"&gt;Customer&lt;/font&gt; c = &lt;font color="#0000ff"&gt;new &lt;/font&gt;&lt;font color="#008080"&gt;Customer&lt;/font&gt;();        &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; c.Name = &lt;font color="#800000"&gt;&amp;quot;Bart&amp;quot;&lt;/font&gt;;        &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; c.City = &lt;font color="#800000"&gt;&amp;quot;Redmond&amp;quot;&lt;/font&gt;;        &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; c.Age = 24;        &lt;br /&gt;&amp;#160;&amp;#160; }        &lt;br /&gt;}&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;It is equivalent to the following however:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font face="Courier New"&gt;&lt;font color="#0000ff"&gt;using&lt;/font&gt; System;&lt;/font&gt; &lt;/p&gt;    &lt;p&gt;&lt;font face="Courier New"&gt;&lt;font color="#0000ff"&gt;class&lt;/font&gt; Oini        &lt;br /&gt;{        &lt;br /&gt;&amp;#160;&amp;#160; &lt;font color="#0000ff"&gt;public static void &lt;/font&gt;Main()        &lt;br /&gt;&amp;#160;&amp;#160; {        &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#008080"&gt;Customer&lt;/font&gt; __t = &lt;font color="#0000ff"&gt;new &lt;/font&gt;&lt;font color="#008080"&gt;Customer&lt;/font&gt;();        &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; __t.Name = &lt;font color="#800000"&gt;&amp;quot;Bart&amp;quot;&lt;/font&gt;;        &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; __t.City = &lt;font color="#800000"&gt;&amp;quot;Redmond&amp;quot;&lt;/font&gt;;        &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; __t.Age = 24;        &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#008080"&gt;Customer&lt;/font&gt; c = __t;        &lt;br /&gt;&amp;#160;&amp;#160; }        &lt;br /&gt;}&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;I know it&amp;#39;s subtle but there&amp;#39;s a very good reason to do it this way: &lt;strong&gt;atomic assignment&lt;/strong&gt;. Assignments should be read from right to left:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font face="Courier New"&gt;&lt;font color="#008080"&gt;Customer&lt;/font&gt; c = &lt;font color="#0000ff"&gt;new &lt;/font&gt;&lt;font color="#008080"&gt;Customer&lt;/font&gt;() { Name = &lt;font color="#800000"&gt;&amp;quot;Bart&amp;quot;&lt;/font&gt;, City = &lt;font color="#800000"&gt;&amp;quot;Redmond&amp;quot;&lt;/font&gt;, Age = 24 };&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;means&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;evaluate the right-hand side (rhs):     &lt;br /&gt;      &lt;br /&gt;&lt;font face="Courier New"&gt;&lt;font color="#0000ff"&gt;new &lt;/font&gt;&lt;font color="#008080"&gt;Customer&lt;/font&gt;() { Name = &lt;font color="#800000"&gt;&amp;quot;Bart&amp;quot;&lt;/font&gt;, City = &lt;font color="#800000"&gt;&amp;quot;Redmond&amp;quot;&lt;/font&gt;, Age = 24 }        &lt;br /&gt;&lt;/font&gt;&lt;/li&gt;    &lt;li&gt;assign it to the left-hand side (lhs):     &lt;br /&gt;      &lt;br /&gt;&lt;font face="Courier New"&gt;&lt;font color="#008080"&gt;Customer&lt;/font&gt; c&lt;/font&gt;&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;therefore, we need a temporary object to evaluate the right-hand side first prior to assigning it to the target variable.&lt;/p&gt;  &lt;p&gt;One place where this subtlety is quite important is the use of multi-threading. It&amp;#39;s a bit of a convoluted sample, I agree, since in multi-threaded circumstances you&amp;#39;ll likely have a locking-strategy or so in place to avoid base states but anyhow, here&amp;#39;s a sample:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font face="Courier New"&gt;&lt;font color="#0000ff"&gt;using&lt;/font&gt; System;        &lt;br /&gt;&lt;font face="Courier New"&gt;&lt;font color="#0000ff"&gt;using&lt;/font&gt; &lt;/font&gt;System.Threading; &lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font face="Courier New"&gt;&lt;font face="Courier New"&gt;&lt;font color="#0000ff"&gt;class &lt;/font&gt;&lt;/font&gt;&lt;font color="#008080"&gt;Customer&lt;/font&gt;        &lt;br /&gt;{        &lt;br /&gt;&amp;#160;&amp;#160; &lt;font face="Courier New"&gt;&lt;font face="Courier New"&gt;&lt;font color="#0000ff"&gt;public string &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;Name { &lt;font color="#0000ff"&gt;get&lt;/font&gt;; &lt;font color="#0000ff"&gt;set&lt;/font&gt;; }        &lt;br /&gt;&amp;#160;&amp;#160; &lt;font face="Courier New"&gt;&lt;font face="Courier New"&gt;&lt;font color="#0000ff"&gt;public string &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;City { &lt;font color="#0000ff"&gt;get&lt;/font&gt;; &lt;font color="#0000ff"&gt;set&lt;/font&gt;; }        &lt;br /&gt;&amp;#160;&amp;#160; &lt;font face="Courier New"&gt;&lt;font face="Courier New"&gt;&lt;font color="#0000ff"&gt;public int &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;Age { &lt;font color="#0000ff"&gt;get&lt;/font&gt;; &lt;font color="#0000ff"&gt;set&lt;/font&gt;; }        &lt;br /&gt;} &lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font face="Courier New"&gt;&lt;font face="Courier New"&gt;&lt;font face="Courier New"&gt;&lt;font color="#0000ff"&gt;class &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font color="#008080"&gt;Demo&lt;/font&gt;        &lt;br /&gt;{        &lt;br /&gt;&amp;#160;&amp;#160; &lt;font color="#0000ff"&gt;static &lt;/font&gt;&lt;font color="#008080"&gt;Customer &lt;/font&gt;c;        &lt;br /&gt;&amp;#160;&amp;#160; &lt;font color="#0000ff"&gt;static int &lt;/font&gt;n = 0;         &lt;br /&gt;&amp;#160;&amp;#160; &lt;font color="#0000ff"&gt;static bool &lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;safe = &lt;font color="#0000ff"&gt;false&lt;/font&gt;;&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font face="Courier New"&gt;&amp;#160;&amp;#160; &lt;font color="#0000ff"&gt;static void &lt;/font&gt;Main(&lt;font color="#0000ff"&gt;string&lt;/font&gt;[] args)        &lt;br /&gt;&amp;#160;&amp;#160; {        &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; safe = args.Length &amp;gt; 0; &lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font face="Courier New"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Init(); &lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font face="Courier New"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#008080"&gt;AppDomain&lt;/font&gt;.CurrentDomain.UnhandledException +=         &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#0000ff"&gt;delegate&lt;/font&gt;(&lt;font color="#0000ff"&gt;object &lt;/font&gt;sender, &lt;font color="#008080"&gt;UnhandledExceptionEventArgs &lt;/font&gt;e)        &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {        &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#008080"&gt;Console&lt;/font&gt;.WriteLine(&lt;font color="#800000"&gt;&amp;quot;Invalid state after &amp;quot;&lt;/font&gt; + n + &lt;font color="#800000"&gt;&amp;quot; assignments.&amp;quot;&lt;/font&gt;);        &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#008080"&gt;Environment&lt;/font&gt;.Exit(1);        &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }; &lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font face="Courier New"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#0000ff"&gt;new &lt;/font&gt;&lt;font color="#008080"&gt;Thread&lt;/font&gt;(() =&amp;gt; Monitor()).Start(); &lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font face="Courier New"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#0000ff"&gt;for &lt;/font&gt;(n = 1; ; n++)        &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Init();        &lt;br /&gt;&amp;#160;&amp;#160; } &lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font face="Courier New"&gt;&amp;#160;&amp;#160; &lt;font color="#0000ff"&gt;static void &lt;/font&gt;Init()        &lt;br /&gt;&amp;#160;&amp;#160; {        &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#0000ff"&gt;if &lt;/font&gt;(safe)        &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {        &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; c = &lt;font color="#0000ff"&gt;new &lt;/font&gt;&lt;font color="#008080"&gt;Customer&lt;/font&gt;() {        &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Name = &lt;font color="#800000"&gt;&amp;quot;Bart&amp;quot;&lt;/font&gt;,        &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; City = &lt;font color="#800000"&gt;&amp;quot;Redmond&amp;quot;&lt;/font&gt;,        &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Age = 24        &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; };        &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }        &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#0000ff"&gt;else&lt;/font&gt;        &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {        &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; c = &lt;font color="#0000ff"&gt;new &lt;/font&gt;&lt;font color="#008080"&gt;Customer&lt;/font&gt;();        &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; c.Name = &lt;font color="#800000"&gt;&amp;quot;Bart&amp;quot;&lt;/font&gt;;        &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; c.City = &lt;font color="#800000"&gt;&amp;quot;Redmond&amp;quot;&lt;/font&gt;;        &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; c.Age = 24;        &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }        &lt;br /&gt;&amp;#160;&amp;#160; } &lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font face="Courier New"&gt;&amp;#160;&amp;#160; &lt;font color="#0000ff"&gt;static void&lt;/font&gt; Monitor()        &lt;br /&gt;&amp;#160;&amp;#160; {        &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#0000ff"&gt;while&lt;/font&gt; (&lt;font color="#0000ff"&gt;true&lt;/font&gt;)        &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {&lt;/font&gt;&lt;font face="Courier New"&gt;       &lt;br /&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#0000ff"&gt;if &lt;/font&gt;(c.Name != &lt;font color="#800000"&gt;&amp;quot;Bart&amp;quot;&lt;/font&gt; || c.City != &lt;font color="#800000"&gt;&amp;quot;Redmond&amp;quot;&lt;/font&gt; || c.Age != 24)        &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#0000ff"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font color="#0000ff"&gt;throw new &lt;/font&gt;&lt;font color="#008080"&gt;Exception&lt;/font&gt;(&lt;font color="#800000"&gt;&amp;quot;Bad state detected&amp;quot;&lt;/font&gt;);        &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }        &lt;br /&gt;&amp;#160;&amp;#160; }        &lt;br /&gt;}&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;If you execute this application without command-line arguments it should fail pretty quickly. However if you run it with some parameter, safe will be set to true, which causes Init to use the C# 3.0 implementation of object initialization, which is atomic. So we shouldn&amp;#39;t get in intermediate states at all.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://community.bartdesmet.net/blogs/bart/WindowsLiveWriter/C3.0ObjectInitializersRevisited_BA21/image_2.png"&gt;&lt;img style="border-right:0px;border-top:0px;border-left:0px;border-bottom:0px;" height="340" alt="image" src="http://community.bartdesmet.net/blogs/bart/WindowsLiveWriter/C3.0ObjectInitializersRevisited_BA21/image_thumb.png" width="677" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Here&amp;#39;s the reverse translation of the Init body using Reflector:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://community.bartdesmet.net/blogs/bart/WindowsLiveWriter/C3.0ObjectInitializersRevisited_BA21/image_4.png"&gt;&lt;img style="border-right:0px;border-top:0px;border-left:0px;border-bottom:0px;" height="513" alt="image" src="http://community.bartdesmet.net/blogs/bart/WindowsLiveWriter/C3.0ObjectInitializersRevisited_BA21/image_thumb_1.png" width="792" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;If you understand this sample, you know why atomic assignment matters (and that&amp;#39;s a good thing :-)). To pinpoint the core problem, consider the following fragment of Init (in the safe-negative case):&lt;/p&gt; &lt;font face="Courier New"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; c = &lt;font color="#0000ff"&gt;new &lt;/font&gt;&lt;font color="#008080"&gt;Customer&lt;/font&gt;();    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; c.Name = &lt;font color="#800000"&gt;&amp;quot;Bart&amp;quot;&lt;/font&gt;;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; c.City = &lt;font color="#800000"&gt;&amp;quot;Redmond&amp;quot;&lt;/font&gt;;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; c.Age = 24;&lt;/font&gt;  &lt;p&gt;If the monitoring thread gets a chance to kick in somewhere in the middle of executing these four statements, the state is &amp;quot;corrupted&amp;quot;. Obviously you can fix this by putting a lock in place (small exercise) but it&amp;#39;s nice to know the atomic character of object initializers in C# 3.0 anyhow.&lt;/p&gt;  &lt;p&gt;Enjoy!&lt;/p&gt;&lt;img src="http://community.bartdesmet.net/aggbug.aspx?PostID=12872" width="1" height="1"&gt;&lt;img alt="via softlogger.com" src="http://softlogger.com/postview.aspx?ArticleID=12659"&gt;</description><author>B# .NET Blog</author><pubDate>2007-11-22T00:00:00</pubDate><category>CSharp</category></item><item><title>Managed and Native Interop - C# or C++/CLI?</title><link>http://softlogger.com/12636/CSharp/managed-and-native-interop--c-or-c--cli.aspx</link><description>&lt;p&gt;This is a topic that I've been thinking a lot about lately. And I would really like to get all of your opinions as well (especially if you disagree with me). &lt;/p&gt;  &lt;p&gt;This debate came up recently (again) on my trip to Tech Ed Developer in Barcelona. If I am having to write interop code, should I use C# and p/invoke, or should I use C++/CLI? I had some very smart people like &lt;a href="http://www.gregcons.com/kateblog/"&gt;Kate Gregory&lt;/a&gt; and &lt;a href="http://www.danielmoth.com/Blog/"&gt;Daniel Moth&lt;/a&gt; to chat with this about. Kate and Daniel are definitely good people to chat with because, honestly, they have completely different opinions on this topic. Kate is on the C++/CLI side of things, especially for serious interop tasks, while Daniel believes that you should keep it in C# no matter how complicated that C# gets. So, what side of the fence do I fall on?&lt;/p&gt;  &lt;p&gt;This is a question I've been pondering for a while now. Since I first came in to this Windows Server 2008 Technical Evangelist, I've had to write a lot of interop code. And I personally believe in using the right tool for the job. And while p/invoke is great for smaller interop jobs between native code and managed code, it can &amp;quot;get out of hand&amp;quot; quickly. For instance, to p/invoke into the new Transactional NTFS APIs, I could look at having to create a bunch (several hundred lines of code or many more) of interop structures merely to call DeviceIoControl to get issue a single TxF command. Here's the thing: all those structures are all ready defined on the native side and could be used with ease (as in, a simple &amp;quot;#include&amp;quot; statement) on the C++/CLI side of things. No extra code necessary. &lt;/p&gt;  &lt;p&gt;But it's not just the structure definitions that are the problem, it is also the programming paradigm used in the native code you are trying to interop with. When dealing with a simple Windows API function, this may not be a problem at all. Of course, it gets a little scary when dealing with COM interop, but at least there are still the tools built into C# to interop with COM. Where the train really starts to derail is when you start writing interop code for a native library that uses a different paradigm. &lt;/p&gt;  &lt;p&gt;For instance, let's look at DeviceIoControl. It's not really one function call, it's a complete API in itself. I've had to get familiar with DeviceIoControl when doing my work with Transactional NTFS. DeviceIoControl uses a much more conversational paradigm than managed developers are perhaps used to. Here's a common &amp;quot;calling session&amp;quot; with DeviceIoControl (minus all the fun exception handling that should be there):&lt;/p&gt;  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;while&lt;/span&gt; (&lt;span class="kwrd"&gt;true&lt;/span&gt;)
{
    &lt;span class="rem"&gt;// Clean-up previously allocated memory&lt;/span&gt;

    &lt;span class="rem"&gt;// Allocate memory&lt;/span&gt;

    &lt;span class="rem"&gt;// Issue command&lt;/span&gt;
    &lt;span class="kwrd"&gt;if&lt;/span&gt; (!DeviceIoControl(...))
    {
        &lt;span class="kwrd"&gt;if&lt;/span&gt; (GetLastError() == ERROR_MORE_DATA)
        {
            &lt;span class="rem"&gt;// Determine how much more memory we need&lt;/span&gt;

            &lt;span class="kwrd"&gt;continue&lt;/span&gt;;
        }
    }
    &lt;span class="kwrd"&gt;else&lt;/span&gt;
    {
        &lt;span class="rem"&gt;// There was enough memory finally&lt;/span&gt;

        &lt;span class="rem"&gt;// Pull data out of buffer we issued to DeviceIoControl&lt;/span&gt;

        &lt;span class="kwrd"&gt;break&lt;/span&gt;;
    }
}&lt;/pre&gt;

&lt;p&gt;When writing managed code against this DeviceIoControl paradigm, you will write more code that is harder to maintain and debug than you will if you simply used C++/CLI to do the interop. With C++/CLI you can use the API natively exactly like it's meant to be used, and then &amp;quot;expose&amp;quot; the code to the managed world via C++/CLI. When I moved my Transaction NTFS wrapper from C# to C++/CLI, I was able to remove a large chunk of code, and it was much easier to read and understand. Using the right tool for the job will do that for you. &lt;/p&gt;

&lt;p&gt;The DeviceIoControl paradigm is just one example though. Another &amp;quot;hang up&amp;quot; when writing interop code in C# is when you need to do some very detailed memory and pointer manipulation. Take this following piece of code that is used within the DeviceIoControl pattern above and is used to get the list of running transactions on a system (assuming the &amp;quot;list&amp;quot; has already been populated):&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="rem"&gt;// Loop through the transaction entries and store them in a list&lt;/span&gt;
TXFS_LIST_TRANSACTIONS_ENTRY *txEntry;
txEntry = (TXFS_LIST_TRANSACTIONS_ENTRY *)((&lt;span class="kwrd"&gt;char&lt;/span&gt; *)txList + &lt;span class="kwrd"&gt;sizeof&lt;/span&gt;(TXFS_LIST_TRANSACTIONS));
&lt;span class="kwrd"&gt;for&lt;/span&gt; (DWORD i = 0; i &amp;lt; txList-&amp;gt;NumberOfTransactions; i++)
{
    TRANSACTION_ENTRY *newEntry = AddTxFEntry(txEntry-&amp;gt;TransactionId, txEntry-&amp;gt;TransactionState);

    &lt;span class="rem"&gt;// Each transaction is attempted to be loaded with their files ASAP (if any).&lt;/span&gt;
    LoadLockedFiles(rmDirectory, newEntry);
    txEntry++;
}&lt;/pre&gt;

&lt;p&gt;This code is a PITA to write in C#. Not only do you have to write all the interop structures for TXFS_LIST_TRANSACTIONS_ENTRY, TXFS_LIST_TRANSACTIONS, and TRANSACTION_ENTRY, but you have to do all the pointer fun via the Marshal helper in C#. Sure, you could pop into unsafe code and deal with pointers directly, but I think if you are willing to do that, you should be more than willing to just use C++/CLI. Why would I go through all that, if I can just write the code and expose the results to managed code via C++/CLI? As soon as I switched the wrapper from C# to C++/CLI, my job got a LOT easier. And this is coming from a programmer that is relatively new to the whole C++ world. If I can write in C++/CLI for interop, I honestly believe any committed C# developer can as well.&lt;/p&gt;

&lt;p&gt;Let's look at a small snippet from the Transactional NTFS Wrapper:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;FileStream^ TransactedFile::Open(System::String ^path, FileMode mode, FileAccess access, FileShare share) {
                
    ...

    &lt;span class="rem"&gt;////////////////////////////////////////////////////////////////////////&lt;/span&gt;
    &lt;span class="rem"&gt;// We need to marshal our values into native types since we are&lt;/span&gt;
    &lt;span class="rem"&gt;// going to call into a native Windows API based on CLR parameters&lt;/span&gt;
    marshal_context ctx;
    &lt;span class="kwrd"&gt;const&lt;/span&gt; wchar_t *marshalledPath = ctx.marshal_as&amp;lt;&lt;span class="kwrd"&gt;const&lt;/span&gt; wchar_t *&amp;gt;(path);

    HANDLE fileHandle = CreateFileTransacted(marshalledPath, 
        marshal_as&amp;lt;DWORD&amp;gt;(access), 
        marshal_as&amp;lt;DWORD&amp;gt;(share),
        NULL, 
        marshal_as&amp;lt;DWORD&amp;gt;(mode), 
        FILE_ATTRIBUTE_NORMAL, 
        NULL, 
        kernelTransactionHandle, 
        NULL, 
        NULL);
    
    ...
}&lt;/pre&gt;

&lt;p&gt;This is the actual segment of code that does the main interop piece for me. Is the above that intimidating? A couple of things to note to those C# developers out there. You can think of the &amp;quot;^&amp;quot; as denoting &amp;quot;by reference&amp;quot;. Yes, it's a bit more complicated than that, but just think of it that way for now, that's all you need to know. And the &amp;quot;::&amp;quot; operator is your namespace operator. So instead of &amp;quot;System.String&amp;quot;, I have &amp;quot;System::String&amp;quot;. Once again, a very simple syntactic difference.&lt;/p&gt;

&lt;p&gt;The marshal_context object is a new object introduced with Visual C++ 2008 as part of the new marshalling library. By using the marshal_context, the context will take care of memory allocation and de-allocation for the strings we are are interop'ing. Very simple. The CreateFileTransacted API expects the path to be a &amp;quot;const wchar_t *&amp;quot;, so I simply marshal our passed System::String as &amp;quot;const wchar_t *&amp;quot; and we're good to go. Since marshal_as&amp;lt;&amp;gt; is template based, it's very easy to extend yourself. And that's what I've done with marshalling System::IO::FileMode/Access/Share as DWORD (which I will show in a future post).&lt;/p&gt;

&lt;p&gt;Now, honestly, is that piece of code that scary? If you have questions about it or things that still scare you, please let me know and I will look at writing a future post on the topic. &lt;/p&gt;

&lt;p&gt;Back to the debate at hand though: C# versus C++/CLI for interop. I can certainly understand where Daniel is coming from. C# developers can quickly become intimidated when seeing C++/CLI code. It isn't the C# code they know and love. But I'm not sure he gives C# developers enough credit. It's an important step for developers to realize that, syntactically, C++/CLI and C# are not that different. If you are familiar with reference types in C#, you are probably more familiar with pointers than you realize. There are some &amp;quot;gotchas&amp;quot; around topics like pinned pointers, but they are concepts you need to know in C# as well if writing interop code there, so they aren't that big of a deal in the end. I'm not saying to not use P/Invoke and C# though. I'm simply saying to use the right tool for the job. If it is a very simple Windows API you are writing interop code for, C# and P/Invoke is probably &amp;quot;good enough&amp;quot;. For more complicated interop jobs though (as in with most of the new enhancements in Vista and Windows Server 2008), why not use C++/CLI since it will make your life easier one you get over the small learning curve?&lt;/p&gt;

&lt;p&gt;Did I have this same opinion before Visual Studio 2008? Yes, and no. Yes, C++/CLI code was still built for interop, but I honestly believe that the introduction of the extensible marshal_as&amp;lt;&amp;gt; construct (combined with other technologies like STL CLR) make interop in C++/CLI even more powerful and easier to use than before. For instance, marshalling strings was not fun to do before Visual Studio 2008 (especially for a developer not extremely aware of the different ways to use strings in native code). However, out of the box, the marshal_as&amp;lt;&amp;gt; construct provides a lot of different ways to work with and to interop with strings. And in all of these ways, you don't have to worry about allocating or de-allocating memory at all (ah, the same joys I get when working in a garbage collected world). And in the case that you are interacting with C++ libraries that are possibly STL-based, STL CLR provides you with a library that you simply don't get in C# (interop'ing with C-based Windows APIs are one thing, interop'ing with proper C++ libraries are a completely different beast when using C# for the interop code). &lt;/p&gt;

&lt;p&gt;If you are a C# developer that writes _any_ interop code, you owe it to yourself to learn C++/CLI. Trust me, it will make your life much easier, and it's not that hard to learn. And being scared of pointers is no excuse. If you are comfortable with reference types in C#, you are probably more familiar with the concept of pointers than you realize. Plus, with STL and Boost (even more so with the upcoming TR1 work), there really is no need to have a pointer anywhere in your modern C++ program (ah, the sweetness that is the shared_ptr). &lt;/p&gt;

&lt;p&gt;So with the launch of Visual Studio 2008, I believe that the &amp;quot;right tool&amp;quot; for the &amp;quot;interop job&amp;quot; is C++/CLI for anything that is beyond trivial. Constructs and libraries like marshal_as&amp;lt;&amp;gt; and STL CLR only drive this point home more. You can feel free to continue to write thousands of lines of managed-code-copying-already-defined-in-header-files simply to p/invoke into an existing Windows API, but me? I will be using Visual C++ 2008 and enjoying every minute of it since I don't have to do any re-invention of the wheel.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=6473386" width="1" height="1"&gt;&lt;img alt="via softlogger.com" src="http://softlogger.com/postview.aspx?ArticleID=12636"&gt;</description><author>Jason Olson                                                                                         </author><pubDate>2007-11-22T00:00:00</pubDate><category>CSharp</category></item><item><title>Query syntax in VB</title><link>http://softlogger.com/11783/CSharp/query-syntax-in-vb.aspx</link><description>&lt;P&gt;One other feature I'm liking in VB is that you can omit the trailing select clause in a query.&lt;/P&gt;
&lt;P&gt;That is, you can simply say this:&lt;/P&gt;&lt;FONT color=#0000ff size=4&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;From&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;FONT size=4&gt; ch &lt;/FONT&gt;&lt;FONT color=#0000ff size=4&gt;In&lt;/FONT&gt;&lt;FONT size=4&gt; &lt;/FONT&gt;&lt;FONT color=#a31515 size=4&gt;"Hello"&lt;/FONT&gt;&lt;FONT size=4&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=4&gt;Where&lt;/FONT&gt;&lt;FONT size=4&gt; ch &amp;lt;&amp;gt; &lt;/FONT&gt;&lt;FONT color=#a31515 size=4&gt;"H"&lt;/FONT&gt;&lt;FONT size=4&gt; &lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;which in C# would look like this:&lt;/P&gt;&lt;FONT color=#0000ff size=4&gt;&lt;FONT color=#0000ff size=4&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;from&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;FONT color=#000000 size=4&gt; ch &lt;/FONT&gt;&lt;FONT color=#0000ff size=4&gt;in&lt;/FONT&gt;&lt;FONT color=#000000 size=4&gt; &lt;/FONT&gt;&lt;FONT color=#a31515 size=4&gt;"Hello"&lt;/FONT&gt;&lt;FONT color=#000000 size=4&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=4&gt;where&lt;/FONT&gt;&lt;FONT color=#000000 size=4&gt; ch&amp;nbsp;!= &lt;/FONT&gt;&lt;FONT color=#a31515 size=4&gt;'H'&lt;/FONT&gt;&lt;FONT color=#000000 size=4&gt;&amp;nbsp;&lt;STRONG&gt;&lt;FONT color=#0000ff&gt;select&lt;/FONT&gt;&lt;FONT color=#000000 size=4&gt; ch &lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;/FONT&gt;&lt;img src ="http://pluralsight.com/blogs/dbox/aggbug/49019.aspx" width = "1" height = "1" /&gt;&lt;img alt="via softlogger.com" src="http://softlogger.com/postview.aspx?ArticleID=11783"&gt;</description><author>Don Boxs Spoutlet</author><pubDate>2007-11-11T00:00:00</pubDate><category>CSharp</category></item><item><title>Creating dumps with Windbg and writing ADPlus Config files</title><link>http://softlogger.com/10613/CSharp/creating-dumps-with-windbg-and-writing-adplus-config-files.aspx</link><description>&lt;p&gt;My colleague Carlo just wrote a post on how to create dumps and how to configure ADPlus with config files, that I thought was really useful&lt;/p&gt; &lt;p&gt;&lt;a href="http://blogs.msdn.com/carloc/archive/2007/10/08/ok-now-how-do-i-capture-my-dump.aspx"&gt;http://blogs.msdn.com/carloc/archive/2007/10/08/ok-now-how-do-i-capture-my-dump.aspx&lt;/a&gt;&lt;/p&gt; &lt;p&gt;He also talks a little about DebugDiag, a tool for creating dumps and doing automated dump analysis for certain cases.&amp;nbsp; Btw, the dumps you generate with debug diag can be read in windbd and vice versa since the dump format is exactly the same.&lt;/p&gt; &lt;p&gt;Tess&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=5378687" width="1" height="1"&gt;&lt;img alt="via softlogger.com" src="http://softlogger.com/postview.aspx?ArticleID=10613"&gt;</description><author>If broken it is, fix it you should</author><pubDate>2007-10-09T00:00:00</pubDate><category>CSharp</category></item><item><title>Determining your Terminal Server Session ID from C#</title><link>http://softlogger.com/7511/CSharp/determining-your-terminal-server-session-id-from-c.aspx</link><description>I ran into an interesting .NET Remoting problem yesterday:&amp;nbsp; Users on Terminal Services were stomping on each other running an app with a "private" remoting server that hadn't taken into account the possibility that multiple user could be trying to run it simultaneously on the same computer.&lt;br&gt;&lt;br&gt;So the next question became: How do we uniquely identify separate instances on the same server?&amp;nbsp; The quick answer was username, but that would fail if a user had multiple terminal server sessions.&amp;nbsp; The better answer was to use the terminal server session id.&amp;nbsp; Here's a code sample to determine your session id:&lt;br&gt;&lt;br&gt;&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;\red0\green0\blue0;\red0\green0\blue255;\red0\green255\blue255;\red0\green255\blue0??;\red255\green0\blue255;\red255\green0\blue0;\red255\green255\blue0;\red255\green255\blue255;??\red0\green0\blue128;\red0\green128\blue128;\red0\green128\blue0;??\red128\green0\blue128;\red128\green0\blue0;\red128\green128\blue0;\red128\green128\blue128;??\red192\green192\blue192;}??\fs20         [\cf10 DllImport\cf0 (\cf13 "kernel32.dll"\cf0 )]\par ??        \cf2 static\cf0  \cf2 extern\cf0  \cf2 bool\cf0  ProcessIdToSessionId(\cf2 uint\cf0  dwProcessId, \cf2 out\cf0  \cf2 uint\cf0  pSessionId);\par ??\par ??        \cf2 static\cf0  \cf2 void\cf0  Main(\cf2 string\cf0 [] args)\par ??        \{\par ??            \cf10 Process\cf0  _currentProcess = \cf10 Process\cf0 .GetCurrentProcess();\par ??            \cf2 uint\cf0  _processID = (\cf2 uint\cf0 )_currentProcess.Id;\par ??            \cf2 uint\cf0  _sessionID;\par ??\par ??            \cf2 bool\cf0  _result = ProcessIdToSessionId(_processID, \cf2 out\cf0  _sessionID);\par ??\par ??            \cf10 Console\cf0 .WriteLine(\cf13 "ProcessIdToSessionId Result: "\cf0  + _result.ToString());\par ??            \cf10 Console\cf0 .WriteLine(\cf13 "Process ID = "\cf0  + _processID.ToString());\par ??            \cf10 Console\cf0 .WriteLine(\cf13 "Session ID = "\cf0  + _sessionID.ToString());\par ??\par ??            IPC(_sessionID.ToString());\par ??\par ??            \cf10 Console\cf0 .ReadLine();\par ??        \}}
--&gt; &lt;div style="font-size: 10pt; background: white 0% 50%; color: black; font-family: courier new; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial"&gt; &lt;p style="margin: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; [&lt;span style="color: teal"&gt;DllImport&lt;/span&gt;(&lt;span style="color: maroon"&gt;"kernel32.dll"&lt;/span&gt;)]&lt;/p&gt; &lt;p style="margin: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;static&lt;/span&gt; &lt;span style="color: blue"&gt;extern&lt;/span&gt; &lt;span style="color: blue"&gt;bool&lt;/span&gt; ProcessIdToSessionId(&lt;span style="color: blue"&gt;uint&lt;/span&gt; dwProcessId, &lt;span style="color: blue"&gt;out&lt;/span&gt; &lt;span style="color: blue"&gt;uint&lt;/span&gt; pSessionId);&lt;/p&gt; &lt;p style="margin: 0px"&gt;&amp;nbsp;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;static&lt;/span&gt; &lt;span style="color: blue"&gt;void&lt;/span&gt; Main(&lt;span style="color: blue"&gt;string&lt;/span&gt;[] args)&lt;/p&gt; &lt;p style="margin: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt; &lt;p style="margin: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: teal"&gt;Process&lt;/span&gt; _currentProcess = &lt;span style="color: teal"&gt;Process&lt;/span&gt;.GetCurrentProcess();&lt;/p&gt; &lt;p style="margin: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;uint&lt;/span&gt; _processID = (&lt;span style="color: blue"&gt;uint&lt;/span&gt;)_currentProcess.Id;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;uint&lt;/span&gt; _sessionID;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&amp;nbsp;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;bool&lt;/span&gt; _result = ProcessIdToSessionId(_processID, &lt;span style="color: blue"&gt;out&lt;/span&gt; _sessionID);&lt;/p&gt; &lt;p style="margin: 0px"&gt;&amp;nbsp;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: teal"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color: maroon"&gt;"ProcessIdToSessionId Result: "&lt;/span&gt; + _result.ToString());&lt;/p&gt; &lt;p style="margin: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: teal"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color: maroon"&gt;"Process ID = "&lt;/span&gt; + _processID.ToString());&lt;/p&gt; &lt;p style="margin: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: teal"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color: maroon"&gt;"Session ID = "&lt;/span&gt; + _sessionID.ToString());&lt;/p&gt; &lt;p style="margin: 0px"&gt;&amp;nbsp;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&amp;nbsp;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: teal"&gt;Console&lt;/span&gt;.ReadLine();&lt;/p&gt; &lt;p style="margin: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;/div&gt;&lt;br&gt;&lt;br&gt;Notes:&lt;br&gt; &lt;ol&gt; &lt;li&gt;On a standalone workstation the session id is zero (0).  &lt;li&gt;The console session on a server is also zero (0).&lt;br&gt;&lt;/li&gt;&lt;/ol&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=4768831" width="1" height="1"&gt;&lt;img alt="via softlogger.com" src="http://softlogger.com/postview.aspx?ArticleID=7511"&gt;</description><author>Scrappydog</author><pubDate>2007-09-05T00:00:00</pubDate><category>CSharp</category></item></channel></rss>