<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Veggerby : IBlog &#187; .NET General</title>
	<atom:link href="http://blog.veggerby.dk/category/net-general/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.veggerby.dk</link>
	<description>Low decoupling, highly incoherent</description>
	<lastBuildDate>Fri, 28 May 2010 19:47:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>ISO 8601/RFC 3339 Compatible Dates</title>
		<link>http://blog.veggerby.dk/2009/10/04/iso-8601rfc-3339-compatible-dates/</link>
		<comments>http://blog.veggerby.dk/2009/10/04/iso-8601rfc-3339-compatible-dates/#comments</comments>
		<pubDate>Sun, 04 Oct 2009 15:09:00 +0000</pubDate>
		<dc:creator>nosey</dc:creator>
				<category><![CDATA[.NET General]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Dates]]></category>
		<category><![CDATA[Extension Methods]]></category>
		<category><![CDATA[ISO]]></category>
		<category><![CDATA[RFC]]></category>

		<guid isPermaLink="false">http://blog.veggerby.dk/2009/10/04/iso-8601rfc-3339-compatible-dates/</guid>
		<description><![CDATA[There are not standard format specifiers for date that takes a date and converts it to an ISO 8601 or RFC 3339 compatible date. Here are two extension methods that does just that. public static string ToISO8601(this DateTime date) { return date.ToString(&#34;yyyy-MM-dd&#34;); } public static string ToRFC3339(this DateTime date) { return date.ToUniversalTime().ToString(&#34;yyyy-MM-ddThh:mm:ssZ&#34;); }]]></description>
			<content:encoded><![CDATA[<p>There are not standard format specifiers for date that takes a date and converts it to an <a href="http://en.wikipedia.org/wiki/ISO_8601#Dates">ISO 8601</a> or <a href="http://www.faqs.org/rfcs/rfc3339.html">RFC 3339</a> compatible date. Here are two extension methods that does just that.</p>
<pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 100%; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px">
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"><span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">string</span> ToISO8601(<span style="color: #0000ff">this</span> DateTime date)
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">{
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #0000ff">return</span> date.ToString(&quot;<span style="color: #8b0000">yyyy-MM-dd</span>&quot;);
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">}
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"><span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">string</span> ToRFC3339(<span style="color: #0000ff">this</span> DateTime date)
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">{
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #0000ff">return</span> date.ToUniversalTime().ToString(&quot;<span style="color: #8b0000">yyyy-MM-ddThh:mm:ssZ</span>&quot;);
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">}</pre>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.veggerby.dk/2009/10/04/iso-8601rfc-3339-compatible-dates/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Generating a Slug From a String</title>
		<link>http://blog.veggerby.dk/2009/10/02/generating-a-slug-from-a-string/</link>
		<comments>http://blog.veggerby.dk/2009/10/02/generating-a-slug-from-a-string/#comments</comments>
		<pubDate>Fri, 02 Oct 2009 18:41:00 +0000</pubDate>
		<dc:creator>nosey</dc:creator>
				<category><![CDATA[.NET General]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Extension Methods]]></category>
		<category><![CDATA[Slug]]></category>
		<category><![CDATA[Unicode]]></category>
		<category><![CDATA[url]]></category>

		<guid isPermaLink="false">http://blog.veggerby.dk/2009/10/02/generating-a-slug-from-a-string/</guid>
		<description><![CDATA[I can’t (and won’t) take full credit for this extension method. The hardcore Unicode stuff is from Michael Kaplan’s blog (jeez, he is hardcore). There is a little danish “stuff” included, for special characters æ, ø and å, which can also be written “ae”, “oe” an “aa”. public static string ToSlug(this string message) { // [...]]]></description>
			<content:encoded><![CDATA[<p>I can’t (and won’t) take full credit for this extension method. The hardcore Unicode stuff is from <a href="http://blogs.msdn.com/michkap/archive/2007/05/14/2629747.aspx">Michael Kaplan’s blog</a> (jeez, he is hardcore). There is a little danish “stuff” included, for special characters æ, ø and å, which can also be written “ae”, “oe” an “aa”.</p>
<pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 100%; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px">
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"><span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">string</span> ToSlug(<span style="color: #0000ff">this</span> <span style="color: #0000ff">string</span> message)
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">{
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #008000">// replace space with -</span>
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    message = Regex.Replace(message, @&quot;<span style="color: #8b0000">[\s/\\\.,+|_]+</span>&quot;, &quot;<span style="color: #8b0000">-</span>&quot;);
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #008000">// normalize the message </span>
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    message = message.Normalize(NormalizationForm.FormD);
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    message = message.Replace(&quot;<span style="color: #8b0000">ø</span>&quot;, &quot;<span style="color: #8b0000">oe</span>&quot;).Replace(&quot;<span style="color: #8b0000">Ø</span>&quot;, &quot;<span style="color: #8b0000">Oe</span>&quot;).Replace(&quot;<span style="color: #8b0000">æ</span>&quot;, &quot;<span style="color: #8b0000">ae</span>&quot;).Replace(&quot;<span style="color: #8b0000">Æ</span>&quot;, &quot;<span style="color: #8b0000">Ae</span>&quot;).Replace(&quot;<span style="color: #8b0000">å</span>&quot;, &quot;<span style="color: #8b0000">aa</span>&quot;).Replace(&quot;<span style="color: #8b0000">Å</span>&quot;, &quot;<span style="color: #8b0000">Aa</span>&quot;);
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    StringBuilder result = <span style="color: #0000ff">new</span> StringBuilder();
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #0000ff">for</span> (<span style="color: #0000ff">int</span> i = 0; i &lt; message.Length; i++)
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    {
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">        UnicodeCategory uc = CharUnicodeInfo.GetUnicodeCategory(message[i]);
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">        <span style="color: #0000ff">if</span> (uc != UnicodeCategory.NonSpacingMark)
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">        {
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">            result.Append(message[i]);
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">        }
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    }
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #0000ff">return</span> Regex.Replace(result.ToString().Normalize(NormalizationForm.FormC), @&quot;<span style="color: #8b0000">[^a-zA-Z0-9\-]</span>&quot;, &quot;<span style="color: #8b0000"></span>&quot;).ToLower();
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">}</pre>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.veggerby.dk/2009/10/02/generating-a-slug-from-a-string/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MD5 Extension Method</title>
		<link>http://blog.veggerby.dk/2009/09/29/md5-extension-method/</link>
		<comments>http://blog.veggerby.dk/2009/09/29/md5-extension-method/#comments</comments>
		<pubDate>Tue, 29 Sep 2009 12:38:00 +0000</pubDate>
		<dc:creator>nosey</dc:creator>
				<category><![CDATA[.NET General]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Extension Methods]]></category>
		<category><![CDATA[hash]]></category>
		<category><![CDATA[md5]]></category>
		<category><![CDATA[Secure Hash]]></category>

		<guid isPermaLink="false">http://blog.veggerby.dk/2009/09/29/md5-extension-method/</guid>
		<description><![CDATA[A nifty little extension method that generated the MD5/SHA-1 hash of a string. These methods are a continuation of my previous post: public static string MD5(this string value) { System.Security.Cryptography.MD5 algorithm = System.Security.Cryptography.MD5.Create(); byte[] data = Encoding.ASCII.GetBytes(value); data = algorithm.ComputeHash(data); string md5 = &#34;&#34;; for (int i = 0; i &#60; data.Length; i++) { md5 [...]]]></description>
			<content:encoded><![CDATA[<p>A nifty little extension method that generated the MD5/SHA-1 hash of a string. These methods are a continuation of <a href="http://blog.veggerby.dk/2008/07/27/formsauthenticationhashpasswordforstoringinconfigfile-continued/">my previous post</a>:</p>
<pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 100%; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px">
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"><span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">string</span> MD5(<span style="color: #0000ff">this</span> <span style="color: #0000ff">string</span> <span style="color: #0000ff">value</span>)
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">{
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    System.Security.Cryptography.MD5 algorithm =
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">        System.Security.Cryptography.MD5.Create();
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #0000ff">byte</span>[] data = Encoding.ASCII.GetBytes(<span style="color: #0000ff">value</span>);
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    data = algorithm.ComputeHash(data);
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #0000ff">string</span> md5 = &quot;<span style="color: #8b0000"></span>&quot;;
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #0000ff">for</span> (<span style="color: #0000ff">int</span> i = 0; i &lt; data.Length; i++)
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    {
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">        md5 += data[i].ToString(&quot;<span style="color: #8b0000">x2</span>&quot;).ToLower();
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    }
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #0000ff">return</span> md5;
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">}</pre>
</pre>
<p>Just substitute <a href="http://msdn.microsoft.com/en-us/library/system.security.cryptography.md5.aspx">MD5</a> for <a href="http://msdn.microsoft.com/en-us/library/system.security.cryptography.sha1.aspx">SHA1</a>, <a href="http://msdn.microsoft.com/en-us/library/system.security.cryptography.sha256.aspx">SHA256</a>, <a href="http://msdn.microsoft.com/en-us/library/system.security.cryptography.sha384.aspx">SHA384</a>, <a href="http://msdn.microsoft.com/en-us/library/system.security.cryptography.sha512.aspx">SHA512</a> or <a href="http://msdn.microsoft.com/en-us/library/system.security.cryptography.ripemd160.aspx">RIPEMD160</a> which ever hash algorithm fits your needs.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.veggerby.dk/2009/09/29/md5-extension-method/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Relative Time Description</title>
		<link>http://blog.veggerby.dk/2009/09/28/relative-time-description/</link>
		<comments>http://blog.veggerby.dk/2009/09/28/relative-time-description/#comments</comments>
		<pubDate>Mon, 28 Sep 2009 19:46:48 +0000</pubDate>
		<dc:creator>nosey</dc:creator>
				<category><![CDATA[.NET General]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Dates]]></category>
		<category><![CDATA[Extension Methods]]></category>

		<guid isPermaLink="false">http://blog.veggerby.dk/2009/09/28/relative-time-description/</guid>
		<description><![CDATA[Showing an absolute date on a webpage, e.g. January 22, 2009 13:01, is of course a very normal way to do it, apart from various different date formats, it is easily read and consumed. However if the date is shown in a context where the absolute date is of little importance, but it is more [...]]]></description>
			<content:encoded><![CDATA[<p>Showing an absolute date on a webpage, e.g. January 22, 2009 13:01, is of course a very normal way to do it, apart from various different date formats, it is easily read and consumed. However if the date is shown in a context where the absolute date is of little importance, but it is more important to know if it was a long time ago, just now or maybe just in a couple of minutes, a relative and more descriptive method is better. </p>
<p>For example the date mentioned above might be described as “8 months ago”. Just by giving it a quick glance you get an idea about when this event occurred.</p>
<p>For this here are a couple of extension methods that generate this descriptive text based on a given time:</p>
<pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 100%; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px">
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"><span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">string</span> ToRelativeTime(<span style="color: #0000ff">this</span> DateTime from)
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">{
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    DateTime now = DateTime.Now;
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #0000ff">return</span> from.ToRelativeTime(now);
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">}
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"><span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">string</span> ToRelativeTime(<span style="color: #0000ff">this</span> DateTime from, <span style="color: #0000ff">bool</span> usePreAndSuffix)
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">{
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    DateTime now = DateTime.Now;
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #0000ff">return</span> from.ToRelativeTime(now, usePreAndSuffix);
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">}
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"><span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">string</span> ToRelativeTime(<span style="color: #0000ff">this</span> DateTime from, DateTime to)
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">{
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #0000ff">return</span> from.ToRelativeTime(to, <span style="color: #0000ff">true</span>);
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">}
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"><span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">string</span> ToRelativeTime(<span style="color: #0000ff">this</span> DateTime from, DateTime to, <span style="color: #0000ff">bool</span> usePreAndSuffix)
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">{
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #0000ff">string</span> prefix = usePreAndSuffix &amp;&amp; (from &gt; to) ? &quot;<span style="color: #8b0000">in </span>&quot; : <span style="color: #0000ff">string</span>.Empty;
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #0000ff">string</span> suffix = !usePreAndSuffix || (from &gt; to) ? <span style="color: #0000ff">string</span>.Empty : &quot;<span style="color: #8b0000"> ago</span>&quot;;
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #008000">// is more than 1 year?</span>
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #0000ff">if</span> (from &gt; to)
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    {
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">        DateTime d = from;
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">        from = to;
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">        to = d;
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    }
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #0000ff">int</span> years = to.Year - from.Year;
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #0000ff">if</span> ((to.Month &lt; from.Month) || ((to.Month == from.Month) &amp;&amp; (to.Day &lt; from.Day)))
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    {
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">        years--;
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    }
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #0000ff">if</span> (years &gt; 1)
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    {
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">        <span style="color: #0000ff">return</span> <span style="color: #0000ff">string</span>.Format(&quot;<span style="color: #8b0000">{0}{1} years{2}</span>&quot;, prefix, years, suffix);
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    }
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #0000ff">else</span> <span style="color: #0000ff">if</span> (years == 1)
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    {
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">        <span style="color: #0000ff">return</span> <span style="color: #0000ff">string</span>.Format(&quot;<span style="color: #8b0000">{0}1 year{1}</span>&quot;, prefix, suffix);
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    }
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #008000">// less than 1 year, is more than 1 month?</span>
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #0000ff">int</span> months = to.Month - from.Month;
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #0000ff">if</span> (months &lt; 0)
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    {
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">        months += 12;
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    }
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #0000ff">if</span> ((to.Day &lt; from.Day) || ((to.Day == from.Day) &amp;&amp; (to.TimeOfDay &lt; from.TimeOfDay)))
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    {
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">        months--;
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    }
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #0000ff">if</span> (months &gt; 1)
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    {
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">        <span style="color: #0000ff">return</span> <span style="color: #0000ff">string</span>.Format(&quot;<span style="color: #8b0000">{0}{1} months{2}</span>&quot;, prefix, months, suffix);
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    }
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #0000ff">else</span> <span style="color: #0000ff">if</span> (months == 1)
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    {
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">        <span style="color: #0000ff">return</span> <span style="color: #0000ff">string</span>.Format(&quot;<span style="color: #8b0000">{0}1 month{1}</span>&quot;, prefix, suffix);
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    }
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #008000">// less than 1 month, is more than 1 day/week?</span>
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    TimeSpan diff = to - from;
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #0000ff">if</span> (diff.Days &gt; 7)
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    {
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">        <span style="color: #0000ff">return</span> <span style="color: #0000ff">string</span>.Format(&quot;<span style="color: #8b0000">{0}{1} weeks{2}</span>&quot;, prefix, diff.Days / 7, suffix);
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    }
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #0000ff">else</span> <span style="color: #0000ff">if</span> (diff.Days &gt; 1)
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    {
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">        <span style="color: #0000ff">return</span> <span style="color: #0000ff">string</span>.Format(&quot;<span style="color: #8b0000">{0}{1} days{2}</span>&quot;, prefix, diff.Days, suffix);
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    }
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #0000ff">else</span> <span style="color: #0000ff">if</span> (diff.Days == 1)
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    {
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">        <span style="color: #0000ff">return</span> <span style="color: #0000ff">string</span>.Format(&quot;<span style="color: #8b0000">{0}1 day{1}</span>&quot;, prefix, suffix);
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    }
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #008000">// less than 1 day, is more than 1 hour?</span>
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #0000ff">if</span> (diff.Hours &gt; 1)
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    {
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">        <span style="color: #0000ff">return</span> <span style="color: #0000ff">string</span>.Format(&quot;<span style="color: #8b0000">{0}{1} hours{2}</span>&quot;, prefix, diff.Hours, suffix);
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    }
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #0000ff">else</span> <span style="color: #0000ff">if</span> (diff.Hours == 1)
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    {
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">        <span style="color: #0000ff">return</span> <span style="color: #0000ff">string</span>.Format(&quot;<span style="color: #8b0000">{0}1 hour{1}</span>&quot;, prefix, suffix);
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    }
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #008000">// less than 1 hour, is more than 1 minute?</span>
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #0000ff">if</span> (diff.Minutes &gt; 1)
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    {
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">        <span style="color: #0000ff">return</span> <span style="color: #0000ff">string</span>.Format(&quot;<span style="color: #8b0000">{0}{1} minutes{2}</span>&quot;, prefix, diff.Minutes, suffix);
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    }
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #0000ff">else</span> <span style="color: #0000ff">if</span> (diff.Minutes == 1)
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    {
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">        <span style="color: #0000ff">return</span> <span style="color: #0000ff">string</span>.Format(&quot;<span style="color: #8b0000">{0}1 minute{1}</span>&quot;, prefix, suffix);
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    }
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #008000">// less than 1 minute</span>
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #0000ff">if</span> (diff.Seconds == 1)
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    {
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">        <span style="color: #0000ff">return</span> <span style="color: #0000ff">string</span>.Format(&quot;<span style="color: #8b0000">{0}1 second{1}</span>&quot;, prefix, suffix);
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    }
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #0000ff">else</span> <span style="color: #0000ff">if</span> (diff.Seconds &lt; 1)
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    {
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">        <span style="color: #0000ff">return</span> <span style="color: #0000ff">string</span>.Format(&quot;<span style="color: #8b0000">{0}less than 1 second{1}</span>&quot;, prefix, suffix);
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    }
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #0000ff">return</span> <span style="color: #0000ff">string</span>.Format(&quot;<span style="color: #8b0000">{0}{1} seconds{2}</span>&quot;, prefix, diff.Seconds, suffix);
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">}</pre>
</pre>
<p>This can of course be optimized for localization etc.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.veggerby.dk/2009/09/28/relative-time-description/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ADO.NET Entitity Framework vs. LINQ to SQL</title>
		<link>http://blog.veggerby.dk/2008/11/01/adonet-entitity-framework-vs-linq-to-sql/</link>
		<comments>http://blog.veggerby.dk/2008/11/01/adonet-entitity-framework-vs-linq-to-sql/#comments</comments>
		<pubDate>Sat, 01 Nov 2008 00:18:12 +0000</pubDate>
		<dc:creator>nosey</dc:creator>
				<category><![CDATA[.NET General]]></category>
		<category><![CDATA[ado.net]]></category>
		<category><![CDATA[entity framework]]></category>
		<category><![CDATA[linq to entities]]></category>
		<category><![CDATA[linq to sql]]></category>

		<guid isPermaLink="false">http://blog.veggerby.dk/?p=102</guid>
		<description><![CDATA[I have never been a huge fan of all the ADO.NET stuff &#8211; one exception: the DataReader. Everything else seems to me just to be bloated functionality around what I really need. How ADO.NET handles connections and commands are in my opinion overly &#34;complex&#34; &#8211; not that they are complex in any way, they could [...]]]></description>
			<content:encoded><![CDATA[<p>I have never been a huge fan of all the <a href="http://msdn.microsoft.com/en-us/data/aa937699.aspx">ADO.NET</a> stuff &#8211; one exception: the <a title="IDataReader Interface" href="http://msdn2.microsoft.com/sh674a6a.aspx">DataReader</a>. Everything else seems to me just to be bloated functionality around what I really need. How ADO.NET handles connections and commands are in my opinion overly &quot;complex&quot; &#8211; not that they are complex in any way, they could just be done <a href="http://msdn.microsoft.com/en-us/library/dd203144.aspx">way simpler</a>. Whenever I have been writing code that access a database, I tend to rely on my trusted companion: the <a href="http://msdn.microsoft.com/en-us/library/cc467894.aspx">Enterprise Library</a>. It provides such a nice and clean abstraction to the unneeded (IMHO) overhead posed by <a title="IDbConnection Interface" href="http://msdn2.microsoft.com/bs16hf60.aspx">Connection</a>, <a title="IDbCommand Interface" href="http://msdn2.microsoft.com/bt2afddc.aspx">Command</a> and <a title="IDataParameter Interface" href="http://msdn2.microsoft.com/b14k9y11.aspx">Parameter</a> handling.</p>
<p>Compare:</p>
<div class="vscode"><span style="color: #2b91af">Database</span> db = <span style="color: #2b91af">DatabaseFactory</span>.CreateDatabase(<span style="color: #a31515">&quot;my connectionstring&quot;</span>);     <br /><span style="color: #0000ff">using</span> (<span style="color: #2b91af">IDataReader</span> reader = db.ExecuteReader(<span style="color: #a31515">&quot;my stored procedure&quot;</span>, <span style="color: #a31515">&quot;my parameter 1&quot;</span>, myParameter2, etc))     <br />{     <br />&#160;&#160;&#160; <span style="color: #008000">// do my thang      <br /></span>}</div>
<p>To:</p>
<div class="vscode"><span style="color: #0000ff">using</span> (<span style="color: #2b91af">SqlConnection</span> conn = <span style="color: #0000ff">new</span> <span style="color: #2b91af">SqlConnection</span>(<span style="color: #a31515">&quot;my connectionstring&quot;</span>))     <br />{     <br />&#160;&#160;&#160; conn.Open();     <br />&#160;&#160;&#160; <span style="color: #2b91af">SqlCommand</span> cmd = conn.CreateCommand();     <br />&#160;&#160;&#160; cmd.CommandText = <span style="color: #a31515">&quot;my stored procedure&quot;</span>;     <br />&#160;&#160;&#160; cmd.CommandType = <span style="color: #2b91af">CommandType</span>.StoredProcedure;     </p>
<p>&#160;&#160;&#160; <span style="color: #2b91af">SqlParameter</span> param = cmd.CreateParameter();     <br />&#160;&#160;&#160; param.ParameterName = <span style="color: #a31515">&quot;@param1&quot;</span>;     <br />&#160;&#160;&#160; param.DbType = <span style="color: #2b91af">DbType</span>.String;     <br />&#160;&#160;&#160; param.Value = <span style="color: #a31515">&quot;my parameter 1&quot;</span>;     <br />&#160;&#160;&#160; cmd.Parameters.Add(param);     </p>
<p>&#160;&#160;&#160; param = cmd.CreateParameter();     <br />&#160;&#160;&#160; param.ParameterName = <span style="color: #a31515">&quot;@param2&quot;</span>;     <br />&#160;&#160;&#160; param.DbType = <span style="color: #2b91af">DbType</span>.Int32;     <br />&#160;&#160;&#160; param.Value = myParameter2;     <br />&#160;&#160;&#160; cmd.Parameters.Add(param);     </p>
<p>&#160;&#160;&#160; param = cmd.CreateParameter();     <br />&#160;&#160;&#160; param.ParameterName = <span style="color: #a31515">&quot;@param3&quot;</span>;     <br />&#160;&#160;&#160; param.DbType = <span style="color: #2b91af">DbType</span>.Int32;     <br />&#160;&#160;&#160; param.Value = etc;     <br />&#160;&#160;&#160; cmd.Parameters.Add(param);     </p>
<p>&#160;&#160;&#160; <span style="color: #0000ff">using</span> (<span style="color: #2b91af">IDataReader</span> reader = cmd.ExecuteReader())     <br />&#160;&#160;&#160; {     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #008000">// do your thang      <br /></span>&#160;&#160;&#160; }     <br />}</div>
<p>And don’t get me started on the <a title="DataSet Class" href="http://msdn2.microsoft.com/bwy42y0e.aspx">DataSet</a>&#8230;</p>
<p>Now, <a href="http://blogs.msdn.com/adonet/archive/2008/10/29/update-on-linq-to-sql-and-linq-to-entities-roadmap.aspx">MS has implied that LINQ to SQL will be deprecated</a> and focus will be moved to the <a href="http://msdn.microsoft.com/en-us/library/bb399572.aspx">ADO.NET Entity Framework</a> and <a href="http://msdn.microsoft.com/en-us/library/bb386992.aspx">LINQ to Entities</a>. This has already stirred up the .NET community: <a href="http://codebetter.com/blogs/david.hayden/archive/2008/10/30/linq-to-sql-gets-kicked-to-the-curb-needs-a-good-home.aspx">David Hayden</a>, <a href="http://codebetter.com/blogs/ian_cooper/archive/2008/07/02/showing-some-support-for-linq-to-sql.aspx">Ian Cooper</a>, <a href="http://ayende.com/Blog/archive/2008/10/31/microsoft-kills-linq-to-sql.aspx">Ayende Rahien</a> to name a few.</p>
<p>I have never really considered using LINQ to SQL in big applications, mainly because I think LINQ to SQL imposes some constraints on my applications – one simple thing like the “low coupling” principle is not something that comes out of the box, it has to be tweaked and twisted to even give just a hint of low coupling. However I see LINQ to SQL as a very, very nice low-level method to create a basic SQL based data foundation.</p>
<p>For example, I am privately playing around with a blog engine based on <a href="http://www.asp.net/mvc">ASP.NET MVC</a> and LINQ, both XML and SQL. In this case LINQ to SQL is near-perfect for my needs. It provides sufficient abstraction from the database without imposing too much overhead, by providing flexibility in all future scenarios if the database suddenly need to be converted to an Oracle DB or refactored/de-normalized due to poor performance or whatever. It allows me to write SQL like-statements that (to a large extent) is verified at compile time. Sure I could do the same in LINQ to Entities, but it feels like firing up a super-tanker for something that really just need to be according to the <a href="http://en.wikipedia.org/wiki/KISS_principle">KISS principle</a>. LINQ to SQL is to a large extent very much KISS’ish, and fits perfectly in to the use I required for my playground project here.</p>
<p>I like to throw in this favorite quote of mine:</p>
<blockquote><p>&quot;Perfection is not when there&#8217;s nothing to add, but when there&#8217;s nothing to take away.&quot;     <br />- Antoine de Saint-Exupéry</p>
</blockquote>
<p>Or <a href="http://en.wikipedia.org/wiki/Occam%27s_razor">Occam’s Razor</a> for that matter:</p>
<blockquote><p>“All other things being equal, the simplest solution is the best”</p>
</blockquote>
<p>Another thing about LINQ to Entities (and this is just based on a my brief experience with the ADO.NET Entity Framework), the designers within Visual Studio are <strike>not very good</strike> <strike>pretty bad</strike> very bad. </p>
<p>When creating a new “ADO.NET Entity Data Model” it does allow a reverse engineering possibility for an existing database. The model you end of with is simply a 1:1 mapping between entities and tables, i.e. the <a href="http://martinfowler.com/eaaCatalog/activeRecord.html">Active Record pattern</a>. This is fine, but LINQ to SQL does the same – again “supertanker”. The Entity Framework is designed to be an abstraction of your database not “just” an Active Record pattern, i.e. your data model does not need to reflect your database schema in a 1:1 mapping. This <u>is</u> pretty neat, and can be useful, especially on larger projects where you are not creating the database schema yourself, or you are working on top of an existing SQL database. BUT if I create a very simple SQL database for a very specific scenario, I don’t really need this.</p>
<p>Another thing that is very bad in the designers is that once your model has been reverse engineered and you want to begin modifying/abstracting it, things get very, very tedious. The tools in the designer are not helping very much, i.e. apart from initial reverse engineering the database, utilizing the schema meta data to create properties etc. is not possible. The model is (granted) fairly intuitive, but the task of adding properties that map to columns, etc. is just overly “complex” (again complex in as it could be done way simpler).</p>
<p>The key feature of the Entity Framework to work on-top of any database has also <u>on my first shot</u> failed. Maybe it is poor database design, I’m not really a DBA so I’ll let others be the judge of that. But I have a scenario where I have a n:n relation between two tables – Person and Group. But instead of having the foreign keys in my cross reference table being the primary key hereof, I have an explicit primary key:</p>
<p><img title="image" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="322" alt="image" src="http://blog.veggerby.dk/wp-content/uploads/2008/11/image.png" width="528" border="0" /> </p>
<p>When creating the ADO.NET Entity Data Model in Visual Studio (by reverse engineering).</p>
<p><img title="image" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="191" alt="image" src="http://blog.veggerby.dk/wp-content/uploads/2008/11/image1.png" width="673" border="0" /> </p>
<p>That is of course fair enough, so I remove the PersonGroup entity and create a many-many association between Person and Group with the following setup:</p>
<p><img title="image" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="129" alt="image" src="http://blog.veggerby.dk/wp-content/uploads/2008/11/image2.png" width="608" border="0" /> </p>
<p>I get this error:</p>
<blockquote><p>Error 3025: Problem in Mapping Fragment starting at line 115: Must specify mapping for all key properties (PersonGroup.Id) of table PersonGroup.</p>
</blockquote>
<p>You also have to map ALL columns in the database to properties in the entity model, maybe I don&#8217;t what that! What if my entity model is really built on top of an already running database, and my job is to create a another user interface for e.g. a mobile device which requires just a subset of the database schema. I don’t want to map the entire shebang, for one because it is very tedious and second because the rest of the schema might contain sensitive information that should not be exposed on the mobile device (or whatever reason).</p>
<p>What is it with that homemade Entity-SQL stuff, that really smells too much like reinventing the wheel &#8211; we already have SQL (a standard) which on top of that has T-SQL and then we have LINQ in our managed code – this is really enough query languages for one application! Do we really need yet another proprietary query language (although it has a lot of similarity with SQL &#8211; but so does T-SQL and LINQ)? I don’t think so!</p>
<p>Not to mention that for demoing LINQ to SQL is just perfect &#8211; however I don&#8217;t (sadly) think that could justify MS investments in the LINQ to SQL framework alone.</p>
<p>This is just my gut feeling, maybe it has no substance when it comes to reality! But one thing I know is: I like LINQ to SQL for what it is, but equally much for <u>what it isn&#8217;t</u>. </p>
<p>Please prove me wrong!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.veggerby.dk/2008/11/01/adonet-entitity-framework-vs-linq-to-sql/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Cool upcoming .NET stuff from Microsoft</title>
		<link>http://blog.veggerby.dk/2008/09/13/cool-upcoming-net-stuff-from-microsoft/</link>
		<comments>http://blog.veggerby.dk/2008/09/13/cool-upcoming-net-stuff-from-microsoft/#comments</comments>
		<pubDate>Sat, 13 Sep 2008 13:41:16 +0000</pubDate>
		<dc:creator>nosey</dc:creator>
				<category><![CDATA[.NET General]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[On .NET]]></category>
		<category><![CDATA[Oslo]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[upcoming]]></category>
		<category><![CDATA[Velocity]]></category>
		<category><![CDATA[Zermatt]]></category>

		<guid isPermaLink="false">http://blog.veggerby.dk/2008/09/13/cool-upcoming-net-stuff-from-microsoft/</guid>
		<description><![CDATA[Silverlight 2.0 Version 2.0 of the ubercool Silverlight, Microsoft&#8217; pendant to Adobe Flash, is drawing nigh. Currently available as beta 2, release in june &#8217;08. Silverlight 2.0 allows embedded code client-side, by some magic, that does not even require having the .NET framework installed on the client. ASP.NET MVC Framework Quoting the ASP.NET MVC page: [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Silverlight 2.0</strong></p>
<p><a href="http://silverlight.net/">Version 2.0</a> of the ubercool Silverlight, <a href="http://microsoft.com">Microsoft&#8217;</a> pendant to Adobe Flash, is drawing nigh. Currently available as <a href="http://weblogs.asp.net/scottgu/archive/2008/06/06/silverlight-2-beta2-released.aspx">beta 2</a>, release in june &#8217;08. Silverlight 2.0 allows embedded code client-side, by some magic, that does not even require having the .NET framework installed on the client.</p>
<p><strong>ASP.NET MVC Framework</strong></p>
<p>Quoting the <a href="http://www.asp.net/mvc/">ASP.NET MVC page</a>:</p>
<blockquote><p>ASP.NET MVC enables you to build Model View Controller (MVC) applications by using the ASP.NET framework. ASP.NET MVC is an alternative, not a replacement, for ASP.NET Web Forms that offers the following benefits: </p>
<ul>
<li>Clear separation of concerns </li>
<li>Testability &#8211; support for Test-Driven Development </li>
<li>Fine-grained control over HTML and JavaScript </li>
<li>Intuitive URLs </li>
</ul>
</blockquote>
<p>References: <a href="http://www.asp.net/mvc/">Official page</a>, <a href="http://weblogs.asp.net/scottgu/archive/2008/09/02/asp-net-mvc-preview-5-and-form-posting-scenarios.aspx">Scott Guthrie MVC Preview 5 Release post</a></p>
<p><strong>Zermatt</strong></p>
<p>Quoting <a href="https://connect.microsoft.com/site/sitehome.aspx?SiteID=642">Zermatt home page</a>:</p>
<blockquote><p>Zermatt is a framework for implementing claims-based identity in your applications. By using it, you&#8217;ll more easily reap the benefits of the claims-based identity model described in this <a href="https://connect.microsoft.com/Downloads/DownloadDetails.aspx?SiteID=642&amp;DownloadID=12901">paper</a>.</p>
</blockquote>
<p>References: <a href="https://connect.microsoft.com/site/sitehome.aspx?SiteID=642">Official page</a>, <a href="http://blogs.msdn.com/vbertocci/archive/2008/07/09/announcing-the-beta-release-of-zermatt-developer-identity-framework.aspx">Vittorio Bertocci blog</a>, <a href="http://www.pluralsight.com/community/blogs/keith/archive/2008/07/09/introducing-microsoft-code-name-zermatt.aspx">Keith Brown blog</a></p>
<p><strong>Velocity</strong></p>
<p>Quoting <a href="http://blogs.msdn.com/velocity/archive/2008/06/02/introducing-project-codename-velocity.aspx">Velocity Blog</a></p>
<blockquote><p>(&#8230;) a distributed caching product to provide the .NET application platform support for developing highly performant, scalable, and highly available applications.</p>
</blockquote>
<p>References: <a href="http://blogs.msdn.com/velocity/">Velocity blog</a></p>
<p><strong>Oslo</strong></p>
<p>Quoting the <a href="http://www.microsoft.com/soa/products/oslo.aspx">official Oslo page</a>:</p>
<blockquote><p>&#8221;Oslo&#8221; is the codename for Microsoft&#8217;s forthcoming modeling platform. Modeling is used across a wide range of domains and allows more people to participate in application design and allows developers to write applications at a much higher level of abstraction. &#8220;Oslo&#8221; consists of:</p>
<ul>
<li>A tool that helps people define and interact with models in a rich and visual manner </li>
<li>A language that helps people create and use textual domain-specific languages and data models </li>
<li>A relational repository that makes models available to both tools and platform components</li>
</ul>
</blockquote>
<p>References: <a href="http://www.microsoft.com/soa/products/oslo.aspx">Official page</a>, <a href="http://douglaspurdy.com/2008/09/06/what-is-oslo/">Douglas Purdy &#8211; &quot;What is Oslo?&quot;</a>, <a href="http://www.pluralsight.com/community/blogs/dbox/archive/2008/09/06/oslo.aspx">Don Box blog</a>, <a href="http://www.microsoft.com/presspass/events/soa-bpm/materials.mspx">Various MS SOA articles (incl. non Oslo stuff)</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.veggerby.dk/2008/09/13/cool-upcoming-net-stuff-from-microsoft/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Must have tools for .NET developers</title>
		<link>http://blog.veggerby.dk/2008/09/12/must-have-tools-for-net-developers/</link>
		<comments>http://blog.veggerby.dk/2008/09/12/must-have-tools-for-net-developers/#comments</comments>
		<pubDate>Fri, 12 Sep 2008 15:17:44 +0000</pubDate>
		<dc:creator>nosey</dc:creator>
				<category><![CDATA[.NET General]]></category>
		<category><![CDATA[Reference Sheet]]></category>
		<category><![CDATA[ASP.NET WPF]]></category>
		<category><![CDATA[On .NET]]></category>
		<category><![CDATA[tools]]></category>

		<guid isPermaLink="false">http://blog.veggerby.dk/2008/09/12/must-have-tools-for-net-developers/</guid>
		<description><![CDATA[Like so many others have done before me I would like to present my take on a compiled list of favorite tools for developing using .NET. Here goes: Reflector The most useful tool ever to reverse engineer assemblies &#8211; yes, it is a gray-zone regarding IP, but nonetheless very, very use full. Kudos to Lutz [...]]]></description>
			<content:encoded><![CDATA[<p>Like so many others have done before me I would like to present my take on a compiled list of favorite tools for developing using .NET.</p>
<p>Here goes:</p>
<p><a href="http://www.red-gate.com/products/reflector/">Reflector</a></p>
<p>The most useful tool ever to reverse engineer assemblies &#8211; yes, it is a gray-zone regarding <a href="http://en.wikipedia.org/wiki/Intellectual_property">IP</a>, but nonetheless very, very use full. <a href="http://en.wikipedia.org/wiki/Kudos">Kudos</a> to <a href="http://www.lutzroeder.com/">Lutz Roeder</a> for this ultimate tool, and thank you very much for your effort in this. Lutz announced some days ago that he would end his work on Reflector. Red Gate (known for their useful tool SQL Compare &#8211; as mentioned later on <img src='http://blog.veggerby.dk/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> ) has taken over and &quot;(&#8230;) will continue to <strong>maintain a free version for the benefit of the community</strong>&quot;. Do they implicitly say that there will be a commercial version!? I hope not &#8211; that would for sure have <u>some</u> effect on the <a href="http://www.codeplex.com/reflectoraddins">Reflector community</a>.</p>
<p><a href="http://www.red-gate.com/products/SQL_Compare/index.htm">Red Gate SQL Compare</a></p>
<p>I really, really hate to include a commercial product in my toolbox, but being there are no free alternatives to a much required tool, I will include the best one I know of (or rather the only one I have used, but it is extremely useful and good so why bother with the others!?). Please drop a comment if you know of free and/or good/better alternatives. Price tag on the basic SQL Compare is $395.</p>
<p><a href="http://www.linqpad.net/">LINQPad</a></p>
<p>Query Analyzer for <a href="http://msdn.microsoft.com/en-us/library/bb308959.aspx">LINQ</a>. Very nice tool to help build, execute and debug queries, wether it be LINQ for SQL, LINQ for Objects or LINQ for XML.</p>
<p><a href="http://code.msdn.microsoft.com/sourceanalysis">StyleCop</a></p>
<p>StyleCop is a <a href="http://msdn.microsoft.com/en-us/vstudio/default.aspx">Visual Studio</a> plug-in that performs code analysis directly on source code with the intent on enforcing a common coding standard for layout, readability, documentation and maintainability. SDK documentation for creating custom rules is available. StyleCop was originally created by one devoted (and might I add brilliant) <a href="http://microsoft.com/">Microsoft</a> employee (Jason Allor) <em>in his spare time</em>. The tool has been <a href="http://blogs.msdn.com/sourceanalysis/archive/2008/05/23/announcing-the-release-of-microsoft-source-analysis.aspx">used internally</a> in Microsoft for years, but was first made available to the general public earlier this year. Follow Jason&#8217;s/the StyleCop blog <a href="http://blogs.msdn.com/sourceanalysis/">here</a>.</p>
<p><a href="http://code.msdn.microsoft.com/codeanalysis">FxCop</a></p>
<p>FxCop is a tool to analyze managed assemblies for possible security issues and possible design and performance improvements that can be implemented. </p>
<p><a href="http://visualsvn.com/">VisualSVN</a></p>
<p>Sorry, but yet another commercial product. If you are using the most excellent <a href="http://en.wikipedia.org/wiki/Revision_control">version control system</a>&#160;<a href="http://subversion.tigris.org/">Subversion</a> (if not then consider it!), there is a most excellent plug-in for Visual Studio. Comes with a free <a href="http://visualsvn.com/server/">server</a> version as well, which simplifies setup of Subversion on a Windows box. A free alternative &#8211; however I did not find it nearly as good as Visual SVN &#8211; is <a href="http://ankhsvn.open.collab.net/">AnkhSVN</a>. Neither unfortunately though are <a href="http://msdn.microsoft.com/en-us/library/bb166170(VS.80).aspx">MSSCCI</a> (Microsoft Source Code Control Interface) which means that they do not plug-in to the native source control module in Visual Studio. Price tag for Visual SVN is $49. For more information about Subversion you can read the <a href="http://svnbook.red-bean.com/">SVN Book online</a>.</p>
<h2>For ASP.NET Developers</h2>
<p>Must haves:</p>
<p><a href="http://getfirefox.com/">Firefox</a> with <a href="http://getfirebug.com/">Firebug</a> and <a href="https://addons.mozilla.org/en-US/firefox/addon/60">Web Developer Toolbar</a></p>
<p>Firefox speaks for itself, and so should Firebug, but a brief introduction: Firebug allows you to inspect and modify HTML, CSS and DOM. Debugging JavaScript and explicitly capture JavaScript <a href="http://www.w3.org/TR/XMLHttpRequest/">XmlHttpRequest</a> calls for debugging <a href="http://en.wikipedia.org/wiki/Ajax_(programming)">AJAX</a>. The Web Developer Toolbar provides some additional functionality to what Firebug adds, but to some extent is a complimentary plugin.</p>
<p>Internet Explorer with <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=E59C3964-672D-4511-BB3E-2D5E1DB91038&amp;displaylang=en">Developer Toolbar</a></p>
<p>It is inevitable that as a web developer you need to assure <a href="http://en.wikipedia.org/wiki/Cross-browser">cross-browser compatibility</a>. Therefor a similar tool exists for Internet Explorer 6 and 7, however it not nearly as cool, so for general debugging, etc. Firebug is the choice, but for IE specific, the Internet Explorer Developer Toolbar does come handy.</p>
<p><a href="http://www.fiddlertool.com/fiddler/">Fiddler</a></p>
<p>Another tool that can help in debugging web applications/services is Fiddler. Fiddler acts as a HTTP proxy, logging all HTTP traffic from the local computer to other computers. This however means that out-of-the-box HTTP debugging when using <a href="http://blog.veggerby.dk/2007/05/20/differences-between-using-cassini-and-iis/">Cassini</a> (i.e. the development web &quot;server&quot; in Visual Studio) is not possible. <a href="http://weblogs.asp.net/asptest/archive/2008/08/13/tip-on-using-fiddler-with-cassini-and-localhost.aspx">It</a> <a href="http://www.codinghorror.com/blog/archives/000590.html">has</a> <a href="http://weblogs.asp.net/lorenh/archive/2008/01/10/tip-for-using-fiddler-on-localhost.aspx">to</a> <a href="http://weblogs.asp.net/scottcate/archive/2008/05/22/working-with-fiddler-on-localhost.aspx">be</a> <a href="http://www.treeratfishing.com/2008/06/08/using-fiddler-with-localhost-traffic/">tweaked</a>.</p>
<h2>For WPF / Silverlight Developers</h2>
<p><a href="http://www.kaxaml.com/">Kaxaml</a></p>
<p>Kaxaml is a lightweight <a href="http://msdn.microsoft.com/en-us/library/ms752059.aspx">XAML</a> editor with the split design / output view similar to the Visual Studio IDE. Kaxaml is a complimentary tool to <a href="http://en.wikipedia.org/wiki/Microsoft_Expression_Blend">Expression Blend</a>, however Blend provides much more functionality, hence &quot;lightweight&quot;.</p>
<p><a href="http://www.codeproject.com/KB/macros/MoleForVisualStudioEdit.aspx">Mole</a></p>
<p>Mole is a reverse engineering tool, similar to Reflector. However Mole disassembles the XAML of a <a href="http://msdn.microsoft.com/en-us/netframework/aa663326.aspx">WPF</a>/<a href="http://silverlight.net">Silverlight</a> application and provides a tree view of the XAML structure. Nice for &quot;how did they do that&quot;, but again gray zone concerning IP.</p>
<h2><a href="http://en.wikipedia.org/wiki/Dark_horse">&quot;Dark Horses&quot;</a></h2>
<p>Since I have not had any real experience with these I will put them on a &quot;dark horse&quot; list, just for reference, since they might prove themselves valuable given the time/opportunity to use them.</p>
<p><a href="http://code.msdn.microsoft.com/fds">Framework Design Studio</a></p>
<p>Quoting the FDS site:</p>
<blockquote><p>Framework Design Studio is a set of tools for reusable library designers. The package contains a GUI tool for viewing, reviewing, and comparing versions of managed APIs. It also contains a command line tool for generating API diff reports. Simple user guide explaining the basics of the tool is included in the setup.</p>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://blog.veggerby.dk/2008/09/12/must-have-tools-for-net-developers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Temporary Stream</title>
		<link>http://blog.veggerby.dk/2008/07/28/temporary-stream/</link>
		<comments>http://blog.veggerby.dk/2008/07/28/temporary-stream/#comments</comments>
		<pubDate>Mon, 28 Jul 2008 17:58:01 +0000</pubDate>
		<dc:creator>nosey</dc:creator>
				<category><![CDATA[.NET General]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[stream]]></category>

		<guid isPermaLink="false">http://blog.veggerby.dk/2008/07/28/temporary-stream/</guid>
		<description><![CDATA[Scenario: you need to store a large block of data, e.g. as the result of an XSL transformation on an XML document. Using a MemoryStream would simply kill your server/application since it would use too much memory. Using a FileStream can be a but tedious since it would require write permissions on a specific folder&#8230; [...]]]></description>
			<content:encoded><![CDATA[<p>Scenario: you need to store a large block of data, e.g. as the result of an XSL transformation on an XML document. Using a <a title="MemoryStream Class" href="http://msdn2.microsoft.com/9a84386f.aspx">MemoryStream</a> would simply kill your server/application since it would use too much memory. Using a <a title="FileStream Class" href="http://msdn2.microsoft.com/y0bs3w9t.aspx">FileStream</a> can be a but tedious since it would require write permissions on a specific folder&#8230;</p>
<p>Wait, doesn&#8217;t this sound just like a temporary file, i.e. storing a file in the TEMP path. </p>
<p>Yes, it does &#8211; and a simple solution is actually just to use a FileStream with a twist:</p>
<div class="vscode"><span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> <span style="color: #2b91af">TempFileStream</span> : <span style="color: #2b91af">FileStream     <br /></span>{    </p>
<p>&#160;&#160;&#160; <span style="color: #0000ff">public</span> TempFileStream()    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; : <span style="color: #0000ff">base</span>(<span style="color: #2b91af">Path</span>.GetTempFileName(), <span style="color: #2b91af">FileMode</span>.OpenOrCreate, <span style="color: #2b91af">FileAccess</span>.ReadWrite)    <br />&#160;&#160;&#160; {    <br />&#160;&#160;&#160; }    </p>
<p>&#160;&#160;&#160; <span style="color: #0000ff">public</span> <span style="color: #0000ff">override</span> <span style="color: #0000ff">void</span> Close()    <br />&#160;&#160;&#160; {    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">base</span>.Close();    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #0000ff">if</span> (<span style="color: #2b91af">File</span>.Exists(Name))    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; {    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #2b91af">File</span>.Delete(Name);    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; }    <br />&#160;&#160;&#160; }    </p>
<p>}</p></div>
<p>Here we simply create a new temporary file with R/W access. In the Close method of the FileStream we simply delete the file. Nice and simple and your temporary file only &quot;lives&quot; during your &quot;using&quot; statement&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.veggerby.dk/2008/07/28/temporary-stream/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FormsAuthentication.HashPasswordForStoringInConfigFile() continued&#8230;</title>
		<link>http://blog.veggerby.dk/2008/07/27/formsauthenticationhashpasswordforstoringinconfigfile-continued/</link>
		<comments>http://blog.veggerby.dk/2008/07/27/formsauthenticationhashpasswordforstoringinconfigfile-continued/#comments</comments>
		<pubDate>Sun, 27 Jul 2008 18:06:26 +0000</pubDate>
		<dc:creator>nosey</dc:creator>
				<category><![CDATA[.NET General]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[formsauthentication]]></category>
		<category><![CDATA[hash]]></category>
		<category><![CDATA[md5]]></category>

		<guid isPermaLink="false">http://blog.veggerby.dk/2008/07/27/formsauthenticationhashpasswordforstoringinconfigfile-continued/</guid>
		<description><![CDATA[In &#34;response&#34; to my own previous post: two little extension methods that does exactly what &#34;we&#34; need: public static string GetHashValue(this MD5 hash, string value) { &#160;&#160;&#160; return GetHashValue(hash, Encoding.UTF8.GetBytes(value)); } public static string GetHashValue(this MD5 hash, byte[] value) { &#160;&#160;&#160; byte[] data = hash.ComputeHash(value); &#160;&#160;&#160; string md5 = &#34;&#34;; &#160;&#160;&#160; for (int i = [...]]]></description>
			<content:encoded><![CDATA[<p>In &quot;response&quot; to my <a href="http://blog.veggerby.dk/2008/07/06/abuse-of-formsauthenticationhashpasswordforstoringinconfigfile-method/">own previous post</a>: two little extension methods that does exactly what &quot;we&quot; need:</p>
<div class="vscode"><span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">string</span> GetHashValue(<span style="color: #0000ff">this</span> <span style="color: #2b91af">MD5</span> hash, <span style="color: #0000ff">string</span> value)    <br />{    <br />&#160;&#160;&#160; <span style="color: #0000ff">return</span> GetHashValue(hash, <span style="color: #2b91af">Encoding</span>.UTF8.GetBytes(value));    <br />}    </p>
<p><span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">string</span> GetHashValue(<span style="color: #0000ff">this</span> <span style="color: #2b91af">MD5</span> hash, <span style="color: #0000ff">byte</span>[] value)    <br />{    <br />&#160;&#160;&#160; <span style="color: #0000ff">byte</span>[] data = hash.ComputeHash(value);    <br />&#160;&#160;&#160; <span style="color: #0000ff">string</span> md5 = <span style="color: #a31515">&quot;&quot;</span>;    <br />&#160;&#160;&#160; <span style="color: #0000ff">for</span> (<span style="color: #0000ff">int</span> i = 0; i &lt; data.Length; i++)    <br />&#160;&#160;&#160; {    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; md5 += data[i].ToString(<span style="color: #a31515">&quot;x2&quot;</span>).ToLowerInvariant();    <br />&#160;&#160;&#160; }    <br />&#160;&#160;&#160; <span style="color: #0000ff">return</span> md5;    <br />}</div>
<p>  Usage:
<div class="vscode"><span style="color: #2b91af">MD5</span> md5 = <span style="color: #2b91af">MD5</span>.Create();    <br /><span style="color: #2b91af">Console</span>.WriteLine(md5.GetHashValue(<span style="color: #a31515">&quot;test&quot;</span>));</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.veggerby.dk/2008/07/27/formsauthenticationhashpasswordforstoringinconfigfile-continued/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using Type.IsAssignableFrom() to check inheritance</title>
		<link>http://blog.veggerby.dk/2008/07/13/using-typeisassignablefrom-to-check-inheritance/</link>
		<comments>http://blog.veggerby.dk/2008/07/13/using-typeisassignablefrom-to-check-inheritance/#comments</comments>
		<pubDate>Sun, 13 Jul 2008 22:07:32 +0000</pubDate>
		<dc:creator>nosey</dc:creator>
				<category><![CDATA[.NET General]]></category>
		<category><![CDATA[Reference Sheet]]></category>
		<category><![CDATA[inheritance]]></category>

		<guid isPermaLink="false">http://blog.veggerby.dk/2008/07/13/using-typeisassignablefrom-to-check-inheritance/</guid>
		<description><![CDATA[Having been in the situation needing to check if a given instance of an object either implements an interface or a class in the form of a given Type object (i.e. &#34;if A is B&#34; wont do) I decided to write a little &#34;note to self&#34; post which others might find useful. This is basically [...]]]></description>
			<content:encoded><![CDATA[<p>Having been in the situation needing to check if a given instance of an object either implements an interface or a class in the form of a given <a href="http://msdn.microsoft.com/en-us/library/system.type.aspx">Type</a> object (i.e. &quot;if A is B&quot; wont do) I decided to write a little &quot;note to self&quot; post which others might find useful.</p>
<p>This is basically just a &quot;wrapper&quot; around <a href="http://www.hanselman.com/blog/">Scott Hanselman&#8217;s</a> post from a long time ago <a href="http://www.hanselman.com/blog/DoesATypeImplementAnInterface.aspx">Does a Type Implement an Interface?</a></p>
<p>For a &quot;class type&quot; you can use the <a href="http://msdn.microsoft.com/en-us/library/system.type.issubclassof.aspx">Type.IsSubclassOf()</a> method and for an interface you can use something in the line of:</p>
<div class="vscode"><span style="color: #0000ff">if</span> (<span style="color: #0000ff">typeof</span>(<span style="color: #2b91af">MyClass</span>).GetInterface(<span style="color: #a31515">&quot;MyNamespace.IMyInterface&quot;</span>) != <span style="color: #0000ff">null</span>)    <br />{    <br />&#160;&#160;&#160; <span style="color: #008000">// MyClass implements IMyInterface     <br /></span>}</div>
<p>However the string literal looks bad also neither solution provides a simple check for &quot;is this type implementing/a subclass of this interface/class&quot;.</p>
<p>The gist of Scott&#8217;s post is that using <a href="http://msdn.microsoft.com/en-us/library/system.type.isassignablefrom.aspx">Type.IsAssignableFrom()</a> can solve your problem concerning interfaces, but the same logic applies for classes. So:</p>
<div class="vscode"><span style="color: #0000ff">if</span> (<span style="color: #0000ff">typeof</span>(<span style="color: #2b91af">IMyInterface</span>).IsAssignableFrom(<span style="color: #0000ff">typeof</span>(<span style="color: #2b91af">MyClass</span>)))    <br />{    <br />&#160;&#160;&#160; <span style="color: #008000">// MyClass implements IMyInterface     <br /></span>}    </p>
<p><span style="color: #0000ff">if</span> (<span style="color: #0000ff">typeof</span>(<span style="color: #2b91af">MyClass</span>).IsAssignableFrom(<span style="color: #0000ff">typeof</span>(<span style="color: #2b91af">MySubClass</span>)))    <br />{    <br />&#160;&#160;&#160; <span style="color: #008000">// MySubClass is a subclass of MyClass     <br /></span>}    </p>
<p><span style="color: #0000ff">if</span> (<span style="color: #0000ff">typeof</span>(<span style="color: #2b91af">IMyExtendedInterface</span>).IsAssignableFrom(<span style="color: #0000ff">typeof</span>(<span style="color: #2b91af">IMyInterface</span>)))    <br />{    <br />&#160;&#160;&#160; <span style="color: #008000">// IMyExtendedInterface extends IMyInterface     <br /></span>}</div>
<p>Actually this is exactly what the MSDN page for Type.IsAssignableFrom() states:</p>
<blockquote><p>true if c and the current Type represent the same type, or if the current Type is in the inheritance hierarchy of c, or if the current Type is an interface that c implements, <u>or if c is a generic type parameter and the current Type represents one of the constraints of c</u></p>
</blockquote>
<p>First in &quot;layman&quot; terms it means:</p>
<div class="vscode"><span style="color: #2b91af">TypeA</span> a;    <br /><span style="color: #2b91af">TypeB</span> b;    <br /><span style="color: #0000ff">if</span> (<span style="color: #0000ff">typeof</span>(<span style="color: #2b91af">TypeA</span>).IsAssignableFrom(<span style="color: #0000ff">typeof</span>(<span style="color: #2b91af">TypeB</span>)))    <br />{    <br />&#160;&#160;&#160; a = b; <span style="color: #008000">// this will work     <br /></span>}</div>
<p>But what does the underlined text then mean in the context of this check? The samples on this on the MSDN page are totally nonsense (e.g. text states &quot;List&lt;int&gt; assignable from List&lt;Type&gt;&quot; but in fact List&lt;int&gt; and int[] are compared). </p>
<p>The point in that statement is that A&lt;T&gt; is assignable from A&lt;S&gt; if T is assignable from S.</p>
<p>So it is a little more inclusive (which is no surprise) than just checking inheritance, but as long as the &quot;master&quot; class/interface is known explicitly (which is most often the case, since a scenario for this is checking if a type specified in config is in the correct inheritance tree) the check will be safe.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.veggerby.dk/2008/07/13/using-typeisassignablefrom-to-check-inheritance/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
