<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>Vault of Thoughts - .NET Blog</title>
    <link>http://vaultofthoughts.net/</link>
    <description>My random thoughts on programming and software development. ASP.NET, C#, Best Practices and other stuff.</description>
    <language>en-us</language>
    <copyright>Michal Talaga</copyright>
    <lastBuildDate>Wed, 20 May 2009 14:49:35 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.0.7226.0</generator>
    <managingEditor>mikeon@vaultofthoughts.net</managingEditor>
    <webMaster>mikeon@vaultofthoughts.net</webMaster>
    <item>
      <trackback:ping>http://vaultofthoughts.net/Trackback.aspx?guid=cdec5758-51b7-4c18-acfc-e46b18fea544</trackback:ping>
      <pingback:server>http://vaultofthoughts.net/pingback.aspx</pingback:server>
      <pingback:target>http://vaultofthoughts.net/PermaLink,guid,cdec5758-51b7-4c18-acfc-e46b18fea544.aspx</pingback:target>
      <dc:creator>Michal Talaga</dc:creator>
      <wfw:comment>http://vaultofthoughts.net/CommentView,guid,cdec5758-51b7-4c18-acfc-e46b18fea544.aspx</wfw:comment>
      <wfw:commentRss>http://vaultofthoughts.net/SyndicationService.asmx/GetEntryCommentsRss?guid=cdec5758-51b7-4c18-acfc-e46b18fea544</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <a href="http://www.typemock.com/">Unit Testing</a> ASP.NET? <a href="http://www.typemock.com/ASP.NET_unit_testing_page.php">ASP.NET
unit testing</a> has never been this easy.<br />
Typemock is launching a new product for ASP.NET developers – the <strong>ASP.NET Bundle</strong> -
and for the launch will be giving out <strong>FREE licenses</strong> to bloggers and
their readers.<br />
The ASP.NET Bundle is the ultimate ASP.NET unit testing solution, and offers both <a href="http://www.typemock.com/">Typemock
Isolator</a>, a <a href="http://www.typemock.com/">unit test</a> tool and <a href="http://sm-art.biz/Ivonna.aspx">Ivonna</a>,
the Isolator add-on for <a href="http://sm-art.biz/Ivonna.aspx">ASP.NET unit testing</a>,
for a bargain price.<br />
Typemock Isolator is a leading <a href="http://www.typemock.com/">.NET unit testing</a> tool
(C# and VB.NET) for many ‘hard to test’ technologies such as <a href="http://typemock.com/sharepointpage.php">SharePoint</a>, <a href="http://www.typemock.com/ASP.NET_unit_testing_page.php">ASP.NET</a>, <a href="http://www.typemock.com/ASP.NET_unit_testing_page.php">MVC</a>, <a href="http://www.typemock.com/wcfpage.php">WCF</a>,
WPF, <a href="http://www.typemock.com/Silverlight_unit_testing_page.php">Silverlight</a> and
more. Note that for <a href="http://www.typemock.com/Silverlight_unit_testing_page.php">unit
testing Silverlight</a> there is an open source Isolator add-on called <a href="http://www.typemock.com/Silverlight_unit_testing_page.php">SilverUnit</a>.<br />
The first 60 bloggers who will blog this text in their blog and <a href="http://blog.typemock.com/2009/05/get-free-typemock-licenses-aspnet.html">tell
us about it</a>, will get a Free Isolator ASP.NET Bundle license (Typemock Isolator
+ Ivonna). If you post this in an ASP.NET <strong>dedicated</strong> blog, you'll
get a license automatically (even if more than 60 submit) during the first week of
this announcement.<br />
Also 8 bloggers will get an <strong>additional 2 licenses</strong> (each) to give
away to their readers / friends.<br />
Go ahead, click the following link for <a href="http://blog.typemock.com/2009/05/get-free-typemock-licenses-aspnet.html">more
information </a>on how to get your free license.
</p>
        <img width="0" height="0" src="http://vaultofthoughts.net/aggbug.ashx?id=cdec5758-51b7-4c18-acfc-e46b18fea544" />
      </body>
      <title>Free ASP.NET Bundle</title>
      <guid isPermaLink="false">http://vaultofthoughts.net/PermaLink,guid,cdec5758-51b7-4c18-acfc-e46b18fea544.aspx</guid>
      <link>http://VaultOfThoughts.net/FreeASPNETBundle.aspx</link>
      <pubDate>Wed, 20 May 2009 14:49:35 GMT</pubDate>
      <description>&lt;p&gt;
&lt;a href="http://www.typemock.com/"&gt;Unit Testing&lt;/a&gt; ASP.NET? &lt;a href="http://www.typemock.com/ASP.NET_unit_testing_page.php"&gt;ASP.NET
unit testing&lt;/a&gt; has never been this easy.&lt;br&gt;
Typemock is launching a new product for ASP.NET developers – the &lt;strong&gt;ASP.NET Bundle&lt;/strong&gt; -
and for the launch will be giving out &lt;strong&gt;FREE licenses&lt;/strong&gt; to bloggers and
their readers.&lt;br&gt;
The ASP.NET Bundle is the ultimate ASP.NET unit testing solution, and offers both &lt;a href="http://www.typemock.com/"&gt;Typemock
Isolator&lt;/a&gt;, a &lt;a href="http://www.typemock.com/"&gt;unit test&lt;/a&gt; tool and &lt;a href="http://sm-art.biz/Ivonna.aspx"&gt;Ivonna&lt;/a&gt;,
the Isolator add-on for &lt;a href="http://sm-art.biz/Ivonna.aspx"&gt;ASP.NET unit testing&lt;/a&gt;,
for a bargain price.&lt;br&gt;
Typemock Isolator is a leading &lt;a href="http://www.typemock.com/"&gt;.NET unit testing&lt;/a&gt; tool
(C# and VB.NET) for many ‘hard to test’ technologies such as &lt;a href="http://typemock.com/sharepointpage.php"&gt;SharePoint&lt;/a&gt;, &lt;a href="http://www.typemock.com/ASP.NET_unit_testing_page.php"&gt;ASP.NET&lt;/a&gt;, &lt;a href="http://www.typemock.com/ASP.NET_unit_testing_page.php"&gt;MVC&lt;/a&gt;, &lt;a href="http://www.typemock.com/wcfpage.php"&gt;WCF&lt;/a&gt;,
WPF, &lt;a href="http://www.typemock.com/Silverlight_unit_testing_page.php"&gt;Silverlight&lt;/a&gt; and
more. Note that for &lt;a href="http://www.typemock.com/Silverlight_unit_testing_page.php"&gt;unit
testing Silverlight&lt;/a&gt; there is an open source Isolator add-on called &lt;a href="http://www.typemock.com/Silverlight_unit_testing_page.php"&gt;SilverUnit&lt;/a&gt;.&lt;br&gt;
The first 60 bloggers who will blog this text in their blog and &lt;a href="http://blog.typemock.com/2009/05/get-free-typemock-licenses-aspnet.html"&gt;tell
us about it&lt;/a&gt;, will get a Free Isolator ASP.NET Bundle license (Typemock Isolator
+ Ivonna). If you post this in an ASP.NET &lt;strong&gt;dedicated&lt;/strong&gt; blog, you'll
get a license automatically (even if more than 60 submit) during the first week of
this announcement.&lt;br&gt;
Also 8 bloggers will get an &lt;strong&gt;additional 2 licenses&lt;/strong&gt; (each) to give
away to their readers / friends.&lt;br&gt;
Go ahead, click the following link for &lt;a href="http://blog.typemock.com/2009/05/get-free-typemock-licenses-aspnet.html"&gt;more
information &lt;/a&gt;on how to get your free license.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://vaultofthoughts.net/aggbug.ashx?id=cdec5758-51b7-4c18-acfc-e46b18fea544" /&gt;</description>
      <comments>http://vaultofthoughts.net/CommentView,guid,cdec5758-51b7-4c18-acfc-e46b18fea544.aspx</comments>
    </item>
    <item>
      <trackback:ping>http://vaultofthoughts.net/Trackback.aspx?guid=d24379b4-4134-4f08-bf94-2b2331bbd2ed</trackback:ping>
      <pingback:server>http://vaultofthoughts.net/pingback.aspx</pingback:server>
      <pingback:target>http://vaultofthoughts.net/PermaLink,guid,d24379b4-4134-4f08-bf94-2b2331bbd2ed.aspx</pingback:target>
      <dc:creator>Michal Talaga</dc:creator>
      <wfw:comment>http://vaultofthoughts.net/CommentView,guid,d24379b4-4134-4f08-bf94-2b2331bbd2ed.aspx</wfw:comment>
      <wfw:commentRss>http://vaultofthoughts.net/SyndicationService.asmx/GetEntryCommentsRss?guid=d24379b4-4134-4f08-bf94-2b2331bbd2ed</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I'm sure most of you know about podcasts. Sites like <a href="http://www.dotnetrocks.com/">.NET
Rocks</a> being one of the most popular for .NET developers. Sooner or later though,
you just run out of podcasts. Especially if you, like me, try to waste no time - which
includes walking your dog with an MP3 player plugged in :-)
</p>
        <p>
There are also cases when the level of podcasts is way below what you would expect.
Once you get a certain level of expertise in any subject, most of the podcasts start
to sound lame and that is natural of course - a sign of you progress.
</p>
        <p>
Worst case scenario however is, when there are no audio materials on the subject of
interest. Been there, seen that, solved it.
</p>
        <p>
Enter <a href="http://objectware.pl/Apps/SpeechR/publish.htm">SpeechR</a>. 
</p>
        <p>
          <a href="http://objectware.pl/Apps/SpeechR/publish.htm">
            <img src="http://vaultofthoughts.net/content/binary/SpeechR.jpg" border="0" />
          </a>
        </p>
        <p>
A small tool that I wrote mostly for myself. SpeechR is a tool that allows me to take
any text and convert it into an audio format (wave or mp3) so I can later put it on
my MP3 player and listen to while... whatever I do that doesn't require focus.
</p>
        <p>
With all the ebooks out there, with all those lenghty manuals or blog posts and a
comming vacation on a beach... What more can a hardcore can you want.
</p>
        <p>
Tool uses System.Speech namespace that was introduced with .NET 3.0 to generate sounds.
System.Speech in turn uses Microsoft Speech API found in Windows. With version 5 it
got pretty good. Just compare Microsoft Anna in Vista to Microsoft Sam in XP.
</p>
        <p>
Of course, Microsoft's voice isn't perfect - far from it. There are however commercial
voices out there that are very good and cost ~30$.
</p>
        <p>
Well. The tool is free, you can install it and enjoy. Please let me know what you
think about it and what features you would like to see in v.Next().
</p>
        <img width="0" height="0" src="http://vaultofthoughts.net/aggbug.ashx?id=d24379b4-4134-4f08-bf94-2b2331bbd2ed" />
      </body>
      <title>Making Your Own Audio Books</title>
      <guid isPermaLink="false">http://vaultofthoughts.net/PermaLink,guid,d24379b4-4134-4f08-bf94-2b2331bbd2ed.aspx</guid>
      <link>http://VaultOfThoughts.net/MakingYourOwnAudioBooks.aspx</link>
      <pubDate>Wed, 25 Jun 2008 18:37:27 GMT</pubDate>
      <description>&lt;p&gt;
I'm sure most of you know about podcasts. Sites like &lt;a href="http://www.dotnetrocks.com/"&gt;.NET
Rocks&lt;/a&gt; being one of the most popular for .NET developers. Sooner or later though,
you just run out of podcasts. Especially if you, like me, try to waste no time - which
includes walking your dog with an MP3 player plugged in :-)
&lt;/p&gt;
&lt;p&gt;
There are also cases when the level of podcasts is way below what you would expect.
Once you get a certain level of expertise in any subject, most of the podcasts start
to sound lame and that is natural of course - a sign of you progress.
&lt;/p&gt;
&lt;p&gt;
Worst case scenario however is, when there are no audio materials on the subject of
interest. Been there, seen that, solved it.
&lt;/p&gt;
&lt;p&gt;
Enter &lt;a href="http://objectware.pl/Apps/SpeechR/publish.htm"&gt;SpeechR&lt;/a&gt;. 
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://objectware.pl/Apps/SpeechR/publish.htm"&gt;&lt;img src="http://vaultofthoughts.net/content/binary/SpeechR.jpg" border=0&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
A small tool that I wrote mostly for myself. SpeechR is a tool that allows me to take
any text and convert it into an audio format (wave or mp3) so I can later put it on
my MP3 player and listen to while... whatever I do that doesn't require focus.
&lt;/p&gt;
&lt;p&gt;
With all the ebooks out there, with all those lenghty manuals or blog posts and a
comming vacation on a beach... What more can a hardcore can you want.
&lt;/p&gt;
&lt;p&gt;
Tool uses System.Speech namespace that was introduced with .NET 3.0 to generate sounds.
System.Speech in turn uses Microsoft Speech API found in Windows. With version 5 it
got pretty good. Just compare Microsoft Anna in Vista to Microsoft Sam in XP.
&lt;/p&gt;
&lt;p&gt;
Of course, Microsoft's voice isn't perfect - far from it. There are however commercial
voices out there that are very good and cost ~30$.
&lt;/p&gt;
&lt;p&gt;
Well. The tool is free, you can install it and enjoy. Please let me know what you
think about it and what features you would like to see in v.Next().
&lt;/p&gt;
&lt;img width="0" height="0" src="http://vaultofthoughts.net/aggbug.ashx?id=d24379b4-4134-4f08-bf94-2b2331bbd2ed" /&gt;</description>
      <comments>http://vaultofthoughts.net/CommentView,guid,d24379b4-4134-4f08-bf94-2b2331bbd2ed.aspx</comments>
      <category>Misc</category>
    </item>
    <item>
      <trackback:ping>http://vaultofthoughts.net/Trackback.aspx?guid=d2377357-7ea9-4f03-93f1-aa8655c641fc</trackback:ping>
      <pingback:server>http://vaultofthoughts.net/pingback.aspx</pingback:server>
      <pingback:target>http://vaultofthoughts.net/PermaLink,guid,d2377357-7ea9-4f03-93f1-aa8655c641fc.aspx</pingback:target>
      <dc:creator>Michal Talaga</dc:creator>
      <wfw:comment>http://vaultofthoughts.net/CommentView,guid,d2377357-7ea9-4f03-93f1-aa8655c641fc.aspx</wfw:comment>
      <wfw:commentRss>http://vaultofthoughts.net/SyndicationService.asmx/GetEntryCommentsRss?guid=d2377357-7ea9-4f03-93f1-aa8655c641fc</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I'm having some very strange problems lately with my Visual Studio. From time to time,
