<?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>Dan Rigsby - Coding Up Style &#187; .Net</title>
	<atom:link href="http://www.danrigsby.com/blog/index.php/category/net/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.danrigsby.com/blog</link>
	<description>Developer.Speaker.Blogger</description>
	<lastBuildDate>Tue, 17 Nov 2009 18:29:29 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>New Webcast: Syndication in .Net</title>
		<link>http://www.danrigsby.com/blog/index.php/2008/11/07/new-webcast-syndication-in-net/</link>
		<comments>http://www.danrigsby.com/blog/index.php/2008/11/07/new-webcast-syndication-in-net/#comments</comments>
		<pubDate>Fri, 07 Nov 2008 12:53:54 +0000</pubDate>
		<dc:creator>Dan Rigsby</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Webcast]]></category>

		<guid isPermaLink="false">http://www.danrigsby.com/blog/index.php/2008/11/07/new-webcast-syndication-in-net/</guid>
		<description><![CDATA[ I have a new 6 min 23 sec training webcast up over Syndication in WCF.&#160; This video shows you how to use the System.ServiceModel.Syndication namespace to create and consume RSS or Atom feeds. It builds on top of the Understanding REST video, but understanding of REST is not necessary. This video also complements a [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.danrigsby.com/blog/wp-content/uploads/2008/11/screencast1thumbthumb.png"><img title="screencast1thumb-thumb" style="border-right: 0px; border-top: 0px; display: inline; margin-left: 0px; border-left: 0px; margin-right: 0px; border-bottom: 0px" height="128" alt="screencast1thumb-thumb" src="http://www.danrigsby.com/blog/wp-content/uploads/2008/11/screencast1thumbthumb-thumb.png" width="128" align="right" border="0" /></a> I have a new 6 min 23 sec training webcast up over Syndication in WCF.&#160; This video shows you how to use the System.ServiceModel.Syndication namespace to create and consume RSS or Atom feeds. It builds on top of the <a href="http://www.danrigsby.com/blog/index.php/2008/09/11/new-webcast-understanding-rest/">Understanding REST video</a>, but understanding of REST is not necessary. This video also complements a recent presentation I have been giving called “<a href="http://www.danrigsby.com/blog/index.php/2008/09/07/resting-on-the-web-with-wcf/">RESTing on the Web with WCF</a>” which includes a segment on working with syndications.</p>
<p>So what are you waiting for?&#160; Head on over and check out the webcast!</p>
<p>The video available through <a href="http://www.jupitermedia.com">JupiterMedia</a> and can be viewed at <a href="http://www.internet.com/video/">http://www.internet.com/video/</a>. Just look for the &quot;Developer Video&quot; titled &quot;Syndication in .Net&quot;.</p>
<p>Direct links are:    <br /><a title="http://link.brightcove.com/services/link/bcpid1431564240/bclid1433966034/bctid1900229538" href="http://link.brightcove.com/services/link/bcpid1431564240/bclid1433966034/bctid1900229538">http://link.brightcove.com/services/link/bcpid1431564240/bclid1433966034/bctid1900229538</a></p>
<div class="wlWriterHeaderFooter" style="text-align:left; margin:0px; padding:4px 4px 4px 4px;"><a href="http://www.dotnetkicks.com/kick/?url=http://www.danrigsby.com/blog/index.php/2008/11/07/new-webcast-syndication-in-net/"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://www.danrigsby.com/blog/index.php/2008/11/07/new-webcast-syndication-in-net/&amp;bgcolor=FF8000&amp;fgcolor=FFFFFF&amp;border=000000&amp;cbgcolor=D4E1ED&amp;cfgcolor=000000" alt="DotNetKicks Image" border="0/"></a></div>
]]></content:encoded>
			<wfw:commentRss>http://www.danrigsby.com/blog/index.php/2008/11/07/new-webcast-syndication-in-net/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>New Webcast: Date &amp; Times in .Net 3.5</title>
		<link>http://www.danrigsby.com/blog/index.php/2008/08/27/new-webcast-date-times-in-net-35/</link>
		<comments>http://www.danrigsby.com/blog/index.php/2008/08/27/new-webcast-date-times-in-net-35/#comments</comments>
		<pubDate>Wed, 27 Aug 2008 21:41:50 +0000</pubDate>
		<dc:creator>Dan Rigsby</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Webcast]]></category>

		<guid isPermaLink="false">http://www.danrigsby.com/blog/index.php/2008/08/27/new-webcast-date-times-in-net-35/</guid>
		<description><![CDATA[ I have a new 9 min 0 sec training webcast out over the new DateTimeInfo and TimeZoneInfo structs in .Net 3.5.&#160; This video complements two of my recent blog posts:

TimeZone vs. TimeZoneInfo in .Net 
DateTime vs. DateTimeOffset in .Net 

It is available through JupiterMedia and can be viewed at http://www.internet.com/video/. Just look for the [...]]]></description>
			<content:encoded><![CDATA[<p><img title="screencast" height="128" alt="screencast" src="http://www.danrigsby.com/blog/wp-content/uploads/2008/08/screencast1.png" width="128" align="right" border="0" /> I have a new 9 min 0 sec training webcast out over the new DateTimeInfo and TimeZoneInfo structs in .Net 3.5.&#160; This video complements two of my recent blog posts:</p>
<ol>
<li><a href="http://www.danrigsby.com/blog/index.php/2008/08/24/timezone-vs-timezoneinfo-in-net/">TimeZone vs. TimeZoneInfo in .Net</a> </li>
<li><a href="http://www.danrigsby.com/blog/index.php/2008/08/23/datetime-vs-datetimeoffset-in-net/">DateTime vs. DateTimeOffset in .Net</a> </li>
</ol>
<p>It is available through <a href="http://www.jupitermedia.com/">JupiterMedia</a> and can be viewed at <a href="http://www.internet.com/video/">http://www.internet.com/video/</a>. Just look for the &quot;Developer Video&quot; titled &quot;Date &amp; Times in .Net 3.5&quot;.&#160; Direct links are:</p>
<p><a href="http://www.internet.com/video/?bcpid=1431564240&amp;bclid=1433966034&amp;bctid=1757572900">http://www.internet.com/video/?bcpid=1431564240&amp;bclid=1433966034&amp;bctid=1757572900</a>     <br /><a title="http://link.brightcove.com/services/link/bcpid1431564240/bclid1433966034/bctid1757572900" href="http://link.brightcove.com/services/link/bcpid1431564240/bclid1433966034/bctid1757572900">http://link.brightcove.com/services/link/bcpid1431564240/bclid1433966034/bctid1757572900</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.danrigsby.com/blog/index.php/2008/08/27/new-webcast-date-times-in-net-35/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>TimeZone vs. TimeZoneInfo in .Net</title>
		<link>http://www.danrigsby.com/blog/index.php/2008/08/24/timezone-vs-timezoneinfo-in-net/</link>
		<comments>http://www.danrigsby.com/blog/index.php/2008/08/24/timezone-vs-timezoneinfo-in-net/#comments</comments>
		<pubDate>Sun, 24 Aug 2008 19:49:00 +0000</pubDate>
		<dc:creator>Dan Rigsby</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://www.danrigsby.com/blog/index.php/2008/08/24/timezone-vs-timezoneinfo-in-net/</guid>
		<description><![CDATA[Working with Dates and Times in .Net 3.5 Series:       Part 1: DateTime vs. DateTimeOffset in .Net       Part 2: TimeZone vs. TimeZoneInfo in .Net

This is Part 2 in a series on working with Dates and Times in .Net 3.5.&#160; You might want to read [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p><strong>Working with Dates and Times in .Net 3.5 Series:</strong>       <br />Part 1: <a href="http://www.danrigsby.com/blog/index.php/2008/08/23/datetime-vs-datetimeoffset-in-net/">DateTime vs. DateTimeOffset in .Net</a>       <br />Part 2: <a href="http://www.danrigsby.com/blog/index.php/2008/08/24/timezone-vs-timezoneinfo-in-net/">TimeZone vs. TimeZoneInfo in .Net</a></p>
</blockquote>
<p><em>This is Part 2 in a series on working with Dates and Times in .Net 3.5.&#160; You might want to read </em><a href="http://www.danrigsby.com/blog/index.php/2008/08/23/datetime-vs-datetimeoffset-in-net/"><em>Part 1: DateTime vs. DateTimeOffset in .Net</em></a><em> in WCF before continuing on with this post.</em></p>
<p><a href="http://www.danrigsby.com/blog/wp-content/uploads/2008/08/moonknt-121.jpg"><img title="MoonKnt_12" style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="264" alt="MoonKnt_12" src="http://www.danrigsby.com/blog/wp-content/uploads/2008/08/moonknt-12-thumb1.jpg" width="175" align="right" border="0" /></a>The <a href="http://msdn.microsoft.com/en-us/library/system.timezone.aspx">TimeZone</a> data type was introduced in .Net 1.0 as a mechanism for retrieving information about the current time zone, and to convert times from local time to Coordinated Universal Time (UTC) or vice versa.&#160; The down side is that you cannot use this to represent any other time zone other than the local zone.&#160; It also can’t be used to convert one date time to another zone.&#160; This is a pretty sever limitation and something that .Net has been lacking for some time.</p>
<p>In .Net 3.5, Microsoft finally introduced a replacement for TimeZone.&#160; The <a href="http://msdn.microsoft.com/en-us/library/system.timezoneinfo.aspx">TimeZoneInfo</a> class fills in all of the gaps where TimeZone left off.&#160; You can represent any time zone and perform various calculations.&#160; Many people have yet to hear of this class, but it is crucial if you are working with applications that need to perform calculations on dates and times which may originate from differet time zones. The major functions of this class include the ability to:</p>
<ul>
<li>Retrieving a time zone that is already defined by the operating system. This can be retrieved by ID or the current local time zone. </li>
<li>Converting times between different time zones. </li>
<li>Enumerating the time zones that are available on a system. </li>
<li>Find all time zones a DateTime or DateTimeOffset can represent. </li>
<li>Creating a new time zone that is not already defined by the operating system. </li>
<li>Serializing a time zone for later retrieval. </li>
</ul>
<p>View the complete list of members here: <a title="http://msdn.microsoft.com/en-us/library/system.timezoneinfo_members.aspx" href="http://msdn.microsoft.com/en-us/library/system.timezoneinfo_members.aspx">http://msdn.microsoft.com/en-us/library/system.timezoneinfo_members.aspx</a></p>
<p>Use this class to work with any time zone that is predefined on a system, to create new time zones, and to easily convert dates and times from one time zone to another. The TimeZoneInfo class replaces the TimeZone class in every way.&#160; For all new development, ignore the TimeZone class and move straight to TimeZoneInfo.&#160; <em>The TimeZone class should probably have been marked as “Obsolete”.</em></p>
<h2>How TimeZone class works</h2>
</p>
</p>
<div>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">TimeZone timeZone = System.TimeZone.CurrentTimeZone;
Console.WriteLine(timeZone.StandardName);</pre>
</div>
<div>&#160;</div>
<div>With the TimeZone class you could pull the current time zone with the static <a href="http://msdn.microsoft.com/en-us/library/system.timezone.currenttimezone.aspx">CurrentTimeZone</a> static property.&#160; The TimeZone class has no constructors and fairly limited use.&#160; You can convert dates and times from the local zone to UTC, but you have no access to other time zones.</div>
<h2>How to retrieve a time zone with TimeZoneInfo</h2>
<div>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">TimeZoneInfo hwZone =
    TimeZoneInfo.FindSystemTimeZoneById(<span style="color: #006080">&quot;Hawaiian Standard Time&quot;</span>);
TimeZoneInfo info = TimeZoneInfo.Local;</pre>
</div>
<div>&#160;</div>
<div>The TimeZoneInfo class allows you to access the local time zone with the <a href="http://msdn.microsoft.com/en-us/library/system.timezoneinfo.local.aspx">Local</a> static property.&#160; This is similar to the TimeZone class.&#160; However, TimeZoneInfo also allows you to reference any time zone with the <a href="http://msdn.microsoft.com/en-us/library/system.timezoneinfo.findsystemtimezonebyid.aspx">FindSystemTimeZoneById</a> static method. This method takes in a string which represents the Id for the time zone. Once you have this time zone, you can work with methods on the object to perform a variety of conversions.</div>
<div>&#160;</div>
<div>A <a href="http://msdn.microsoft.com/en-us/library/system.timezonenotfoundexception.aspx">TimeZoneNotFoundException</a> is thrown if the time zone ID could not be found on the local system.</div>
<h2>How to convert times between different time zones with TimeZoneInfo</h2>
<p>The TimeZoneInfo provides a few conversion methods to allow conversions between different time zones.&#160; The most useful of which is the <a href="http://msdn.microsoft.com/en-us/library/system.timezoneinfo.converttime.aspx">ConvertTime</a> method.&#160; With this, you can pass in a date/time and the time zone in which you want to convert it into.&#160; If you are using <a href="http://msdn.microsoft.com/en-us/library/system.datetimeoffset.aspx">DateTimeOffset</a>, then when you compare the two date/time values, they are equivalent since they both represent the same time, just in different time zones.</p>
<div>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">DateTimeOffset nowDateTime = DateTimeOffset.Now;
DateTimeOffset newDateTime = TimeZoneInfo.ConvertTime(
    nowDateTime,
    TimeZoneInfo.FindSystemTimeZoneById(<span style="color: #006080">&quot;Hawaiian Standard Time&quot;</span>));
Console.WriteLine(<span style="color: #006080">&quot;Now: {0}&quot;</span>, nowDateTime);
Console.WriteLine(<span style="color: #006080">&quot;Now in Hawaii: {0}&quot;</span>, newDateTime);</pre>
</div>
<div>&#160;</div>
<div><a href="http://www.danrigsby.com/blog/wp-content/uploads/2008/08/timezoneinfo1.gif"><img title="timezoneinfo1" height="201" alt="timezoneinfo1" src="http://www.danrigsby.com/blog/wp-content/uploads/2008/08/timezoneinfo1-thumb.gif" width="437" border="0" /></a>&#160;</div>
<h2>How to enumerate through all time zones on the computer with TimeZoneInfo</h2>
<p>The <a href="http://msdn.microsoft.com/en-us/library/system.timezoneinfo.getsystemtimezones.aspx">GetSystemTimeZones</a> method of the TimeZoneInfo class returns a <a href="http://msdn.microsoft.com/en-us/library/ms132474.aspx">ReadOnlyCollection</a> of all of the time zones that the current system knows about.</p>
<div>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">ReadOnlyCollection&lt;TimeZoneInfo&gt; timeZones = TimeZoneInfo.GetSystemTimeZones();
Console.WriteLine(<span style="color: #006080">&quot;All time zones:&quot;</span>);
<span style="color: #0000ff">foreach</span> (TimeZoneInfo timeZoneInfo <span style="color: #0000ff">in</span> timeZones)
{
    Console.WriteLine(<span style="color: #006080">&quot;   {0}&quot;</span>, timeZoneInfo.DisplayName);
}</pre>
</div>
</p>
<p><a href="http://www.danrigsby.com/blog/wp-content/uploads/2008/08/timezoneinfo2.gif"><img title="timezoneinfo2" height="249" alt="timezoneinfo2" src="http://www.danrigsby.com/blog/wp-content/uploads/2008/08/timezoneinfo2-thumb.gif" width="437" border="0" /></a>&#160;</p>
<h2>How to find all time zones a DateTime or DateTimeOffset can represent with TimeZoneInfome</h2>
<p>Most date time offset can represent multiple time zones.&#160; For instance, if a date and time have a –6 hour offset, this could be in the Central Time, Central American, Saskatchewan, or Guadalajara.&#160; With the TimeZoneInfo class, you can easily find all of the time zones that the date and time could represent by simply interating over all of the time zones on the system and comparing their offset to the offset stored in the <a href="http://msdn.microsoft.com/en-us/library/system.datetimeoffset.aspx">DateTimeOffset</a> object:</p>
<div>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">DateTimeOffset current = DateTimeOffset.Now;
ReadOnlyCollection&lt;TimeZoneInfo&gt; timeZones = TimeZoneInfo.GetSystemTimeZones();
Console.WriteLine(<span style="color: #006080">&quot;You might be in the following time zones:&quot;</span>);
<span style="color: #0000ff">foreach</span> (TimeZoneInfo timeZoneInfo <span style="color: #0000ff">in</span> timeZones)
{
    <span style="color: #008000">// Compare offset with offset for that date in that time zone</span>
    <span style="color: #0000ff">if</span> (timeZoneInfo.GetUtcOffset(current).Equals(current.Offset))
    {
        Console.WriteLine(<span style="color: #006080">&quot;   {0}&quot;</span>, timeZoneInfo.DisplayName);
    }
}</pre>
</div>
<div>&#160;</div>
<div>This code outputs all of the following time zones.&#160; DateTimeOffset.Now happens to represent “Eastern Time” in this example.</div>
<div>&#160;</div>
<div><a href="http://www.danrigsby.com/blog/wp-content/uploads/2008/08/timezoneinfo3.gif"><img title="timezoneinfo3" height="201" alt="timezoneinfo3" src="http://www.danrigsby.com/blog/wp-content/uploads/2008/08/timezoneinfo3-thumb.gif" width="437" border="0" /></a>&#160;</div>
<h2>How to create a new time zone with TimeZoneInfo</h2>
<p>The TimeZoneInfo class has no constructors, so it is impossible to new up a new instance.&#160; However, it does provide a static method called <a href="http://msdn.microsoft.com/en-us/library/bb309898.aspx">CreateCustomTimeZone</a> that allows you to create a new time zone to work with.&#160; This method has a couple of overrides to provide you with everything needed to create a new time zone.&#160; The following creates a new simple time zone called “My Custom Time Zone” which has a –4 hour offset from <a href="http://wwp.greenwichmeantime.com/what-is-gmt.htm">GMT</a> and observes daylight savings time.</p>
<div>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">TimeZoneInfo info = TimeZoneInfo.CreateCustomTimeZone(
    <span style="color: #006080">&quot;My Custom Time Zone&quot;</span>,
    <span style="color: #0000ff">new</span> TimeSpan(-4, 0, 0),
    <span style="color: #006080">&quot;My Custom Time Zone&quot;</span>,
    <span style="color: #006080">&quot;My Custom Time Zone&quot;</span>,
    <span style="color: #006080">&quot;My Custom Time Zone&quot;</span>,
    <span style="color: #0000ff">new</span> TimeZoneInfo.AdjustmentRule[] { },
    <span style="color: #0000ff">false</span>);</pre>
</div>
<h2>How to serialize a time zone with TimeZoneInfo</h2>
<p>One of the unique features of the TimeZoneInfo class is that it has a native method to serialize the time zone to a string.&#160; The <a href="http://msdn.microsoft.com/en-us/library/system.timezoneinfo.toserializedstring.aspx">ToSerializedString</a> method is unlike other serialization methods in that it doesn’t serialize to xml by default, but instead to a semicolon delimited list.&#160; This serialized string can be stored to disk or some other location for later retrieval.</p>
</p>
</p>
</p>
<div>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">TimeZoneInfo info = TimeZoneInfo.Local;
<span style="color: #0000ff">string</span> serialized = info.ToSerializedString();</pre>
</div>
<div>&#160;</div>
<div>This code produces the following output:</div>
<blockquote>
<p>Eastern Standard Time;-300;(GMT-05:00) Eastern Time (US &amp; Canada);Eastern Standard Time;Eastern Daylight Time;[01:01:0001;12:31:2006;60;[0;02:00:00;4;1;0;];[0;02:00:00;10;5;0;];][01:01:2007;12:31:9999;60;[0;02:00:00;3;2;0;];[0;02:00:00;11;1;0;];];</p>
</blockquote>
<p>To deserialize the string back into a TimeZoneInfo class, you can use the <a href="http://msdn.microsoft.com/en-us/library/system.timezoneinfo.fromserializedstring.aspx">FromSerializedString</a> static method to create a new TimeZoneInfo object.</p>
<div>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">TimeZoneInfo info2 = TimeZoneInfo.FromSerializedString(serialized);</pre>
</div>
<div class="wlWriterHeaderFooter" style="text-align:left; margin:0px; padding:4px 4px 4px 4px;"><a href="http://www.dotnetkicks.com/kick/?url=http://www.danrigsby.com/blog/index.php/2008/08/24/timezone-vs-timezoneinfo-in-net/"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://www.danrigsby.com/blog/index.php/2008/08/24/timezone-vs-timezoneinfo-in-net/&amp;bgcolor=FF8000&amp;fgcolor=FFFFFF&amp;border=000000&amp;cbgcolor=D4E1ED&amp;cfgcolor=000000" alt="DotNetKicks Image" border="0/"></a></div>
]]></content:encoded>
			<wfw:commentRss>http://www.danrigsby.com/blog/index.php/2008/08/24/timezone-vs-timezoneinfo-in-net/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>DateTime vs. DateTimeOffset in .Net</title>
		<link>http://www.danrigsby.com/blog/index.php/2008/08/23/datetime-vs-datetimeoffset-in-net/</link>
		<comments>http://www.danrigsby.com/blog/index.php/2008/08/23/datetime-vs-datetimeoffset-in-net/#comments</comments>
		<pubDate>Sun, 24 Aug 2008 01:58:00 +0000</pubDate>
		<dc:creator>Dan Rigsby</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://www.danrigsby.com/blog/?p=343</guid>
		<description><![CDATA[Working with Dates and Times in .Net 3.5 Series:       Part 1: DateTime vs. DateTimeOffset in .Net       Part 2: TimeZone vs. TimeZoneInfo in .Net

 The DateTime data type has been around since .Net 1.0 and suited us well for a long time.&#160; It simply [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p><strong>Working with Dates and Times in .Net 3.5 Series:</strong>       <br />Part 1: <a href="http://www.danrigsby.com/blog/index.php/2008/08/23/datetime-vs-datetimeoffset-in-net/">DateTime vs. DateTimeOffset in .Net</a>       <br />Part 2: <a href="http://www.danrigsby.com/blog/index.php/2008/08/24/timezone-vs-timezoneinfo-in-net/">TimeZone vs. TimeZoneInfo in .Net</a></p>
</blockquote>
<p><a href="http://www.danrigsby.com/blog/wp-content/uploads/2008/08/moonknt-12.jpg"><img title="MoonKnt_12" style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; margin: 0px 5px 0px 0px; border-right-width: 0px" height="264" alt="MoonKnt_12" src="http://www.danrigsby.com/blog/wp-content/uploads/2008/08/moonknt-12-thumb.jpg" width="175" align="left" border="0" /></a> The <a href="http://msdn.microsoft.com/en-us/library/system.datetime.aspx">DateTime</a> data type has been around since .Net 1.0 and suited us well for a long time.&#160; It simply defines a date and a time together and offers methods for working with these constructs. It is a struct and hence can’t be set to null.&#160; This caused some people some problems over the years.&#160; Especially when modeling a DateTime from the database, since in most databases like SQL Server, the datetime field can be null.&#160; So, usually a null DateTime would be set to <a href="http://msdn.microsoft.com/en-us/library/system.datetime.minvalue.aspx">DateTime.MinValue</a>.&#160; However, this wasn’t the most optimal solution.</p>
<p>In .Net 2.0 nullable types were introduced.&#160; Now, we could have a null DateTime by simply defining the field as&#160; <a href="http://msdn.microsoft.com/en-us/library/b3h38hb0.aspx">System.Nullable</a>&lt;DateTime&gt; (or DateTime?) instead of the standard DateTime.&#160; This allowed us to set the field to null, and pull the value using the Value property of the field.</p>
<p>In .Net 3.5 an entirely new date/time field was added called <a href="http://msdn.microsoft.com/en-us/library/system.datetimeoffset.aspx">DateTimeOffset</a>.&#160; This data extends the DateTime to add in the concept of a timezone offset.&#160; It is still a struct, so you need to use System.Nullable&lt;DateTimeOffest&gt; if you want to be able to have a null value. A <a href="http://msdn.microsoft.com/en-us/library/system.datetimeoffset.aspx">DateTimeOffset</a> value is not tied to a particular time zone, but can originate from any of a variety of time zones.&#160; For example, there are can multiple timezones that represent the same offset such as UTC –6:00 which can be Central Time, Central American, Saskatchewan, or Guadalajara.&#160; So you don’t know the timezone that the datetime represents, but you do know the offset.&#160; This is all you need to perform comparisons to other DateTimeOffsets. </p>
<p><img title="180px-Primemeridian" style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="98" alt="180px-Primemeridian" src="http://www.danrigsby.com/blog/wp-content/uploads/2008/08/180pxprimemeridian.jpg" width="184" align="right" border="0" />The offset value represents the time difference between the current time and <a href="http://wwp.greenwichmeantime.com/what-is-gmt.htm">Greenwich Mean Time</a> (GMT) this is known as Coordinated Universal Time (UTC).&#160; GMT historically is the time when the sun crosses the <a href="http://en.wikipedia.org/wiki/Greenwich_meridian">Prime Meridian</a> line which is located a 0 Longitude. IT is measured from the Greenwich Meridian Line at the Royal Observatory in Greenwich, England.&#160; This is the place from where all time zones are measured. Even the atomic clocks of the world are adjusted by leap seconds to maintain synchronicity with GMT. </p>
<p>So why is UTC so important to software developers?&#160; This may be an obvious answer to most, but if you haven’t been exposed to this, it’s because many applications need to be globalized and may be run in different timezones.&#160; If someone enters in a date and time, is that relative to their timezone or the timezone the server is sitting on.&#160; This can be vastly different and can really cause problems in your application.&#160; Comparing all dates and times to the relative time of GMT allows applications to understand what the date and time actually represent.</p>
</p>
</p>
<h2>What does DateTime and DateTimeOffest look like</h2>
<div>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">Console.WriteLine(DateTime.Now);
Console.WriteLine(DateTimeOffset.Now);</pre>
</div>
<div>&#160;</div>
<div><a href="http://www.danrigsby.com/blog/wp-content/uploads/2008/08/datetime1.gif"><img title="datetime1" height="141" alt="datetime1" src="http://www.danrigsby.com/blog/wp-content/uploads/2008/08/datetime1-thumb.gif" width="429" border="0" /></a> </div>
<div>&#160;</div>
<div>This print out shows the basic difference in the two types.&#160; The DateTime shows the Date and Time, while the DateTimeOffset shows the Date, Time, and offset.&#160; This offset represents the difference from GMT.&#160; In this case 4 hours behind GMT.</div>
<h2>How to convert from DateTime to DateTimeOffset</h2>
<div>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">DateTime d1 = DateTime.Now;
DateTimeOffset o1 = <span style="color: #0000ff">new</span> DateTimeOffset(d1);
DateTimeOffset of1 = <span style="color: #0000ff">new</span> DateTimeOffset(d1, <span style="color: #0000ff">new</span> TimeSpan(-5, 0, 0));</pre>
</div>
<div>&#160;</div>
<div>To convert a DateTime into a DateTimeOffset, you just need to pass the DateTime value into one of the constructors of the DateTimeOffset.&#160; You could just pass the DateTime in (as in o1 above), or you can also pass in the DateTime and an offset (as in of1 above).&#160; If you don’t supply an offset, then GMT is assumed.</div>
<h2>How to convert from DateTimeOffest to DateTime</h2>
<div>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">DateTimeOffset o2 = DateTimeOffset.Now;
DateTime d2 = o2.DateTime;</pre>
</div>
<div>&#160;</div>
<div>Converting a DateTimeOffset to a DateTime is easy.&#160; Since the DateTimeOffset value contains all of the data of a DateTime field and more, there is a simple DateTime property on the DateTimeOffset struct that returns a DateTime representation of the value.</div>
<h2>How to manually set DateTime and DateTimeOffset</h2>
<div>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">DateTime dt1 = <span style="color: #0000ff">new</span> DateTime(2008, 8, 22, 1, 0, 0);
DateTimeOffset do1 = <span style="color: #0000ff">new</span> DateTimeOffset(2008, 8, 22, 1, 0, 0, <span style="color: #0000ff">new</span> TimeSpan(-5, 0, 0));
Console.WriteLine(dt1);
Console.WriteLine(do1);</pre>
</div>
<div>&#160;</div>
<div><a href="http://www.danrigsby.com/blog/wp-content/uploads/2008/08/datetime2.gif"><img title="datetime2" height="141" alt="datetime2" src="http://www.danrigsby.com/blog/wp-content/uploads/2008/08/datetime2-thumb.gif" width="429" border="0" /></a>&#160;</div>
<div>&#160;</div>
<div>Manually setting a DateTimeOffset is very similar to setting the value of a DateTime.&#160; The only difference is that you can also pass in a <a href="http://msdn.microsoft.com/en-us/library/system.timespan.aspx">TimeSpan</a> as the last argument that represents the GMT offset.</div>
<h2>Arithmetic with Datetime and DateTimeOffest</h2>
<div>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">DateTime dateTime1 = DateTime.Now;
DateTime dateTime2 = DateTime.UtcNow;
Console.WriteLine(<span style="color: #006080">&quot;{0} - {1} =&quot;</span>, dateTime1, dateTime2);
Console.WriteLine(dateTime1 - dateTime2);

Console.WriteLine();

DateTimeOffset offset1 = DateTimeOffset.Now;
DateTimeOffset offset2 = DateTimeOffset.UtcNow;
Console.WriteLine(<span style="color: #006080">&quot;{0} - {1} =&quot;</span>, offset1, offset2);
Console.WriteLine(offset1 - offset2);</pre>
</div>
<div>&#160;</div>
</p>
<p><a href="http://www.danrigsby.com/blog/wp-content/uploads/2008/08/datetime3.gif"><img title="datetime3" height="141" alt="datetime3" src="http://www.danrigsby.com/blog/wp-content/uploads/2008/08/datetime3-thumb.gif" width="525" border="0" /></a> </p>
<p>With this example we can see that the difference between Now and UtcNow is 0.&#160; This means that the DateTimeOffset sees the UTC version of the time and the local version of the time as equal.&#160; But what about something more complicated? Are 12 PM EST and 9AM PST equal?</p>
<div>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">DateTimeOffset ao1 = <span style="color: #0000ff">new</span> DateTimeOffset(2008, 8, 22, 12, 0, 0, <span style="color: #0000ff">new</span> TimeSpan(-5, 0, 0));
DateTimeOffset ao2 = <span style="color: #0000ff">new</span> DateTimeOffset(2008, 8, 22, 9, 0, 0, <span style="color: #0000ff">new</span> TimeSpan(-8, 0, 0));
Console.WriteLine(ao1 == ao2);</pre>
</div>
<div>&#160;</div>
<div>This code creates 2 times.&#160; One is 12 PM August, 22 2008 and the second is 9 AM August, 22 2008.&#160; However, the offsets for each are set for Eastern Standard time and Pacific Standard time respectively.&#160; If we compare these two values, are they equal?&#160; If you guessed “Yes”, then you are right.&#160; The Equals() method of DateTimeOffset knows now to compare against the offsets.&#160; This is incredibly useful when comparing times cared in different time zones.</div>
<h2>When to use DateTime or DateTimeOffest</h2>
<p>Use DateTimeOffest structure to work with dates and times whose offset (or difference) from UTC is known or when calculations need to be performed on dates that may be from different timezones. The <a href="http://msdn.microsoft.com/en-us/library/system.datetimeoffset.aspx">DateTimeOffset</a> value is also more portable from one computer to another than a <a href="http://msdn.microsoft.com/en-us/library/system.datetime.aspx">DateTime</a> value.&#160; DateTimeOffset doesn’t necessarily replace DateTime though.&#160; DateTime is still useful to represent a single date or time or when the timezone information is unknown or not important.&#160; However most developers should explore using DateTimeOffest more in general use especially in enterprise level systems.</p>
<p>DateTime may also be the best type to represent a DateTime from the database since the DateTime fields in most databases don’t store timezone information.&#160; In SQL Server 2008 a DateTimeOffset structure was introduced to the database as well.&#160; This type is very comparable to the DateTimeOffset field in .Net.&#160; So a good rule of thumb may be to use the corresponding types when mapping between SQL Server 2008 and .Net 3.5.</p>
<p>&#160;</p>
<p><strong>Update:</strong> Nicholas Allen posted a reminder of how to deal with DateTimeOffest fields when working with svcutil.exe: <a title="http://blogs.msdn.com/drnick/archive/2008/09/04/getting-better-time-formats.aspx" href="http://blogs.msdn.com/drnick/archive/2008/09/04/getting-better-time-formats.aspx">http://blogs.msdn.com/drnick/archive/2008/09/04/getting-better-time-formats.aspx</a></p>
<div class="wlWriterHeaderFooter" style="text-align:left; margin:0px; padding:4px 4px 4px 4px;"><a href="http://www.dotnetkicks.com/kick/?url=http://www.danrigsby.com/blog/index.php/2008/08/23/datetime-vs-datetimeoffset-in-net/"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://www.danrigsby.com/blog/index.php/2008/08/23/datetime-vs-datetimeoffset-in-net/&amp;bgcolor=FF8000&amp;fgcolor=FFFFFF&amp;border=000000&amp;cbgcolor=D4E1ED&amp;cfgcolor=000000" alt="DotNetKicks Image" border="0/"></a></div>
]]></content:encoded>
			<wfw:commentRss>http://www.danrigsby.com/blog/index.php/2008/08/23/datetime-vs-datetimeoffset-in-net/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Visual Studio 2008 SP1 and .Net Framework 3.5 SP1 now Officially RTM</title>
		<link>http://www.danrigsby.com/blog/index.php/2008/08/11/visual-studio-2008-sp1-and-net-framework-35-sp1-now-offically-rtm/</link>
		<comments>http://www.danrigsby.com/blog/index.php/2008/08/11/visual-studio-2008-sp1-and-net-framework-35-sp1-now-offically-rtm/#comments</comments>
		<pubDate>Mon, 11 Aug 2008 16:22:40 +0000</pubDate>
		<dc:creator>Dan Rigsby</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://www.danrigsby.com/blog/index.php/2008/08/11/visual-studio-2008-sp1-and-net-framework-35-sp1-now-offically-rtm/</guid>
		<description><![CDATA[We knew it would be released soon since SQL Server 2008 went RTM with .Net Framework 3.5 SP1.&#160; Visual Studio 2008 SP1 is now RTM and available for download off the MSDN subscriber’s web site:

They are available for general download here:

Download .Net Framework 3.5 SP1 here: http://www.microsoft.com/downloads/details.aspx?FamilyId=AB99342F-5D1A-413D-8319-81DA479AB0D7&#38;displaylang=en
Download Visual Studio 2008 SP1 here: http://www.microsoft.com/downloads/details.aspx?FamilyID=fbee1648-7106-44a7-9649-6d9f6d58056e&#38;DisplayLang=en 

Get downloading!&#160; [...]]]></description>
			<content:encoded><![CDATA[<p>We knew it would be <a href="http://www.danrigsby.com/blog/index.php/2008/08/07/net-framework-35-and-visual-studio-2008-sp1-very-close-to-release/">released soon</a> since <a href="http://www.danrigsby.com/blog/index.php/2008/08/06/sql-server-2008-rtm/">SQL Server 2008 went RTM</a> with .Net Framework 3.5 SP1.&#160; Visual Studio 2008 SP1 is now RTM and available for download off the MSDN subscriber’s web site:</p>
<p><a href="http://www.danrigsby.com/blog/wp-content/uploads/2008/08/vs2008sp1.png"><img title="VS2008SP1" style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="353" alt="VS2008SP1" src="http://www.danrigsby.com/blog/wp-content/uploads/2008/08/vs2008sp1-thumb.png" width="697" border="0" /></a></p>
<p>They are available for general download here:</p>
<ul>
<li>Download .Net Framework 3.5 SP1 here: <a title="http://www.microsoft.com/downloads/details.aspx?FamilyId=AB99342F-5D1A-413D-8319-81DA479AB0D7&amp;displaylang=en" href="http://www.microsoft.com/downloads/details.aspx?FamilyId=AB99342F-5D1A-413D-8319-81DA479AB0D7&amp;displaylang=en">http://www.microsoft.com/downloads/details.aspx?FamilyId=AB99342F-5D1A-413D-8319-81DA479AB0D7&amp;displaylang=en</a></li>
<li>Download Visual Studio 2008 SP1 here: <a title="http://www.microsoft.com/downloads/details.aspx?FamilyID=fbee1648-7106-44a7-9649-6d9f6d58056e&amp;DisplayLang=en" href="http://www.microsoft.com/downloads/details.aspx?FamilyID=fbee1648-7106-44a7-9649-6d9f6d58056e&amp;DisplayLang=en">http://www.microsoft.com/downloads/details.aspx?FamilyID=fbee1648-7106-44a7-9649-6d9f6d58056e&amp;DisplayLang=en</a> </li>
</ul>
<p>Get downloading!&#160; The servers are busy at the moment, but this is worth the wait.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.danrigsby.com/blog/index.php/2008/08/11/visual-studio-2008-sp1-and-net-framework-35-sp1-now-offically-rtm/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>.Net Framework 3.5 and Visual Studio 2008 SP1 very close to release</title>
		<link>http://www.danrigsby.com/blog/index.php/2008/08/07/net-framework-35-and-visual-studio-2008-sp1-very-close-to-release/</link>
		<comments>http://www.danrigsby.com/blog/index.php/2008/08/07/net-framework-35-and-visual-studio-2008-sp1-very-close-to-release/#comments</comments>
		<pubDate>Thu, 07 Aug 2008 18:44:36 +0000</pubDate>
		<dc:creator>Dan Rigsby</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://www.danrigsby.com/blog/index.php/2008/08/07/net-framework-35-and-visual-studio-2008-sp1-very-close-to-release/</guid>
		<description><![CDATA[&#160; When installing SQL Server 2008 RTM, it failed with the following error:
 
The SQL Server 2008 install installed a new version of .Net Framework 3.5 SP1, but if you have Visual Studio installed, you must upgrade to SP1 which isn’t officially released yet.&#160; This does appear to be the final version of the .Net [...]]]></description>
			<content:encoded><![CDATA[<p>&#160; When installing <a href="http://www.danrigsby.com/blog/index.php/2008/08/06/sql-server-2008-rtm/">SQL Server 2008 RTM</a>, it failed with the following error:</p>
<p><a href="http://www.danrigsby.com/blog/wp-content/uploads/2008/08/mssqlsp1.jpg"><img title="MSSQLSP1" style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="216" alt="MSSQLSP1" src="http://www.danrigsby.com/blog/wp-content/uploads/2008/08/mssqlsp1-thumb.jpg" width="484" border="0" /></a> </p>
<p>The SQL Server 2008 install installed a new version of .Net Framework 3.5 SP1, but if you have Visual Studio installed, you <strong>must</strong> upgrade to SP1 which isn’t officially released yet.&#160; This does appear to be the final version of the .Net Framework 3.5 SP1 since it is shipping with SQL Server 2008 RTM.&#160; Expect an official release within days along with Visual Studio 2008 SP1!</p>
<p><a href="http://www.danrigsby.com/blog/wp-content/uploads/2008/08/vsabout.png"><img title="VSAbout" style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="493" alt="VSAbout" src="http://www.danrigsby.com/blog/wp-content/uploads/2008/08/vsabout-thumb.png" width="644" border="0" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.danrigsby.com/blog/index.php/2008/08/07/net-framework-35-and-visual-studio-2008-sp1-very-close-to-release/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>JavaScriptSerializer Undeprecated in .NET 3.5 SP1</title>
		<link>http://www.danrigsby.com/blog/index.php/2008/05/28/javascriptserializer-undeprecated-in-net-35-sp1/</link>
		<comments>http://www.danrigsby.com/blog/index.php/2008/05/28/javascriptserializer-undeprecated-in-net-35-sp1/#comments</comments>
		<pubDate>Wed, 28 May 2008 13:29:33 +0000</pubDate>
		<dc:creator>Dan Rigsby</dc:creator>
				<category><![CDATA[.Net]]></category>

		<guid isPermaLink="false">http://www.danrigsby.com/blog/?p=229</guid>
		<description><![CDATA[According to Scott Guthrie (see comments in this post) it appears that the JavaScriptSerializer will be undeprecated in .NET 3.5 SP1.&#160; In was deprecated in .Net 3.5 and the DataContractJsonSerializer replaced it.&#160; Each of these serializers serializes to Json and each have their pluses and minuses:

JavaScriptSerializer supports anonymous types.
JavaScriptSerializer works with plain strings so it [...]]]></description>
			<content:encoded><![CDATA[<p>According to <a href="http://weblogs.asp.net/scottgu">Scott Guthrie</a> (<a href="http://www.aaronlerch.com/blog/2008/05/27/first-thoughts-on-aspnet-mvc-preview-3/#comments">see comments in this post</a>) it appears that the <a href="http://msdn.microsoft.com/en-us/library/system.web.script.serialization.javascriptserializer.aspx">JavaScriptSerializer</a> will be undeprecated in .NET 3.5 SP1.&#160; In was deprecated in .Net 3.5 and the <a href="http://msdn.microsoft.com/en-us/library/system.runtime.serialization.json.datacontractjsonserializer.aspx">DataContractJsonSerializer</a> replaced it.&#160; Each of these serializers serializes to Json and each have their pluses and minuses:</p>
<ul>
<li>JavaScriptSerializer supports anonymous types.</li>
<li>JavaScriptSerializer works with plain strings so it can be easier to use.</li>
<li>DataContractJsonSerializer can serialize DateTimes into UTC format.&#160;&#160; Very important over the web!</li>
</ul>
<p>I guess the big question I have is, do we really need both? Isn&#8217;t there a way to combine these into one serializer? </p>
<p>What about the act of undeprecating a class?&#160; Do you think this is a good thing?</p>
<p><em>See these links for more information about the DataContractJsonSerializer:</em></p>
<ul>
<li><a title="http://www.west-wind.com/WebLog/posts/218001.aspx" href="http://www.west-wind.com/WebLog/posts/218001.aspx">http://www.west-wind.com/WebLog/posts/218001.aspx</a></li>
<li><a title="http://pietschsoft.com/post/2008/02/NET-35-JSON-Serialization-using-the-DataContractJsonSerializer.aspx" href="http://pietschsoft.com/post/2008/02/NET-35-JSON-Serialization-using-the-DataContractJsonSerializer.aspx">http://pietschsoft.com/post/2008/02/NET-35-JSON-Serialization-using-the-DataContractJsonSerializer.aspx</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.danrigsby.com/blog/index.php/2008/05/28/javascriptserializer-undeprecated-in-net-35-sp1/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Sexagesimal Conversions in .Net</title>
		<link>http://www.danrigsby.com/blog/index.php/2008/04/30/sexagesimal-conversions-in-net/</link>
		<comments>http://www.danrigsby.com/blog/index.php/2008/04/30/sexagesimal-conversions-in-net/#comments</comments>
		<pubDate>Wed, 30 Apr 2008 12:22:06 +0000</pubDate>
		<dc:creator>Dan Rigsby</dc:creator>
				<category><![CDATA[.Net]]></category>

		<guid isPermaLink="false">http://www.danrigsby.com/blog/?p=189</guid>
		<description><![CDATA[No, that is not a dirty word, and yes, it is fun to say. [sek-suh-jes-uh-muhl]
Sexagesimal is a base-60 number system much like our own base-10 decimal system.&#160; Throughout history different cultures have chosen different base numbering systems based on things they considered common or sacred.&#160; Many people today recognize numbers as always being base-10, and [...]]]></description>
			<content:encoded><![CDATA[<p>No, that is not a dirty word, and yes, it is fun to say. [sek-s<i>uh</i>-<b>jes</b>-<i>uh</i>-m<i>uh</i>l]</p>
<p><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" border="0" alt="7520012074151" align="right" src="http://www.danrigsby.com/blog/wp-content/uploads/2008/04/7520012074151-thumb.jpg" width="113" height="175" /><a href="http://en.wikipedia.org/wiki/Sexagesimal">Sexagesimal</a> is a base-60 number system much like our own base-10 decimal system.&#160; Throughout history different cultures have chosen different base <a href="http://en.wikipedia.org/wiki/Numeral_system#Sixty">numbering systems</a> based on things they considered common or sacred.&#160; Many people today recognize numbers as always being base-10, and it can be quite difficult to explain a different numbering system to a child.&#160; Those of us in computer science are quite use to a base-2 (binary) system.&#160; Some of the more common historic number systems are:</p>
<ol>
<li><strong>Base-5</strong> (<a href="http://en.wikipedia.org/wiki/Quinary">quinary</a>): This system has been popular because five can easily be represented by the five fingers on one hand </li>
<li><strong>Base-8</strong> (<a href="http://en.wikipedia.org/wiki/Octal">octal</a>): Some cultures used only their fingers to count and used the thumbs as place holders.&#160; While other cultures, such as the <a href="http://en.wikipedia.org/wiki/Yuki_tribe">Yuki</a> Native American tribe of Northern California , counted the spaces between the fingers.&#160; The Yuki actually started counting with 0 as well (much like C based languages).&#160; So the numbers 0-7 were counted on their fingers. </li>
<li><strong>Base-10</strong> (<a href="http://en.wikipedia.org/wiki/Decimal">decimal</a>): We are all familiar with the base-10 system which is almost universally used around the world.&#160; Historical this is based on the fact that humans have ten fingers on which to count. </li>
<li><strong>Base-12</strong> (<a href="http://en.wikipedia.org/wiki/Duodecimal">duodecimal</a>):&#160; This system is based on the knuckles of the four fingers.&#160; Each finger has 3 knuckles and the thumb is used as the place holder.&#160; Twelve is also an important unit in British measurement such as 12 inches in a foot, 12 pennies to a shilling, 12 numbers used in our time units, etc. </li>
<li><strong>Base-20</strong> (<a href="http://en.wikipedia.org/wiki/Vigesimal">vigesimal</a>): The base-20 system originates from the combination of ten fingers and ten toes on which to count.&#160; This is most widely known to be used by the <a href="http://en.wikipedia.org/wiki/Maya_civilization">Mayan civilization</a>. </li>
<li><strong>Base-60</strong> (<a href="http://en.wikipedia.org/wiki/Sexagesimal">sexigesimal</a>): The base-60 system dates back to the <a href="http://en.wikipedia.org/wiki/Sumerians">Sumerians</a> and the early cultures of Mesopotamia.&#160; It&#8217;s hard to say where this system originated from, but common belief is that it is a combination of the base-10 and base-12 systems. </li>
</ol>
<p>So why is the base-60 system still important to us today?&#160; Well for one, there are 60 seconds in a minute and 60 minutes in an hour.&#160; This measurement one of the Sumerian&#8217;s lasting impressions today.&#160; Their calendar and type systems have been adopted and modified throughout the Asia and Europe.&#160; We can blame the Sumerian&#8217;s for not having enough time in the day.</p>
<p><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" border="0" alt="180px-Geographic_coordinates_sphere.svg" align="right" src="http://www.danrigsby.com/blog/wp-content/uploads/2008/04/180px-geographic-coordinates-spheresvg-thumb.png" width="180" height="177" /> Another popular use for the base-60 system is in angular measure in our <a href="http://en.wikipedia.org/wiki/Spherical_coordinates#Spherical_coordinates">spherical coordinate system</a> of the Earth.&#160; A <a href="http://en.wikipedia.org/wiki/Degree_%28angle%29">degree</a> is divided into 60 <a href="http://en.wikipedia.org/wiki/Minute_of_arc">minutes</a> and a minute is divided into 60 <a href="http://en.wikipedia.org/wiki/Second_of_arc">seconds</a>.&#160; Our system of <a href="http://en.wikipedia.org/wiki/Latitude_and_Longitude">Latitudes and Longitudes</a> is expressed in these terms.&#160; With the popularity of geo-spatial and mapping tools such as <a href="http://maps.google.com/">Google Maps</a> and <a href="http://www.google.com/url?sa=t&amp;ct=res&amp;cd=4&amp;url=http%3A%2F%2Fmaps.live.com%2F&amp;ei=ymkYSKqCNYKuigGYivWpDA&amp;usg=AFQjCNHn1_W3Ai9_6Y0xBdD_1LaIgdb-gg&amp;sig2=JRwBSNcOp2c-rOlmuOZqAA">Microsoft Live Maps</a>, it has become important to be able to convert from degrees/minutes/seconds into a decimal notation and vice versa.</p>
<blockquote><p><strong>Example:</strong></p>
<p>(49&#176;30&#8242;02&quot;N, 123&#176;30&#8242;30&quot;)</p>
<p>&#160;</p>
<p>49 degrees, 30 minutes, and 2 seconds by 123 degrees, 30 minutes, and 30 seconds</p>
</blockquote>
<p>Below is a utilities class that I originally wrote for an astronomical observatory simulation application called <a href="http://www.codeplex.com/IUPUIStellarResults">StellarResults</a> (which is available on codeplex).&#160; This program would simulate observatories around the world and what astronomical objects they could see at a give time of day.&#160; I soon realized that I needed to push this library down to a more basic level so that I could use it for other geo-spatial calculations such as working with geo-coded locations, or entering locations into a database.&#160; Libraries like this will also be useful when working with the new <a href="http://www.google.com/url?sa=t&amp;ct=res&amp;cd=1&amp;url=http%3A%2F%2Fwww.microsoft.com%2Fsqlserver%2F2008%2Fen%2Fus%2Fspatial-data.aspx&amp;ei=vXYYSMalI6HAiAGlw62UDA&amp;usg=AFQjCNGJBx7ldIuSi-WP0IKzh_1tXcWC8A&amp;sig2=F_HPY_UE0jr-PJIBXX3xTw">spatial database features</a> in Microsoft SQL Server 2008.</p>
<div>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">class</span> GISUtilities
{
    <span style="color: #cc6633">#region</span> Sexagesimal
    <span style="color: #008000">/// &lt;summary&gt;</span>
    <span style="color: #008000">/// Converts from degrees, minues, seconds to a double.</span>
    <span style="color: #008000">/// &lt;/summary&gt;</span>
    <span style="color: #008000">/// &lt;param name=&quot;degrees&quot;&gt;The degrees.&lt;/param&gt;</span>
    <span style="color: #008000">/// &lt;param name=&quot;minutes&quot;&gt;The minutes.&lt;/param&gt;</span>
    <span style="color: #008000">/// &lt;param name=&quot;seconds&quot;&gt;The seconds.&lt;/param&gt;</span>
    <span style="color: #008000">/// &lt;returns&gt;&lt;/returns&gt;</span>
    <span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">double</span> ConvertSexagesimalToDouble(
        <span style="color: #0000ff">int</span> degrees,
        <span style="color: #0000ff">int</span> minutes,
        <span style="color: #0000ff">int</span> seconds)
    {
        <span style="color: #0000ff">return</span> ((<span style="color: #0000ff">double</span>)degrees % 360) + ((<span style="color: #0000ff">double</span>)minutes / 60) + ((<span style="color: #0000ff">double</span>)seconds / 3600);
    }

    <span style="color: #008000">/// &lt;summary&gt;</span>
    <span style="color: #008000">/// Converts from degrees, minues, seconds to a string.</span>
    <span style="color: #008000">/// &lt;/summary&gt;</span>
    <span style="color: #008000">/// &lt;param name=&quot;degrees&quot;&gt;The degrees.&lt;/param&gt;</span>
    <span style="color: #008000">/// &lt;param name=&quot;minutes&quot;&gt;The minutes.&lt;/param&gt;</span>
    <span style="color: #008000">/// &lt;param name=&quot;seconds&quot;&gt;The seconds.&lt;/param&gt;</span>
    <span style="color: #008000">/// &lt;returns&gt;&lt;/returns&gt;</span>
    <span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">string</span> ConvertSexagesimalToString(
        <span style="color: #0000ff">int</span> degrees,
        <span style="color: #0000ff">int</span> minutes,
        <span style="color: #0000ff">int</span> seconds)
    {
        <span style="color: #0000ff">return</span> String.Format(
            <span style="color: #006080">&quot;{0}&#176; {1}' {2}''&quot;</span>,
            degrees.ToString(),
            minutes.ToString(),
            seconds.ToString());
    }

    <span style="color: #008000">/// &lt;summary&gt;</span>
    <span style="color: #008000">/// Converts from a double to degrees, minues, seconds.</span>
    <span style="color: #008000">/// &lt;/summary&gt;</span>
    <span style="color: #008000">/// &lt;param name=&quot;value&quot;&gt;The value to convert.&lt;/param&gt;</span>
    <span style="color: #008000">/// &lt;param name=&quot;degrees&quot;&gt;The degrees.&lt;/param&gt;</span>
    <span style="color: #008000">/// &lt;param name=&quot;minutes&quot;&gt;The minutes.&lt;/param&gt;</span>
    <span style="color: #008000">/// &lt;param name=&quot;seconds&quot;&gt;The seconds.&lt;/param&gt;</span>
    <span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">void</span> ConvertDoubleToSexagesimal(
        <span style="color: #0000ff">double</span> <span style="color: #0000ff">value</span>,
        <span style="color: #0000ff">out</span> <span style="color: #0000ff">int</span> degrees,
        <span style="color: #0000ff">out</span> <span style="color: #0000ff">int</span> minutes,
        <span style="color: #0000ff">out</span> <span style="color: #0000ff">int</span> seconds)
    {
        degrees = (<span style="color: #0000ff">int</span>)<span style="color: #0000ff">value</span>;
        minutes = (<span style="color: #0000ff">int</span>)((<span style="color: #0000ff">value</span> - degrees) * 60);
        seconds = (<span style="color: #0000ff">int</span>)((<span style="color: #0000ff">value</span> - degrees - (minutes / 60)) * 3600);
    }
    <span style="color: #cc6633">#endregion</span> Sexagesimal

    <span style="color: #cc6633">#region</span> HMS
    <span style="color: #008000">/// &lt;summary&gt;</span>
    <span style="color: #008000">/// Converts from hours, minues, seconds to a double.</span>
    <span style="color: #008000">/// &lt;/summary&gt;</span>
    <span style="color: #008000">/// &lt;param name=&quot;hours&quot;&gt;The hours.&lt;/param&gt;</span>
    <span style="color: #008000">/// &lt;param name=&quot;minutes&quot;&gt;The minutes.&lt;/param&gt;</span>
    <span style="color: #008000">/// &lt;param name=&quot;seconds&quot;&gt;The seconds.&lt;/param&gt;</span>
    <span style="color: #008000">/// &lt;returns&gt;&lt;/returns&gt;</span>
    <span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">double</span> ConvertHMSToDouble(
        <span style="color: #0000ff">int</span> hours,
        <span style="color: #0000ff">int</span> minutes,
        <span style="color: #0000ff">int</span> seconds)
    {
        <span style="color: #0000ff">return</span> ((<span style="color: #0000ff">double</span>)hours % 360) * 15 + ((<span style="color: #0000ff">double</span>)minutes / 60) * 15 + ((<span style="color: #0000ff">double</span>)seconds / 3600) * 15;
    }

    <span style="color: #008000">/// &lt;summary&gt;</span>
    <span style="color: #008000">/// Converts from hours, minues, seconds to a string.</span>
    <span style="color: #008000">/// &lt;/summary&gt;</span>
    <span style="color: #008000">/// &lt;param name=&quot;hours&quot;&gt;The hours.&lt;/param&gt;</span>
    <span style="color: #008000">/// &lt;param name=&quot;minutes&quot;&gt;The minutes.&lt;/param&gt;</span>
    <span style="color: #008000">/// &lt;param name=&quot;seconds&quot;&gt;The seconds.&lt;/param&gt;</span>
    <span style="color: #008000">/// &lt;returns&gt;&lt;/returns&gt;</span>
    <span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">string</span> ConvertHMSToString(
        <span style="color: #0000ff">int</span> hours,
        <span style="color: #0000ff">int</span> minutes,
        <span style="color: #0000ff">int</span> seconds)
    {
        <span style="color: #0000ff">return</span> String.Format(
            <span style="color: #006080">&quot;{0}h {1}m {2}s&quot;</span>,
            hours.ToString(),
            minutes.ToString(),
            seconds.ToString());
    }

    <span style="color: #008000">/// &lt;summary&gt;</span>
    <span style="color: #008000">/// Converts from a double to hours, minues, seconds.</span>
    <span style="color: #008000">/// &lt;/summary&gt;</span>
    <span style="color: #008000">/// &lt;param name=&quot;value&quot;&gt;The value to convert.&lt;/param&gt;</span>
    <span style="color: #008000">/// &lt;param name=&quot;hours&quot;&gt;The hours.&lt;/param&gt;</span>
    <span style="color: #008000">/// &lt;param name=&quot;minutes&quot;&gt;The minutes.&lt;/param&gt;</span>
    <span style="color: #008000">/// &lt;param name=&quot;seconds&quot;&gt;The seconds.&lt;/param&gt;</span>
    <span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">void</span> ConvertDoubleToHMS(
        <span style="color: #0000ff">double</span> <span style="color: #0000ff">value</span>,
        <span style="color: #0000ff">out</span> <span style="color: #0000ff">int</span> hours,
        <span style="color: #0000ff">out</span> <span style="color: #0000ff">int</span> minutes,
        <span style="color: #0000ff">out</span> <span style="color: #0000ff">int</span> seconds)
    {
        <span style="color: #0000ff">double</span> totalseconds = <span style="color: #0000ff">value</span> / 15 * 3600;

        hours = (<span style="color: #0000ff">int</span>)Math.Truncate(totalseconds / 3600);
        minutes = (<span style="color: #0000ff">int</span>)Math.Truncate((totalseconds - hours * 3600) / 60);
        seconds = (<span style="color: #0000ff">int</span>)Math.Truncate(totalseconds - (hours * 3600) - (minutes * 60));
    }
    <span style="color: #cc6633">#endregion</span> HMS
}</pre>
</div>
<div>&#160;</div>
<p>So a conversion from Latitude or Longitude to a double would look something like this:</p>
<div>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff">double</span> latitude = GISUtilities.ConvertSexagesimalToDouble(100, 34, 20);</pre>
</div>
<div>&#160;</div>
<div>There are also methods in this library to convert between hours/minutes/seconds as well as the degree/minutes/seconds primarily used in geo-spatial calculations.</div>
<div>&#160;</div>
<p><a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fwww.danrigsby.com%2fblog%2findex.php%2f2008%2f04%2f30%2fsexagesimal-conversions-in-net%2f"><img border="0" alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.danrigsby.com%2fblog%2findex.php%2f2008%2f04%2f30%2fsexagesimal-conversions-in-net%2f&amp;bgcolor=FF9900" /></a> </p>
<div>&#160;</div>
]]></content:encoded>
			<wfw:commentRss>http://www.danrigsby.com/blog/index.php/2008/04/30/sexagesimal-conversions-in-net/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>How to grayout an image in .Net</title>
		<link>http://www.danrigsby.com/blog/index.php/2008/03/28/how-to-grayout-an-image-in-net/</link>
		<comments>http://www.danrigsby.com/blog/index.php/2008/03/28/how-to-grayout-an-image-in-net/#comments</comments>
		<pubDate>Sat, 29 Mar 2008 03:49:44 +0000</pubDate>
		<dc:creator>Dan Rigsby</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Common Libraries]]></category>

		<guid isPermaLink="false">http://www.danrigsby.com/blog/index.php/2008/03/28/how-to-grayout-an-image-in-net/</guid>
		<description><![CDATA[Here is a handy method for making a grayscale version of an image.&#160; I use this method a lot to grayout icons that I wish to show as disabled.&#160; All you need to do is pass in the image and it will apply a grayscale over it.&#160; The key to getting all of this to [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a handy method for making a grayscale version of an image.&nbsp; I use this method a lot to grayout icons that I wish to show as disabled.&nbsp; All you need to do is pass in the image and it will apply a grayscale over it.&nbsp; The key to getting all of this to work is the <a href="http://msdn2.microsoft.com/en-us/library/system.drawing.imaging.colormatrix.aspx">ColorMatrix</a>.&nbsp; There is a detailed article about how this works on codeproject: <a title="http://www.codeproject.com/KB/GDI-plus/colormatrix.aspx" href="http://www.codeproject.com/KB/GDI-plus/colormatrix.aspx">http://www.codeproject.com/KB/GDI-plus/colormatrix.aspx</a>.</p>
<div>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">void</span> ApplyGrayscale(
    <span style="color: #0000ff">ref</span> Image image)
{
    <span style="color: #008000">// Build color matrix set at 1/3</span>
    ColorMatrix matrix = <span style="color: #0000ff">new</span> ColorMatrix();
    matrix[0, 0] = 1/3f;
    matrix[0, 1] = 1/3f;
    matrix[0, 2] = 1/3f;
    matrix[1, 0] = 1/3f;
    matrix[1, 1] = 1/3f;
    matrix[1, 2] = 1/3f;
    matrix[2, 0] = 1/3f;
    matrix[2, 1] = 1/3f;
    matrix[2, 2] = 1/3f;

    <span style="color: #008000">// Create image attributes that will applied to the image</span>
    ImageAttributes attributes = <span style="color: #0000ff">new</span> ImageAttributes();
    attributes.SetColorMatrix(matrix);

    Graphics g = <span style="color: #0000ff">null</span>;
    <span style="color: #0000ff">try</span>
    {
        <span style="color: #008000">// Get the graphics object from the image</span>
        g = Graphics.FromImage(image);

        <span style="color: #008000">// Redraw the image on the graphics object using the grayscale color matrix</span>
        g.DrawImage(image,
            <span style="color: #0000ff">new</span> Rectangle(0, 0, image.Width, image.Height),
            0,
            0,
            image.Width,
            image.Height,
            GraphicsUnit.Pixel,
            attributes);
    }
    <span style="color: #0000ff">finally</span>
    {
        <span style="color: #0000ff">if</span> (g != <span style="color: #0000ff">null</span>)
        {
            g.Dispose();
        }
    }
}</pre>
</div>
<p>&nbsp;</p>
<p>Here are some sample before and after images (of my daughter Claire):</p>
<table cellspacing="0" cellpadding="2" width="400" border="0">
<tbody>
<tr>
<td valign="top" width="200"><a href="http://www.danrigsby.com/blog/wp-content/uploads/2008/03/claire.jpg"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="182" alt="claire" src="http://www.danrigsby.com/blog/wp-content/uploads/2008/03/claire-thumb.jpg" width="243" border="0"></a> </td>
<td valign="top" width="200"><a href="http://www.danrigsby.com/blog/wp-content/uploads/2008/03/clairegray.jpg"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="182" alt="clairegray" src="http://www.danrigsby.com/blog/wp-content/uploads/2008/03/clairegray-thumb.jpg" width="243" border="0"></a> </td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p>Here is another example with a more typical line-of-business image:</p>
<table cellspacing="0" cellpadding="2" width="538" border="0">
<tbody>
<tr>
<td valign="top" width="268"><a href="http://www.danrigsby.com/blog/wp-content/uploads/2008/03/disk-blue.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="48" alt="disk_blue" src="http://www.danrigsby.com/blog/wp-content/uploads/2008/03/disk-blue-thumb.png" width="48" border="0"></a> </td>
<td valign="top" width="268"><a href="http://www.danrigsby.com/blog/wp-content/uploads/2008/03/disk-bluegray.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="48" alt="disk_bluegray" src="http://www.danrigsby.com/blog/wp-content/uploads/2008/03/disk-bluegray-thumb.png" width="48" border="0"></a> </td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p>To make this easier to try out or use, I have wrapped the method into a executable as well.&nbsp; You can download the source for this here: <a href="http://www.danrigsby.com/Files/Rigsby.ImageUtilities.Grayscale.zip">http://www.danrigsby.com/Files/Rigsby.ImageUtilities.Grayscale.zip</a></p>
<p>To run the program, compile the code and execute the exe file while passing in the source file name and the file name you want to save the new grayscaled image to, like this:</p>
<div>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">Rigsby.ImageUtilities.Grayscale.exe "c:\Claire.jpg" "c:\Claire-Gray.jpg"</pre>
</div>
<div>&nbsp;</div>
]]></content:encoded>
			<wfw:commentRss>http://www.danrigsby.com/blog/index.php/2008/03/28/how-to-grayout-an-image-in-net/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Disposable Base Class</title>
		<link>http://www.danrigsby.com/blog/index.php/2008/03/15/disposable-base-class/</link>
		<comments>http://www.danrigsby.com/blog/index.php/2008/03/15/disposable-base-class/#comments</comments>
		<pubDate>Sat, 15 Mar 2008 17:24:27 +0000</pubDate>
		<dc:creator>Dan Rigsby</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Common Libraries]]></category>

		<guid isPermaLink="false">http://www.danrigsby.com/blog/index.php/2008/03/15/disposable-base-class/</guid>
		<description><![CDATA[Many classes are built that implement System.IDisposable, which is a good thing.&#160; This pattern makes for a good design to clean up your objects and can be used by the using statement to easily dispose of your objects.&#160; This article already assumes that you know the basics of the Dispose Pattern. However sometimes having just [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.danrigsby.com/blog/wp-content/uploads/2008/03/trashcan.jpg"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" border="0" alt="trashcan" align="right" src="http://www.danrigsby.com/blog/wp-content/uploads/2008/03/trashcan-thumb.jpg" width="74" height="100" /></a>Many classes are built that implement <a href="http://msdn2.microsoft.com/en-us/library/system.idisposable.aspx">System.IDisposable</a>, which is a good thing.&#160; This pattern makes for a good design to clean up your objects and can be used by the <a href="http://msdn2.microsoft.com/en-us/library/yh598w02.aspx">using statement</a> to easily dispose of your objects.&#160; This article already assumes that you know the basics of the <a href="http://haacked.com/archive/2005/11/18/ACloserLookAtDisposePattern.aspx">Dispose Pattern</a>. However sometimes having just a Dispose() method isn&#8217;t always enough.&#160; Many times you a combination of a Disposed event, a void Dispose(bool disposing) method for use by a deconstructor, a boolean flag to check if the object IsDisposed, and maybe a method to check if the object is disposed that can throw an exception.&#160; Some &quot;best practices&quot; often dictate that you should be using some of these additional things.&#160; You may be writing this logic over and over again for each class, or you might start with a basic IDisposable pattern and weeks later you decide to refactor it to add in something like the boolean flag for IsDisposed.</p>
<p>After facing these same issues for awhile, I decided to put together a simple Diposable base class with all of the recommended patterns for using Disposable.&#160; Of course, this can&#8217;t always be used since you might already have a base class.&#160; But many times a class will derive from IDisposable and nothing else.&#160; This is just screaming for a Disposable base class that encapsulates this logic!&#160; For classes that already have a base class, I also have a code snippet to include everything that&#8217;s in the base class.</p>
<p>Here are the features of the Disposable Base Class and Code Snippet:</p>
<ol>
<li><strong>void Dispose() Method</strong> &#8211; This is just the standard Dispose method that is defined in the IDisposable interface. </li>
<li><strong>void Dispose(bool disposing) Method</strong> &#8211; This method is called from the Dispose() method passing in true.&#160; Its called from the deconstructor using false.&#160; This is the method that you should override in your parent class and check if disposing is true before disposing of managed code.&#160; The reason for this is that the deconstructor would have already disposed of the managed code, so you shouldn&#8217;t try to do it again.&#160; If the deconstrutor called this method, you should only dispose of unmanaged code. </li>
<li><strong>void CheckDisposed() Method</strong> &#8211; This method is marked protected and is used by the parent class to check if the object is disposed.&#160; It will throw an <a href="http://msdn2.microsoft.com/en-us/library/system.objectdisposedexception.aspx">ObjectDisposedException</a> if necessary. </li>
<li><strong>bool IsDisposed Property</strong> &#8211; A simple property to check whether or not this object has been disposed yet. </li>
<li><strong>Disposed Event</strong> &#8211; This event is fired when the object has been disposed. </li>
</ol>
<p>To use the base class, you just override the Dispose(bool disposing) method. An example of this base class in use could look like this:</p>
<div>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> MyClass : Disposable
{
    <span style="color: #0000ff">protected</span> <span style="color: #0000ff">override</span> <span style="color: #0000ff">void</span> Dispose(<span style="color: #0000ff">bool</span> disposing)
    {
        <span style="color: #0000ff">if</span> (disposing)
        {
            <span style="color: #008000">// Dispose any managed code here</span>
        }

        <span style="color: #008000">// Dispose any unmanaged code here</span>

        <span style="color: #0000ff">base</span>.Dispose(disposing);
    }
}</pre>
</div>
<p>&#160;</p>
<p>Here is the base class:</p>
<div style="border-right: gray 1px solid; padding-right: 4px; padding-left: 4px; font-size: 8pt; border-top: gray 1px solid; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff">using</span> System;
<span style="color: #0000ff">using</span> System.ComponentModel;

<span style="color: #0000ff">namespace</span> Rigsby
{
    <span style="color: #008000">/// &lt;summary&gt;</span>
    <span style="color: #008000">/// Represents a basic disposable class.</span>
    <span style="color: #008000">/// &lt;/summary&gt;</span>
    <span style="color: #0000ff">public</span> <span style="color: #0000ff">abstract</span> <span style="color: #0000ff">class</span> Disposable : IDisposable
    {
        <span style="color: #cc6633">#region</span> Private Properties
        <span style="color: #0000ff">private</span> <span style="color: #0000ff">bool</span> m_IsDisposed = <span style="color: #0000ff">false</span>;
        <span style="color: #cc6633">#endregion</span> Private Properties

        <span style="color: #cc6633">#region</span> Public Properties
        <span style="color: #008000">/// &lt;summary&gt;</span>
        <span style="color: #008000">/// Gets a value indicating whether this instance is disposed.</span>
        <span style="color: #008000">/// &lt;/summary&gt;</span>
        <span style="color: #008000">/// &lt;value&gt;</span>
        <span style="color: #008000">///     &lt;c&gt;true&lt;/c&gt; if this instance is disposed; otherwise, &lt;c&gt;false&lt;/c&gt;.</span>
        <span style="color: #008000">/// &lt;/value&gt;</span>
        [Browsable(<span style="color: #0000ff">false</span>)]
        <span style="color: #0000ff">public</span> <span style="color: #0000ff">bool</span> IsDisposed
        {
            get
            {
                <span style="color: #0000ff">return</span> m_IsDisposed;
            }
        }
        <span style="color: #cc6633">#endregion</span> Public Properties

        <span style="color: #cc6633">#region</span> Constructors
        <span style="color: #008000">/// &lt;summary&gt;</span>
        <span style="color: #008000">/// Initializes a new instance of the &lt;see cref=&quot;Disposable&quot;/&gt; class.</span>
        <span style="color: #008000">/// &lt;/summary&gt;</span>
        <span style="color: #0000ff">public</span> Disposable()
        {
        }

        <span style="color: #008000">/// &lt;summary&gt;</span>
        <span style="color: #008000">/// Releases unmanaged resources and performs other cleanup operations before the</span>
        <span style="color: #008000">/// &lt;see cref=&quot;Disposable&quot;/&gt; is reclaimed by garbage collection.</span>
        <span style="color: #008000">/// &lt;/summary&gt;</span>
        ~Disposable()
        {
            Dispose(<span style="color: #0000ff">false</span>);
        }
        <span style="color: #cc6633">#endregion</span> Constructors

        <span style="color: #cc6633">#region</span> IDisposable Members
        <span style="color: #0000ff">private</span> <span style="color: #0000ff">event</span> System.EventHandler m_Disposed;

        <span style="color: #008000">/// &lt;summary&gt;</span>
        <span style="color: #008000">/// Occurs when this instance is disposed.</span>
        <span style="color: #008000">/// &lt;/summary&gt;</span>
        <span style="color: #0000ff">public</span> <span style="color: #0000ff">event</span> System.EventHandler Disposed
        {
            add
            {
                m_Disposed += <span style="color: #0000ff">value</span>;
            }
            remove
            {
                m_Disposed -= <span style="color: #0000ff">value</span>;
            }
        }

        <span style="color: #008000">/// &lt;summary&gt;</span>
        <span style="color: #008000">/// Releases unmanaged and - optionally - managed resources</span>
        <span style="color: #008000">/// &lt;/summary&gt;</span>
        <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> Dispose()
        {
            <span style="color: #0000ff">if</span> (!m_IsDisposed)
            {
                <span style="color: #0000ff">this</span>.Dispose(<span style="color: #0000ff">true</span>);
                GC.SuppressFinalize(<span style="color: #0000ff">this</span>);
            }
        }

        <span style="color: #008000">/// &lt;summary&gt;</span>
        <span style="color: #008000">/// Releases unmanaged and - optionally - managed resources</span>
        <span style="color: #008000">/// &lt;/summary&gt;</span>
        <span style="color: #008000">/// &lt;param name=&quot;disposing&quot;&gt;&lt;c&gt;true&lt;/c&gt; to release both managed and unmanaged resources; &lt;c&gt;false&lt;/c&gt; to release only unmanaged resources.&lt;/param&gt;</span>
        <span style="color: #0000ff">protected</span> <span style="color: #0000ff">virtual</span> <span style="color: #0000ff">void</span> Dispose(<span style="color: #0000ff">bool</span> disposing)
        {
            <span style="color: #0000ff">try</span>
            {
                <span style="color: #0000ff">if</span> (disposing)
                {
                    EventHandler handler = m_Disposed;
                    <span style="color: #0000ff">if</span> (handler != <span style="color: #0000ff">null</span>)
                    {
                        handler(<span style="color: #0000ff">this</span>, EventArgs.Empty);
                        handler = <span style="color: #0000ff">null</span>;
                    }
                }
            }
            <span style="color: #0000ff">finally</span>
            {
                m_IsDisposed = <span style="color: #0000ff">true</span>;
            }
        }
        <span style="color: #cc6633">#endregion</span> IDisposable Members

        <span style="color: #008000">/// &lt;summary&gt;</span>
        <span style="color: #008000">///    &lt;para&gt;</span>
        <span style="color: #008000">///        Checks if the instance has been disposed of, and if it has, throws an &lt;see cref=&quot;ObjectDisposedException&quot;/&gt;; otherwise, does nothing.</span>
        <span style="color: #008000">///    &lt;/para&gt;</span>
        <span style="color: #008000">/// &lt;/summary&gt;</span>
        <span style="color: #008000">/// &lt;exception cref=&quot;ObjectDisposedException&quot;&gt;</span>
        <span style="color: #008000">///    The instance has been disposed of.</span>
        <span style="color: #008000">///    &lt;/exception&gt;</span>
        <span style="color: #008000">///    &lt;remarks&gt;</span>
        <span style="color: #008000">///    &lt;para&gt;</span>
        <span style="color: #008000">///        Derived classes should call this method at the start of all methods and properties that should not be accessed after a call to &lt;see cref=&quot;Dispose()&quot;/&gt;.</span>
        <span style="color: #008000">///    &lt;/para&gt;</span>
        <span style="color: #008000">/// &lt;/remarks&gt;</span>
        <span style="color: #0000ff">protected</span> <span style="color: #0000ff">void</span> CheckDisposed()
        {
            <span style="color: #0000ff">if</span> (m_IsDisposed)
            {
                <span style="color: #0000ff">string</span> typeName = GetType().FullName;

                <span style="color: #008000">// TODO: You might want to move the message string into a resource file</span>
                <span style="color: #0000ff">throw</span> <span style="color: #0000ff">new</span> ObjectDisposedException(
                    typeName,
                    String.Format(System.Globalization.CultureInfo.InvariantCulture,
                        <span style="color: #006080">&quot;Cannot access a disposed {0}.&quot;</span>,
                        typeName));
            }
        }
    }
}</pre>
</div>
<p>Here is the code snippet version, or <a href="http://www.danrigsby.com/files/IDisposable.zip">download it here</a>.&#160; If you use the snippet, you will want to manually change your class to derive from the IDisposable interface, then add this snippet.</p>
<div style="border-right: gray 1px solid; padding-right: 4px; padding-left: 4px; font-size: 8pt; border-top: gray 1px solid; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff">&lt;?</span><span style="color: #800000">xml</span> <span style="color: #ff0000">version</span><span style="color: #0000ff">=&quot;1.0&quot;</span> <span style="color: #ff0000">encoding</span><span style="color: #0000ff">=&quot;utf-8&quot;</span>?<span style="color: #0000ff">&gt;</span> <span style="color: #0000ff">&lt;</span><span style="color: #800000">CodeSnippets</span> <span style="color: #ff0000">xmlns</span><span style="color: #0000ff">=&quot;http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet&quot;</span><span style="color: #0000ff">&gt;</span>   <span style="color: #0000ff">&lt;</span><span style="color: #800000">CodeSnippet</span> <span style="color: #ff0000">Format</span><span style="color: #0000ff">=&quot;1.0.0&quot;</span><span style="color: #0000ff">&gt;</span>     <span style="color: #0000ff">&lt;</span><span style="color: #800000">Header</span><span style="color: #0000ff">&gt;</span>       <span style="color: #0000ff">&lt;</span><span style="color: #800000">Title</span><span style="color: #0000ff">&gt;</span>IDisposable<span style="color: #0000ff">&lt;/</span><span style="color: #800000">Title</span><span style="color: #0000ff">&gt;</span>       <span style="color: #0000ff">&lt;</span><span style="color: #800000">Shortcut</span><span style="color: #0000ff">&gt;</span>       <span style="color: #0000ff">&lt;/</span><span style="color: #800000">Shortcut</span><span style="color: #0000ff">&gt;</span>       <span style="color: #0000ff">&lt;</span><span style="color: #800000">Description</span><span style="color: #0000ff">&gt;</span>Implements the IDisposable interface with additional best practices.<span style="color: #0000ff">&lt;/</span><span style="color: #800000">Description</span><span style="color: #0000ff">&gt;</span>       <span style="color: #0000ff">&lt;</span><span style="color: #800000">Author</span><span style="color: #0000ff">&gt;</span>Dan Rigsby<span style="color: #0000ff">&lt;/</span><span style="color: #800000">Author</span><span style="color: #0000ff">&gt;</span>     <span style="color: #0000ff">&lt;/</span><span style="color: #800000">Header</span><span style="color: #0000ff">&gt;</span>     <span style="color: #0000ff">&lt;</span><span style="color: #800000">Snippet</span><span style="color: #0000ff">&gt;</span>       <span style="color: #0000ff">&lt;</span><span style="color: #800000">Code</span> <span style="color: #ff0000">Language</span><span style="color: #0000ff">=&quot;csharp&quot;</span><span style="color: #0000ff">&gt;&lt;!</span>[CDATA[        #region IDisposable Members
        private bool m_IsDisposed = false;
        private event System.EventHandler m_Disposed;

        /// <span style="color: #0000ff">&lt;</span><span style="color: #800000">summary</span><span style="color: #0000ff">&gt;</span>
        /// Gets a value indicating whether this instance is disposed.
        /// <span style="color: #0000ff">&lt;/</span><span style="color: #800000">summary</span><span style="color: #0000ff">&gt;</span>
        /// <span style="color: #0000ff">&lt;</span><span style="color: #800000">value</span><span style="color: #0000ff">&gt;</span>
        ///     <span style="color: #0000ff">&lt;</span><span style="color: #800000">c</span><span style="color: #0000ff">&gt;</span>true<span style="color: #0000ff">&lt;/</span><span style="color: #800000">c</span><span style="color: #0000ff">&gt;</span> if this instance is disposed; otherwise, <span style="color: #0000ff">&lt;</span><span style="color: #800000">c</span><span style="color: #0000ff">&gt;</span>false<span style="color: #0000ff">&lt;/</span><span style="color: #800000">c</span><span style="color: #0000ff">&gt;</span>.
        /// <span style="color: #0000ff">&lt;/</span><span style="color: #800000">value</span><span style="color: #0000ff">&gt;</span>
        [System.ComponentModel.Browsable(false)]
        public bool IsDisposed
        {
            get
            {
                return m_IsDisposed;
            }
        }

        /// <span style="color: #0000ff">&lt;</span><span style="color: #800000">summary</span><span style="color: #0000ff">&gt;</span>
        /// Occurs when this instance is disposed.
        /// <span style="color: #0000ff">&lt;/</span><span style="color: #800000">summary</span><span style="color: #0000ff">&gt;</span>
        public event System.EventHandler Disposed
        {
            add
            {
                m_Disposed += value;
            }
            remove
            {
                m_Disposed -= value;
            }
        }

        /// <span style="color: #0000ff">&lt;</span><span style="color: #800000">summary</span><span style="color: #0000ff">&gt;</span>
        /// Releases unmanaged and - optionally - managed resources
        /// <span style="color: #0000ff">&lt;/</span><span style="color: #800000">summary</span><span style="color: #0000ff">&gt;</span>
        public void Dispose()
        {
            if (!m_IsDisposed)
            {
                this.Dispose(true);
                System.GC.SuppressFinalize(this);
            }
        }

        /// <span style="color: #0000ff">&lt;</span><span style="color: #800000">summary</span><span style="color: #0000ff">&gt;</span>
        /// Releases unmanaged and - optionally - managed resources
        /// <span style="color: #0000ff">&lt;/</span><span style="color: #800000">summary</span><span style="color: #0000ff">&gt;</span>
        /// <span style="color: #0000ff">&lt;</span><span style="color: #800000">param</span> <span style="color: #ff0000">name</span><span style="color: #0000ff">=&quot;disposing&quot;</span><span style="color: #0000ff">&gt;&lt;</span><span style="color: #800000">c</span><span style="color: #0000ff">&gt;</span>true<span style="color: #0000ff">&lt;/</span><span style="color: #800000">c</span><span style="color: #0000ff">&gt;</span> to release both managed and unmanaged resources; <span style="color: #0000ff">&lt;</span><span style="color: #800000">c</span><span style="color: #0000ff">&gt;</span>false<span style="color: #0000ff">&lt;/</span><span style="color: #800000">c</span><span style="color: #0000ff">&gt;</span> to release only unmanaged resources.<span style="color: #0000ff">&lt;/</span><span style="color: #800000">param</span><span style="color: #0000ff">&gt;</span>
        protected virtual void Dispose(bool disposing)
        {
            try
            {
                if (disposing)
                {
                    System.EventHandler handler = m_Disposed;
                    if (handler != null)
                    {
                        handler(this, System.EventArgs.Empty);
                        handler = null;
                    }
                }
            }
            finally
            {
                m_IsDisposed = true;
            }
        }

        /// <span style="color: #0000ff">&lt;</span><span style="color: #800000">summary</span><span style="color: #0000ff">&gt;</span>
        ///    <span style="color: #0000ff">&lt;</span><span style="color: #800000">para</span><span style="color: #0000ff">&gt;</span>
        ///        Checks if the instance has been disposed of, and if it has, throws an <span style="color: #0000ff">&lt;</span><span style="color: #800000">see</span> <span style="color: #ff0000">cref</span><span style="color: #0000ff">=&quot;ObjectDisposedException&quot;</span><span style="color: #0000ff">/&gt;</span>; otherwise, does nothing.
        ///    <span style="color: #0000ff">&lt;/</span><span style="color: #800000">para</span><span style="color: #0000ff">&gt;</span>
        /// <span style="color: #0000ff">&lt;/</span><span style="color: #800000">summary</span><span style="color: #0000ff">&gt;</span>
        /// <span style="color: #0000ff">&lt;</span><span style="color: #800000">exception</span> <span style="color: #ff0000">cref</span><span style="color: #0000ff">=&quot;System.ObjectDisposedException&quot;</span><span style="color: #0000ff">&gt;</span>
        ///    The instance has been disposed of.
        ///    <span style="color: #0000ff">&lt;/</span><span style="color: #800000">exception</span><span style="color: #0000ff">&gt;</span>
        ///    <span style="color: #0000ff">&lt;</span><span style="color: #800000">remarks</span><span style="color: #0000ff">&gt;</span>
        ///    <span style="color: #0000ff">&lt;</span><span style="color: #800000">para</span><span style="color: #0000ff">&gt;</span>
        ///        Derived classes should call this method at the start of all methods and properties that should not be accessed after a call to <span style="color: #0000ff">&lt;</span><span style="color: #800000">see</span> <span style="color: #ff0000">cref</span><span style="color: #0000ff">=&quot;Dispose()&quot;</span><span style="color: #0000ff">/&gt;</span>.
        ///    <span style="color: #0000ff">&lt;/</span><span style="color: #800000">para</span><span style="color: #0000ff">&gt;</span>
        /// <span style="color: #0000ff">&lt;/</span><span style="color: #800000">remarks</span><span style="color: #0000ff">&gt;</span>
        protected void CheckDisposed()
        {
            if (m_IsDisposed)
            {
                string typeName = GetType().FullName;

                // TODO: You might want to move the message string into a resource file
                throw new System.ObjectDisposedException(
                    typeName,
                    String.Format(System.Globalization.CultureInfo.InvariantCulture,
                        &quot;Cannot access a disposed {0}.&quot;,
                        typeName));
            }
        }
        #endregion IDisposable Members]]<span style="color: #0000ff">&gt;&lt;/</span><span style="color: #800000">Code</span><span style="color: #0000ff">&gt;</span>     <span style="color: #0000ff">&lt;/</span><span style="color: #800000">Snippet</span><span style="color: #0000ff">&gt;</span>   <span style="color: #0000ff">&lt;/</span><span style="color: #800000">CodeSnippet</span><span style="color: #0000ff">&gt;</span> <span style="color: #0000ff">&lt;/</span><span style="color: #800000">CodeSnippets</span><span style="color: #0000ff">&gt;</span></pre>
</div>
<p><a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fwww.danrigsby.com%2fblog%2findex.php%2f2008%2f03%2f15%2fdisposable-base-class%2f"><img border="0" alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.danrigsby.com%2fblog%2findex.php%2f2008%2f03%2f15%2fdisposable-base-class%2f&amp;bgcolor=FF9900" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.danrigsby.com/blog/index.php/2008/03/15/disposable-base-class/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

