<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://weblogs.asp.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Omer van Kloeten's .NET Zen : How To</title><link>http://weblogs.asp.net/okloeten/archive/tags/How+To/default.aspx</link><description>Tags: How To</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><item><title>Circumventing the KB957543 .NET 3.5 SP1 Regression Bug</title><link>http://weblogs.asp.net/okloeten/archive/2009/01/29/6868393.aspx</link><pubDate>Thu, 29 Jan 2009 16:23:18 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6868393</guid><dc:creator>Omer van Kloeten</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/okloeten/rsscomments.aspx?PostID=6868393</wfw:commentRss><comments>http://weblogs.asp.net/okloeten/archive/2009/01/29/6868393.aspx#comments</comments><description>&lt;p&gt;A couple of days ago I hit a regression bug in .NET 3.5 SP1, in which when you have a generic class that implements ISerializable and has static variables – you can not serialize it using a BinaryFormatter without your application either hanging (x86) or raising an exception (x64 – a TargetInvocationException containing an OutOfMemoryException). This only happens if you use a reference type as a generic argument.&lt;/p&gt;  &lt;p&gt;It’s already &lt;a href="http://www.hanselman.com/blog/UpdateOnNETFramework35SP1AndWindowsUpdate.aspx"&gt;well known&lt;/a&gt;, but I have yet to find a workaround documented anywhere. You could simply install the &lt;a href="http://code.msdn.microsoft.com/KB957543"&gt;hotfix&lt;/a&gt;, but well, I wouldn’t if I were you – it hasn’t been thoroughly tested yet. Moreover, you might not even be able to do so due to either internal politics, strict IT rules or the fact that you simply do not have control over the hosting server.&lt;/p&gt;  &lt;p&gt;Let’s take the simplest class that causes the issue:&lt;/p&gt;  &lt;pre class="code"&gt;&lt;code&gt;[&lt;span style="color: #2b91af"&gt;Serializable&lt;/span&gt;]
&lt;span style="color: blue"&gt;public class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;MyClass&lt;/span&gt;&amp;lt;T&amp;gt; : &lt;span style="color: #2b91af"&gt;ISerializable
&lt;/span&gt;{
    &lt;span style="color: blue"&gt;private static int &lt;/span&gt;list = 0;

    &lt;span style="color: blue"&gt;public &lt;/span&gt;MyClass()
    {
    }

    &lt;span style="color: blue"&gt;protected &lt;/span&gt;MyClass(&lt;span style="color: #2b91af"&gt;SerializationInfo &lt;/span&gt;info, &lt;span style="color: #2b91af"&gt;StreamingContext &lt;/span&gt;context)
    {
    }

    &lt;span style="color: blue"&gt;void &lt;/span&gt;&lt;span style="color: #2b91af"&gt;ISerializable&lt;/span&gt;.GetObjectData(&lt;span style="color: #2b91af"&gt;SerializationInfo &lt;/span&gt;info, &lt;span style="color: #2b91af"&gt;StreamingContext &lt;/span&gt;context)
    {
    }
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;When using the class as such:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;code&gt;&lt;span style="color: blue"&gt;using &lt;/span&gt;(&lt;span style="color: #2b91af"&gt;MemoryStream &lt;/span&gt;stream = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;MemoryStream&lt;/span&gt;())
{
    &lt;span style="color: #2b91af"&gt;BinaryFormatter &lt;/span&gt;formatter = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;BinaryFormatter&lt;/span&gt;();
    formatter.Serialize(stream, &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;MyClass&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;string&lt;/span&gt;&amp;gt;());
    stream.Position = 0;
    &lt;span style="color: #2b91af"&gt;MyClass&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;string&lt;/span&gt;&amp;gt; item = (&lt;span style="color: #2b91af"&gt;MyClass&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;string&lt;/span&gt;&amp;gt;)formatter.Deserialize(stream);
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The last line will hit the bug.&lt;/p&gt;

&lt;p&gt;To work around this issue, simply move your static variables into a new subclass:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;code&gt;[&lt;span style="color: #2b91af"&gt;Serializable&lt;/span&gt;]
&lt;span style="color: blue"&gt;public class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;MyClass&lt;/span&gt;&amp;lt;T&amp;gt; : &lt;span style="color: #2b91af"&gt;ISerializable
&lt;/span&gt;{
    &lt;span style="color: blue"&gt;private static class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;KB957543
    &lt;/span&gt;{
        &lt;span style="color: blue"&gt;public static int &lt;/span&gt;list = 0;
    }

    &lt;span style="color: blue"&gt;public &lt;/span&gt;MyClass()
    {
    }

    &lt;span style="color: blue"&gt;protected &lt;/span&gt;MyClass(&lt;span style="color: #2b91af"&gt;SerializationInfo &lt;/span&gt;info, &lt;span style="color: #2b91af"&gt;StreamingContext &lt;/span&gt;context)
    {
    }

    &lt;span style="color: blue"&gt;void &lt;/span&gt;&lt;span style="color: #2b91af"&gt;ISerializable&lt;/span&gt;.GetObjectData(&lt;span style="color: #2b91af"&gt;SerializationInfo &lt;/span&gt;info, &lt;span style="color: #2b91af"&gt;StreamingContext &lt;/span&gt;context)
    {
    }
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;You can still access all of your static variables and you don’t hit the bug.&lt;/p&gt;

&lt;p&gt;Note that when you use anonymous methods or lambdas, they are cached as static variables of the type, meaning that you will have to manually type all of your lambdas.&lt;/p&gt;

&lt;p&gt;Here’s an example of such a type that is prone to the bug:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;code&gt;[&lt;span style="color: #2b91af"&gt;Serializable&lt;/span&gt;]
&lt;span style="color: blue"&gt;public class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;MyClass&lt;/span&gt;&amp;lt;T&amp;gt; : &lt;span style="color: #2b91af"&gt;ISerializable
&lt;/span&gt;{
    &lt;span style="color: blue"&gt;public &lt;/span&gt;MyClass()
    {
    }

    &lt;span style="color: blue"&gt;public static string &lt;/span&gt;Concat(&lt;span style="color: #2b91af"&gt;IEnumerable&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;int&lt;/span&gt;&amp;gt; numbers)
    {
        &lt;span style="color: blue"&gt;return string&lt;/span&gt;.Join(&lt;span style="color: #a31515"&gt;&amp;quot;, &amp;quot;&lt;/span&gt;, numbers.Select(i =&amp;gt; i.ToString()).ToArray());
    }

    &lt;span style="color: blue"&gt;protected &lt;/span&gt;MyClass(&lt;span style="color: #2b91af"&gt;SerializationInfo &lt;/span&gt;info, &lt;span style="color: #2b91af"&gt;StreamingContext &lt;/span&gt;context)
    {
    }

    &lt;span style="color: blue"&gt;void &lt;/span&gt;&lt;span style="color: #2b91af"&gt;ISerializable&lt;/span&gt;.GetObjectData(&lt;span style="color: #2b91af"&gt;SerializationInfo &lt;/span&gt;info, &lt;span style="color: #2b91af"&gt;StreamingContext &lt;/span&gt;context)
    {
    }
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;If we look through Reflector, we can see that there is a cached delegate in our type:&lt;/p&gt;

&lt;p&gt;&lt;img title="" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="186" alt="" src="http://weblogs.asp.net/blogs/okloeten/image_292AD855.png" width="589" border="0" /&gt; &lt;/p&gt;

&lt;p&gt;Since this is a static member, it makes the type susceptible to the bug and we now need to manually create the cached member ourselves:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;code&gt;[&lt;span style="color: #2b91af"&gt;Serializable&lt;/span&gt;]
&lt;span style="color: blue"&gt;public class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;MyClass&lt;/span&gt;&amp;lt;T&amp;gt; : &lt;span style="color: #2b91af"&gt;ISerializable
&lt;/span&gt;{
    &lt;span style="color: blue"&gt;private static class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;KB957543
    &lt;/span&gt;{
        &lt;span style="color: blue"&gt;public static readonly &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Func&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;int&lt;/span&gt;, &lt;span style="color: blue"&gt;string&lt;/span&gt;&amp;gt; ToString = i =&amp;gt; i.ToString();
    }

    &lt;span style="color: blue"&gt;public &lt;/span&gt;MyClass()
    {
    }

    &lt;span style="color: blue"&gt;public static string &lt;/span&gt;Concat(&lt;span style="color: #2b91af"&gt;IEnumerable&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;int&lt;/span&gt;&amp;gt; numbers)
    {
        &lt;span style="color: blue"&gt;return string&lt;/span&gt;.Join(&lt;span style="color: #a31515"&gt;&amp;quot;, &amp;quot;&lt;/span&gt;, numbers.Select(&lt;span style="color: #2b91af"&gt;KB957543&lt;/span&gt;.ToString).ToArray());
    }

    &lt;span style="color: blue"&gt;protected &lt;/span&gt;MyClass(&lt;span style="color: #2b91af"&gt;SerializationInfo &lt;/span&gt;info, &lt;span style="color: #2b91af"&gt;StreamingContext &lt;/span&gt;context)
    {
    }

    &lt;span style="color: blue"&gt;void &lt;/span&gt;&lt;span style="color: #2b91af"&gt;ISerializable&lt;/span&gt;.GetObjectData(&lt;span style="color: #2b91af"&gt;SerializationInfo &lt;/span&gt;info, &lt;span style="color: #2b91af"&gt;StreamingContext &lt;/span&gt;context)
    {
    }
}&lt;/code&gt;&lt;/pre&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6868393" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/okloeten/archive/tags/How+To/default.aspx">How To</category><category domain="http://weblogs.asp.net/okloeten/archive/tags/Advices/default.aspx">Advices</category><category domain="http://weblogs.asp.net/okloeten/archive/tags/.NET/default.aspx">.NET</category></item><item><title>Your Mouth Says Windows-1255, But Your Eyes Say ISO-8859-1</title><link>http://weblogs.asp.net/okloeten/archive/2008/12/18/6795056.aspx</link><pubDate>Thu, 18 Dec 2008 16:45:34 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6795056</guid><dc:creator>Omer van Kloeten</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/okloeten/rsscomments.aspx?PostID=6795056</wfw:commentRss><comments>http://weblogs.asp.net/okloeten/archive/2008/12/18/6795056.aspx#comments</comments><description>&lt;h4&gt;I recently wrote an engine that gets XML files stored at our clients’ servers using HTTP requests. One of our clients decided to serve the XML file with one encoding and encode the file itself with another. This posed a problem to XDocument.&lt;/h4&gt;  &lt;p&gt;The client decided to encode their XML using the Windows-1255 encoding (Hebrew), noting the encoding correctly in the XML’s declaration, but served the file stating the ISO-8859-1 (Latin) encoding. This meant that I couldn’t just use &lt;em&gt;XDocument&lt;/em&gt;’s normal &lt;em&gt;Load&lt;/em&gt; method to load directly from the stream because &lt;strong&gt;XDocument looks at the HTTP headers and takes the document’s encoding from them&lt;/strong&gt;.&lt;/p&gt;  &lt;p&gt;Here’s a snippet of the code I used to get over that:&lt;/p&gt;  &lt;pre class="code"&gt;&lt;code&gt;&lt;span style="color: blue"&gt;using &lt;/span&gt;(&lt;span style="color: #2b91af"&gt;HttpWebResponse &lt;/span&gt;response = (&lt;span style="color: #2b91af"&gt;HttpWebResponse&lt;/span&gt;)request.GetResponse())
{
    &lt;span style="color: green"&gt;// Use response's charset.
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;encoding = &lt;span style="color: #2b91af"&gt;Encoding&lt;/span&gt;.GetEncoding(&lt;span style="color: #a31515"&gt;&amp;quot;ISO-8859-1&amp;quot;&lt;/span&gt;);

    &lt;span style="color: blue"&gt;if &lt;/span&gt;(!&lt;span style="color: blue"&gt;string&lt;/span&gt;.IsNullOrEmpty(response.CharacterSet))
        encoding = &lt;span style="color: #2b91af"&gt;Encoding&lt;/span&gt;.GetEncoding(response.CharacterSet);

    &lt;span style="color: blue"&gt;byte&lt;/span&gt;[] bytes = ReadStream(response.GetResponseStream());

    &lt;span style="color: green"&gt;// Get the XML with the response's charset.
    &lt;/span&gt;&lt;span style="color: blue"&gt;string &lt;/span&gt;xml = &lt;span style="color: blue"&gt;new string&lt;/span&gt;(encoding.GetChars(bytes));
    &lt;span style="color: blue"&gt;int &lt;/span&gt;endOfDeclaration = xml.IndexOf(&lt;span style="color: #a31515"&gt;&amp;quot;?&amp;gt;&amp;quot;&lt;/span&gt;);

    &lt;span style="color: blue"&gt;if &lt;/span&gt;(endOfDeclaration != -1)
    {
        &lt;span style="color: green"&gt;// Try to find out the encoding from the declaration.
        &lt;/span&gt;&lt;span style="color: blue"&gt;string &lt;/span&gt;decl = xml.Substring(0, endOfDeclaration + 2) + &lt;span style="color: #a31515"&gt;&amp;quot;&amp;lt;duperoot /&amp;gt;&amp;quot;&lt;/span&gt;;
        &lt;span style="color: #2b91af"&gt;XDocument &lt;/span&gt;declDoc = &lt;span style="color: #2b91af"&gt;XDocument&lt;/span&gt;.Parse(decl);
        &lt;span style="color: blue"&gt;var &lt;/span&gt;docEncoding = &lt;span style="color: #2b91af"&gt;Encoding&lt;/span&gt;.GetEncoding(declDoc.Declaration.Encoding);

        &lt;span style="color: blue"&gt;if &lt;/span&gt;(docEncoding == encoding)
            &lt;span style="color: blue"&gt;return &lt;/span&gt;xml;
        &lt;span style="color: blue"&gt;else
            return new string&lt;/span&gt;(docEncoding.GetChars(bytes));
    }
    &lt;span style="color: blue"&gt;else
    &lt;/span&gt;{
        &lt;span style="color: green"&gt;// Not XML or something... Send up.
&lt;/span&gt;    }
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;What I did here was to create a new document with the original XML’s declaration (the Latin characters which make up the XML’s declaration always have the same byte position), add a dupe root and parse that to get the name of the encoding used by the document. I then use that encoding to decode the document correctly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note &lt;/strong&gt;that I’m using ISO-8859-1 as the default response’s encoding, since that is what HTTP’s specification demands.&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6795056" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/okloeten/archive/tags/How+To/default.aspx">How To</category></item><item><title>Did You Know? Type Member Lookup by Prefix</title><link>http://weblogs.asp.net/okloeten/archive/2007/12/16/5460771.aspx</link><pubDate>Sun, 16 Dec 2007 06:51:21 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:5460771</guid><dc:creator>Omer van Kloeten</dc:creator><slash:comments>4</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/okloeten/rsscomments.aspx?PostID=5460771</wfw:commentRss><comments>http://weblogs.asp.net/okloeten/archive/2007/12/16/5460771.aspx#comments</comments><description>&lt;p&gt;You can look up for prefixed members, using reflection, by placing an asterisk after the prefix:&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color: rgb(43,145,175)"&gt;MemberInfo&lt;/span&gt;[] members = &lt;span style="color: rgb(0,0,255)"&gt;typeof&lt;/span&gt;(&lt;span style="color: rgb(43,145,175)"&gt;A&lt;/span&gt;).GetMember(&lt;span style="color: rgb(163,21,21)"&gt;&lt;strong&gt;&lt;em&gt;"hidden*"&lt;/em&gt;&lt;/strong&gt;&lt;/span&gt;, 
    &lt;span style="color: rgb(43,145,175)"&gt;BindingFlags&lt;/span&gt;.NonPublic | &lt;span style="color: rgb(43,145,175)"&gt;BindingFlags&lt;/span&gt;.Instance);

&lt;span style="color: rgb(0,128,0)"&gt;// members now contains three members: hiddenFlag1, hiddenFlag2 and hiddenMethod
&lt;/span&gt;
&lt;span style="color: rgb(0,128,0)"&gt;// ...&lt;/span&gt;

&lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;class&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;A
&lt;/span&gt;{
    &lt;span style="color: rgb(0,0,255)"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;bool&lt;/span&gt; hiddenFlag1;
    &lt;span style="color: rgb(0,0,255)"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;bool&lt;/span&gt; hiddenFlag2;

    &lt;span style="color: rgb(0,0,255)"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;void&lt;/span&gt; hiddenMethod()
    {
    }

    &lt;span style="color: rgb(0,0,255)"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;void&lt;/span&gt; reallyHiddenMethod()
    {
    }
}&lt;/pre&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=5460771" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/okloeten/archive/tags/How+To/default.aspx">How To</category></item><item><title>Registering to a DependencyProperty's Change Event</title><link>http://weblogs.asp.net/okloeten/archive/2007/09/18/3940922.aspx</link><pubDate>Tue, 18 Sep 2007 12:19:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:3940922</guid><dc:creator>Omer van Kloeten</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/okloeten/rsscomments.aspx?PostID=3940922</wfw:commentRss><comments>http://weblogs.asp.net/okloeten/archive/2007/09/18/3940922.aspx#comments</comments><description>
&lt;p&gt;&lt;span class="post-author vcard"&gt;&lt;span class="fn"&gt;Sebastien Lambla wrote a cool post about &lt;/span&gt;&lt;/span&gt;&lt;a href="http://serialseb.blogspot.com/2007/08/wpf-tips-5-receive-notifications-for.html" target="_blank" mce_href="http://serialseb.blogspot.com/2007/08/wpf-tips-5-receive-notifications-for.html"&gt;how to correctly get notifications for the changes in dependency property values&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In a nutshell:&lt;/p&gt;

&lt;pre&gt;DependencyPropertyDescriptor prop = DependencyPropertyDescriptor.FromProperty(&lt;br&gt;    MyType.MyDependencyProperty,&lt;br&gt;    &lt;font color="blue"&gt;typeof&lt;/font&gt;(MyType));&lt;br&gt;&lt;br&gt;prop.AddValueChanged(&lt;font color="blue"&gt;this&lt;/font&gt;, &lt;font color="blue"&gt;this&lt;/font&gt;.OnMyDependencyPropertyChanged);&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=3940922" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/okloeten/archive/tags/How+To/default.aspx">How To</category><category domain="http://weblogs.asp.net/okloeten/archive/tags/WPF/default.aspx">WPF</category></item><item><title>How To Create a Really Accurate Timer</title><link>http://weblogs.asp.net/okloeten/archive/2007/05/08/2521930.aspx</link><pubDate>Tue, 08 May 2007 13:01:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:2521930</guid><dc:creator>Omer van Kloeten</dc:creator><slash:comments>5</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/okloeten/rsscomments.aspx?PostID=2521930</wfw:commentRss><comments>http://weblogs.asp.net/okloeten/archive/2007/05/08/2521930.aspx#comments</comments><description>&lt;p&gt;Some of the work on my current project requires accurately timing events, at a frequency of a few dozen per second (that means that each event has to follow the previous one within a few milliseconds). The resolution of those calls is so small, that even System.Threading.Timer can not handle it and lags behind.&lt;/p&gt;&lt;p&gt;After some searching, I found that &lt;strong&gt;Win32 Multimedia Timers&lt;/strong&gt; are a good solution to this problem, as they are (probably) the timers with the highest resolution available on the platform. At the moment, there is no official wrapper for the API in the Framework and &lt;a href="http://www.codeproject.com/script/Articles/list_articles.asp?userid=44266"&gt;Leslie Sanford&amp;#39;s article&lt;/a&gt; offers a nice implementation.&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=2521930" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/okloeten/archive/tags/How+To/default.aspx">How To</category></item><item><title>Save User Details For Team Explorer</title><link>http://weblogs.asp.net/okloeten/archive/2007/01/21/1445108.aspx</link><pubDate>Sun, 21 Jan 2007 13:55:44 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:1445108</guid><dc:creator>Omer van Kloeten</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/okloeten/rsscomments.aspx?PostID=1445108</wfw:commentRss><comments>http://weblogs.asp.net/okloeten/archive/2007/01/21/1445108.aspx#comments</comments><description>&lt;p&gt;&lt;/p&gt; &lt;p&gt;Since I've started working with CodePlex, Team System failed to even remember my username whenever I started Visual Studio. After digging a bit, I found the answer.&lt;/p&gt; &lt;ol&gt; &lt;li&gt;Start the &lt;strong&gt;Stored User Names and Passwords&lt;/strong&gt; control panel: &lt;em&gt;rundll32 keymgr.dll,KRShowKeyMgr&lt;/em&gt;&lt;/li&gt; &lt;li&gt;Add a new server (for CodePlex, it's &lt;em&gt;tfs01.codeplex.com&lt;/em&gt;), then type your username and password.&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;Now the username will appear in the list.&lt;/p&gt; &lt;p&gt;I'm still looking for a way to save the password too.&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=1445108" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/okloeten/archive/tags/How+To/default.aspx">How To</category><category domain="http://weblogs.asp.net/okloeten/archive/tags/Advices/default.aspx">Advices</category><category domain="http://weblogs.asp.net/okloeten/archive/tags/Community/default.aspx">Community</category></item><item><title>Quick Blurb - Generic Types</title><link>http://weblogs.asp.net/okloeten/archive/2004/10/07/239397.aspx</link><pubDate>Thu, 07 Oct 2004 20:17:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:239397</guid><dc:creator>Omer van Kloeten</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/okloeten/rsscomments.aspx?PostID=239397</wfw:commentRss><comments>http://weblogs.asp.net/okloeten/archive/2004/10/07/239397.aspx#comments</comments><description>&lt;p&gt;Just a quickie that's been bothering me:&lt;/p&gt;&lt;p&gt;The types MyType and MyType&amp;lt;T&amp;gt; are not the same type, as you might already know. Also, MyType&amp;lt;int&amp;gt; and MyType&amp;lt;string&amp;gt; are not of the same type. So, how do I find out if MyType&amp;lt;int&amp;gt; and MyType&amp;lt;string&amp;gt; are from the same MyType&amp;lt;T&amp;gt;?&lt;/p&gt;&lt;p&gt;I will use the Type.GetGenericTypeDefinition() method like so:&lt;/p&gt;&lt;pre&gt;MyType&amp;lt;int&amp;gt; i, MyType&amp;lt;string&amp;gt; s;&lt;br /&gt;bool b = s.GetType().GetGenericTypeDefinition() == i.GetType().GetGenericTypeDefinition();&lt;/pre&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Cool.&lt;/p&gt; &lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=239397" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/okloeten/archive/tags/How+To/default.aspx">How To</category></item><item><title>Storing Application Configuration</title><link>http://weblogs.asp.net/okloeten/archive/2004/06/28/168073.aspx</link><pubDate>Mon, 28 Jun 2004 20:40:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:168073</guid><dc:creator>Omer van Kloeten</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/okloeten/rsscomments.aspx?PostID=168073</wfw:commentRss><comments>http://weblogs.asp.net/okloeten/archive/2004/06/28/168073.aspx#comments</comments><description>&lt;p&gt;&lt;a href="http://haacked.com/"&gt;Phil Haack&lt;/a&gt;'s words &lt;a href="http://haacked.com/archive/2004/06/28/699.aspx"&gt;"Do not store user settings in an application configuration file!"&lt;/a&gt; reminded me of something I made a while back, in order to store user settings in an application. I used the &lt;a href="http://spaz.ice.org/code/ObjectModelGenerator/"&gt;Object Model Generator&lt;/a&gt; to create an object oriented representation of my configuration and wrote a wrapper for it to load from, and persist back to, an Xml based format.&lt;br /&gt;
Here's some code for you:&lt;/p&gt;
&lt;p&gt;&lt;pre&gt;&lt;font color="blue"&gt;using&lt;/font&gt; System;
&lt;font color="blue"&gt;using&lt;/font&gt; System.IO;
&lt;font color="blue"&gt;using&lt;/font&gt; System.IO.IsolatedStorage;

&lt;font color="blue"&gt;namespace&lt;/font&gt; Utilities.Configuration
{
	&lt;font color="blue"&gt;public class&lt;/font&gt; ConfigurationFile
	{
		&lt;font color="blue"&gt;private static&lt;/font&gt; IsolatedStorageFile m_IsolatedStorage = &lt;font color="blue"&gt;null&lt;/font&gt;;
		&lt;font color="blue"&gt;private static&lt;/font&gt; ConfigurationElement m_Element = &lt;font color="blue"&gt;null&lt;/font&gt;;

		&lt;font color="green"&gt;// This is the name of the configuration file I will use in isolated storage.&lt;/font&gt;
		&lt;font color="blue"&gt;private const string&lt;/font&gt; ConfigurationFileName = "configuration.xml";

		&lt;font color="green"&gt;// This class can not be inherited.&lt;/font&gt;
		&lt;font color="blue"&gt;private&lt;/font&gt; ConfigurationFile()
		{
		}

		&lt;font color="green"&gt;// The static constructor loads the file and creates the document object
		// model out of it, then stores it in memory for manipulations.&lt;/font&gt;
		&lt;font color="blue"&gt;static&lt;/font&gt; ConfigurationFile()
		{
			&lt;font color="green"&gt;// Load the configuration file's contents.&lt;/font&gt;
			&lt;font color="blue"&gt;string&lt;/font&gt; configurationFile = LoadConfigurationFile();

			&lt;font color="blue"&gt;if&lt;/font&gt; (configurationFile != &lt;font color="blue"&gt;null&lt;/font&gt;)
			{
				&lt;font color="green"&gt;// If the configuration file existed, create the object grid from it.&lt;/font&gt;
				ConfigurationDocument document = new ConfigurationDocument();
				document.LoadXml(configurationFile);
				m_Element = document.CreateDOM();
			}
			&lt;font color="blue"&gt;else&lt;/font&gt;
			{
				&lt;font color="green"&gt;// If the configuration file has not been found,
				// create a new object grid.&lt;/font&gt;
				m_Element = new ConfigurationElement();
			}
		}

		&lt;font color="green"&gt;// Using this property, we can access the configuration settings.&lt;/font&gt;
		&lt;font color="blue"&gt;public static&lt;/font&gt; ConfigurationElement DOM
		{
			&lt;font color="blue"&gt;get&lt;/font&gt;
			{
				&lt;font color="blue"&gt;return&lt;/font&gt; m_Element;
			}
		}

		&lt;font color="green"&gt;// This method is called when the application is closed,
		// causing it to commit all the changes made to the object
		// grid back to the configuration file in the isolated storage.&lt;/font&gt;
		&lt;font color="blue"&gt;public static void&lt;/font&gt; Close()
		{
			&lt;font color="green"&gt;// Save the configuration file.&lt;/font&gt;
			SaveConfigurationFile(ConfigurationDocument.FromDOM(m_Element).OuterXml);

			&lt;font color="green"&gt;// Dispose of the isolates storage file.&lt;/font&gt;
			&lt;font color="blue"&gt;if&lt;/font&gt; (m_IsolatedStorage != &lt;font color="blue"&gt;null&lt;/font&gt;)
			{
				m_IsolatedStorage.Dispose();
			}
		}

		&lt;font color="blue"&gt;private static string&lt;/font&gt; LoadConfigurationFile()
		{
			&lt;font color="blue"&gt;if&lt;/font&gt; (m_IsolatedStorage == &lt;font color="blue"&gt;null&lt;/font&gt;)
			{
				&lt;font color="green"&gt;// This gets storage isolated for this user using this application.&lt;/font&gt;
				m_IsolatedStorage = IsolatedStorageFile.GetUserStoreForAssembly();
			}

			&lt;font color="green"&gt;// This looks for the file. If it is found,
			// it reads its contents and returns that.&lt;/font&gt;
			&lt;font color="blue"&gt;if&lt;/font&gt; (m_IsolatedStorage.GetFileNames(ConfigurationFileName).Length == 1)
			{
				&lt;font color="blue"&gt;using&lt;/font&gt; (StreamReader sr = new StreamReader(new IsolatedStorageFileStream(ConfigurationFileName, FileMode.Open, FileAccess.Read, FileShare.Read, m_IsolatedStorage)))
				{
					&lt;font color="blue"&gt;return&lt;/font&gt; sr.ReadToEnd();
				}
			}
			&lt;font color="blue"&gt;else&lt;/font&gt;
			{
				&lt;font color="blue"&gt;return null&lt;/font&gt;;
			}
		}

		&lt;font color="blue"&gt;private static void&lt;/font&gt; SaveConfigurationFile(&lt;font color="blue"&gt;string&lt;/font&gt; fileData)
		{
			&lt;font color="green"&gt;// Store the data to its original file location.&lt;/font&gt;
			&lt;font color="blue"&gt;using&lt;/font&gt; (StreamWriter sw = new StreamWriter(new IsolatedStorageFileStream(ConfigurationFileName, FileMode.Create, FileAccess.Write, FileShare.None, m_IsolatedStorage)))
			{
				sw.Write(fileData);
			}
		}
	}
}&lt;/pre&gt;&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=168073" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/okloeten/archive/tags/How+To/default.aspx">How To</category><category domain="http://weblogs.asp.net/okloeten/archive/tags/Advices/default.aspx">Advices</category></item><item><title>True Autosizable Label, part II</title><link>http://weblogs.asp.net/okloeten/archive/2004/06/13/154659.aspx</link><pubDate>Sun, 13 Jun 2004 16:49:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:154659</guid><dc:creator>Omer van Kloeten</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/okloeten/rsscomments.aspx?PostID=154659</wfw:commentRss><comments>http://weblogs.asp.net/okloeten/archive/2004/06/13/154659.aspx#comments</comments><description>&lt;p&gt;A while back, I &lt;a href="http://weblogs.asp.net/okloeten/archive/2004/03/30/103384.aspx"&gt;wrote&lt;/a&gt; about the Windows Forms Label not autosizing in the vertical sense as well as the horizontal sense. I added some code that would add that ability to the Label class.&lt;/p&gt;
&lt;p&gt;Today I received a &lt;a href="http://weblogs.asp.net/okloeten/archive/2004/03/30/103384.aspx#154634"&gt;comment&lt;/a&gt; from Chris Hockenberry telling me my code isn't Compact Framework compatible. I originally didn't mean for it to be CF-compatible, but Chris even went and added some code in the comment! Too cool :)&lt;/p&gt;
&lt;p&gt;Go and check out his &lt;a href="http://weblogs.asp.net/okloeten/archive/2004/03/30/103384.aspx#154634"&gt;code&lt;/a&gt; if you need this ability in your application.&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=154659" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/okloeten/archive/tags/How+To/default.aspx">How To</category></item><item><title>How To: Debug Into File References -- Correction</title><link>http://weblogs.asp.net/okloeten/archive/2004/02/05/68121.aspx</link><pubDate>Thu, 05 Feb 2004 18:15:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:68121</guid><dc:creator>Omer van Kloeten</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/okloeten/rsscomments.aspx?PostID=68121</wfw:commentRss><comments>http://weblogs.asp.net/okloeten/archive/2004/02/05/68121.aspx#comments</comments><description>&lt;p&gt;Quite a while ago, I posted a way to &lt;a href="http://weblogs.asp.net/okloeten/archive/2003/11/03/35418.aspx"&gt;debug into file references&lt;/a&gt; when you have the source code. At the time, we believed it to be the only way, even though it did not work at all times. However, I have found an easier way to do just that:&lt;/p&gt;&lt;p&gt;&lt;ol&gt;&lt;li&gt;While debugging, break and open the Modules pane (Ctrl+Alt+U).&lt;/li&gt;&lt;li&gt;Right click your Assembly and select "Reload Symbols".&lt;/li&gt;&lt;li&gt;Select the PDB file for your assembly.&lt;/li&gt;&lt;li&gt;Step into the code.&lt;/ol&gt;&lt;/p&gt;&lt;p&gt;Easy, isn't it?&lt;br/&gt;You can also reload the symbols from the Call Stack window, when selecting any method from the Assembly you wish to debug.&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=68121" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/okloeten/archive/tags/How+To/default.aspx">How To</category></item><item><title>How To: Debug Into File References</title><link>http://weblogs.asp.net/okloeten/archive/2003/11/03/35418.aspx</link><pubDate>Mon, 03 Nov 2003 06:44:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:35418</guid><dc:creator>Omer van Kloeten</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/okloeten/rsscomments.aspx?PostID=35418</wfw:commentRss><comments>http://weblogs.asp.net/okloeten/archive/2003/11/03/35418.aspx#comments</comments><description>&lt;p&gt;It's annoying to have a DLL in Debug mode that you had another team make and give you their source with it, but not be able to debug into it without adding the source project to your solution and using a Project Reference.&lt;br /&gt;
Who said you couldn't?&lt;/p&gt;

&lt;p&gt;AmiD has come up with a simple way that allows you to debug into the source of file references:
&lt;ol&gt;
&lt;li&gt;Take the PDB file that was created in your bin\Debug directory and place it in the same directory as the compiled Assembly (if it's in the GAC, you'll have to place it in the same directory as the version that is in the GAC; usually %WINDIR%\assembly\GAC\%Assembly Name%\%Version%).&lt;/li&gt;
&lt;li&gt;Take the solution referencing the Assembly file and delete its .SUO file. This file saves Visual Studio.NET's configuration (Breakpoints, Open Document Windows, etc.).&lt;/li&gt;
&lt;li&gt;Go to where you want to Debug Into (F11) the Assembly, press F11 and a dialog would appear asking you where the source files are. This selection can only be made once (unless you re-delete the SUO file).&lt;/li&gt;&lt;/ol&gt;&lt;/p&gt;

&lt;p&gt;This allows you to Debug into File References, provided you have the source files.&lt;/p&gt;

&lt;TABLE style="MARGIN: auto" cellSpacing=0 border=0 cellpading="0"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;Hack Value: &lt;/TD&gt;
&lt;TD&gt;[&lt;/TD&gt;&lt;TD&gt;X&lt;/TD&gt;&lt;TD&gt;X&lt;/TD&gt;&lt;TD&gt;X&lt;/TD&gt;&lt;TD&gt;X&lt;/TD&gt;&lt;TD&gt;-&lt;/TD&gt;&lt;TD&gt;]&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Cool Value: &lt;/TD&gt;
&lt;TD&gt;[&lt;/TD&gt;&lt;TD&gt;X&lt;/TD&gt;&lt;TD&gt;X&lt;/TD&gt;&lt;TD&gt;X&lt;/TD&gt;&lt;TD&gt;-&lt;/TD&gt;&lt;TD&gt;-&lt;/TD&gt;&lt;TD&gt;]&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Usable Value: &lt;/TD&gt;
&lt;TD&gt;[&lt;/TD&gt;&lt;TD&gt;X&lt;/TD&gt;&lt;TD&gt;X&lt;/TD&gt;&lt;TD&gt;X&lt;/TD&gt;&lt;TD&gt;X&lt;/TD&gt;&lt;TD&gt;X&lt;/TD&gt;&lt;TD&gt;]&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=35418" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/okloeten/archive/tags/How+To/default.aspx">How To</category></item><item><title>How To: Create a Component Conscious UITypeEditor</title><link>http://weblogs.asp.net/okloeten/archive/2003/10/31/35028.aspx</link><pubDate>Fri, 31 Oct 2003 19:24:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:35028</guid><dc:creator>Omer van Kloeten</dc:creator><slash:comments>6</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/okloeten/rsscomments.aspx?PostID=35028</wfw:commentRss><comments>http://weblogs.asp.net/okloeten/archive/2003/10/31/35028.aspx#comments</comments><description>&lt;p&gt;Many a time do I find Design-Time support in Visual Studio.NET to be a no-man's land, be it because no one in my surroundings knows how to do something I have to do and I have to resort to an hour or more of internet research, at times in vain, or be it because I have to look into and touch Microsoft's internal/private classes.&lt;/p&gt;
&lt;p&gt;This time I encountered a problem which required me to create a UITypeEditor that is on an Extender Provider's provided property. Easy enough, but it doesn't stop at that. I had to use reflection to scan the component this provided property was applied to, to find all public boolean properties with get/set accessors. Now we're in that no-man's land I was talking about earlier.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Point of Interest:&lt;/b&gt; If you want to apply Design-Time support attributes to properties supplied by an Extender Provider, you must apply them to both the Get and Set methods you create.&lt;/p&gt;
&lt;p&gt;The following is the solution to this problem. I tried documenting it as best I can:
&lt;pre style="font-size: 0.7em"&gt;&lt;font color="blue"&gt;using&lt;/font&gt; System;
&lt;font color="blue"&gt;using&lt;/font&gt; System.ComponentModel;
&lt;font color="blue"&gt;using&lt;/font&gt; System.Globalization;
&lt;font color="blue"&gt;using&lt;/font&gt; System.Collections;
&lt;font color="blue"&gt;using&lt;/font&gt; System.Drawing.Design;
&lt;font color="blue"&gt;using&lt;/font&gt; System.Windows.Forms;
&lt;font color="blue"&gt;using&lt;/font&gt; System.Windows.Forms.Design;
&lt;font color="blue"&gt;using&lt;/font&gt; System.Reflection;

&lt;font color="darkgray"&gt;///&lt;/font&gt;&lt;font color="green"&gt; &lt;font color="darkgray"&gt;&amp;lt;summary&amp;gt;&lt;/font&gt;
&lt;font color="darkgray"&gt;///&lt;/font&gt; Written by Omer van Kloeten. All rights reserved.
&lt;font color="darkgray"&gt;///&lt;/font&gt; &lt;font color="darkgray"&gt;&amp;lt;/summary&amp;gt;&lt;/font&gt;&lt;/font&gt;
&lt;font color="blue"&gt;namespace&lt;/font&gt; HowTo
{
    &lt;font color="darkgray"&gt;///&lt;/font&gt;&lt;font color="green"&gt; &lt;font color="darkgray"&gt;&amp;lt;summary&amp;gt;&lt;/font&gt;&lt;/font&gt;
    &lt;font color="darkgray"&gt;///&lt;/font&gt;&lt;font color="green"&gt; Provides a user interface for selecting a state property.&lt;/font&gt;
    &lt;font color="darkgray"&gt;///&lt;/font&gt;&lt;font color="green"&gt; &lt;font color="darkgray"&gt;&amp;lt;/summary&amp;gt;&lt;/font&gt;&lt;/font&gt;
    &lt;font color="blue"&gt;public&lt;/font&gt; &lt;font color="blue"&gt;class&lt;/font&gt; ConsciousTypeEditor : UITypeEditor
    {
        &lt;font color="green"&gt;// This class is the list that will pop up when we click
        // on the down arrow of the mock-combo box in the designer.&lt;/font&gt;
        &lt;font color="blue"&gt;private&lt;/font&gt; &lt;font color="blue"&gt;class&lt;/font&gt; PropertiesList : ListBox
        {
            &lt;font color="blue"&gt;public&lt;/font&gt; PropertiesList(Component component)
            {
                &lt;font color="green"&gt;// Go over all properties, filtering out the ones we need (public/get/set/boolean).
                // None is a reserved type for a case where no property is selected.&lt;/font&gt;
                &lt;font color="blue"&gt;foreach&lt;/font&gt; (PropertyInfo info &lt;font color="blue"&gt;in&lt;/font&gt; component.GetType().GetProperties())
                {
                    &lt;font color="blue"&gt;if&lt;/font&gt; (info.GetGetMethod(false) != &lt;font color="blue"&gt;null&lt;/font&gt; &amp;&amp;
                        info.GetSetMethod(false) != &lt;font color="blue"&gt;null&lt;/font&gt; &amp;&amp;
                        info.PropertyType == &lt;font color="blue"&gt;typeof&lt;/font&gt;(&lt;font color="blue"&gt;bool&lt;/font&gt;) &amp;&amp;
                        info.Name != "None")
                    {
                        &lt;font color="blue"&gt;this&lt;/font&gt;.Items.Add(info.Name);
                    }
                }

                &lt;font color="blue"&gt;this&lt;/font&gt;.Items.Add("None");


                &lt;font color="blue"&gt;this&lt;/font&gt;.Sorted = &lt;font color="blue"&gt;true&lt;/font&gt;;
                &lt;font color="green"&gt; // Not setting the border to none just doesn't look good.&lt;/font&gt;
                &lt;font color="blue"&gt;this&lt;/font&gt;.BorderStyle = BorderStyle.None;
            }
        }

        &lt;font color="darkgray"&gt;///&lt;/font&gt;&lt;font color="green"&gt; &lt;font color="darkgray"&gt;&amp;lt;summary&amp;gt;&lt;/font&gt;&lt;/font&gt;
        &lt;font color="darkgray"&gt;///&lt;/font&gt;&lt;font color="green"&gt; Displays a list of available values for the specified component than sets the value.&lt;/font&gt;
        &lt;font color="darkgray"&gt;///&lt;/font&gt;&lt;font color="green"&gt; &lt;font color="darkgray"&gt;&amp;lt;/summary&amp;gt;&lt;/font&gt;&lt;/font&gt;
        &lt;font color="darkgray"&gt;///&lt;/font&gt;&lt;font color="green"&gt; &lt;font color="darkgray"&gt;&amp;lt;param name="context"&amp;gt;&lt;/font&gt;An ITypeDescriptorContext that can be used to gain additional context information.&lt;font color="darkgray"&gt;&amp;lt;/param&amp;gt;&lt;/font&gt;&lt;/font&gt;
        &lt;font color="darkgray"&gt;///&lt;/font&gt;&lt;font color="green"&gt; &lt;font color="darkgray"&gt;&amp;lt;param name="provider"&amp;gt;&lt;/font&gt;A service provider object through which editing services may be obtained.&lt;font color="darkgray"&gt;&amp;lt;/param&amp;gt;&lt;/font&gt;&lt;/font&gt;
        &lt;font color="darkgray"&gt;///&lt;/font&gt;&lt;font color="green"&gt; &lt;font color="darkgray"&gt;&amp;lt;param name="value"&amp;gt;&lt;/font&gt;An instance of the value being edited.&lt;font color="darkgray"&gt;&amp;lt;/param&amp;gt;&lt;/font&gt;&lt;/font&gt;
        &lt;font color="darkgray"&gt;///&lt;/font&gt;&lt;font color="green"&gt; &lt;font color="darkgray"&gt;&amp;lt;returns&amp;gt;&lt;/font&gt;The new value of the object. If the value of the object hasn't changed, this method should return the same object it was passed.&lt;font color="darkgray"&gt;&amp;lt;/returns&amp;gt;&lt;/font&gt;&lt;/font&gt;
        &lt;font color="blue"&gt;public&lt;/font&gt; &lt;font color="blue"&gt;override&lt;/font&gt; &lt;font color="blue"&gt;object&lt;/font&gt; EditValue(ITypeDescriptorContext context, IServiceProvider provider, &lt;font color="blue"&gt;object&lt;/font&gt; &lt;font color="blue"&gt;value&lt;/font&gt;)
        {
            &lt;font color="blue"&gt;if&lt;/font&gt; (provider != &lt;font color="blue"&gt;null&lt;/font&gt;)
            {
                &lt;font color="green"&gt;// This service is in charge of popping our ListBox.&lt;/font&gt;
                IWindowsFormsEditorService service1 = ((IWindowsFormsEditorService) provider.GetService(typeof(IWindowsFormsEditorService)));

                &lt;font color="blue"&gt;if&lt;/font&gt; (service1 != &lt;font color="blue"&gt;null&lt;/font&gt;)
                {
                    &lt;font color="green"&gt;// This is an internal Microsoft class representing the PropertyGrid entry for our component.&lt;/font&gt;
                    &lt;font color="blue"&gt;if&lt;/font&gt; (provider.GetType().FullName == "System.Windows.Forms.PropertyGridInternal.PropertyDescriptorGridEntry")
                    {
                        &lt;font color="green"&gt;// Get the component we're working on via reflection.&lt;/font&gt;
                        Component comp = ((Component)(provider.GetType().GetProperty("Component").GetGetMethod().Invoke(provider, &lt;font color="blue"&gt;new&lt;/font&gt; &lt;font color="blue"&gt;object&lt;/font&gt;[0])));

                        PropertiesList list = new PropertiesList(comp);

                        &lt;font color="green"&gt;// Drop the list control.&lt;/font&gt;
                        service1.DropDownControl(list);

                        &lt;font color="blue"&gt;if&lt;/font&gt; (list.SelectedIndices.Count == 1)
                        {
                            &lt;font color="blue"&gt;value&lt;/font&gt; = list.SelectedItem.ToString();
                        }

                        &lt;font color="green"&gt;// Close the list control after selection.&lt;/font&gt;
                        service1.CloseDropDown();
                    }
                }
             }

            &lt;font color="blue"&gt;return&lt;/font&gt; &lt;font color="blue"&gt;value&lt;/font&gt;;
        }

        &lt;font color="darkgray"&gt;///&lt;/font&gt;&lt;font color="green"&gt; &lt;font color="darkgray"&gt;&amp;lt;summary&amp;gt;&lt;/font&gt;&lt;/font&gt;
        &lt;font color="darkgray"&gt;///&lt;/font&gt;&lt;font color="green"&gt; Gets the editing style of the &lt;font color="darkgray"&gt;&amp;lt;see cref="EditValue"/&amp;gt;&lt;/font&gt; method.&lt;/font&gt;
        &lt;font color="darkgray"&gt;///&lt;/font&gt;&lt;font color="green"&gt; &lt;font color="darkgray"&gt;&amp;lt;/summary&amp;gt;&lt;/font&gt;&lt;/font&gt;
        &lt;font color="darkgray"&gt;///&lt;/font&gt;&lt;font color="green"&gt; &lt;font color="darkgray"&gt;&amp;lt;param name="context"&amp;gt;&lt;/font&gt;An ITypeDescriptorContext that can be used to gain additional context information.&lt;font color="darkgray"&gt;&amp;lt;/param&amp;gt;&lt;/font&gt;&lt;/font&gt;
        &lt;font color="darkgray"&gt;///&lt;/font&gt;&lt;font color="green"&gt; &lt;font color="darkgray"&gt;&amp;lt;returns&amp;gt;&lt;/font&gt;Returns the DropDown style, since this editor uses a drop down list.&lt;font color="darkgray"&gt;&amp;lt;/returns&amp;gt;&lt;/font&gt;&lt;/font&gt;
        &lt;font color="blue"&gt;public&lt;/font&gt; &lt;font color="blue"&gt;override&lt;/font&gt; UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
        {
            &lt;font color="green"&gt;// We're using a drop down style UITypeEditor.&lt;/font&gt;
            &lt;font color="blue"&gt;return&lt;/font&gt; UITypeEditorEditStyle.DropDown;
        }
    }
}&lt;/pre&gt;
&lt;table border="0" cellspacing="0" cellpading="0" style="margin: auto auto"&gt;
&lt;tr&gt;
&lt;td&gt;Hack Value: &lt;/td&gt;&lt;td&gt;[&lt;/td&gt;&lt;td&gt;X&lt;/td&gt;&lt;td&gt;X&lt;/td&gt;&lt;td&gt;X&lt;/td&gt;&lt;td&gt;X&lt;/td&gt;&lt;td&gt;X&lt;/td&gt;&lt;td&gt;]&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Cool Value: &lt;/td&gt;&lt;td&gt;[&lt;/td&gt;&lt;td&gt;X&lt;/td&gt;&lt;td&gt;X&lt;/td&gt;&lt;td&gt;X&lt;/td&gt;&lt;td&gt;X&lt;/td&gt;&lt;td&gt;-&lt;/td&gt;&lt;td&gt;]&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Usable Value: &lt;/td&gt;&lt;td&gt;[&lt;/td&gt;&lt;td&gt;X&lt;/td&gt;&lt;td&gt;X&lt;/td&gt;&lt;td&gt;X&lt;/td&gt;&lt;td&gt;X&lt;/td&gt;&lt;td&gt;-&lt;/td&gt;&lt;td&gt;]&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=35028" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/okloeten/archive/tags/How+To/default.aspx">How To</category></item><item><title>How To: Manually Run a Type Initializer</title><link>http://weblogs.asp.net/okloeten/archive/2003/10/30/34726.aspx</link><pubDate>Thu, 30 Oct 2003 20:01:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:34726</guid><dc:creator>Omer van Kloeten</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/okloeten/rsscomments.aspx?PostID=34726</wfw:commentRss><comments>http://weblogs.asp.net/okloeten/archive/2003/10/30/34726.aspx#comments</comments><description>&lt;p&gt;A &lt;span title="Type Initializers are also known as Static Constructor" class="titled"&gt;Type Initializer&lt;/span&gt; is first called when referencing a &lt;span title="Shared in VB.NET" class="titled"&gt;static&lt;/span&gt; member or creating an instance of the class.&lt;br&gt;
This might cause problems to some developers as the Type Initializers are not called upon loading the AppDomain, loading the Assembly or using Reflection on the Type.&lt;/p&gt;
&lt;p&gt;This is solved by using &lt;a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemruntimecompilerservicesruntimehelpersclassrunclassconstructortopic.asp"&gt;System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor(RuntimeTypeHandle)&lt;/a&gt;, which invokes the Type Initializer.&lt;/p&gt;
&lt;p&gt;Personally, I tried using it once and stopped since it's just too hackish.&lt;/p&gt;
&lt;table border="0" cellspacing="0" cellpading="0" style="margin: auto auto"&gt;
&lt;tr&gt;
&lt;td&gt;Hack Value: &lt;/td&gt;&lt;td&gt;[&lt;/td&gt;&lt;td&gt;X&lt;/td&gt;&lt;td&gt;X&lt;/td&gt;&lt;td&gt;X&lt;/td&gt;&lt;td&gt;X&lt;/td&gt;&lt;td&gt;-&lt;/td&gt;&lt;td&gt;]&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Cool Value: &lt;/td&gt;&lt;td&gt;[&lt;/td&gt;&lt;td&gt;X&lt;/td&gt;&lt;td&gt;X&lt;/td&gt;&lt;td&gt;X&lt;/td&gt;&lt;td&gt;X&lt;/td&gt;&lt;td&gt;-&lt;/td&gt;&lt;td&gt;]&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Usable Value: &lt;/td&gt;&lt;td&gt;[&lt;/td&gt;&lt;td&gt;X&lt;/td&gt;&lt;td&gt;X&lt;/td&gt;&lt;td&gt;-&lt;/td&gt;&lt;td&gt;-&lt;/td&gt;&lt;td&gt;-&lt;/td&gt;&lt;td&gt;]&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=34726" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/okloeten/archive/tags/How+To/default.aspx">How To</category></item></channel></rss>