a random feature just stops working. From not being able to pin/unpin windows, through
random component not installed/missing, to just not being able to even start the IDE.
</p>
        <p>
Some of the problems go away after restarting Visual Studio. Some of the problems
go away after restarting Windows. Some of the problems just STAY!
</p>
        <p>
After asking "<a href="http://en.wikipedia.org/wiki/Minor_characters_from_The_Hitchhiker%27s_Guide_to_the_Galaxy#Deep_Thought">Deep
Thought</a>" for <a href="http://en.wikipedia.org/wiki/Answer_to_Life%2C_the_Universe%2C_and_Everything">the
ultimate answer to life</a>, I got it, and it was 42...
</p>
        <p>
Naaah. Actually asking google was helpful in a way. It gave me some clues on what
can I do to "reset" Visual Studio without reinstalling it or even worse, the whole
Windows. The answer was:
</p>
        <p>
          <strong>
            <font size="4">devenv /resetskippkgs</font>
          </strong>
        </p>
        <p>
Remember this one. You will need it. Sooner or later, but you will. It solves a lot
of different issues.
</p>
        <img width="0" height="0" src="http://vaultofthoughts.net/aggbug.ashx?id=d2377357-7ea9-4f03-93f1-aa8655c641fc" />
      </body>
      <title>The answer is: 42</title>
      <guid isPermaLink="false">http://vaultofthoughts.net/PermaLink,guid,d2377357-7ea9-4f03-93f1-aa8655c641fc.aspx</guid>
      <link>http://VaultOfThoughts.net/TheAnswerIs42.aspx</link>
      <pubDate>Tue, 24 Jun 2008 20:08:45 GMT</pubDate>
      <description>&lt;p&gt;
I'm having some very strange problems lately with my Visual Studio. From time to time,
a random feature just stops working. From not being able to pin/unpin windows, through
random component not installed/missing, to just not being able to even start the IDE.
&lt;/p&gt;
&lt;p&gt;
Some of the problems go away after restarting Visual Studio. Some of the problems
go away after restarting Windows. Some of the problems just STAY!
&lt;/p&gt;
&lt;p&gt;
After asking "&lt;a href="http://en.wikipedia.org/wiki/Minor_characters_from_The_Hitchhiker%27s_Guide_to_the_Galaxy#Deep_Thought"&gt;Deep
Thought&lt;/a&gt;" for &lt;a href="http://en.wikipedia.org/wiki/Answer_to_Life%2C_the_Universe%2C_and_Everything"&gt;the
ultimate answer to life&lt;/a&gt;, I got it, and it was 42...
&lt;/p&gt;
&lt;p&gt;
Naaah. Actually asking google was helpful in a way. It gave me some clues on what
can I do to "reset" Visual Studio without reinstalling it or even worse, the whole
Windows. The answer was:
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;&lt;font size=4&gt;devenv /resetskippkgs&lt;/font&gt;&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
Remember this one. You will need it. Sooner or later, but you will. It solves a lot
of different issues.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://vaultofthoughts.net/aggbug.ashx?id=d2377357-7ea9-4f03-93f1-aa8655c641fc" /&gt;</description>
      <comments>http://vaultofthoughts.net/CommentView,guid,d2377357-7ea9-4f03-93f1-aa8655c641fc.aspx</comments>
      <category>Misc</category>
    </item>
    <item>
      <trackback:ping>http://vaultofthoughts.net/Trackback.aspx?guid=691e9de8-9b99-42a3-b464-36d1f36d3fc1</trackback:ping>
      <pingback:server>http://vaultofthoughts.net/pingback.aspx</pingback:server>
      <pingback:target>http://vaultofthoughts.net/PermaLink,guid,691e9de8-9b99-42a3-b464-36d1f36d3fc1.aspx</pingback:target>
      <dc:creator>Michal Talaga</dc:creator>
      <wfw:comment>http://vaultofthoughts.net/CommentView,guid,691e9de8-9b99-42a3-b464-36d1f36d3fc1.aspx</wfw:comment>
      <wfw:commentRss>http://vaultofthoughts.net/SyndicationService.asmx/GetEntryCommentsRss?guid=691e9de8-9b99-42a3-b464-36d1f36d3fc1</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
"Invalid URI: The Uri scheme is too long" - now that's a peculiar message. I got it
while doing some Xslt transformations. It comes out that <em>XslCompiledTransform</em> can't
just read any xml and transform it. There are issues if Uri scheme is too long. What
is too long? Can't really tell, since mine wasn't THAT long.
</p>
        <p>
The following code did not work for me:
</p>
        <pre class="code">
          <span style="COLOR: rgb(43,145,175)">XslCompiledTransform</span> xsl
= <span style="COLOR: rgb(0,0,255)">new</span><span style="COLOR: rgb(43,145,175)">XslCompiledTransform</span>();
xsl.Load(<span style="COLOR: rgb(163,21,21)">"t.xsl"</span>); <span style="COLOR: rgb(43,145,175)">XmlWriter</span> writer
= <span style="COLOR: rgb(43,145,175)">XmlWriter</span>.Create(<span style="COLOR: rgb(163,21,21)">"dest.xml"</span>);
xsl.Transform(<span style="COLOR: rgb(43,145,175)">File</span>.ReadAllText(<span style="COLOR: rgb(163,21,21)">"source.xml"</span>),
writer);</pre>
        <a href="http://11011.net/software/vspaste">
        </a>
        <p>
So I had to use this one:
</p>
        <pre class="code">
          <span style="COLOR: rgb(43,145,175)">XslCompiledTransform</span> xsl
= <span style="COLOR: rgb(0,0,255)">new</span><span style="COLOR: rgb(43,145,175)">XslCompiledTransform</span>();
xsl.Load(<span style="COLOR: rgb(163,21,21)">"t.xsl"</span>); <span style="COLOR: rgb(0,0,255)">using</span> (<span style="COLOR: rgb(43,145,175)">XmlWriter</span> writer
= <span style="COLOR: rgb(43,145,175)">XmlWriter</span>.Create(<span style="COLOR: rgb(163,21,21)">"dest.xml"</span>))
{ <span style="COLOR: rgb(0,0,255)">using</span> (<span style="COLOR: rgb(43,145,175)">XmlReader</span> reader
= <span style="COLOR: rgb(43,145,175)">XmlReader</span>.Create(<span style="COLOR: rgb(163,21,21)">"source.xml"</span>))
{ xsl.Transform(reader, writer); } }</pre>
        <a href="http://11011.net/software/vspaste">
        </a>
        <p>
