<?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>DotBert &#187; .NET</title>
	<atom:link href="http://dotbert.loedeman.nl/category/net/feed" rel="self" type="application/rss+xml" />
	<link>http://dotbert.loedeman.nl</link>
	<description>.NET thoughts by Bert Loedeman</description>
	<lastBuildDate>Thu, 18 Mar 2010 12:49:31 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Clean and minified Javascript</title>
		<link>http://dotbert.loedeman.nl/clean-and-minified-javascript</link>
		<comments>http://dotbert.loedeman.nl/clean-and-minified-javascript#comments</comments>
		<pubDate>Wed, 03 Feb 2010 14:09:48 +0000</pubDate>
		<dc:creator>Bert Loedeman</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[tip]]></category>

		<guid isPermaLink="false">http://dotbert.loedeman.nl/?p=201</guid>
		<description><![CDATA[It has been a while since I last posted a technical post. I&#8217;m sorry, but I am too busy enjoying my work to keep you posted as much as I should.
Just a few days ago I was playing around with YSlow and PageSpeed, two add-ons on Firefox. Both stated my Javascript files were 1) to [...]]]></description>
			<content:encoded><![CDATA[<p>It has been a while since I last posted a technical post. I&#8217;m sorry, but I am too busy enjoying my work to keep you posted as much as I should.</p>
<p>Just a few days ago I was playing around with <a title="http://developer.yahoo.com/yslow/" href="http://developer.yahoo.com/yslow/" target="_blank">YSlow</a> and <a title="http://code.google.com/intl/nl/speed/page-speed/" href="http://code.google.com/intl/nl/speed/page-speed/" target="_blank">PageSpeed</a>, two add-ons on Firefox. Both stated my Javascript files were 1) to many and 2) not at all at minimum size.</p>
<p>Searching for an automated way of cleaning up and minifying my Javascript files, I bumped in on <a title="http://www.crockford.com/javascript/jsmin.html" href="http://www.crockford.com/javascript/jsmin.html" target="_blank">JSMin</a>, a Javascript minifier that can be downloaded in <a title="http://www.crockford.com/javascript/jsmin.cs" href="http://www.crockford.com/javascript/jsmin.cs" target="_blank">C#</a>. Do you hear the term HttpModule in your head already as I did?</p>
<p>When you try to implement JSMin, do consider the fact that your Javascript files will be stripped really rigorous: some of my files did not work anymore after minifying. The reason for this is that Javascript gives you the opportunity to write bad code. To prevent myself from writing rubbish Javascript files that fall apart using JSMin, I now use &#8216;the tool that hurts feelings&#8217;, <a title="http://www.jslint.com/" href="http://www.jslint.com/" target="_blank">JSLint</a>. It hints you about bad code and, when obliged to, prevents you from failure when using JSMin afterwards <img src='http://dotbert.loedeman.nl/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' title="Clean and minified Javascript" />  &#8230;</p>
<p>Lucky coding <img src='http://dotbert.loedeman.nl/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' title="Clean and minified Javascript" />  !</p>
]]></content:encoded>
			<wfw:commentRss>http://dotbert.loedeman.nl/clean-and-minified-javascript/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The using statement and XmlReader.Create</title>
		<link>http://dotbert.loedeman.nl/the-using-statement-and-xmlreadercreate</link>
		<comments>http://dotbert.loedeman.nl/the-using-statement-and-xmlreadercreate#comments</comments>
		<pubDate>Mon, 07 Sep 2009 11:29:43 +0000</pubDate>
		<dc:creator>Bert Loedeman</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[tip]]></category>
		<category><![CDATA[visual studio 2008]]></category>

		<guid isPermaLink="false">http://dotbert.loedeman.nl/?p=150</guid>
		<description><![CDATA[Are you also fond of using the using statement (e.g. when dealing with streams)? I am, since it kind-of guarantees me that streams are closed when I think they should be closed, even if I do not specify the Dispose() command. You probably noticed the &#8216;kind-of guarantee&#8217; part. You are right, this is not always [...]]]></description>
			<content:encoded><![CDATA[<p>Are you also fond of using the using statement (e.g. when dealing with streams)? I am, since it kind-of guarantees me that streams are closed when I think they should be closed, even if I do not specify the Dispose() command. You probably noticed the &#8216;kind-of guarantee&#8217; part. You are right, this is not always the case. It took me a while to find out the the following is not going to work as smooth as expected:</p>
<pre class="brush: csharp;">
using (var reader = XmlReader.Create(File.Open(fileName, FileMode.Open)))
    { ... }
</pre>
<p>You probably wonder what&#8217;s the problem of the code printed above. I don&#8217;t see it too, however, I know there is a problem related to this code. The problem lies in the Create overload used in the example code. It uses default XmlReaderSettings. Unfortunately, this settings do not include having the CloseInput property set to true. You can do the math: no closed file at all! That&#8217;s a guarantee for having troubles on the file &#8216;being in use already&#8217;.</p>
<p>The solution to this problem is quite simple:</p>
<pre class="brush: csharp;">
using (XmlReader reader = XmlReader.Create(File.Open(path, FileMode.Open),
         new XmlReaderSettings { CloseInput = true })) { ... }
</pre>
<p>How can we call this? A &#8216;bug&#8217;? No, at least not technically spoken. Since the XmlReader creates the stream, it should close it too. The case is, you should not expext it knowing the using statement as most people know it (fail-proofing your code). Since I know this, I am a little bit scared about using using statements without calling the stream&#8217;s constructor. You can do so, but be sure it does what you expect it to do&#8230; In my opinion, the using statement still remains very helpful, please I do not consider it being as perfect as I thought it to be for years <img src='http://dotbert.loedeman.nl/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' title="The using statement and XmlReader.Create" />  &#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://dotbert.loedeman.nl/the-using-statement-and-xmlreadercreate/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Calculate age (for instance, on reference data)</title>
		<link>http://dotbert.loedeman.nl/calculate-age-for-instance-on-reference-data</link>
		<comments>http://dotbert.loedeman.nl/calculate-age-for-instance-on-reference-data#comments</comments>
		<pubDate>Wed, 02 Sep 2009 09:53:01 +0000</pubDate>
		<dc:creator>Bert Loedeman</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[datetime]]></category>
		<category><![CDATA[tip]]></category>

		<guid isPermaLink="false">http://dotbert.loedeman.nl/?p=133</guid>
		<description><![CDATA[Now and then, I have to calculate ages (for instance, on a reference date). The method to calculate ages in .NET is pretty simple, although it can be &#8216;a pain in the ass&#8217; to find out how simple it should have been   &#8230; Enjoy the code   !

public static class DateTimeHelper
{
  [...]]]></description>
			<content:encoded><![CDATA[<p>Now and then, I have to calculate ages (for instance, on a reference date). The method to calculate ages in .NET is pretty simple, although it can be &#8216;a pain in the ass&#8217; to find out how simple it should have been <img src='http://dotbert.loedeman.nl/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' title="Calculate age (for instance, on reference data)" />  &#8230; Enjoy the code <img src='http://dotbert.loedeman.nl/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' title="Calculate age (for instance, on reference data)" />  !</p>
<pre class="brush: csharp;">
public static class DateTimeHelper
{
    public static int CalculateAge(DateTime birthday)
    {
        return CalculateAge(DateTime.Now, birthday);
    }

    public static int CalculateAge(DateTime referenceDate, DateTime birthday)
    {
        // calculate age in years on the given reference date.
        var comparisonDate = new DateTime(birthday.Year, referenceDate.Month, referenceDate.Day);

        return (comparisonDate.Date &lt; birthday.Date)
                      ? referenceDate.Year - birthday.Year - 1
                      : referenceDate.Year - birthday.Year;
    }
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://dotbert.loedeman.nl/calculate-age-for-instance-on-reference-data/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dutch bank account number check</title>
		<link>http://dotbert.loedeman.nl/dutch-bank-account-number-check</link>
		<comments>http://dotbert.loedeman.nl/dutch-bank-account-number-check#comments</comments>
		<pubDate>Thu, 13 Aug 2009 07:55:31 +0000</pubDate>
		<dc:creator>Bert Loedeman</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[11-proef]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[elfproef]]></category>

		<guid isPermaLink="false">http://dotbert.loedeman.nl/?p=111</guid>
		<description><![CDATA[For a Dutch customer I currently work for, I worked out the bank account number check (in Dutch: elfproef voor bankrekeningnummers). After checking out the Internet for the correct definition of Dutch bank account numbers (found on Wikipedia), I created the next check in C#:

var cleanAccNumber = accountNumber.Replace(&#34;.&#34;, &#34;&#34;);

// A bank account number consists of [...]]]></description>
			<content:encoded><![CDATA[<p>For a Dutch customer I currently work for, I worked out the bank account number check (in Dutch: elfproef voor bankrekeningnummers). After checking out the Internet for the correct definition of Dutch bank account numbers (found on Wikipedia), I created the next check in C#:</p>
<pre class="brush: csharp;">
var cleanAccNumber = accountNumber.Replace(&quot;.&quot;, &quot;&quot;);

// A bank account number consists of 9 or 10 digits
if (!(cleanAccNumber.Length == 9 || cleanAccNumber.Length == 10)) return false;

// ... all being numeric and not resulting in a 0 when converted to a number ...
long l;
if (!long.TryParse(cleanAccNumber, out l)) return false;
if (l == 0) return false;

// pad it to the left to 10 digits with preceding zero's.
cleanAccNumber = cleanAccNumber.PadLeft(10, '0');

// ... the number must be validatable to the so-called 11-proof ...
long total = 0;
for (var i = 1; i &lt;= cleanAccNumber.Length; i++)
{
// 11-proof for 10 digit bank account numbers (bron: Wikipedia): (1*A + 2*B + 3*C + 4*D + 5*E + 6*F + 7*G + 8*H + 9*H + 10*I) % 11 == 0
var number = Convert.ToInt32(cleanAccNumber[i - 1].ToString());
total += number*i;
}

// ... not result in a 0 when dividing by 11 ...
if (total == 0) return false;

// ... and not have a modulo when dividing by 11.
return total % 11 == 0;
</pre>
<p>Good luck when you should build one for yourself!</p>
]]></content:encoded>
			<wfw:commentRss>http://dotbert.loedeman.nl/dutch-bank-account-number-check/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to insert blank rule (&lt;br /&gt;) from C# code</title>
		<link>http://dotbert.loedeman.nl/how-to-insert-blank-rule-from-c-code</link>
		<comments>http://dotbert.loedeman.nl/how-to-insert-blank-rule-from-c-code#comments</comments>
		<pubDate>Thu, 13 Aug 2009 07:37:26 +0000</pubDate>
		<dc:creator>Bert Loedeman</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[web user control]]></category>

		<guid isPermaLink="false">http://dotbert.loedeman.nl/?p=102</guid>
		<description><![CDATA[Once in a while I have to develop custom user controls that require blank rules in them. Almost always I think again: &#8216;I should have blogged about it, would have saved me lots of time searching&#8217;   &#8230; Well, no more, because here it is&#8230;
Many people using blank rules in C# code, use the [...]]]></description>
			<content:encoded><![CDATA[<p>Once in a while I have to develop custom user controls that require blank rules in them. Almost always I think again: &#8216;I should have blogged about it, would have saved me lots of time searching&#8217; <img src='http://dotbert.loedeman.nl/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' title="How to insert blank rule (&lt;br /&gt;) from C# code" />  &#8230; Well, no more, because here it is&#8230;</p>
<p>Many people using blank rules in C# code, use the following commands:</p>
<pre class="brush: csharp;">
var brControl1 = new HtmlGenericControl { InnerHtml = &quot;&lt;br /&gt;&quot; };
var brControl2 = new HtmlGenericControl(&quot;br&quot;);
</pre>
<p>However, brControl1 also prints a &lt;span&gt; tag and brControl2 prints &lt;br&gt;&lt;/br&gt;. Both options are not really useful. You should take notice of the fact that the HtmlGenericControl is not meant to be used for anything else than span, body, div and font (what is designed for &#8216;as the word goes&#8217;).  The way to go when printing a blank rule is:</p>
<pre class="brush: csharp;">
var brControl3 = new LiteralControl(&quot;&lt;br /&gt;&quot;);
</pre>
<p>This actually prints exactly what you would like it to print, namely &lt;br /&gt;. Hope this helps you too <img src='http://dotbert.loedeman.nl/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' title="How to insert blank rule (&lt;br /&gt;) from C# code" />  ! BTW, if you are using the HtmlTextWriter class, you can also use the WriteBreak() function if you like.</p>
]]></content:encoded>
			<wfw:commentRss>http://dotbert.loedeman.nl/how-to-insert-blank-rule-from-c-code/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
