<?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>corniel.nl/blog &#187; Hello World!</title>
	<atom:link href="http://www.corniel.nl/blog/category/helloworld/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.corniel.nl/blog</link>
	<description>Corniels kijk op de wereld: lekker belangerijk...</description>
	<lastBuildDate>Wed, 08 Sep 2010 17:22:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Idiots</title>
		<link>http://www.corniel.nl/blog/2010/08/16/idiots/</link>
		<comments>http://www.corniel.nl/blog/2010/08/16/idiots/#comments</comments>
		<pubDate>Mon, 16 Aug 2010 08:26:48 +0000</pubDate>
		<dc:creator>Corniel</dc:creator>
				<category><![CDATA[Hello World!]]></category>

		<guid isPermaLink="false">http://www.corniel.nl/blog/?p=533</guid>
		<description><![CDATA[Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning (..) Rick Cook]]></description>
			<content:encoded><![CDATA[<blockquote><p>Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning (..)</p></blockquote>
<p><a href="http://en.wikipedia.org/wiki/Rick_Cook" target="_blank">Rick Cook</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.corniel.nl/blog/2010/08/16/idiots/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Windows multi icon</title>
		<link>http://www.corniel.nl/blog/2010/07/23/windows-multi-icon/</link>
		<comments>http://www.corniel.nl/blog/2010/07/23/windows-multi-icon/#comments</comments>
		<pubDate>Fri, 23 Jul 2010 14:08:36 +0000</pubDate>
		<dc:creator>Corniel</dc:creator>
				<category><![CDATA[Hello World!]]></category>

		<guid isPermaLink="false">http://www.corniel.nl/blog/?p=503</guid>
		<description><![CDATA[Creating a Windows icon containing multiple bitmaps is not supported by .NET. Fortunately, on the net (the other one) I fount a (version 1.1) .NET implementation to read a multi icon. The re-usability wasn&#8217;t that great, merging and writing was not supported, and as .NET 1.1 did not support Typed lists yet, I had to [...]]]></description>
			<content:encoded><![CDATA[<p>Creating a Windows icon containing multiple bitmaps is not supported by .NET. Fortunately, on the net (the other one) I fount a (version 1.1) .NET implementation to read a multi icon.</p>
<p>The re-usability wasn&#8217;t that great, merging and writing was not supported, and as .NET 1.1 did not support Typed lists yet, I had to rewrite it all:</p>
<pre class="brush: c#">using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;

namespace HelloWorld.Xamples.Drawing
{
    /// &lt;summary&gt;Represents a Windows multi icon, which is a collection of small bitmap images
    /// used to represent an object. Icons can be thought of as transparent
    /// bitmaps, although their size is determined by the system.
    /// &lt;/summary&gt;
    public class MultiIcon : List&lt;Icon&gt;
    {
        /// &lt;summary&gt;Initializes a new instance of the Tjip.Drawing.MultiIcon class.&lt;/summary&gt;
        public MultiIcon() { }

        /// &lt;summary&gt;Represents the Widows multi icon as System.String.&lt;/summary&gt;
        public override string ToString()
        {
            var str = string.Format(&quot;{0} Items: {1}&quot;,
                GetType().FullName,
                this.Count);
            if (this.Count == 1)
            {
                str += string.Format(&quot;, Size: {0} px&quot;,
                    this.First().Width);
            }
            if (this.Count &gt; 1)
            {
                str += string.Format(&quot;, Smallest: {0} px, Largest: {1} px&quot;,
                    this.GetSmallest().Width,
                    this.GetLargest().Width);
            }
            return str;
        }

        /// &lt;summary&gt;Loads a Windows multi icon based on the specfied path.&lt;/summary&gt;
        /// &lt;param name=&quot;filepath&quot;&gt;The filepath to load from.&lt;/param&gt;
        public static MultiIcon Load(string filepath)
        {
            using (var stream = new FileStream(filepath, FileMode.Open, FileAccess.Read))
            {
                return Load(stream);
            }
        }
        /// &lt;summary&gt;Loads a Windows multi icon from a stream.&lt;/summary&gt;
        /// &lt;param name=&quot;stream&quot;&gt;The stream to load from.&lt;/param&gt;
        public static MultiIcon Load(Stream stream)
        {
            // Read the stream.
            using (var reader = new BinaryReader(stream))
            {
                var icon = new MultiIcon();
                var entries = new List&lt;MultiIconEntry&gt;();

                // Read the header.
                var header = reader.ReadMultiIconHeader();

                // Read the icon entries.
                for (int i = 0; i &lt; header.Count; i++)
                {
                    var entry = reader.ReadMultiIconEntry();
                    entries.Add(entry);
                }
                // Read the icons based on the entries.
                foreach (var entry in entries)
                {
                    var ico = reader.ReadIcon(header, entry);
                    icon.Add(ico);
                }
                return icon;
            }
        }
    }

    /// &lt;summary&gt;Methods for Windows multi icon, that should be available
    /// for all collections of Widows icons.&lt;/summary&gt;
    public static class MultiIconExtensions
    {
        /// &lt;summary&gt;Saves the Windows icons to a single file.&lt;/summary&gt;
        /// &lt;param name=&quot;icon&quot;&gt;The list of icons.&lt;/param&gt;
        /// &lt;param name=&quot;filepath&quot;&gt;The filepath to save to.&lt;/param&gt;
        public static void Save(this IList&lt;Icon&gt; icons, string filepath)
        {
            using (var stream = new FileStream(filepath, FileMode.CreateNew, FileAccess.Write))
            {
                icons.Save(stream);
            }
        }
        /// &lt;summary&gt;Saves the Windows icons to a single stream.&lt;/summary&gt;
        /// &lt;param name=&quot;icon&quot;&gt;The list of icons.&lt;/param&gt;
        /// &lt;param name=&quot;stream&quot;&gt;The stream to save to.&lt;/param&gt;
        public static void Save(this IList&lt;Icon&gt; icons, Stream stream)
        {
            using (var writer = new BinaryWriter(stream))
            {
                long startposition = stream.Position;

                var entries = new List&lt;MultiIconEntry&gt;();
                var buffers = new List&lt;byte[]&gt;();
                // create header.
                var header = new MultiIconHeader()
                {
                    Count = (short)icons.Count,
                };
                // create entries.
                for (int i = 0; i &lt; icons.Count; i++)
                {
                    using (var icon_stream = new MemoryStream())
                    {
                        var entry = new MultiIconEntry();
                        var item = icons[i];
                        item.Save(icon_stream);
                        icon_stream.Position = 0;

                        using (var reader = new BinaryReader(icon_stream))
                        {
                            // icoHeader.Reserved[2],
                            // icoHeader.Type[2],
                            // none.Pos[2],
                            // Width[1],
                            // Height[1],
                            // ColorCount[1],
                            // Reserved[1]
                            // Planes[2]
                            // BitCount[2]
                            // BytesInRes[4]
                            // none.OffSet[4]
                            var header_reserved = reader.ReadInt16();
                            var header_type = reader.ReadInt16();
                            var none_startpos = reader.ReadInt16();
                            entry.Width = reader.ReadByte();
                            entry.Height = reader.ReadByte();
                            entry.ColorCount = reader.ReadByte();
                            entry.Reserved = reader.ReadByte();
                            entry.Planes = reader.ReadInt16();
                            entry.BitCount = reader.ReadInt16();
                            entry.BytesInRes = reader.ReadInt32();
                            entry.ImageOffset = MultiIconHeader.ByteSize + MultiIconEntry.ByteSize * icons.Count + buffers.Sum(buf =&gt; buf.Length);
                            var none_offset = reader.ReadInt32();

                            var buffer = new byte[icon_stream.Length - icon_stream.Position];
                            icon_stream.Read(buffer, 0, buffer.Length);
                            entries.Add(entry);
                            buffers.Add(buffer);
                        }
                    }
                }
                // Writer header.
                writer.Write(header);

                // Write entries.
                foreach (var entry in entries)
                {
                    writer.Write(entry);
                }
                // Write images.
                foreach (var buffer in buffers)
                {
                    writer.Write(buffer);
                }
                // Clear buffer and save.
                writer.Flush();
            }
        }

        /// &lt;summary&gt;Gets the smallest icon.&lt;/summary&gt;
        /// &lt;param name=&quot;icon&quot;&gt;The list of icons.&lt;/param&gt;
        /// &lt;returns&gt;The smallest icon.&lt;/returns&gt;
        public static Icon GetSmallest(this IEnumerable&lt;Icon&gt; icons)
        {
            var icon =
            (
                from
                    item in icons
                orderby
                    item.Width ascending
                select
                    item
            )
            .FirstOrDefault();

            return icon;
        }
        /// &lt;summary&gt;Gets the largest icon.&lt;/summary&gt;
        /// &lt;param name=&quot;icon&quot;&gt;The list of icons.&lt;/param&gt;
        /// &lt;returns&gt;The largest icon.&lt;/returns&gt;
        public static Icon GetLargest(this IEnumerable&lt;Icon&gt; icons)
        {
            var icon =
            (
                from
                    item in icons
                orderby
                    item.Width descending
                select
                    item
            )
            .FirstOrDefault();

            return icon;
        }
    }
    /// &lt;summary&gt;Represents the header of a Windows (multi) icon.&lt;/summary&gt;
    internal class MultiIconHeader
    {
        /// &lt;summary&gt;The byte size of a single icon header.&lt;/summary&gt;
        public const int ByteSize = 2 + 2 + 2;

        /// &lt;summary&gt;Initializes a new instance of the Tjip.Drawing.MultiIconHeader class.&lt;/summary&gt;
        public MultiIconHeader()
        {
            this.Type = 1;
        }

        public short Reserved { get; set; }
        public short Type { get; set; }
        public short Count { get; set; }
    }

    /// &lt;summary&gt;Extenion methods for MultiIconHeader.&lt;/summary&gt;
    internal static class MultiIconHeaderExtensions
    {
        /// &lt;summary&gt;Reads a Windows (multi) icon header from the current stream
        /// and advances the current position of the stream by six bytes.
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;reader&quot;&gt;The reader.&lt;/param&gt;
        public static MultiIconHeader ReadMultiIconHeader(this BinaryReader reader)
        {
            var header = new MultiIconHeader()
            {
                Reserved = reader.ReadInt16(),
                Type = reader.ReadInt16(),
                Count = reader.ReadInt16(),
            };
            return header;
        }

        /// &lt;summary&gt;Writes a Windows (multi) icon header to the current stream
        /// and advances the current position of the stream by six bytes.
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;writer&quot;&gt;The writer.&lt;/param&gt;
        /// &lt;param name=&quot;header&quot;&gt;The Windows multi icon header to write.&lt;/param&gt;
        public static void Write(this BinaryWriter writer, MultiIconHeader header)
        {
            writer.Write(header.Reserved);
            writer.Write(header.Type);
            writer.Write(header.Count);
        }
    }
    /// &lt;summary&gt;Represents the entry of a Windows (multi) icon.&lt;/summary&gt;
    internal class MultiIconEntry
    {
        /// &lt;summary&gt;The byte size of a single icon entry.&lt;/summary&gt;
        public const int ByteSize = 1 + 1 + 1 + 1 + 2 + 2 + 4 + 4;

        /// &lt;summary&gt;Initializes a new instance of the Tjip.Drawing.MultiIconEntry class.&lt;/summary&gt;
        public MultiIconEntry() { }

        public byte Width { get; set; }
        public byte Height { get; set; }
        public byte ColorCount { get; set; }
        public byte Reserved { get; set; }
        public short Planes { get; set; }
        public short BitCount { get; set; }
        public int BytesInRes { get; set; }
        public int ImageOffset { get; set; }
    }

    /// &lt;summary&gt;Extenion methods for MultiIconEntry.&lt;/summary&gt;
    internal static class MultiIconEntryrExtensions
    {
        /// &lt;summary&gt;Reads a Windows (multi) icon entry from the current stream
        /// and advances the current position of the stream by sixteen bytes.
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;reader&quot;&gt;The reader.&lt;/param&gt;
        public static MultiIconEntry ReadMultiIconEntry(this BinaryReader reader)
        {
            var entry = new MultiIconEntry()
            {
                Width = reader.ReadByte(),
                Height = reader.ReadByte(),
                ColorCount = reader.ReadByte(),
                Reserved = reader.ReadByte(),
                Planes = reader.ReadInt16(),
                BitCount = reader.ReadInt16(),
                BytesInRes = reader.ReadInt32(),
                ImageOffset = reader.ReadInt32(),
            };
            return entry;
        }

        /// &lt;summary&gt;Reads a Windows icon from the current stream
        /// and advances the current position of the stream to the end of the
        /// Windows icon in the stream.
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;reader&quot;&gt;The reader.&lt;/param&gt;
        public static Icon ReadIcon(this BinaryReader reader, MultiIconHeader header, MultiIconEntry entry)
        {
            const short ICON_STREAM_START = 1;
            const int ICON_STREAM_OFFSET = 22;

            using (var newIcon = new MemoryStream())
            {
                using (var writer = new BinaryWriter(newIcon))
                {
                    // Write it
                    writer.Write(header.Reserved);
                    writer.Write(header.Type);
                    writer.Write(ICON_STREAM_START);
                    writer.Write(entry.Width);
                    writer.Write(entry.Height);
                    writer.Write(entry.ColorCount);
                    writer.Write(entry.Reserved);
                    writer.Write(entry.Planes);
                    writer.Write(entry.BitCount);
                    writer.Write(entry.BytesInRes);
                    writer.Write(ICON_STREAM_OFFSET);

                    // Grab the icon
                    byte[] tmpBuffer = new byte[entry.BytesInRes];
                    reader.BaseStream.Position = entry.ImageOffset;
                    reader.Read(tmpBuffer, 0, entry.BytesInRes);
                    writer.Write(tmpBuffer);

                    // Finish up
                    writer.Flush();
                    newIcon.Position = 0;
                    return new Icon(newIcon);
                }
            }
        }

        /// &lt;summary&gt;Writes a Windows (multi) icon entry to the current stream
        /// and advances the current position of the stream by sixteen bytes.
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;writer&quot;&gt;The writer.&lt;/param&gt;
        /// &lt;param name=&quot;entry&quot;&gt;The Windows multi icon entry to write.&lt;/param&gt;
        public static void Write(this BinaryWriter writer, MultiIconEntry entry)
        {
            writer.Write(entry.Width);
            writer.Write(entry.Height);
            writer.Write(entry.ColorCount);
            writer.Write(entry.Reserved);
            writer.Write(entry.Planes);
            writer.Write(entry.BitCount);
            writer.Write(entry.BytesInRes);
            writer.Write(entry.ImageOffset);
        }
    }
}</pre>
<p>It works perfectly. The only thing I still need to solve is the conversion of PNG24 to ICO:</p>
<pre class="brush: c#">var icon = Icon.FromHandle(new Bitmap(&quot;some_pgn24.png&quot;).GetHicon());</pre>
<p>This results in an icon that does not have an alpha-channel. When I solved this, I will inform you.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.corniel.nl/blog/2010/07/23/windows-multi-icon/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ISO 8601</title>
		<link>http://www.corniel.nl/blog/2009/12/18/iso8601/</link>
		<comments>http://www.corniel.nl/blog/2009/12/18/iso8601/#comments</comments>
		<pubDate>Fri, 18 Dec 2009 15:40:03 +0000</pubDate>
		<dc:creator>Corniel</dc:creator>
				<category><![CDATA[Hello World!]]></category>

		<guid isPermaLink="false">http://www.corniel.nl/blog/?p=214</guid>
		<description><![CDATA[Probably you are familiar with ISO. Some guys in a big office creating tons of paperwork every year. One of the standards they created is 8601. One of the items it describes is the number of the week, witch is commonly used. Unfortunately Microsoft didn’t add an implementation for this week number in its .NET [...]]]></description>
			<content:encoded><![CDATA[<p>Probably you are familiar with ISO. Some guys in a big office creating tons of paperwork every year. One of the standards they created is <a href="http://en.wikipedia.org/wiki/ISO_8601" target="_blank">8601</a>. One of the items it describes is the number of the week, witch is commonly used.</p>
<p>Unfortunately Microsoft didn’t add an implementation for this week number in its .NET framework. A colleague of mine found one and added it to our extensions:</p>
<pre class="brush: c#">namespace HelloWorld.Extensions
{
public static class DateTimeExtensions
{
/// Returns ISO WeekNumber (1-53) for a given year.
///
The datetime.         public static int ISOWeekNumberOld(this System.DateTime dt)
{
// Set Year
int yyyy = dt.Year;
// Set Month
int mm = dt.Month;
// Set Day
int dd = dt.Day;
// Declare other required variables
int DayOfYearNumber;
int Jan1WeekDay;
int WeekNumber = 0, WeekDay;
int i, j, k, l, m, n;
int[] Mnth = new int[12] { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 };
int YearNumber;
// Set DayofYear Number for yyyy mm dd
DayOfYearNumber = dd + Mnth[mm - 1];
// Increase of Dayof Year Number by 1, if year is leapyear and month is february
if ((DateTime.IsLeapYear(yyyy) == true) &amp;amp;&amp;amp; (mm == 2))
DayOfYearNumber += 1;
// Find the Jan1WeekDay for year
i = (yyyy - 1) % 100;
j = (yyyy - 1) - i;
k = i + i / 4;
Jan1WeekDay = 1 + (((((j / 100) % 4) * 5) + k) % 7);
// Calcuate the WeekDay for the given date
l = DayOfYearNumber + (Jan1WeekDay - 1);
WeekDay = 1 + ((l - 1) % 7);
// Find if the date falls in YearNumber set WeekNumber to 52 or 53
if ((DayOfYearNumber &amp;lt;= (8 - Jan1WeekDay)) &amp;amp;&amp;amp; (Jan1WeekDay &amp;gt; 4))
{
YearNumber = yyyy - 1;
if ((Jan1WeekDay == 5) || ((Jan1WeekDay == 6) &amp;amp;&amp;amp; (Jan1WeekDay &amp;gt; 4)))
WeekNumber = 53;
else
WeekNumber = 52;
}
else
YearNumber = yyyy;
// Set WeekNumber to 1 to 53 if date falls in YearNumber
if (YearNumber == yyyy)
{
if (DateTime.IsLeapYear(yyyy) == true)
m = 366;
else
m = 365;
if ((m - DayOfYearNumber) &amp;lt; (4 - WeekDay))                 {                     YearNumber = yyyy + 1;                     WeekNumber = 1;                 }             }             if (YearNumber == yyyy)             {                 n = DayOfYearNumber + (7 - WeekDay) + (Jan1WeekDay - 1);                 WeekNumber = n / 7;                 if (Jan1WeekDay &amp;gt; 4)
WeekNumber -= 1;
}
return (WeekNumber);
}
}
}
</pre>
<p>Not only is this an extreme unreadable piece of code, it seems to be invalid as well. So I decided to create something more understandable:</p>
<pre class="brush: c#">namespace HelloWorld
{
/// Represents a date as specified by ISO 8601 week date.
///
/// See: http://en.wikipedia.org/wiki/ISO_8601
/// and: http://en.wikipedia.org/wiki/ISO_week_date
///
public struct Iso8601WeekDate
{
private int m_Day;
private int m_Year;
private int m_Week;
private DateTime m_Date;

/// Initializes a new instance of the Tjip.Iso8601WeekDate structure to the specified System.DateTime.
///
The date of the ISO 8601 WeekDate.         public Iso8601WeekDate(DateTime date)
{
// Only the date will be available.
m_Date = date.Date;
// Set the year.
m_Year = date.Year;
// The day is oke by default, Unless its sunday (int value = 0)...
m_Day = (date.DayOfWeek == DayOfWeek.Sunday) ? 7 : (int)date.DayOfWeek;

// Now the week number.
DateTime startdate = GetFirstDayOfFirtWeekOfYear(date.Year);
DateTime enddate = GetFirstDayOfFirtWeekOfYear(date.Year + 1);
// The date is member of a week in the next year.
if (m_Date &amp;gt;= enddate)
{
startdate = enddate;
m_Year++;
}
// The date is member of a week in the previous year.
if (m_Date &amp;lt; startdate)
{
startdate = GetFirstDayOfFirtWeekOfYear(date.Year - 1);
m_Year--;
}
// Day of the week.
int dayofyear = (m_Date - startdate).Days;

// The week number is not zero based.
m_Week = dayofyear / 7 + 1;
}

/// Gets the date component of this instance.
public DateTime Date { get { return m_Date; } }
/// Gets the year component of the date represented by this instance.
public int Year { get { return m_Year; } }
/// Gets the week component of the date represented by this instance.
public int Week { get { return m_Week; } }
/// Gets the day component of the date represented by this instance.
public int Day { get { return m_Day; } }

/// Gets the date of the first day of the first week of the year.
///
/// Source: http://en.wikipedia.org/wiki/ISO_8601
///
/// There are mutually equivalent descriptions of week 01:
/// - the week with the year&#039;s first Thursday in it (the formal ISO definition),
/// - the week with 4 January in it,
/// - the first week with the majority (four or more) of its days in the starting year,
/// - the week starting with the Monday in the period 29 December – 4 January.
///
public static DateTime GetFirstDayOfFirtWeekOfYear(int year)
{
DateTime start = new DateTime(year, 01, 04);
while (start.DayOfWeek != DayOfWeek.Monday)
{
start = start.AddDays(-1);
}
return start;
}

/// Represents the Tjip.Iso8601WeekDate as System.String.
public override string ToString()
{
return ToString(&quot;YYYY-Www-D&quot;);
}
/// Represents the Tjip.Iso8601WeekDate as System.String.
///
The format.         ///
/// Representations of the following formatting are allowed:
/// - YYYYWww
/// - YYYY-Www
/// - YYYYWwwD
/// - YYYY-Www-D
///
/// [YYYY] indicates the ISO week-numbering year which is slightly different
/// to the calendar year (see below).
///
/// [Www] is the week number prefixed by the letter &#039;W&#039;, from W01 through W53.
///
/// [D] is the weekday number, from 1 through 7, beginning with
///
/// Monday and ending with Sunday. This form is popular in the
/// manufacturing industries.
///
public string ToString(string format)
{
switch (format)
{
case &quot;YYYYWww&quot;: return string.Format(&quot;{0}W{1:00}&quot;, this.Year, this.Week, this.Day);
case &quot;YYYY-Www&quot;: return string.Format(&quot;{0}-W{1:00}&quot;, this.Year, this.Week, this.Day);
case &quot;YYYYWwwD&quot;: return string.Format(&quot;{0}W{1:00}{2}&quot;, this.Year, this.Week, this.Day);
case &quot;YYYY-Www-D&quot;: return string.Format(&quot;{0}-W{1:00}-{2}&quot;, this.Year, this.Week, this.Day);
default: throw new NotSupportedException(string.Format(&quot;The format &#039;{0}&#039; is not supported.&quot;, format));
}
}
/// Returns the hash code for this instance.
///
/// A 32-bit signed integer that is the hash code for this instance.
///
public override int GetHashCode()
{
// It should be fast, so shift.
//       ..3.....6............14 = 23 bit
// bits: DDDWWWWWWYYYYYYYYYYYYYY
int hash = this.Day + this.Week &amp;gt;&amp;gt; 3 + this.Year &amp;gt;&amp;gt; 9;
return hash;
}
}
}</pre>
<p>And to extend it to System.DateTime:</p>
<pre class="brush: c#">namespace HelloWorld.Extensions
{
public static class DateTimeExtensions
{
public static Iso8601WeekDate ToIso8601WeekDate(this DateTime dt)
{
return new Iso8601WeekDate(dt);
}
/// Returns the (ISO 8601) number of the week.
///
The datetime.         /// The (ISO 8601) number of the week.
///
///  Source: http://en.wikipedia.org/wiki/ISO_8601
///
public static int ISO8601WeekNumber(this DateTime dt)
{
Iso8601WeekDate weekdate = new Iso8601WeekDate(dt);
return weekdate.Week;
}
}
}</pre>
<p>Not only is this imho much easier to read (and working correctly), you can format it like ISO spected it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.corniel.nl/blog/2009/12/18/iso8601/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WTF (3)</title>
		<link>http://www.corniel.nl/blog/2009/11/30/wtf-3/</link>
		<comments>http://www.corniel.nl/blog/2009/11/30/wtf-3/#comments</comments>
		<pubDate>Mon, 30 Nov 2009 08:54:19 +0000</pubDate>
		<dc:creator>Corniel</dc:creator>
				<category><![CDATA[Hello World!]]></category>

		<guid isPermaLink="false">http://www.corniel.nl/blog/?p=174</guid>
		<description><![CDATA[Well, no comment required, i guess. (..) if (contextvalue == 0) { string empty = &#34;&#34;; return (empty.ToString()); }]]></description>
			<content:encoded><![CDATA[<p>Well, no comment required, i guess.</p>
<pre class="brush: c#">(..)
if (contextvalue == 0)
{
    string empty = &quot;&quot;;
    return (empty.ToString());
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.corniel.nl/blog/2009/11/30/wtf-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Roman numerals</title>
		<link>http://www.corniel.nl/blog/2009/08/20/roman-numerals/</link>
		<comments>http://www.corniel.nl/blog/2009/08/20/roman-numerals/#comments</comments>
		<pubDate>Thu, 20 Aug 2009 06:39:50 +0000</pubDate>
		<dc:creator>Corniel</dc:creator>
				<category><![CDATA[Hello World!]]></category>

		<guid isPermaLink="false">http://www.corniel.nl/blog/?p=79</guid>
		<description><![CDATA[Sometimes, you write a piece of code you’re proud of. Because it’s a clever, elegant, or just fun. The snippet I post here is a bit of all, at least in my opinion. /// &#60;summary&#62;Converts an System.Int32 to Roman number strings. /// &#60;remarks&#62;http://en.wikipedia.org/wiki/Roman_numerals&#60;/remarks&#62; /// &#60;/summary&#62; /// &#60;param name=&#34;number&#34;&#62;Number to convert.&#60;/param&#62; /// &#60;returns&#62;Formatted Roman number.&#60;/returns&#62; public [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes, you write a piece of code you’re proud of. Because it’s a clever, elegant, or just fun. The snippet I post here is a bit of all, at least in my opinion.</p>
<pre class="brush: c#">/// &lt;summary&gt;Converts an System.Int32 to Roman number strings.
/// &lt;remarks&gt;http://en.wikipedia.org/wiki/Roman_numerals&lt;/remarks&gt;
/// &lt;/summary&gt;
/// &lt;param name=&quot;number&quot;&gt;Number to convert.&lt;/param&gt;
/// &lt;returns&gt;Formatted Roman number.&lt;/returns&gt;
public static string ToFormattedRomanNumber(int number)
{
    if (number &lt;= 0 || number &gt; 3999)
    {
        throw new ArgumentOutOfRangeException(&quot;With the default ASCII set only Roman numerals between 1 and 4000 can be represented.&quot;);
    }
    //                 1,   5,   10,  50,  100, 500, 1000.
    string[] order = { &quot;I&quot;, &quot;V&quot;, &quot;X&quot;, &quot;L&quot;, &quot;C&quot;, &quot;D&quot;, &quot;M&quot; };
    int pointer = 0;
    int digits = number;
    string result = string.Empty;

    while (digits &gt; 0)
    {
        int digit = digits % 10;
        switch (digit)
        {
            case 0: break;
            case 1: result = string.Format(
            	&quot;{1}{0}&quot;, result, order[pointer]);
            	break;
            case 2: result = string.Format(
            	&quot;{1}{1}{0}&quot;, result, order[pointer]);
            	break;
            case 3: result = string.Format(
            	&quot;{1}{1}{1}{0}&quot;, result, order[pointer]);
            	break;
            case 4: result = string.Format(
            	&quot;{1}{2}{0}&quot;, result, order[pointer], order[pointer + 1]);
            	break;
            case 5: result = string.Format(
            	&quot;{1}{0}&quot;, result, order[pointer + 1]);
            	break;
            case 6: result = string.Format(
            	&quot;{2}{1}{0}&quot;, result, order[pointer], order[pointer + 1]);
            	break;
            case 7: result = string.Format(
            	&quot;{2}{1}{1}{0}&quot;, result, order[pointer], order[pointer + 1]);
            	break;
            case 8: result = string.Format(
            	&quot;{2}{1}{1}{1}{0}&quot;, result, order[pointer], order[pointer + 1]);
            	break;
            case 9: result = string.Format(
            	&quot;{1}{2}{0}&quot;, result, order[pointer], order[pointer + 2]);
            	break;
        }
        digits = digits / 10;
        pointer = pointer + 2;
    }
    return result;
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.corniel.nl/blog/2009/08/20/roman-numerals/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WTF (2)</title>
		<link>http://www.corniel.nl/blog/2009/08/14/wtf-2/</link>
		<comments>http://www.corniel.nl/blog/2009/08/14/wtf-2/#comments</comments>
		<pubDate>Fri, 14 Aug 2009 14:27:41 +0000</pubDate>
		<dc:creator>Corniel</dc:creator>
				<category><![CDATA[Hello World!]]></category>

		<guid isPermaLink="false">http://www.corniel.nl/blog/?p=69</guid>
		<description><![CDATA[While reviewing some code for a project of our company I found this: public override void Redirect(PipelineContext pipelineContext) { string linkcp = &#34;&#34;; if (linkcp == null &#124;&#124; linkcp == &#34;&#34; &#124;&#124; linkcp.Length == 0) linkcp = &#34;default.aspx&#34;; pipelineContext.Response.Redirect(linkcp); } It first drew my attention because of the if-statement (testing a string being not null [...]]]></description>
			<content:encoded><![CDATA[<p>While reviewing some code for a project of our company I found this:</p>
<pre class="brush: c#">public override void Redirect(PipelineContext pipelineContext)
{
string linkcp = &quot;&quot;;
if (linkcp == null || linkcp == &quot;&quot; || linkcp.Length == 0)
linkcp = &quot;default.aspx&quot;;

pipelineContext.Response.Redirect(linkcp);
}</pre>
<p>It first drew my attention because of the if-statement (testing a string being not null or string.Empty three times) and its missing brackets. But it surprised &#8211; well, shocked &#8211; me because the variable that was assigned, and validated afterwords directly. The writer of this piece of WTF declared that it was generated, and needed some custom implementation&#8230;</p>
<p>I couldn’t help, but think why not &#8211; in that case &#8211; do it this way:</p>
<pre class="brush: c#">public override void Redirect(PipelineContext pipelineContext)
{
string linkcp = string.Empty;
// TODO: implement logic.
if (string.IsNullOrEmpty(linkcp))
{
linkcp = &quot;~/default.aspx&quot;;
}
pipelineContext.Response.Redirect(linkcp);
}</pre>
<p>or, if should fail while not implemented yet</p>
<pre class="brush: c#">public override void Redirect(PipelineContext pipelineContext)
{
string linkcp = string.Empty;
throw new NotImplementedException(&quot;TODO: implement logic.&quot;);
if (string.IsNullOrEmpty(linkcp))
{
linkcp = &quot;~/default.aspx&quot;;
}
pipelineContext.Response.Redirect(linkcp);
}</pre>
<p>What is it about writing comments that my fellow developers seems to dislike that much? It would make reading and understanding code so much easier&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.corniel.nl/blog/2009/08/14/wtf-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WTF (1)</title>
		<link>http://www.corniel.nl/blog/2009/07/29/wtf-1/</link>
		<comments>http://www.corniel.nl/blog/2009/07/29/wtf-1/#comments</comments>
		<pubDate>Wed, 29 Jul 2009 07:06:17 +0000</pubDate>
		<dc:creator>Corniel</dc:creator>
				<category><![CDATA[Hello World!]]></category>

		<guid isPermaLink="false">http://www.corniel.nl/blog/?p=54</guid>
		<description><![CDATA[Let me start by pointing out that VisualBasic is not my cup of tea. I don’t like all those implicit castings. Like this: Function DecimalSeparator() As String DecimalSeparator = (1 / 2).ToString.Substring(1, 1) End Function The .Net way of doing things is of course: Function DecimalSeparator() As String Return System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator End Function But  I guess [...]]]></description>
			<content:encoded><![CDATA[<p>Let me start by pointing out that VisualBasic is not my cup of tea. I don’t like all those implicit castings. Like this:</p>
<pre class="brush: vb">Function DecimalSeparator() As String
DecimalSeparator = (1 / 2).ToString.Substring(1, 1)
End Function</pre>
<p>The .Net way of doing things is of course:</p>
<pre class="brush: vb">Function DecimalSeparator() As String
Return System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator
End Function</pre>
<p>But  I guess that was too much for this programmer.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.corniel.nl/blog/2009/07/29/wtf-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