The problem is the <em>Transform</em> method and <em>File.ReadAllText</em> that returns
the whole source xml string at once. <em>XslCompiledTransform</em> just can't handle
it for some reason.
</p>
        <img width="0" height="0" src="http://vaultofthoughts.net/aggbug.ashx?id=691e9de8-9b99-42a3-b464-36d1f36d3fc1" />
      </body>
      <title>Invalid URI: The Uri scheme is too long</title>
      <guid isPermaLink="false">http://vaultofthoughts.net/PermaLink,guid,691e9de8-9b99-42a3-b464-36d1f36d3fc1.aspx</guid>
      <link>http://VaultOfThoughts.net/InvalidURITheUriSchemeIsTooLong.aspx</link>
      <pubDate>Tue, 24 Jun 2008 20:01:05 GMT</pubDate>
      <description>&lt;p&gt;
"Invalid URI: The Uri scheme is too long" - now that's a peculiar message. I got it
while doing some Xslt transformations. It comes out that &lt;em&gt;XslCompiledTransform&lt;/em&gt; can't
just read any xml and transform it. There are issues if Uri scheme is too long. What
is too long? Can't really tell, since mine wasn't THAT long.
&lt;/p&gt;
&lt;p&gt;
The following code did not work for me:
&lt;/p&gt;
&lt;pre class=code&gt;&lt;span style="COLOR: rgb(43,145,175)"&gt;XslCompiledTransform&lt;/span&gt; xsl
= &lt;span style="COLOR: rgb(0,0,255)"&gt;new&lt;/span&gt; &lt;span style="COLOR: rgb(43,145,175)"&gt;XslCompiledTransform&lt;/span&gt;();
xsl.Load(&lt;span style="COLOR: rgb(163,21,21)"&gt;"t.xsl"&lt;/span&gt;); &lt;span style="COLOR: rgb(43,145,175)"&gt;XmlWriter&lt;/span&gt; writer
= &lt;span style="COLOR: rgb(43,145,175)"&gt;XmlWriter&lt;/span&gt;.Create(&lt;span style="COLOR: rgb(163,21,21)"&gt;"dest.xml"&lt;/span&gt;);
xsl.Transform(&lt;span style="COLOR: rgb(43,145,175)"&gt;File&lt;/span&gt;.ReadAllText(&lt;span style="COLOR: rgb(163,21,21)"&gt;"source.xml"&lt;/span&gt;),
writer);&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt; 
&lt;p&gt;
So I had to use this one:
&lt;/p&gt;
&lt;pre class=code&gt;&lt;span style="COLOR: rgb(43,145,175)"&gt;XslCompiledTransform&lt;/span&gt; xsl
= &lt;span style="COLOR: rgb(0,0,255)"&gt;new&lt;/span&gt; &lt;span style="COLOR: rgb(43,145,175)"&gt;XslCompiledTransform&lt;/span&gt;();
xsl.Load(&lt;span style="COLOR: rgb(163,21,21)"&gt;"t.xsl"&lt;/span&gt;); &lt;span style="COLOR: rgb(0,0,255)"&gt;using&lt;/span&gt; (&lt;span style="COLOR: rgb(43,145,175)"&gt;XmlWriter&lt;/span&gt; writer
= &lt;span style="COLOR: rgb(43,145,175)"&gt;XmlWriter&lt;/span&gt;.Create(&lt;span style="COLOR: rgb(163,21,21)"&gt;"dest.xml"&lt;/span&gt;))
{ &lt;span style="COLOR: rgb(0,0,255)"&gt;using&lt;/span&gt; (&lt;span style="COLOR: rgb(43,145,175)"&gt;XmlReader&lt;/span&gt; reader
= &lt;span style="COLOR: rgb(43,145,175)"&gt;XmlReader&lt;/span&gt;.Create(&lt;span style="COLOR: rgb(163,21,21)"&gt;"source.xml"&lt;/span&gt;))
{ xsl.Transform(reader, writer); } }&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt; 
&lt;p&gt;
The problem is the &lt;em&gt;Transform&lt;/em&gt; method and &lt;em&gt;File.ReadAllText&lt;/em&gt; that returns
the whole source xml string at once. &lt;em&gt;XslCompiledTransform&lt;/em&gt; just can't handle
it for some reason.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://vaultofthoughts.net/aggbug.ashx?id=691e9de8-9b99-42a3-b464-36d1f36d3fc1" /&gt;</description>
      <comments>http://vaultofthoughts.net/CommentView,guid,691e9de8-9b99-42a3-b464-36d1f36d3fc1.aspx</comments>
      <category>.NET</category>
    </item>
    <item>
      <trackback:ping>http://vaultofthoughts.net/Trackback.aspx?guid=87212578-ebbd-4db0-8aca-f990374b1668</trackback:ping>
      <pingback:server>http://vaultofthoughts.net/pingback.aspx</pingback:server>
      <pingback:target>http://vaultofthoughts.net/PermaLink,guid,87212578-ebbd-4db0-8aca-f990374b1668.aspx</pingback:target>
      <dc:creator>Michal Talaga</dc:creator>
      <wfw:comment>http://vaultofthoughts.net/CommentView,guid,87212578-ebbd-4db0-8aca-f990374b1668.aspx</wfw:comment>
      <wfw:commentRss>http://vaultofthoughts.net/SyndicationService.asmx/GetEntryCommentsRss?guid=87212578-ebbd-4db0-8aca-f990374b1668</wfw:commentRss>
      <slash:comments>3</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Now! That has to be one of my greatest findings! Ever!
</p>
        <p>
The Indexer method (the one that allows for doing object[something]) of the Hashtable
class in .NET has a Thread.Sleep(1) inside one of the loops!!!!
</p>
        <p>
Yes I repeat <strong>Thread.Sleep(1)</strong>!
</p>
        <p>
Why would anyone want to insert a Thread.Sleep() call in to a Hashtable, or any other
BCL class for that matter, is beyond me.
</p>
        <p>
Can you beat this gem?
</p>
        <img width="0" height="0" src="http://vaultofthoughts.net/aggbug.ashx?id=87212578-ebbd-4db0-8aca-f990374b1668" />
      </body>
      <title>Hashtable Indexer - What The Hell?</title>
      <guid isPermaLink="false">http://vaultofthoughts.net/PermaLink,guid,87212578-ebbd-4db0-8aca-f990374b1668.aspx</guid>
      <link>http://VaultOfThoughts.net/HashtableIndexerWhatTheHell.aspx</link>
      <pubDate>Sat, 31 May 2008 20:09:21 GMT</pubDate>
      <description>&lt;p&gt;
Now! That has to be one of my greatest findings! Ever!
&lt;/p&gt;
&lt;p&gt;
The Indexer method (the one that allows for doing object[something]) of the Hashtable
class in .NET has a Thread.Sleep(1) inside one of the loops!!!!
&lt;/p&gt;
&lt;p&gt;
Yes I repeat &lt;strong&gt;Thread.Sleep(1)&lt;/strong&gt;!
&lt;/p&gt;
&lt;p&gt;
Why would anyone want to insert a Thread.Sleep() call in to a Hashtable, or any other
BCL class for that matter, is beyond me.
&lt;/p&gt;
&lt;p&gt;
Can you beat this gem?
&lt;/p&gt;
&lt;img width="0" height="0" src="http://vaultofthoughts.net/aggbug.ashx?id=87212578-ebbd-4db0-8aca-f990374b1668" /&gt;</description>
      <comments>http://vaultofthoughts.net/CommentView,guid,87212578-ebbd-4db0-8aca-f990374b1668.aspx</comments>
      <category>.NET</category>
    </item>
    <item>
      <trackback:ping>http://vaultofthoughts.net/Trackback.aspx?guid=9e4722f5-ff8a-4817-a283-e6a5526c8b86</trackback:ping>
      <pingback:server>http://vaultofthoughts.net/pingback.aspx</pingback:server>
      <pingback:target>http://vaultofthoughts.net/PermaLink,guid,9e4722f5-ff8a-4817-a283-e6a5526c8b86.aspx</pingback:target>
      <dc:creator>Michal Talaga</dc:creator>
      <wfw:comment>http://vaultofthoughts.net/CommentView,guid,9e4722f5-ff8a-4817-a283-e6a5526c8b86.aspx</wfw:comment>
      <wfw:commentRss>http://vaultofthoughts.net/SyndicationService.asmx/GetEntryCommentsRss?guid=9e4722f5-ff8a-4817-a283-e6a5526c8b86</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
"There is no such method!" That's what everyone is told by Microsoft. Microsoft is
even insolent enough to provide us with <a href="http://blogs.msdn.com/junfeng/archive/2004/02/20/76467.aspx">reasons
why they did not include Directory.Copy method in .NET Framework</a>.
</p>
        <p>
I find those arguments unacceptable. Sure, they are valid at some level, but it's
wouldn't be the only piece of code that goes "mainstream" and does what 99% of people
would expect it to do, without considering special cases. 
</p>
        <p>
So I went and almost implemented my own Directory.Copy. Almost.
</p>
        <p>
It came out that Microsoft does not live to its own words! There is a method in .NET
Framework, that allow us to copy a directory, just like that, in one call. It is hidden
in a <em>Microsoft.VisualBasic.dll</em> assembly in a <em>Microsoft.VisualBasic.FileIO.FileSystem</em> type
and is called (not surprisingly) <em>CopyDirectory</em>.
</p>
        <p>
Although it is in VisualBasic namespace, there is nothing that prevents us from using
it in C#. Only a reference to an assembly is needed.
</p>
        <p>
Well Microsoft? What you say to that?
</p>
        <img width="0" height="0" src="http://vaultofthoughts.net/aggbug.ashx?id=9e4722f5-ff8a-4817-a283-e6a5526c8b86" />
      </body>
      <title>Directory.Copy In .NET</title>
      <guid isPermaLink="false">http://vaultofthoughts.net/PermaLink,guid,9e4722f5-ff8a-4817-a283-e6a5526c8b86.aspx</guid>
      <link>http://VaultOfThoughts.net/DirectoryCopyInNET.aspx</link>
      <pubDate>Wed, 21 May 2008 19:07:50 GMT</pubDate>
      <description>&lt;p&gt;
"There is no such method!" That's what everyone is told by Microsoft. Microsoft is
even insolent enough to provide us with &lt;a href="http://blogs.msdn.com/junfeng/archive/2004/02/20/76467.aspx"&gt;reasons
why they did not include Directory.Copy method in .NET Framework&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
I find those arguments unacceptable. Sure, they are valid at some level, but it's
wouldn't be the only piece of code that goes "mainstream" and does what 99% of people
would expect it to do, without considering special cases. 
&lt;/p&gt;
&lt;p&gt;
So I went and almost implemented my own Directory.Copy. Almost.
&lt;/p&gt;
&lt;p&gt;
It came out that Microsoft does not live to its own words! There is a method in .NET
Framework, that allow us to copy a directory, just like that, in one call. It is hidden
in a &lt;em&gt;Microsoft.VisualBasic.dll&lt;/em&gt; assembly in a &lt;em&gt;Microsoft.VisualBasic.FileIO.FileSystem&lt;/em&gt; type
and is called (not surprisingly) &lt;em&gt;CopyDirectory&lt;/em&gt;.
&lt;/p&gt;
&lt;p&gt;
Although it is in VisualBasic namespace, there is nothing that prevents us from using
it in C#. Only a reference to an assembly is needed.
&lt;/p&gt;
&lt;p&gt;
Well Microsoft? What you say to that?
&lt;/p&gt;
&lt;img width="0" height="0" src="http://vaultofthoughts.net/aggbug.ashx?id=9e4722f5-ff8a-4817-a283-e6a5526c8b86" /&gt;</description>
      <comments>http://vaultofthoughts.net/CommentView,guid,9e4722f5-ff8a-4817-a283-e6a5526c8b86.aspx</comments>
      <category>.NET</category>
    </item>
    <item>
      <trackback:ping>http://vaultofthoughts.net/Trackback.aspx?guid=9b74565e-c0a3-4ff7-9ae1-368000d5cc17</trackback:ping>
      <pingback:server>http://vaultofthoughts.net/pingback.aspx</pingback:server>
      <pingback:target>http://vaultofthoughts.net/PermaLink,guid,9b74565e-c0a3-4ff7-9ae1-368000d5cc17.aspx</pingback:target>
      <dc:creator>Michal Talaga</dc:creator>
      <wfw:comment>http://vaultofthoughts.net/CommentView,guid,9b74565e-c0a3-4ff7-9ae1-368000d5cc17.aspx</wfw:comment>
      <wfw:commentRss>http://vaultofthoughts.net/SyndicationService.asmx/GetEntryCommentsRss?guid=9b74565e-c0a3-4ff7-9ae1-368000d5cc17</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Another day, another gotcha.
</p>
        <p>
While working with regular expressions I was matching some input string to a pattern
with one group capture (is it the correct name?). I made a regex.Match() thing, got
a match and since it was just a test code, I wen stright for getting the second group
out of the match (first being the whole match):
</p>
        <pre class="code">DoSomething(match.Groups[1].Value);</pre>
        <a href="http://11011.net/software/vspaste">
        </a>
        <p>
I was pretty much expecting an IndexOutOfRangeException, or something similar, in
case there were no matches. To my surprise I got no exception! To the contrary I got
a result, an empty one, but a result.
</p>
        <p>
Quick peek inside the code and it came out, that that's just how <em>GroupCollection</em>'s
indexer is implemented. It returns an empty group in case you try to get one that
doesn't exist.
</p>
        <p>
Is it intuitive? I seriously doubt it. That's a first time I see a collection with
an indexer, that allows me to access elements by index that is beyond the collection's
elements count! 
</p>
        <p>
I don't like when those kinds of things happen...
</p>
        <img width="0" height="0" src="http://vaultofthoughts.net/aggbug.ashx?id=9b74565e-c0a3-4ff7-9ae1-368000d5cc17" />
      </body>
      <title>Regex.Match().Groups Gotcha</title>
      <guid isPermaLink="false">http://vaultofthoughts.net/PermaLink,guid,9b74565e-c0a3-4ff7-9ae1-368000d5cc17.aspx</guid>
      <link>http://VaultOfThoughts.net/RegexMatchGroupsGotcha.aspx</link>
      <pubDate>Wed, 21 May 2008 18:54:36 GMT</pubDate>
      <description>&lt;p&gt;
Another day, another gotcha.
&lt;/p&gt;
&lt;p&gt;
While working with regular expressions I was matching some input string to a pattern
with one group capture (is it the correct name?). I made a regex.Match() thing, got
a match and since it was just a test code, I wen stright for getting the second group
out of the match (first being the whole match):
&lt;/p&gt;
&lt;pre class=code&gt;DoSomething(match.Groups[1].Value);&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt; 
&lt;p&gt;
I was pretty much expecting an IndexOutOfRangeException, or something similar, in
case there were no matches. To my surprise I got no exception! To the contrary I got
a result, an empty one, but a result.
&lt;/p&gt;
&lt;p&gt;
Quick peek inside the code and it came out, that that's just how &lt;em&gt;GroupCollection&lt;/em&gt;'s
indexer is implemented. It returns an empty group in case you try to get one that
doesn't exist.
&lt;/p&gt;
&lt;p&gt;
Is it intuitive? I seriously doubt it. That's a first time I see a collection with
an indexer, that allows me to access elements by index that is beyond the collection's
elements count! 
&lt;/p&gt;
&lt;p&gt;
I don't like when those kinds of things happen...
&lt;/p&gt;
&lt;img width="0" height="0" src="http://vaultofthoughts.net/aggbug.ashx?id=9b74565e-c0a3-4ff7-9ae1-368000d5cc17" /&gt;</description>
      <comments>http://vaultofthoughts.net/CommentView,guid,9b74565e-c0a3-4ff7-9ae1-368000d5cc17.aspx</comments>
      <category>.NET</category>
    </item>
    <item>
      <trackback:ping>http://vaultofthoughts.net/Trackback.aspx?guid=237a2709-0d18-4ef9-99ed-b19d55765156</trackback:ping>
      <pingback:server>http://vaultofthoughts.net/pingback.aspx</pingback:server>
      <pingback:target>http://vaultofthoughts.net/PermaLink,guid,237a2709-0d18-4ef9-99ed-b19d55765156.aspx</pingback:target>
      <dc:creator>Michal Talaga</dc:creator>
      <wfw:comment>http://vaultofthoughts.net/CommentView,guid,237a2709-0d18-4ef9-99ed-b19d55765156.aspx</wfw:comment>
      <wfw:commentRss>http://vaultofthoughts.net/SyndicationService.asmx/GetEntryCommentsRss?guid=237a2709-0d18-4ef9-99ed-b19d55765156</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Just few days ago, my friend at work found a peculiar error message in ASP.NET <em>RangeValidator</em> control.
He was trying to validate length of a string in a <em>TextBox</em>. Controls on page
definded as follows:
</p>
        <pre class="code">
          <span style="COLOR: rgb(0,0,255)">&lt;</span>
          <span style="COLOR: rgb(163,21,21)">asp</span>
          <span style="COLOR: rgb(0,0,255)">:</span>
          <span style="COLOR: rgb(163,21,21)">TextBox</span>
          <span style="COLOR: rgb(255,0,0)">runat</span>
          <span style="COLOR: rgb(0,0,255)">="server"</span>
          <span style="COLOR: rgb(255,0,0)">ID</span>
          <span style="COLOR: rgb(0,0,255)">="TB"</span>
          <span style="COLOR: rgb(0,0,255)">/&gt;
&lt;</span>
          <span style="COLOR: rgb(163,21,21)">asp</span>
          <span style="COLOR: rgb(0,0,255)">:</span>
          <span style="COLOR: rgb(163,21,21)">RangeValidator</span>
          <span style="COLOR: rgb(255,0,0)">runat</span>
          <span style="COLOR: rgb(0,0,255)">="server"</span>
          <span style="COLOR: rgb(255,0,0)">ID</span>
          <span style="COLOR: rgb(0,0,255)">="RV"</span>
          <span style="COLOR: rgb(255,0,0)">MinimumValue</span>
          <span style="COLOR: rgb(0,0,255)">="3"</span>
          <span style="COLOR: rgb(255,0,0)">MaximumValue</span>
          <span style="COLOR: rgb(0,0,255)">="20"</span>
          <span style="COLOR: rgb(255,0,0)">ControlToValidate</span>
          <span style="COLOR: rgb(0,0,255)">="TB"</span>
          <span style="COLOR: rgb(255,0,0)">Type</span>
          <span style="COLOR: rgb(0,0,255)">="String"</span>
          <span style="COLOR: rgb(0,0,255)">/&gt;</span>
        </pre>
        <a href="http://11011.net/software/vspaste">
        </a>
        <p>
What he got was a best error message ever:
</p>
        <p>
"<em>The MaximumValue 20 cannot be less than the MinimumValue 3</em>"
</p>
        <p>
That's right! 20 cannot be less than 3!
</p>
        <p>
Interesting isn't it?
</p>
        <p>
I made some research of my own and I've found out that sane people should not look
inside <em>RaneValidator</em>'s (and other related classes) code! What it does inside
is it uses a <em>String.Compare</em> to check if ranges are ok.
</p>
        <p>
Of course, the problem are not the ranges, but the <em>Type</em> property of a validator.
If set to String, it treates minimum and maximum values as strings and compares them
as such - meaning that it compares character by character instead of just number to
number.
</p>
        <p>
That explains, why my friend got the error, but it certainly does not justify the
text of the message! It might take long hours for an inexperienced developer to find
where the problem lies. Come on Microsoft! You can do better than that!
</p>
        <p>
Funny thing is that I never even thought about using <em>RangeValidator</em> to ensure
string length, but suggested <em>RegularExpressionValidator</em> right from the start
:-).
</p>
        <img width="0" height="0" src="http://vaultofthoughts.net/aggbug.ashx?id=237a2709-0d18-4ef9-99ed-b19d55765156" />
      </body>
      <title>RangeValidator Can't Count?</title>
      <guid isPermaLink="false">http://vaultofthoughts.net/PermaLink,guid,237a2709-0d18-4ef9-99ed-b19d55765156.aspx</guid>
      <link>http://VaultOfThoughts.net/RangeValidatorCantCount.aspx</link>
      <pubDate>Wed, 21 May 2008 18:44:48 GMT</pubDate>
      <description>&lt;p&gt;
Just few days ago, my friend at work found a peculiar error message in ASP.NET &lt;em&gt;RangeValidator&lt;/em&gt; control.
He was trying to validate length of a string in a &lt;em&gt;TextBox&lt;/em&gt;. Controls on page
definded as follows:
&lt;/p&gt;
&lt;pre class=code&gt;&lt;span style="COLOR: rgb(0,0,255)"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: rgb(163,21,21)"&gt;asp&lt;/span&gt;&lt;span style="COLOR: rgb(0,0,255)"&gt;:&lt;/span&gt;&lt;span style="COLOR: rgb(163,21,21)"&gt;TextBox&lt;/span&gt; &lt;span style="COLOR: rgb(255,0,0)"&gt;runat&lt;/span&gt;&lt;span style="COLOR: rgb(0,0,255)"&gt;="server"&lt;/span&gt; &lt;span style="COLOR: rgb(255,0,0)"&gt;ID&lt;/span&gt;&lt;span style="COLOR: rgb(0,0,255)"&gt;="TB"&lt;/span&gt; &lt;span style="COLOR: rgb(0,0,255)"&gt;/&amp;gt;
&amp;lt;&lt;/span&gt;&lt;span style="COLOR: rgb(163,21,21)"&gt;asp&lt;/span&gt;&lt;span style="COLOR: rgb(0,0,255)"&gt;:&lt;/span&gt;&lt;span style="COLOR: rgb(163,21,21)"&gt;RangeValidator&lt;/span&gt; &lt;span style="COLOR: rgb(255,0,0)"&gt;runat&lt;/span&gt;&lt;span style="COLOR: rgb(0,0,255)"&gt;="server"&lt;/span&gt; &lt;span style="COLOR: rgb(255,0,0)"&gt;ID&lt;/span&gt;&lt;span style="COLOR: rgb(0,0,255)"&gt;="RV"&lt;/span&gt; &lt;span style="COLOR: rgb(255,0,0)"&gt;MinimumValue&lt;/span&gt;&lt;span style="COLOR: rgb(0,0,255)"&gt;="3"&lt;/span&gt; &lt;span style="COLOR: rgb(255,0,0)"&gt;MaximumValue&lt;/span&gt;&lt;span style="COLOR: rgb(0,0,255)"&gt;="20"&lt;/span&gt; &lt;span style="COLOR: rgb(255,0,0)"&gt;ControlToValidate&lt;/span&gt;&lt;span style="COLOR: rgb(0,0,255)"&gt;="TB"&lt;/span&gt; &lt;span style="COLOR: rgb(255,0,0)"&gt;Type&lt;/span&gt;&lt;span style="COLOR: rgb(0,0,255)"&gt;="String"&lt;/span&gt; &lt;span style="COLOR: rgb(0,0,255)"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt; 
&lt;p&gt;
What he got was a best error message ever:
&lt;/p&gt;
&lt;p&gt;
"&lt;em&gt;The MaximumValue 20 cannot be less than the MinimumValue 3&lt;/em&gt;"
&lt;/p&gt;
&lt;p&gt;
That's right! 20 cannot be less than 3!
&lt;/p&gt;
&lt;p&gt;
Interesting isn't it?
&lt;/p&gt;
&lt;p&gt;
I made some research of my own and I've found out that sane people should not look
inside &lt;em&gt;RaneValidator&lt;/em&gt;'s (and other related classes) code! What it does inside
is it uses a &lt;em&gt;String.Compare&lt;/em&gt; to check if ranges are ok.
&lt;/p&gt;
&lt;p&gt;
Of course, the problem are not the ranges, but the &lt;em&gt;Type&lt;/em&gt; property of a validator.
If set to String, it treates minimum and maximum values as strings and compares them
as such - meaning that it compares character by character instead of just number to
number.
&lt;/p&gt;
&lt;p&gt;
That explains, why my friend got the error, but it certainly does not justify the
text of the message! It might take long hours for an inexperienced developer to find
where the problem lies. Come on Microsoft! You can do better than that!
&lt;/p&gt;
&lt;p&gt;
Funny thing is that I never even thought about using &lt;em&gt;RangeValidator&lt;/em&gt; to ensure
string length, but suggested &lt;em&gt;RegularExpressionValidator&lt;/em&gt; right from the start
:-).
&lt;/p&gt;
&lt;img width="0" height="0" src="http://vaultofthoughts.net/aggbug.ashx?id=237a2709-0d18-4ef9-99ed-b19d55765156" /&gt;</description>
      <comments>http://vaultofthoughts.net/CommentView,guid,237a2709-0d18-4ef9-99ed-b19d55765156.aspx</comments>
      <category>ASP.NET</category>
    </item>
    <item>
      <trackback:ping>http://vaultofthoughts.net/Trackback.aspx?guid=3c91b1f9-f013-47b9-a02f-8b58712ac9db</trackback:ping>
      <pingback:server>http://vaultofthoughts.net/pingback.aspx</pingback:server>
      <pingback:target>http://vaultofthoughts.net/PermaLink,guid,3c91b1f9-f013-47b9-a02f-8b58712ac9db.aspx</pingback:target>
      <dc:creator>Michal Talaga</dc:creator>
      <wfw:comment>http://vaultofthoughts.net/CommentView,guid,3c91b1f9-f013-47b9-a02f-8b58712ac9db.aspx</wfw:comment>
      <wfw:commentRss>http://vaultofthoughts.net/SyndicationService.asmx/GetEntryCommentsRss?guid=3c91b1f9-f013-47b9-a02f-8b58712ac9db</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
As we all know, ASP.NET uses one form model to do all it's magic. Love it or hate
it, we have to live with it. 99% of the time, it is not a problem, but then there
is this 1%...
</p>
        <p>
The main problem with ASP.NET's model is that the <strong>form</strong> tag has a
fixed <strong>action</strong> attribute. What if we want to change it? No, there is
no simple way of doing it. Solutions vary. Most common one is to create your own FormControl
that inherits from <em>HtmlForm</em> and override <em>RenderAttributes</em> method.
Unfortunately, inside that method, we have to do everything the original method does
and only change the <strong>action</strong> attribute to the desired value. Ugly!
</p>
        <p>
Another one is to provide an OutputFilter for the Response but that is also a lot
of coding.
</p>
        <p>
My preferred way of dealing with this issue is to provide my own, special <em>HtmlTextWriter</em>.
Its role is to intercept the <em>WriteAttribute</em> method call and provide my own
value. Following code illustrates the concept:
</p>
        <pre class="code">
          <span style="COLOR: rgb(0,0,255)">class</span>
          <span style="COLOR: rgb(43,145,175)">ActionAttributeWriter </span> : <span style="COLOR: rgb(43,145,175)">HtmlTextWriter </span>{ <span style="COLOR: rgb(0,0,255)">string</span> action; <span style="COLOR: rgb(0,0,255)">public</span> ActionAttributeWriter( <span style="COLOR: rgb(43,145,175)">HtmlTextWriter</span> writer, <span style="COLOR: rgb(0,0,255)">string</span> action)
: <span style="COLOR: rgb(0,0,255)">base</span>(writer) { <span style="COLOR: rgb(0,0,255)">this</span>.action
= action; } <span style="COLOR: rgb(0,0,255)">public</span><span style="COLOR: rgb(0,0,255)">override</span><span style="COLOR: rgb(0,0,255)">void</span> WriteAttribute
(<span style="COLOR: rgb(0,0,255)">string</span> name, <span style="COLOR: rgb(0,0,255)">string</span> value, <span style="COLOR: rgb(0,0,255)">bool</span> fEncode)
{ <span style="COLOR: rgb(0,0,255)">if</span> (name == <span style="COLOR: rgb(163,21,21)">"action"</span>)
{ value = action; } <span style="COLOR: rgb(0,0,255)">base</span>.WriteAttribute(name,
value, fEncode); } } </pre>
        <a href="http://11011.net/software/vspaste">
        </a>
        <p>
Only thing that is needed then is to use this writer instead of a normal one. <em>Page.CreateHtmlTextWriter</em> can
be used for this purpose:
</p>
        <pre class="code">
          <span style="COLOR: rgb(0,0,255)">protected</span>
          <span style="COLOR: rgb(0,0,255)">override</span>
          <span style="COLOR: rgb(43,145,175)">HtmlTextWriter</span> CreateHtmlTextWriter(System.IO.<span style="COLOR: rgb(43,145,175)">TextWriter</span> tw)
{ <span style="COLOR: rgb(43,145,175)">ActionAttributeWriter</span> writer = <span style="COLOR: rgb(0,0,255)">new</span><span style="COLOR: rgb(43,145,175)">ActionAttributeWriter</span>( <span style="COLOR: rgb(0,0,255)">base</span>.CreateHtmlTextWriter(tw),
"action"); <span style="COLOR: rgb(0,0,255)">return</span> writer; }</pre>
        <a href="http://11011.net/software/vspaste">
        </a>
        <p>
Solution is not very clean and I would certainly not recommend it for a public product,
but it's better than nothing.
</p>
        <img width="0" height="0" src="http://vaultofthoughts.net/aggbug.ashx?id=3c91b1f9-f013-47b9-a02f-8b58712ac9db" />
      </body>
      <title>Overriding ASP.NET Form Action Attribute</title>
      <guid isPermaLink="false">http://vaultofthoughts.net/PermaLink,guid,3c91b1f9-f013-47b9-a02f-8b58712ac9db.aspx</guid>
      <link>http://VaultOfThoughts.net/OverridingASPNETFormActionAttribute.aspx</link>
      <pubDate>Sat, 17 May 2008 13:09:17 GMT</pubDate>
      <description>&lt;p&gt;
As we all know, ASP.NET uses one form model to do all it's magic. Love it or hate
it, we have to live with it. 99% of the time, it is not a problem, but then there
is this 1%...
&lt;/p&gt;
&lt;p&gt;
The main problem with ASP.NET's model is that the &lt;strong&gt;form&lt;/strong&gt; tag has a
fixed &lt;strong&gt;action&lt;/strong&gt; attribute. What if we want to change it? No, there is
no simple way of doing it. Solutions vary. Most common one is to create your own FormControl
that inherits from &lt;em&gt;HtmlForm&lt;/em&gt; and override &lt;em&gt;RenderAttributes&lt;/em&gt; method.
Unfortunately, inside that method, we have to do everything the original method does
and only change the &lt;strong&gt;action&lt;/strong&gt; attribute to the desired value. Ugly!
&lt;/p&gt;
&lt;p&gt;
Another one is to provide an OutputFilter for the Response but that is also a lot
of coding.
&lt;/p&gt;
&lt;p&gt;
My preferred way of dealing with this issue is to provide my own, special &lt;em&gt;HtmlTextWriter&lt;/em&gt;.
Its role is to intercept the &lt;em&gt;WriteAttribute&lt;/em&gt; method call and provide my own
value. Following code illustrates the concept:
&lt;/p&gt;
&lt;pre class=code&gt;&lt;span style="COLOR: rgb(0,0,255)"&gt;class&lt;/span&gt; &lt;span style="COLOR: rgb(43,145,175)"&gt;ActionAttributeWriter &lt;/span&gt; : &lt;span style="COLOR: rgb(43,145,175)"&gt;HtmlTextWriter &lt;/span&gt;{ &lt;span style="COLOR: rgb(0,0,255)"&gt;string&lt;/span&gt; action; &lt;span style="COLOR: rgb(0,0,255)"&gt;public&lt;/span&gt; ActionAttributeWriter( &lt;span style="COLOR: rgb(43,145,175)"&gt;HtmlTextWriter&lt;/span&gt; writer, &lt;span style="COLOR: rgb(0,0,255)"&gt;string&lt;/span&gt; action)
: &lt;span style="COLOR: rgb(0,0,255)"&gt;base&lt;/span&gt;(writer) { &lt;span style="COLOR: rgb(0,0,255)"&gt;this&lt;/span&gt;.action
= action; } &lt;span style="COLOR: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="COLOR: rgb(0,0,255)"&gt;override&lt;/span&gt; &lt;span style="COLOR: rgb(0,0,255)"&gt;void&lt;/span&gt; WriteAttribute
(&lt;span style="COLOR: rgb(0,0,255)"&gt;string&lt;/span&gt; name, &lt;span style="COLOR: rgb(0,0,255)"&gt;string&lt;/span&gt; value, &lt;span style="COLOR: rgb(0,0,255)"&gt;bool&lt;/span&gt; fEncode)
{ &lt;span style="COLOR: rgb(0,0,255)"&gt;if&lt;/span&gt; (name == &lt;span style="COLOR: rgb(163,21,21)"&gt;"action"&lt;/span&gt;)
{ value = action; } &lt;span style="COLOR: rgb(0,0,255)"&gt;base&lt;/span&gt;.WriteAttribute(name,
value, fEncode); } } &lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt; 
&lt;p&gt;
Only thing that is needed then is to use this writer instead of a normal one. &lt;em&gt;Page.CreateHtmlTextWriter&lt;/em&gt; can
be used for this purpose:
&lt;/p&gt;
&lt;pre class=code&gt;&lt;span style="COLOR: rgb(0,0,255)"&gt;protected&lt;/span&gt; &lt;span style="COLOR: rgb(0,0,255)"&gt;override&lt;/span&gt; &lt;span style="COLOR: rgb(43,145,175)"&gt;HtmlTextWriter&lt;/span&gt; CreateHtmlTextWriter(System.IO.&lt;span style="COLOR: rgb(43,145,175)"&gt;TextWriter&lt;/span&gt; tw)
{ &lt;span style="COLOR: rgb(43,145,175)"&gt;ActionAttributeWriter&lt;/span&gt; writer = &lt;span style="COLOR: rgb(0,0,255)"&gt;new&lt;/span&gt; &lt;span style="COLOR: rgb(43,145,175)"&gt;ActionAttributeWriter&lt;/span&gt;( &lt;span style="COLOR: rgb(0,0,255)"&gt;base&lt;/span&gt;.CreateHtmlTextWriter(tw),
"action"); &lt;span style="COLOR: rgb(0,0,255)"&gt;return&lt;/span&gt; writer; }&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt; 
&lt;p&gt;
Solution is not very clean and I would certainly not recommend it for a public product,
but it's better than nothing.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://vaultofthoughts.net/aggbug.ashx?id=3c91b1f9-f013-47b9-a02f-8b58712ac9db" /&gt;</description>
      <comments>http://vaultofthoughts.net/CommentView,guid,3c91b1f9-f013-47b9-a02f-8b58712ac9db.aspx</comments>
      <category>ASP.NET</category>
    </item>
    <item>
      <trackback:ping>http://vaultofthoughts.net/Trackback.aspx?guid=c86b09e8-3a94-4a40-88a0-3fc72e2064b2</trackback:ping>
      <pingback:server>http://vaultofthoughts.net/pingback.aspx</pingback:server>
      <pingback:target>http://vaultofthoughts.net/PermaLink,guid,c86b09e8-3a94-4a40-88a0-3fc72e2064b2.aspx</pingback:target>
      <dc:creator>Michal Talaga</dc:creator>
      <wfw:comment>http://vaultofthoughts.net/CommentView,guid,c86b09e8-3a94-4a40-88a0-3fc72e2064b2.aspx</wfw:comment>
      <wfw:commentRss>http://vaultofthoughts.net/SyndicationService.asmx/GetEntryCommentsRss?guid=c86b09e8-3a94-4a40-88a0-3fc72e2064b2</wfw:commentRss>
      <slash:comments>5</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Today I needed to add an special field to my LINQ query. A kind of Row Number column.
Actually it was not a row number nor was it a column since LINQ deals with objects,
but since it was used for presenting data in a tabular way, I see no other name that
fits the description.
</p>
        <p>
So, I needed a data displayed in a following format:
</p>
        <table>
          <tbody>
            <tr>
              <td>
Lp.</td>
              <td>
Name</td>
            </tr>
            <tr>
              <td>
1</td>
              <td>
Murray N. Rothbard</td>
            </tr>
            <tr>
              <td>
2</td>
              <td>
Hans-Hermann Hoppe</td>
            </tr>
            <tr>
              <td>
3</td>
              <td>
Ludwig von Mises</td>
            </tr>
          </tbody>
        </table>
        <p>
First column had to be generated somehow. Using LINQ. I made few quick searches on
google, but whith no success, so I came out with my own solution:
</p>
        <pre class="code">
          <span style="color: rgb(0,0,255)">int</span> i = 1; <span style="color: rgb(0,0,255)">return</span><span style="color: rgb(0,0,255)">from</span> author <span style="color: rgb(0,0,255)">in</span> DataContext.Authors <span style="color: rgb(0,0,255)">select</span><span style="color: rgb(0,0,255)">new</span><span style="color: rgb(43,145,175)">Author</span>()
{ Lp = i++, Name = author.Name }; </pre>
        <a href="http://11011.net/software/vspaste">
        </a>
        <p>
So very simple. Isn't it?
</p>
        <img width="0" height="0" src="http://vaultofthoughts.net/aggbug.ashx?id=c86b09e8-3a94-4a40-88a0-3fc72e2064b2" />
      </body>
      <title>LINQ Row Number Column</title>
      <guid isPermaLink="false">http://vaultofthoughts.net/PermaLink,guid,c86b09e8-3a94-4a40-88a0-3fc72e2064b2.aspx</guid>
      <link>http://VaultOfThoughts.net/LINQRowNumberColumn.aspx</link>
      <pubDate>Fri, 04 Apr 2008 22:15:34 GMT</pubDate>
      <description>&lt;p&gt;
Today I needed to add an special field to my LINQ query. A kind of Row Number column.
Actually it was not a row number nor was it a column since LINQ deals with objects,
but since it was used for presenting data in a tabular way, I see no other name that
fits the description.
&lt;/p&gt;
&lt;p&gt;
So, I needed a data displayed in a following format:
&lt;/p&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
Lp.&lt;/td&gt;
&lt;td&gt;
Name&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
1&lt;/td&gt;
&lt;td&gt;
Murray N. Rothbard&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
2&lt;/td&gt;
&lt;td&gt;
Hans-Hermann Hoppe&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
3&lt;/td&gt;
&lt;td&gt;
Ludwig von Mises&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;
First column had to be generated somehow. Using LINQ. I made few quick searches on
google, but whith no success, so I came out with my own solution:
&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="color: rgb(0,0,255)"&gt;int&lt;/span&gt; i = 1; &lt;span style="color: rgb(0,0,255)"&gt;return&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;from&lt;/span&gt; author &lt;span style="color: rgb(0,0,255)"&gt;in&lt;/span&gt; DataContext.Authors &lt;span style="color: rgb(0,0,255)"&gt;select&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;Author&lt;/span&gt;()
{ Lp = i++, Name = author.Name }; &lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt; 
&lt;p&gt;
So very simple. Isn't it?
&lt;/p&gt;
&lt;img width="0" height="0" src="http://vaultofthoughts.net/aggbug.ashx?id=c86b09e8-3a94-4a40-88a0-3fc72e2064b2" /&gt;</description>
      <comments>http://vaultofthoughts.net/CommentView,guid,c86b09e8-3a94-4a40-88a0-3fc72e2064b2.aspx</comments>
    </item>
    <item>
      <trackback:ping>http://vaultofthoughts.net/Trackback.aspx?guid=6ad99098-07ed-4a28-b03d-26d75961d2e7</trackback:ping>
      <pingback:server>http://vaultofthoughts.net/pingback.aspx</pingback:server>
      <pingback:target>http://vaultofthoughts.net/PermaLink,guid,6ad99098-07ed-4a28-b03d-26d75961d2e7.aspx</pingback:target>
      <dc:creator>Michal Talaga</dc:creator>
      <wfw:comment>http://vaultofthoughts.net/CommentView,guid,6ad99098-07ed-4a28-b03d-26d75961d2e7.aspx</wfw:comment>
      <wfw:commentRss>http://vaultofthoughts.net/SyndicationService.asmx/GetEntryCommentsRss?guid=6ad99098-07ed-4a28-b03d-26d75961d2e7</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Today while using Reflector I've noticed one funny thing. It came out, that we are
able to see where Microsoft keeps their PublicKey files and what are their names :-)
</p>
        <p>
Few samples:
</p>
        <table>
          <tbody>
            <tr>
              <td>
mscorlib</td>
              <td>
f:\RedBits\Tools\devdiv\EcmaPublicKey.snk</td>
            </tr>
            <tr>
              <td>
System.Data.Linq</td>
              <td>
f:\dd\tools\devdiv\EcmaPublicKey.snk</td>
            </tr>
            <tr>
              <td>
System.Web</td>
              <td>
f:\RedBits\Tools\devdiv\FinalPublicKey.snk</td>
            </tr>
            <tr>
              <td>
Microsoft.VisualBasic</td>
              <td>
f:\\RedBits\\Tools\\devdiv\\FinalPublicKey.snk</td>
            </tr>
          </tbody>
        </table>
        <p>
Nothing special, but... Keep this in mind when doing RTM so you don't something that
shouldn't be distributed, like: CustomersIHate\Customer1\Key.snk
</p>
        <img width="0" height="0" src="http://vaultofthoughts.net/aggbug.ashx?id=6ad99098-07ed-4a28-b03d-26d75961d2e7" />
      </body>
      <title>Microsoft .NET Assemblies Public Key Names</title>
      <guid isPermaLink="false">http://vaultofthoughts.net/PermaLink,guid,6ad99098-07ed-4a28-b03d-26d75961d2e7.aspx</guid>
      <link>http://VaultOfThoughts.net/MicrosoftNETAssembliesPublicKeyNames.aspx</link>
      <pubDate>Wed, 02 Apr 2008 16:55:40 GMT</pubDate>
      <description>&lt;p&gt;
Today while using Reflector I've noticed one funny thing. It came out, that we are
able to see where Microsoft keeps their PublicKey files and what are their names :-)
&lt;/p&gt;
&lt;p&gt;
Few samples:
&lt;/p&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
mscorlib&lt;/td&gt;
&lt;td&gt;
f:\RedBits\Tools\devdiv\EcmaPublicKey.snk&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
System.Data.Linq&lt;/td&gt;
&lt;td&gt;
f:\dd\tools\devdiv\EcmaPublicKey.snk&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
System.Web&lt;/td&gt;
&lt;td&gt;
f:\RedBits\Tools\devdiv\FinalPublicKey.snk&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
Microsoft.VisualBasic&lt;/td&gt;
&lt;td&gt;
f:\\RedBits\\Tools\\devdiv\\FinalPublicKey.snk&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;
Nothing special, but... Keep this in mind when doing RTM so you don't something that
shouldn't be distributed, like: CustomersIHate\Customer1\Key.snk
&lt;/p&gt;
&lt;img width="0" height="0" src="http://vaultofthoughts.net/aggbug.ashx?id=6ad99098-07ed-4a28-b03d-26d75961d2e7" /&gt;</description>
      <comments>http://vaultofthoughts.net/CommentView,guid,6ad99098-07ed-4a28-b03d-26d75961d2e7.aspx</comments>
      <category>.NET</category>
    </item>
    <item>
      <trackback:ping>http://vaultofthoughts.net/Trackback.aspx?guid=39797173-aa4c-4e2d-9f84-6eeed5923bdc</trackback:ping>
      <pingback:server>http://vaultofthoughts.net/pingback.aspx</pingback:server>
      <pingback:target>http://vaultofthoughts.net/PermaLink,guid,39797173-aa4c-4e2d-9f84-6eeed5923bdc.aspx</pingback:target>
      <dc:creator>Michal Talaga</dc:creator>
      <wfw:comment>http://vaultofthoughts.net/CommentView,guid,39797173-aa4c-4e2d-9f84-6eeed5923bdc.aspx</wfw:comment>
      <wfw:commentRss>http://vaultofthoughts.net/SyndicationService.asmx/GetEntryCommentsRss?guid=39797173-aa4c-4e2d-9f84-6eeed5923bdc</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
One thing that I like about SQL is the IN operator which checks if an argument is
equal to any of the listed elements. C#/.NET doesn't offer this kind of operator which
forces us to use code similar to the one below:
</p>
        <pre class="code">
          <span style="color: rgb(0,0,255)">int</span> i = 5; <span style="color: rgb(0,0,255)">if</span> (i
== 5 || i == 4 || i == 3) { <span style="color: rgb(0,0,255)">return</span>; }</pre>
        <a href="http://11011.net/software/vspaste">
        </a>
        <p>
Wouldn't it be better if we could just write like this:
</p>
        <pre class="code">
          <span style="color: rgb(0,0,255)">if</span> (i.In(5, 4, 3)) { <span style="color: rgb(0,0,255)">return</span>;
} </pre>
        <a href="http://11011.net/software/vspaste">
        </a>
        <p>
What we need is a simple Extension Method:
</p>
        <pre class="code">
          <span style="color: rgb(0,0,255)">public</span>
          <span style="color: rgb(0,0,255)">static</span>
          <span style="color: rgb(0,0,255)">bool</span> In&lt;T&gt;(<span style="color: rgb(0,0,255)">this</span> T
source, <span style="color: rgb(0,0,255)">params</span> T[] values) { <span style="color: rgb(0,0,255)">return</span> values.Any(v
=&gt; v.Equals(source)); }</pre>
        <a href="http://11011.net/software/vspaste">
        </a>
        <p>
Few things to notice. First I'm using generic type parameter T to avoid boxing for
Value Types. Second, it would probably be a wise thing to write few overrides like
this:
</p>
        <pre class="code">
          <span style="color: rgb(0,0,255)">public</span>
          <span style="color: rgb(0,0,255)">static</span>
          <span style="color: rgb(0,0,255)">bool</span> In(<span style="color: rgb(0,0,255)">this</span><span style="color: rgb(43,145,175)">IComparable</span> source, <span style="color: rgb(0,0,255)">params</span><span style="color: rgb(43,145,175)">IComparable</span>[]
values) { <span style="color: rgb(0,0,255)">return</span> values.Any(v =&gt; v.CompareTo(source)
== 0); } </pre>
        <a href="http://11011.net/software/vspaste">
        </a>
        <p>
And another one for generic version. Finally it would be wise to provide an overload
that accepts <em>IEqualityComparer</em>, like like LINQ extension methods do.
</p>
        <p>
Whatever you do, you just have to love Extension Methods :-)
</p>
        <img width="0" height="0" src="http://vaultofthoughts.net/aggbug.ashx?id=39797173-aa4c-4e2d-9f84-6eeed5923bdc" />
      </body>
      <title>Element In Collection Extension Method</title>
      <guid isPermaLink="false">http://vaultofthoughts.net/PermaLink,guid,39797173-aa4c-4e2d-9f84-6eeed5923bdc.aspx</guid>
      <link>http://VaultOfThoughts.net/ElementInCollectionExtensionMethod.aspx</link>
      <pubDate>Tue, 01 Apr 2008 20:32:49 GMT</pubDate>
      <description>&lt;p&gt;
One thing that I like about SQL is the IN operator which checks if an argument is
equal to any of the listed elements. C#/.NET doesn't offer this kind of operator which
forces us to use code similar to the one below:
&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="color: rgb(0,0,255)"&gt;int&lt;/span&gt; i = 5; &lt;span style="color: rgb(0,0,255)"&gt;if&lt;/span&gt; (i
== 5 || i == 4 || i == 3) { &lt;span style="color: rgb(0,0,255)"&gt;return&lt;/span&gt;; }&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt; 
&lt;p&gt;
Wouldn't it be better if we could just write like this:
&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="color: rgb(0,0,255)"&gt;if&lt;/span&gt; (i.In(5, 4, 3)) { &lt;span style="color: rgb(0,0,255)"&gt;return&lt;/span&gt;;
} &lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt; 
&lt;p&gt;
What we need is a simple Extension Method:
&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;static&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;bool&lt;/span&gt; In&amp;lt;T&amp;gt;(&lt;span style="color: rgb(0,0,255)"&gt;this&lt;/span&gt; T
source, &lt;span style="color: rgb(0,0,255)"&gt;params&lt;/span&gt; T[] values) { &lt;span style="color: rgb(0,0,255)"&gt;return&lt;/span&gt; values.Any(v
=&amp;gt; v.Equals(source)); }&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt; 
&lt;p&gt;
Few things to notice. First I'm using generic type parameter T to avoid boxing for
Value Types. Second, it would probably be a wise thing to write few overrides like
this:
&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;static&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;bool&lt;/span&gt; In(&lt;span style="color: rgb(0,0,255)"&gt;this&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;IComparable&lt;/span&gt; source, &lt;span style="color: rgb(0,0,255)"&gt;params&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;IComparable&lt;/span&gt;[]
values) { &lt;span style="color: rgb(0,0,255)"&gt;return&lt;/span&gt; values.Any(v =&amp;gt; v.CompareTo(source)
== 0); } &lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt; 
&lt;p&gt;
And another one for generic version. Finally it would be wise to provide an overload
that accepts &lt;em&gt;IEqualityComparer&lt;/em&gt;, like like LINQ extension methods do.
&lt;/p&gt;
&lt;p&gt;
Whatever you do, you just have to love Extension Methods :-)
&lt;/p&gt;
&lt;img width="0" height="0" src="http://vaultofthoughts.net/aggbug.ashx?id=39797173-aa4c-4e2d-9f84-6eeed5923bdc" /&gt;</description>
      <comments>http://vaultofthoughts.net/CommentView,guid,39797173-aa4c-4e2d-9f84-6eeed5923bdc.aspx</comments>
    </item>
    <item>
      <trackback:ping>http://vaultofthoughts.net/Trackback.aspx?guid=3eb1672d-aeb6-4d34-b544-991bae0fab9f</trackback:ping>
      <pingback:server>http://vaultofthoughts.net/pingback.aspx</pingback:server>
      <pingback:target>http://vaultofthoughts.net/PermaLink,guid,3eb1672d-aeb6-4d34-b544-991bae0fab9f.aspx</pingback:target>
      <dc:creator>Michal Talaga</dc:creator>
      <wfw:comment>http://vaultofthoughts.net/CommentView,guid,3eb1672d-aeb6-4d34-b544-991bae0fab9f.aspx</wfw:comment>
      <wfw:commentRss>http://vaultofthoughts.net/SyndicationService.asmx/GetEntryCommentsRss?guid=3eb1672d-aeb6-4d34-b544-991bae0fab9f</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
There is a nice little base class hidden inside <em>System.Collections.ObjectModel</em> namespace.
Its name is <em>KeyedCollection</em>. Its there to solve all those situations when
we need a collection where items are to be unique, a "collection whose keys are embedded
in the values" - as MSDN describes it.
</p>
        <p>
As nice as the class is, there is one problem. It is abstract. The reason it is abstract
is the <em>GetKeyForItem</em> method. For each type what we need a unique collection,
we need to create a new class, inherit it from the <em>KeyedCollection</em> and override
that one method. I think that's a bit of a waste of time and needles complexity in
most cases. Fortunately, there is hope.
</p>
        <p>
Enter KCollection. The idea behind it is to use Lambda Expressions where we had to
override the <em>GetKeyForItem</em> method before. Sample code should explain everything:
</p>
        <pre class="code">
          <span style="COLOR: rgb(0,0,255)">class</span>
          <span style="COLOR: rgb(43,145,175)">KCollection</span>&lt;TKey,
TItem&gt; : <span style="COLOR: rgb(43,145,175)">KeyedCollection</span>&lt;TKey, TItem&gt;
{ <span style="COLOR: rgb(43,145,175)">Func</span>&lt;TItem, TKey&gt; getKey; <span style="COLOR: rgb(0,0,255)">public</span> KCollection(<span style="COLOR: rgb(43,145,175)">Func</span>&lt;TItem,
TKey&gt; getKey) { <span style="COLOR: rgb(0,0,255)">this</span>.getKey = getKey;
} <span style="COLOR: rgb(0,0,255)">protected</span><span style="COLOR: rgb(0,0,255)">override</span> TKey
GetKeyForItem(TItem item) { <span style="COLOR: rgb(0,0,255)">return</span> getKey(item);
} }</pre>
        <a href="http://11011.net/software/vspaste">
        </a>
        <p>
And usage looks as follows:
</p>
        <pre class="code">
          <span style="COLOR: rgb(43,145,175)">KCollection</span>&lt;<span style="COLOR: rgb(0,0,255)">int</span>, <span style="COLOR: rgb(43,145,175)">Client</span>&gt;
kcol = <span style="COLOR: rgb(0,0,255)">new</span><span style="COLOR: rgb(43,145,175)">KCollection</span>&lt;<span style="COLOR: rgb(0,0,255)">int</span>, <span style="COLOR: rgb(43,145,175)">Client</span>&gt;(c
=&gt; c.Id);</pre>
        <p>
Where Client is a simple class:
</p>
        <pre class="code">
          <span style="COLOR: rgb(0,0,255)">class</span>
          <span style="COLOR: rgb(43,145,175)">Client </span>{ <span style="COLOR: rgb(0,0,255)">public</span><span style="COLOR: rgb(0,0,255)">int</span> Id; <span style="COLOR: rgb(0,0,255)">public</span><span style="COLOR: rgb(0,0,255)">string</span> Name;
} </pre>
        <p>
Of course we could achieve similar functionality using .NET 2.0 and delegates, I think
Lambda Expressions are just nicer.
</p>
        <img width="0" height="0" src="http://vaultofthoughts.net/aggbug.ashx?id=3eb1672d-aeb6-4d34-b544-991bae0fab9f" />
      </body>
      <title>KeyedCollection Lambda Expression Way</title>
      <guid isPermaLink="false">http://vaultofthoughts.net/PermaLink,guid,3eb1672d-aeb6-4d34-b544-991bae0fab9f.aspx</guid>
      <link>http://VaultOfThoughts.net/KeyedCollectionLambdaExpressionWay.aspx</link>
      <pubDate>Sat, 29 Mar 2008 13:44:47 GMT</pubDate>
      <description>&lt;p&gt;
There is a nice little base class hidden inside &lt;em&gt;System.Collections.ObjectModel&lt;/em&gt; namespace.
Its name is &lt;em&gt;KeyedCollection&lt;/em&gt;. Its there to solve all those situations when
we need a collection where items are to be unique, a "collection whose keys are embedded
in the values" - as MSDN describes it.
&lt;/p&gt;
&lt;p&gt;
As nice as the class is, there is one problem. It is abstract. The reason it is abstract
is the &lt;em&gt;GetKeyForItem&lt;/em&gt; method. For each type what we need a unique collection,
we need to create a new class, inherit it from the &lt;em&gt;KeyedCollection&lt;/em&gt; and override
that one method. I think that's a bit of a waste of time and needles complexity in
most cases. Fortunately, there is hope.
&lt;/p&gt;
&lt;p&gt;
Enter KCollection. The idea behind it is to use Lambda Expressions where we had to
override the &lt;em&gt;GetKeyForItem&lt;/em&gt; method before. Sample code should explain everything:
&lt;/p&gt;
&lt;pre class=code&gt;&lt;span style="COLOR: rgb(0,0,255)"&gt;class&lt;/span&gt; &lt;span style="COLOR: rgb(43,145,175)"&gt;KCollection&lt;/span&gt;&amp;lt;TKey,
TItem&amp;gt; : &lt;span style="COLOR: rgb(43,145,175)"&gt;KeyedCollection&lt;/span&gt;&amp;lt;TKey, TItem&amp;gt;
{ &lt;span style="COLOR: rgb(43,145,175)"&gt;Func&lt;/span&gt;&amp;lt;TItem, TKey&amp;gt; getKey; &lt;span style="COLOR: rgb(0,0,255)"&gt;public&lt;/span&gt; KCollection(&lt;span style="COLOR: rgb(43,145,175)"&gt;Func&lt;/span&gt;&amp;lt;TItem,
TKey&amp;gt; getKey) { &lt;span style="COLOR: rgb(0,0,255)"&gt;this&lt;/span&gt;.getKey = getKey;
} &lt;span style="COLOR: rgb(0,0,255)"&gt;protected&lt;/span&gt; &lt;span style="COLOR: rgb(0,0,255)"&gt;override&lt;/span&gt; TKey
GetKeyForItem(TItem item) { &lt;span style="COLOR: rgb(0,0,255)"&gt;return&lt;/span&gt; getKey(item);
} }&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt; 
&lt;p&gt;
And usage looks as follows:
&lt;/p&gt;
&lt;pre class=code&gt;&lt;span style="COLOR: rgb(43,145,175)"&gt;KCollection&lt;/span&gt;&amp;lt;&lt;span style="COLOR: rgb(0,0,255)"&gt;int&lt;/span&gt;, &lt;span style="COLOR: rgb(43,145,175)"&gt;Client&lt;/span&gt;&amp;gt;
kcol = &lt;span style="COLOR: rgb(0,0,255)"&gt;new&lt;/span&gt; &lt;span style="COLOR: rgb(43,145,175)"&gt;KCollection&lt;/span&gt;&amp;lt;&lt;span style="COLOR: rgb(0,0,255)"&gt;int&lt;/span&gt;, &lt;span style="COLOR: rgb(43,145,175)"&gt;Client&lt;/span&gt;&amp;gt;(c
=&amp;gt; c.Id);&lt;/pre&gt;
&lt;p&gt;
Where Client is a simple class:
&lt;/p&gt;
&lt;pre class=code&gt;&lt;span style="COLOR: rgb(0,0,255)"&gt;class&lt;/span&gt; &lt;span style="COLOR: rgb(43,145,175)"&gt;Client &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;int&lt;/span&gt; Id; &lt;span style="COLOR: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="COLOR: rgb(0,0,255)"&gt;string&lt;/span&gt; Name;
} &lt;/pre&gt;
&lt;p&gt;
Of course we could achieve similar functionality using .NET 2.0 and delegates, I think
Lambda Expressions are just nicer.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://vaultofthoughts.net/aggbug.ashx?id=3eb1672d-aeb6-4d34-b544-991bae0fab9f" /&gt;</description>
      <comments>http://vaultofthoughts.net/CommentView,guid,3eb1672d-aeb6-4d34-b544-991bae0fab9f.aspx</comments>
      <category>.NET</category>
    </item>
    <item>
      <trackback:ping>http://vaultofthoughts.net/Trackback.aspx?guid=ab20e2dd-c740-4d28-a471-a0cbd17df516</trackback:ping>
      <pingback:server>http://vaultofthoughts.net/pingback.aspx</pingback:server>
      <pingback:target>http://vaultofthoughts.net/PermaLink,guid,ab20e2dd-c740-4d28-a471-a0cbd17df516.aspx</pingback:target>
      <dc:creator>Michal Talaga</dc:creator>
      <wfw:comment>http://vaultofthoughts.net/CommentView,guid,ab20e2dd-c740-4d28-a471-a0cbd17df516.aspx</wfw:comment>
      <wfw:commentRss>http://vaultofthoughts.net/SyndicationService.asmx/GetEntryCommentsRss?guid=ab20e2dd-c740-4d28-a471-a0cbd17df516</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I've never liked VB.NET. Probably because I was (un)fortunate enough to work with
VB6 for 2 years, even though .NET and C# were already there. Nevertheless I'm aware
that VB.NET tends to offer some very useful syntax not found in C#.
</p>
        <p>
One thing that I've recently discovered is the ability to specify a "Key Properties"
when defining an Anonymous Type.
</p>
        <p>
Syntax for the declaration is more or less as follows:
</p>
        <pre class="code">
          <span style="COLOR: rgb(0,0,255)">Dim</span> person = <span style="COLOR: rgb(0,0,255)">New</span><span style="COLOR: rgb(0,0,255)">With</span> {<span style="COLOR: rgb(0,0,255)">Key</span> .Id
= 1, .Name = <span style="COLOR: rgb(163,21,21)">"John"</span>}</pre>
        <a href="http://11011.net/software/vspaste">
        </a>
        <p>
Notice the Key keyword before Id property. Now the interesting thing is that VB.NET
compiler generates the Equals method that compares objects for equality, using only
the Key Properties as opposed to comparing all properties when code is generated by
C# compiler.
</p>
        <p>
Now tell me that VB.NET is slower than C#.
</p>
        <p>
More on the topic can be found on <a href="http://msdn2.microsoft.com/en-us/library/bb384767.aspx">MSDN
article on Anonymous Types in VB.NET</a>, in section on Key Properties of course.
</p>
        <img width="0" height="0" src="http://vaultofthoughts.net/aggbug.ashx?id=ab20e2dd-c740-4d28-a471-a0cbd17df516" />
      </body>
      <title>Key Properties In VB.NET</title>
      <guid isPermaLink="false">http://vaultofthoughts.net/PermaLink,guid,ab20e2dd-c740-4d28-a471-a0cbd17df516.aspx</guid>
      <link>http://VaultOfThoughts.net/KeyPropertiesInVBNET.aspx</link>
      <pubDate>Sat, 29 Mar 2008 10:59:11 GMT</pubDate>
      <description>&lt;p&gt;
I've never liked VB.NET. Probably because I was (un)fortunate enough to work with
VB6 for 2 years, even though .NET and C# were already there. Nevertheless I'm aware
that VB.NET tends to offer some very useful syntax not found in C#.
&lt;/p&gt;
&lt;p&gt;
One thing that I've recently discovered is the ability to specify a "Key Properties"
when defining an Anonymous Type.
&lt;/p&gt;
&lt;p&gt;
Syntax for the declaration is more or less as follows:
&lt;/p&gt;
&lt;pre class=code&gt;&lt;span style="COLOR: rgb(0,0,255)"&gt;Dim&lt;/span&gt; person = &lt;span style="COLOR: rgb(0,0,255)"&gt;New&lt;/span&gt; &lt;span style="COLOR: rgb(0,0,255)"&gt;With&lt;/span&gt; {&lt;span style="COLOR: rgb(0,0,255)"&gt;Key&lt;/span&gt; .Id
= 1, .Name = &lt;span style="COLOR: rgb(163,21,21)"&gt;"John"&lt;/span&gt;}&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt; 
&lt;p&gt;
Notice the Key keyword before Id property. Now the interesting thing is that VB.NET
compiler generates the Equals method that compares objects for equality, using only
the Key Properties as opposed to comparing all properties when code is generated by
C# compiler.
&lt;/p&gt;
&lt;p&gt;
Now tell me that VB.NET is slower than C#.
&lt;/p&gt;
&lt;p&gt;
More on the topic can be found on &lt;a href="http://msdn2.microsoft.com/en-us/library/bb384767.aspx"&gt;MSDN
article on Anonymous Types in VB.NET&lt;/a&gt;, in section on Key Properties of course.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://vaultofthoughts.net/aggbug.ashx?id=ab20e2dd-c740-4d28-a471-a0cbd17df516" /&gt;</description>
      <comments>http://vaultofthoughts.net/CommentView,guid,ab20e2dd-c740-4d28-a471-a0cbd17df516.aspx</comments>
      <category>.NET</category>
    </item>
  </channel>
</rss>