<?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:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Please stop, you're hurting my brains!</title>
	<atom:link href="http://hurtsmybrains.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://hurtsmybrains.wordpress.com</link>
	<description>The Adventures of a Pragmatic Misanthropist</description>
	<pubDate>Mon, 17 Mar 2008 15:25:28 +0000</pubDate>
	<generator>http://wordpress.org/?v=MU</generator>
	<language>en</language>
			<item>
		<title>handling unhandled asp.net exceptions</title>
		<link>http://hurtsmybrains.wordpress.com/2008/03/17/handling-unhandled-aspnet-exceptions/</link>
		<comments>http://hurtsmybrains.wordpress.com/2008/03/17/handling-unhandled-aspnet-exceptions/#comments</comments>
		<pubDate>Mon, 17 Mar 2008 15:25:28 +0000</pubDate>
		<dc:creator>abusement</dc:creator>
		
		<category><![CDATA[.NET Programming]]></category>

		<category><![CDATA[Debugging]]></category>

		<category><![CDATA[Software Design]]></category>

		<category><![CDATA[asp.net]]></category>

		<category><![CDATA[debugging asp.net exceptions]]></category>

		<category><![CDATA[design for extensibility]]></category>

		<category><![CDATA[provider model]]></category>

		<category><![CDATA[unhandled exception]]></category>

		<guid isPermaLink="false">http://hurtsmybrains.wordpress.com/?p=25</guid>
		<description><![CDATA[At some point in their career everyone who creates ASP.NET applications has had issues with their site throwing exceptions that aren&#8217;t trapped.  We end up displaying a friendly error page at best, and at worst display the yellow ASP.NET error screen of death.  Generally speaking it&#8217;s best practice to configure your ASP.NET application to use [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>At some point in their career everyone who creates ASP.NET applications has had issues with their site throwing exceptions that aren&#8217;t trapped.  We end up displaying a friendly error page at best, and at worst display the yellow ASP.NET error screen of death.  Generally speaking it&#8217;s best practice to configure your ASP.NET application to use friendly error pages so that your users aren&#8217;t presented with an exception and stack trace that are meaningless to them.</p>
<p>But how do you find out what exceptions are being thrown by users who are not you?  Over the years I&#8217;ve created many versions of the same type of code to handle these situations, so last night I created a project on codeplex that I&#8217;m calling <a target="_blank" href="http://www.codeplex.com/sigh" title="Sigh.net">sigh.net</a>.  Essentially, <a target="_blank" href="http://www.codeplex.com/sigh" title="Sigh.net">sigh.net</a> is a provider based unhandled exception handler for ASP.NET applications.  You can download the source at <a href="http://www.codeplex.com/sigh">http://www.codeplex.com/sigh</a>.</p>
<p>It&#8217;s extremely simple to use and doesn&#8217;t require you to change or add any code to your application.  I currently have an email provider created and am in the process of creating a SQL database provider.</p>
<p>Enjoy!</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/hurtsmybrains.wordpress.com/25/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/hurtsmybrains.wordpress.com/25/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/hurtsmybrains.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/hurtsmybrains.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/hurtsmybrains.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/hurtsmybrains.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/hurtsmybrains.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/hurtsmybrains.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/hurtsmybrains.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/hurtsmybrains.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/hurtsmybrains.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/hurtsmybrains.wordpress.com/25/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hurtsmybrains.wordpress.com&blog=2425424&post=25&subd=hurtsmybrains&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://hurtsmybrains.wordpress.com/2008/03/17/handling-unhandled-aspnet-exceptions/feed/</wfw:commentRss>
		</item>
		<item>
		<title>creating streaming tutorials with silverlight</title>
		<link>http://hurtsmybrains.wordpress.com/2008/03/05/creating-streaming-tutorials-with-silverlight/</link>
		<comments>http://hurtsmybrains.wordpress.com/2008/03/05/creating-streaming-tutorials-with-silverlight/#comments</comments>
		<pubDate>Wed, 05 Mar 2008 19:41:21 +0000</pubDate>
		<dc:creator>abusement</dc:creator>
		
		<category><![CDATA[Silverlight]]></category>

		<category><![CDATA[code project]]></category>

		<category><![CDATA[microsoft]]></category>

		<category><![CDATA[screen capture]]></category>

		<category><![CDATA[streaming video]]></category>

		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://hurtsmybrains.wordpress.com/?p=24</guid>
		<description><![CDATA[I&#8217;ve wanted to work with Silverlight for some time now, though I&#8217;ve not had a use for the technology until recently.  I wanted to create tutorial videos for .netSavant to help people learn a bit about the product.  After a bit of searching I found a fantastic code project article written by Karl Shifflett that walks [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I&#8217;ve wanted to work with Silverlight for some time now, though I&#8217;ve not had a use for the technology until recently.  I wanted to create tutorial videos for <a target="_blank" href="http://www.dotnetsavant.com" title=".netSavant - supreme code generation">.netSavant</a> to help people learn a bit about the product.  After a bit of searching I found a fantastic <a target="_blank" href="http://www.codeproject.com/KB/scrapbook/HowToCreateArticleVideos.aspx">code project article</a> written by Karl Shifflett that walks you through the entire process of not only creating a high quality screen capture tutorial, but publishing it as a streaming silverlight video.</p>
<p><a target="_blank" href="http://www.codeproject.com/KB/scrapbook/HowToCreateArticleVideos.aspx">Click Here to read the article</a></p>
<p>To date I&#8217;ve only created and published a single tutorial for <a target="_blank" href="http://www.dotnetsavant.com" title=".netSavant - supreme code generation">.netSavant</a>.  I&#8217;ve several more planned that will hopefully be a bit more polished as I become more comfortable talking, effectively, to no one.</p>
<p><a target="_blank" href="http://www.dotnetsavant.com/Overview/Tutorials.aspx">http://www.dotnetsavant.com/Overview/Tutorials.aspx</a></p>
<p>Enjoy!</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/hurtsmybrains.wordpress.com/24/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/hurtsmybrains.wordpress.com/24/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/hurtsmybrains.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/hurtsmybrains.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/hurtsmybrains.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/hurtsmybrains.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/hurtsmybrains.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/hurtsmybrains.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/hurtsmybrains.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/hurtsmybrains.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/hurtsmybrains.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/hurtsmybrains.wordpress.com/24/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hurtsmybrains.wordpress.com&blog=2425424&post=24&subd=hurtsmybrains&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://hurtsmybrains.wordpress.com/2008/03/05/creating-streaming-tutorials-with-silverlight/feed/</wfw:commentRss>
		</item>
		<item>
		<title>system.nullable vs. tryparse : revisited</title>
		<link>http://hurtsmybrains.wordpress.com/2008/03/01/systemnullable-vs-tryparse-revisited/</link>
		<comments>http://hurtsmybrains.wordpress.com/2008/03/01/systemnullable-vs-tryparse-revisited/#comments</comments>
		<pubDate>Sat, 01 Mar 2008 16:12:03 +0000</pubDate>
		<dc:creator>abusement</dc:creator>
		
		<category><![CDATA[.NET Programming]]></category>

		<category><![CDATA[.net 2.0]]></category>

		<category><![CDATA[C#]]></category>

		<category><![CDATA[generics]]></category>

		<category><![CDATA[Nullable]]></category>

		<category><![CDATA[tryparse]]></category>

		<guid isPermaLink="false">http://hurtsmybrains.wordpress.com/?p=23</guid>
		<description><![CDATA[As a followup to my system.nullable vs. tryparse entry, I&#8217;ve decided to publish the nullable parser code that I use in the data access system of .netSavant.
Download the C# file (in txt format)
Enjoy!
       ]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>As a followup to my <a target="_blank" href="http://hurtsmybrains.wordpress.com/2008/01/03/systemnullable-vs-tryparse/" title="system.nullable vs. tryparse">system.nullable vs. tryparse</a> entry, I&#8217;ve decided to publish the <a target="_blank" href="http://www.dotnetsavant.com/BlogCode/NullableParser.txt" title="download the nullable parser code">nullable parser</a> code that I use in the data access system of <a target="_blank" href="http://www.dotnetsavant.com" title=".netSavant - supreme code generation">.netSavant</a>.</p>
<p><a target="_blank" href="http://www.dotnetsavant.com/BlogCode/NullableParser.txt" title="download the nullable parser code">Download the C# file</a> (in txt format)</p>
<p>Enjoy!</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/hurtsmybrains.wordpress.com/23/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/hurtsmybrains.wordpress.com/23/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/hurtsmybrains.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/hurtsmybrains.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/hurtsmybrains.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/hurtsmybrains.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/hurtsmybrains.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/hurtsmybrains.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/hurtsmybrains.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/hurtsmybrains.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/hurtsmybrains.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/hurtsmybrains.wordpress.com/23/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hurtsmybrains.wordpress.com&blog=2425424&post=23&subd=hurtsmybrains&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://hurtsmybrains.wordpress.com/2008/03/01/systemnullable-vs-tryparse-revisited/feed/</wfw:commentRss>
		</item>
		<item>
		<title>.netSavant rc1 released!</title>
		<link>http://hurtsmybrains.wordpress.com/2008/02/23/netsavant-rc1-released/</link>
		<comments>http://hurtsmybrains.wordpress.com/2008/02/23/netsavant-rc1-released/#comments</comments>
		<pubDate>Sat, 23 Feb 2008 16:30:22 +0000</pubDate>
		<dc:creator>abusement</dc:creator>
		
		<category><![CDATA[ADO.NET]]></category>

		<category><![CDATA[Software Design]]></category>

		<category><![CDATA[Visual Studio Addin Development]]></category>

		<category><![CDATA[addin development]]></category>

		<category><![CDATA[awesome]]></category>

		<category><![CDATA[code generation]]></category>

		<category><![CDATA[new product release]]></category>

		<category><![CDATA[visual studio .net]]></category>

		<guid isPermaLink="false">http://hurtsmybrains.wordpress.com/?p=22</guid>
		<description><![CDATA[I&#8217;m proud to announce the release of my new code generating addin, .netSavant.  You can download the release candidate on the website from our download page.
The addin will help you create robust ado.net code with an intuitive drag and drop interface.  Additionally it will generate best practice implementations of three (currently) system interfaces:


System.IEquatable&#60;T&#62;


System.IDisposable


System.ICloneable


Currently I am [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I&#8217;m proud to announce the release of my new code generating addin, .netSavant.  You can download the release candidate on the <a target="_blank" href="http://www.dotnetsavant.com" title=".netSavant - supreme code generation">website</a> from our <a target="_blank" href="http://www.dotnetsavant.com/Download/Index.aspx" title=".netSavant - supreme code generation">download page</a>.</p>
<p>The addin will help you create robust ado.net code with an intuitive drag and drop interface.  Additionally it will generate best practice implementations of three (currently) system interfaces:</p>
<ul>
<li>
<div>System.IEquatable&lt;T&gt;</div>
</li>
<li>
<div>System.IDisposable</div>
</li>
<li>
<div>System.ICloneable</div>
</li>
</ul>
<p>Currently I am working on the example code that will help to explain how to best use the ado.net code that is generated.  I&#8217;m also working on more and better F.A.Q. entries to answer those pesky little problems that come along with learning a new tool.</p>
<p>If there is any functionality that you&#8217;d like to see added to the addin <a target="_blank" href="http://www.dotnetsavant.com/Contact.aspx" title=".netSavant - supreme code generation">let me know</a>; I&#8217;ll entertain any reasonable request.</p>
<p>Enjoy!</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/hurtsmybrains.wordpress.com/22/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/hurtsmybrains.wordpress.com/22/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/hurtsmybrains.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/hurtsmybrains.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/hurtsmybrains.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/hurtsmybrains.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/hurtsmybrains.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/hurtsmybrains.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/hurtsmybrains.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/hurtsmybrains.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/hurtsmybrains.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/hurtsmybrains.wordpress.com/22/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hurtsmybrains.wordpress.com&blog=2425424&post=22&subd=hurtsmybrains&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://hurtsmybrains.wordpress.com/2008/02/23/netsavant-rc1-released/feed/</wfw:commentRss>
		</item>
		<item>
		<title>writing an installer class for a visual studio.net addin</title>
		<link>http://hurtsmybrains.wordpress.com/2008/02/22/writing-an-installer-class-for-a-visual-studionet-addin/</link>
		<comments>http://hurtsmybrains.wordpress.com/2008/02/22/writing-an-installer-class-for-a-visual-studionet-addin/#comments</comments>
		<pubDate>Fri, 22 Feb 2008 04:47:31 +0000</pubDate>
		<dc:creator>abusement</dc:creator>
		
		<category><![CDATA[Visual Studio Addin Development]]></category>

		<category><![CDATA[addin]]></category>

		<category><![CDATA[addin installer]]></category>

		<category><![CDATA[custom action]]></category>

		<category><![CDATA[linq to xml]]></category>

		<category><![CDATA[visual studio 2005]]></category>

		<category><![CDATA[visual studio 2008]]></category>

		<guid isPermaLink="false">http://hurtsmybrains.wordpress.com/?p=12</guid>
		<description><![CDATA[You&#8217;ve struggled through understanding commands and toolbars, pulled your hair out deciphering confusing API&#8217;s, and scarred your neighborhood with red-faced screams of frustration as you debug unhandled exceptions that crash visual studio.  After weeks, months or yes even years polishing an addin you still aren&#8217;t finished until you create an installer program.
The installer projects available in visual studio make [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>You&#8217;ve struggled through understanding commands and toolbars, pulled your hair out deciphering confusing API&#8217;s, and scarred your neighborhood with red-faced screams of frustration as you debug unhandled exceptions that crash visual studio.  After weeks, months or yes even years polishing an addin you still aren&#8217;t finished until you create an installer program.</p>
<p>The installer projects available in visual studio make creating an installer a trivial affair; however there are a few things to consider when making an installer for an addin project.</p>
<p><span id="more-12"></span></p>
<p><strong></strong></p>
<h2>The .addin file</h2>
<p>When you create a new addin project in visual studio 2005 or 2008 you will have an xml file in the root directory of your application named YourProjectName.addin.  Opening this file will show you the base structure of the xml that among other things defines the location of your addin assembly.  The trick of installing the addin via an installer project is placing this file in an appropriate location on the user&#8217;s workstation as well as modifying the xml to point to the location where your addin is installed.</p>
<p>Addins for visual studio 2005 and 2008 are installed by placing the .addin file in one of several locations on a developer&#8217;s workstation.  These locations are managed through visual studio under the Tools &gt; Options &gt; Environment &gt; Add-in/Macro Security options page.  Here you will find a list of paths that visual studio will investigate when it loads to locate various addins that you may have installed.</p>
<p>I caution you on modifying this list; most addins that are written will be installed in one of the default paths specified by here.  If you change these default paths you could easily lose access to any addins that you already have installed.</p>
<h2>Where to put your .addin file</h2>
<p>For my addin, <a target="_blank" href="http://www.dotnetsavant.com" title=".netSavant">.netSavant</a>, I use the following line of code during my installation process to generate a file path that the .addin file will be saved to:</p>
<p>Path.Combine(Environment.GetEnvironmentVariable(&#8221;ALLUSERSPROFILE&#8221;), @&#8221;Application Data\Microsoft\MSEnvShared\Addins\DotNetSavant.AddIn&#8221;);</p>
<p>This will generate a string value that looks like C:\Documents and Settings\All Users\Application Data\Microsoft\MSEnvShared\Addins\DotNetSavant.Addin (on my laptop).  Again, there are other locations that you could save the file to though I&#8217;ve found this one to be the most reliable as far as it&#8217;s existence on developer workstations, and being configured in visual studio (its included in vs.net by default).</p>
<p>One complexity to think of; If your user is installing on a non-english version of windows, I&#8217;m honestly not sure how to best compose the file save path.  I suppose I&#8217;ll have to deal with this eventuality eventually.  Until then I&#8217;m going to live in my quiet and warm happy place.</p>
<h2>Creating the Installer Class</h2>
<p>As with any installer project, if you want to perform some kind of custom installation action you&#8217;ll need to create an Installer class somewhere in your application.  This is as simple as creating a new class file and having it inherit from System.Configuration.Installer.  You&#8217;ll need to decorate your new class with the RunInstaller(true) attribute and override the Install, Uninstall, and Rollback methods.  These methods will be used to install your .addin file, remove your .addin file when your addin is uninstalled and roll back any installation tasks that you&#8217;ve performed if there is an error during the installation process.</p>
<h2>Overriding Install</h2>
<p>The most complex method of the installation process, this is where you&#8217;ll create your .addin file and save it to the path that I&#8217;ve mentioned above.</p>
<p>For <a target="_blank" href="http://www.dotnetsavant.com">.netSavant</a> I store my .addin file in the root directory of my project and set its build action to &#8220;Embedded Resource&#8221;.  This way I can make simple adjustments to the file and it will always be available as a resource of the assembly.  This comes in handy during the installation process, specifically the Install method because I can access the embedded resource, modify the path defined in the Assembly nodes and write the xml contents to disk.</p>
<p>Since the release of vs.net 2008 I&#8217;ve updated my own installer to use a block of LINQ that looks something like this:</p>
<pre name="code" class="csharp">

XDocument linqXmlDocument = null;
string installationPath = base.Context.Parameters[&quot;AssemblyPath&quot;];
string addinResourceFile = Assembly.GetExecutingAssembly().GetName().Name + &quot;.DotNetSavant.addin&quot;;

using (Stream resourceStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(addinResourceFile)) {
    linqXmlDocument = XDocument.Load(XmlReader.Create(resourceStream));
}
var query = from assemblyNode in linqXmlDocument.Descendants()
    where assemblyNode.Name.LocalName.ToLower().Equals(&quot;assembly&#038;quot <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />
    select assemblyNode;

foreach (XElement assemblyNode in query) {
    assemblyNode.SetValue(installationPath);
}
string addinXml = linqXmlDocument.ToString();
</pre>
<p>Note the use of base.Context.Parameters["assemblypath"].  The base installer object gives you access to these values to access form information collected during the installation process.  In this case I&#8217;m accessing the path that the user specified as the installation directory for the addin.</p>
<h2>Overriding Uninstall</h2>
<p>When uninstalling your addin, it would be prudent to delete the .addin file from the user&#8217;s file system.  Its just common sense that when you uninstall something you should remove everything that was added to the users computer during the installation process.</p>
<h2>Overriding Rollback</h2>
<p>The rollback method is where you will implement any clean up code that will be run if the installation process needs to terminate before its completion.  Be aware that you&#8217;ll not know at what point in the installation process this method might be invoked by your installer package, so any cleanup that you perform should be wrapped inside of try blocks so that the rollback method can execute cleanly.</p>
<h2>Back to the Installer Project</h2>
<p>Now that you have an installer class it&#8217;s a simple matter to wire it up to your installer.  Make sure that your installer references either the build output of your project or the compiled assembly of your project directly.  Then, right click on the installer project and select View &gt; Custom Actions.  You&#8217;ll see four folder icons labeled Install, Commit, Rollback and Uninstall.  Simply right click on a folder, click &#8220;add custom action&#8221; and browse to the assembly that contains your installer class.  Do this once each for the Install, Rollback and Uninstall folders to end up with a configuration that looks something like this:</p>
<p><img src="http://hurtsmybrains.files.wordpress.com/2008/02/installer-customactions.png" alt="Installer - Custom Actions" /></p>
<p>At this point the installer project is configured to use the custom installation process defined by the installer class.  When the installer is run the .addin file will be successfully written to a legitimate addin path as part of the installation process.  Conversely it will be removed from the file system during uninstallation.</p>
<h2>Potential Issues</h2>
<p>I hinted earlier that non-english users might have issues installing the addin using my methodology.  This is because I hard-code part of the .addin installation path in English during my install process.  It will be impossible to guarantee that the paths specified by default in visual studio will always be in English, thus we have a potential localization problem to deal with.  Remember that if you don&#8217;t see your addin in the addin manager in visual studio you most likely saved your .addin file to a path that is not recognized by the development environment.</p>
<p>Another common issue that is easy to overlook; make sure that you&#8217;ve specified a valid path to your assembly in your .addin files&#8217; Assembly node.  If this path is incorrect visual studio will not load your addin.</p>
<p>Enjoy!</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/hurtsmybrains.wordpress.com/12/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/hurtsmybrains.wordpress.com/12/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/hurtsmybrains.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/hurtsmybrains.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/hurtsmybrains.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/hurtsmybrains.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/hurtsmybrains.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/hurtsmybrains.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/hurtsmybrains.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/hurtsmybrains.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/hurtsmybrains.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/hurtsmybrains.wordpress.com/12/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hurtsmybrains.wordpress.com&blog=2425424&post=12&subd=hurtsmybrains&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://hurtsmybrains.wordpress.com/2008/02/22/writing-an-installer-class-for-a-visual-studionet-addin/feed/</wfw:commentRss>
	
		<media:content url="http://hurtsmybrains.files.wordpress.com/2008/02/installer-customactions.png" medium="image">
			<media:title type="html">Installer - Custom Actions</media:title>
		</media:content>
	</item>
		<item>
		<title>visual studio options pages</title>
		<link>http://hurtsmybrains.wordpress.com/2008/02/15/visual-studio-options-pages/</link>
		<comments>http://hurtsmybrains.wordpress.com/2008/02/15/visual-studio-options-pages/#comments</comments>
		<pubDate>Fri, 15 Feb 2008 14:01:25 +0000</pubDate>
		<dc:creator>abusement</dc:creator>
		
		<category><![CDATA[Visual Studio Addin Development]]></category>

		<category><![CDATA[addin configuration]]></category>

		<category><![CDATA[tools options pages]]></category>

		<category><![CDATA[visual studio 2005]]></category>

		<category><![CDATA[visual studio 2008]]></category>

		<guid isPermaLink="false">http://hurtsmybrains.wordpress.com/?p=21</guid>
		<description><![CDATA[Like many addin developers I create options pages in visual studio to handle configuration of my software.  While extremely simple to create these pages, it is not obvious how they should be configured to load with visual studio.  Additionally, the documentation for creating options pages provided by Microsoft describes in detail how to create options [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Like many addin developers I create options pages in visual studio to handle configuration of my software.  While extremely simple to create these pages, it is not obvious how they should be configured to load with visual studio.  Additionally, the documentation for creating options pages provided by Microsoft describes in detail how to create options pages, though neglects to describe how to make visual studio recognize your options page control.</p>
<p>Fortunately this is extremly simple to wire up.</p>
<p><span id="more-21"></span></p>
<pre name="code" class="xml">

&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-16&quot; standalone=&quot;no&quot;?&gt;
&lt;Extensibility xmlns=&quot;&lt;a href=&quot;http://schemas.microsoft.com/AutomationExtensibility&quot; mce_href=&quot;http://schemas.microsoft.com/AutomationExtensibility&quot;&gt;http://schemas.microsoft.com/AutomationExtensibility&lt;/a&gt;&quot;&gt;
  &lt;HostApplication&gt;
    &lt;Name&gt;Microsoft Visual Studio&lt;/Name&gt;
    &lt;Version&gt;9.0&lt;/Version&gt;
  &lt;/HostApplication&gt;
  &lt;HostApplication&gt;
    &lt;Name&gt;Microsoft Visual Studio&lt;/Name&gt;
    &lt;Version&gt;8.0&lt;/Version&gt;
  &lt;/HostApplication&gt;
  &lt;Addin&gt;
    &lt;FriendlyName&gt;.netSavant&lt;/FriendlyName&gt;
    &lt;Description&gt;.netSavant is a powerful code generator for the .net framework and Visual Studio.NET.  For more information please visit &lt;a href=&quot;http://www.dotnetsavant.com/&quot; mce_href=&quot;http://www.dotnetsavant.com/&quot;&gt;http://www.dotnetsavant.com&lt;/a&gt; &lt;/Description&gt;
    &lt;AboutBoxDetails&gt;For more information about .netSavant please visit &lt;a href=&quot;http://www.dotnetsavant.com/&quot; mce_href=&quot;http://www.dotnetsavant.com/&quot;&gt;http://www.dotnetsavant.com&lt;/a&gt; &lt;/AboutBoxDetails&gt;
    &lt;AboutIconData&gt;&lt;/AboutIconData&gt;
    &lt;Assembly&gt;Path to .netSavant assembly&lt;/Assembly&gt;
    &lt;FullClassName&gt;DotNetSavant.Connect&lt;/FullClassName&gt;
    &lt;LoadBehavior&gt;1&lt;/LoadBehavior&gt;
    &lt;CommandPreload&gt;1&lt;/CommandPreload&gt;
    &lt;CommandLineSafe&gt;0&lt;/CommandLineSafe&gt;
  &lt;/Addin&gt;
  &lt;ToolsOptionsPage&gt;
    &lt;Category Name=&quot;DotNetSavant&quot;&gt;
      &lt;SubCategory Name=&quot;Adapter Generation&quot;&gt;
        &lt;Assembly&gt;Path to .netSavant assembly&lt;/Assembly&gt;
        &lt;FullClassName&gt;DotNetSavant.Controls.AdapterSettingsOptionsPage&lt;/FullClassName&gt;
      &lt;/SubCategory&gt;
    &lt;/Category&gt;
  &lt;/ToolsOptionsPage&gt;
&lt;/Extensibility&gt; 
</pre>
<p>You&#8217;ll notice that I added a ToolsOptionPage node under the root Extensibility node of a standard .addin xml file.  Here you can identify hierarchal categories that will be displayed as visual studio options pages.In this example I&#8217;ve added a top level options page called &#8220;DotNetSavant&#8221; with a sub category named &#8220;Adapter Generation&#8221;.  Similar to the addin node of the base .addin file, both Category and SubCategory nodes can specify a single Assembly and FullClassName node.  Set the assembly nodes&#8217; inner text to the path of the assembly where your options pages control exists and then specify the fully qualified name of your options pages class in the FullClassName node and your options pages will load with visual studio.Enjoy!</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/hurtsmybrains.wordpress.com/21/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/hurtsmybrains.wordpress.com/21/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/hurtsmybrains.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/hurtsmybrains.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/hurtsmybrains.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/hurtsmybrains.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/hurtsmybrains.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/hurtsmybrains.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/hurtsmybrains.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/hurtsmybrains.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/hurtsmybrains.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/hurtsmybrains.wordpress.com/21/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hurtsmybrains.wordpress.com&blog=2425424&post=21&subd=hurtsmybrains&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://hurtsmybrains.wordpress.com/2008/02/15/visual-studio-options-pages/feed/</wfw:commentRss>
		</item>
		<item>
		<title>unhandled addin exceptions vs. visual studio.net</title>
		<link>http://hurtsmybrains.wordpress.com/2008/02/09/unhandled-addin-exceptions-vs-visual-studionet/</link>
		<comments>http://hurtsmybrains.wordpress.com/2008/02/09/unhandled-addin-exceptions-vs-visual-studionet/#comments</comments>
		<pubDate>Sat, 09 Feb 2008 16:48:45 +0000</pubDate>
		<dc:creator>abusement</dc:creator>
		
		<category><![CDATA[Debugging]]></category>

		<category><![CDATA[Visual Studio Addin Development]]></category>

		<category><![CDATA[.NET]]></category>

		<category><![CDATA[addin]]></category>

		<category><![CDATA[instrumentation]]></category>

		<category><![CDATA[unhandled exception]]></category>

		<category><![CDATA[visual studio]]></category>

		<guid isPermaLink="false">http://hurtsmybrains.wordpress.com/?p=13</guid>
		<description><![CDATA[One of the most frustrating things I&#8217;ve found when programming addins for visual studio is the inability to globally trap unhandled exceptions the way that you can when  authoring a windows application.  Essentially visual studio intercepts exceptions your addin throws that you neglect to handle.  The worst part is that you don&#8217;t get any information [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>One of the most frustrating things I&#8217;ve found when programming addins for visual studio is the inability to globally trap unhandled exceptions the way that you can when  authoring a windows application.  Essentially visual studio intercepts exceptions your addin throws that you neglect to handle.  The worst part is that you don&#8217;t get any information about the exception before visual studio crashes!  Its great that Microsoft gets a dump of the crash, but you&#8217;re left standing empty handed and scratching your head.</p>
<p><span id="more-13"></span></p>
<p>Generally speaking an addin framework should not allow an addin to crash the host application.  It points to either a design concept that I can&#8217;t comprehend, a significant oversight in the design of the visual studio addin framework, or simply some kind of interop issue that visual studio doesn&#8217;t handle well.</p>
<p>Short of making sure that every block of code in your addin that can throw an exception is wrapped in a try block we don&#8217;t have a good methodology for dealing with unhandled exceptions.  While this is a good thing because it forces you to write solid code it can be exceptionally frustrating to to debug unforeseen issues in a production environment.</p>
<p>I&#8217;m still looking for a good way to trap or instrument unhandled exceptions in addins that I write, especially in runtime environments.  If I find a good approach I&#8217;ll be sure to write about it.</p>
<p>Enjoy!</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/hurtsmybrains.wordpress.com/13/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/hurtsmybrains.wordpress.com/13/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/hurtsmybrains.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/hurtsmybrains.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/hurtsmybrains.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/hurtsmybrains.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/hurtsmybrains.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/hurtsmybrains.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/hurtsmybrains.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/hurtsmybrains.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/hurtsmybrains.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/hurtsmybrains.wordpress.com/13/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hurtsmybrains.wordpress.com&blog=2425424&post=13&subd=hurtsmybrains&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://hurtsmybrains.wordpress.com/2008/02/09/unhandled-addin-exceptions-vs-visual-studionet/feed/</wfw:commentRss>
		</item>
		<item>
		<title>visual studio.net 2008 extension methods</title>
		<link>http://hurtsmybrains.wordpress.com/2008/01/08/visual-studionet-2008-extension-methods/</link>
		<comments>http://hurtsmybrains.wordpress.com/2008/01/08/visual-studionet-2008-extension-methods/#comments</comments>
		<pubDate>Tue, 08 Jan 2008 06:06:32 +0000</pubDate>
		<dc:creator>abusement</dc:creator>
		
		<category><![CDATA[.NET Programming]]></category>

		<category><![CDATA[Software Design]]></category>

		<category><![CDATA[.NET 3.5]]></category>

		<category><![CDATA[2008]]></category>

		<category><![CDATA[extension method]]></category>

		<category><![CDATA[visual studio]]></category>

		<guid isPermaLink="false">http://hurtsmybrains.wordpress.com/2008/01/08/visual-studionet-2008-extension-methods/</guid>
		<description><![CDATA[Now that visual studio.net 2008 has been released developers have a much improved development environment and framework to produce high quality code with.  Extension methods are one of the new framework and IDE features that provides a powerful and clever method of extending objects that you do not have source code for or otherwise can&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Now that visual studio.net 2008 has been released developers have a much improved development environment and framework to produce high quality code with.  Extension methods are one of the new framework and IDE features that provides a powerful and clever method of extending objects that you do not have source code for or otherwise can&#8217;t directly extend.</p>
<p>Simply put, extension methods allow you to add new methods to the public contract of an existing type without sub-classing, decorating or recompiling the original type.  Prior to this release there were a few options available to solve this problem.</p>
<p><span id="more-10"></span></p>
<h2>The Decorator Pattern</h2>
<p>The decorator is a great design pattern for extending the functionality of an object without sub-classing.  Without going into the nitty gritty details of decorator implementation, essentially you create an object that takes the object that you want to decorate as an argument to your new objects constructor.  Next, you&#8217;d create whatever methods you need in your object, accessing the &#8220;decorated&#8221; object as needed.</p>
<p>Using this pattern, you can extended the functionality of an existing object without subclasing or resorting to libraries of static methods.  Unfortunately this pattern is overkill for minor object extensions or use with value types.  I commonly use this pattern to create read-only versions of objects without having to change the functionality of the underlying object.  Another great example are the various stream objects in the System.IO namespace.</p>
<h2>Subclassing</h2>
<p>This option is self explainatory.  Simply create an object that inherits from the object you want to extend and add additional functionality.  Unfortunately if your object to extend is sealed you&#8217;ll need to use a decorator or the dreaded &#8220;helper&#8221;.</p>
<h2>The &#8220;Helper&#8221; Object</h2>
<p>Nearly every piece of software that I&#8217;ve ever supported has one or fifty of these objects.  I&#8217;ve seen string helpers, integer helpers, business object helpers, User Interface helpers, and ADO.NET helpers to name just a few.</p>
<p>Personally I don&#8217;t care for this technique, though it can be extremely effective for minor object extension or use with value types.  It is susceptible to abuse through massive overloading, lack of commenting and documentation and poor overall design.</p>
<h2>Enter the Extension Method</h2>
<p>Essentially, these methods are similar to the static methods used in the helper object with one very important distinction; they exist as methods defined as part of the contract of the defined type.</p>
<pre name="code" class="csharp">

public static class Extensions {
    public static bool InRange&lt;T&gt;(this T value, T lower, T upper) where T : struct, IComparable&lt;T&gt; {
        if(value.CompareTo(lower) &gt;= 0 &amp;&amp; value.CompareTo(upper) &lt;= 0) {
            return true;
        }
        return false;
    }
}
</pre>
<p>In this example I&#8217;ve illustrated a very powerful generic method that allows a developer to see if a value falls into a range of acceptable values.  Because it is generic and constrained by the IComparable&lt;T&gt; interface we have the ability to perform a comparison using the CompareTo(T) method exposed by the interface.  Syntactically, this is nearly identical to a standard static method with the exception of the <em>this</em> keyword that decorates the first argument of the method.  The <em>this</em> keyword tells the compiler that this method should be added to structs of type T (the generic type identifier).Using this new method is simple.</p>
<pre name="code" class="csharp">

decimal price = 12.99;
if(price.InRange&lt;decimal&gt;(1, 49.95)){
    Console.WriteLine(&quot;The price specified is within the specified range.&quot;);

}else{
    Console.WriteLine(&quot;The price specified is not within the specified range.&quot;);
}
</pre>
<p>This particular extension method is configured using the decimal type, though it will work for any struct that implements the IClomparable interface.  What&#8217;s important is that visual studio.net 2008 will display this method using intellisense on objects that match both the <em>this</em> (generic) declaration as well as the interface constraint.There are countless applications for extension methods.  They provide a more intuitive method of extending objects without resorting to other techniques that might require extensive design consideration.Enjoy!</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/hurtsmybrains.wordpress.com/10/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/hurtsmybrains.wordpress.com/10/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/hurtsmybrains.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/hurtsmybrains.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/hurtsmybrains.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/hurtsmybrains.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/hurtsmybrains.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/hurtsmybrains.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/hurtsmybrains.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/hurtsmybrains.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/hurtsmybrains.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/hurtsmybrains.wordpress.com/10/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hurtsmybrains.wordpress.com&blog=2425424&post=10&subd=hurtsmybrains&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://hurtsmybrains.wordpress.com/2008/01/08/visual-studionet-2008-extension-methods/feed/</wfw:commentRss>
		</item>
		<item>
		<title>nullable types and ado.net parameters</title>
		<link>http://hurtsmybrains.wordpress.com/2008/01/05/nullable-types-and-adonet-parameters/</link>
		<comments>http://hurtsmybrains.wordpress.com/2008/01/05/nullable-types-and-adonet-parameters/#comments</comments>
		<pubDate>Sat, 05 Jan 2008 02:39:24 +0000</pubDate>
		<dc:creator>abusement</dc:creator>
		
		<category><![CDATA[.NET Programming]]></category>

		<category><![CDATA[ADO.NET]]></category>

		<category><![CDATA[.NET]]></category>

		<category><![CDATA[nullable type]]></category>

		<category><![CDATA[tryparse]]></category>

		<category><![CDATA[visual studio]]></category>

		<guid isPermaLink="false">http://hurtsmybrains.wordpress.com/2008/01/05/nullable-types-and-adonet-parameters/</guid>
		<description><![CDATA[As most people are aware the .NET 2.0 framework supports nullable value types.  There are many articles on this topic and a few that address the issues of using nullable types in combination with your ado.net code.  However, most of these discuss the issue of using nullable types in combination with the DbDataReader objects, though few address [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>As most people are aware the .NET 2.0 framework supports nullable value types.  There are many articles on this topic and a few that address the issues of using nullable types in combination with your ado.net code.  However, most of these discuss the issue of using nullable types in combination with the DbDataReader objects, though few address the conflicts that arise when using a nullable type to set or get an ado.net parameter value.</p>
<p>Prior to .net 2.0 you&#8217;d run into this issue when attempting to pass a null string to the value of an input parameter.  In this case most of us would have written conditional code that looked something like this:</p>
<pre name="code" class="csharp">

string firstName = null;
if(firstName == null) {
    Command.Parameters[&quot;FirstName&quot;].Value = DBNull.Value;
} else {
    Command.Parameters[&quot;FirstName&quot;].Value = firstName;
} 
</pre>
<p>Or you could have used a ternary operation: </p>
<pre name="code" class="csharp">

string firstName = null;
Command.Parameters[&quot;FirstName&quot;].Value = firstName == null ? (object)DBNull.Value : firstName;
</pre>
<p><span id="more-9"></span>With the inception of nullable types you now have to perform the same logic for all parameters that will use a nullable type to set its value.  This isn&#8217;t a huge deal really, though it will start to get a bit tedious with stored procedures that have a lot of parameters to assign and downright egregious over the lifecycle of your project.  Fortunately there is a little known (and used) operator that we can use to solve this issue cleanly; the null coalescing operator &#8220;??&#8221;.  This operator specifies that if the argument on the left evaluates to null then the argument on the right will be substituted.</p>
<pre name="code" class="csharp">

int? age = null;
Command.Parameters[&quot;Age&quot;].Value = age ?? (object)DBNull.Value;
</pre>
<p>This code is far more readable than the previous conditional statement.  Alternatively you could write a simple method that takes the parameter and the value that you want to assign to it and have the value set using the conditional method above (reusability, huzzah!), but that would either involve an inline method call or a loop over the parameters collection.  These approaches while certainly valid aren&#8217;t nearly as compelling as using the coalescing operator.Unfortunately vb.net programmers don&#8217;t have a comparable operator and so they&#8217;ll have to resort to either the conditional, the ternary or the inline method techniques.</p>
<pre name="code" class="vb">

Dim age As Integer? = Nothing
Command.Parameters(&quot;Age&quot;).Value = IIf(age Is Nothing, DirectCast(DBNull.Value, Object), age)
</pre>
<p>So far I&#8217;ve explained how to handle input parameters, but whats the best way to handle output parameters?  Working from my previous post on <a target="_blank" href="http://hurtsmybrains.wordpress.com/2008/01/03/systemnullable-vs-tryparse/">system.nullable vs. tryparse</a> we can use the new NullableParser static object and its TryParse methods to set the value of a nullable variable properly from a stored procedure output parameter.</p>
<pre name="code" class="csharp">

int? age = null;
NullableParser.TryParse(Command.Parameters[&quot;Age&quot;].Value.ToString(), out age, true);
</pre>
<p>Asside from being easy to read and support, this code provides a robust and efficient method for setting the nullable age variable to the value of the Age output parameter using the familiar T.TryParse(string s, out T result) syntax.Enjoy!</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/hurtsmybrains.wordpress.com/9/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/hurtsmybrains.wordpress.com/9/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/hurtsmybrains.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/hurtsmybrains.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/hurtsmybrains.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/hurtsmybrains.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/hurtsmybrains.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/hurtsmybrains.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/hurtsmybrains.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/hurtsmybrains.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/hurtsmybrains.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/hurtsmybrains.wordpress.com/9/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hurtsmybrains.wordpress.com&blog=2425424&post=9&subd=hurtsmybrains&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://hurtsmybrains.wordpress.com/2008/01/05/nullable-types-and-adonet-parameters/feed/</wfw:commentRss>
		</item>
		<item>
		<title>system.nullable vs. tryparse</title>
		<link>http://hurtsmybrains.wordpress.com/2008/01/03/systemnullable-vs-tryparse/</link>
		<comments>http://hurtsmybrains.wordpress.com/2008/01/03/systemnullable-vs-tryparse/#comments</comments>
		<pubDate>Thu, 03 Jan 2008 04:44:47 +0000</pubDate>
		<dc:creator>abusement</dc:creator>
		
		<category><![CDATA[.NET Programming]]></category>

		<category><![CDATA[.net 2.0]]></category>

		<category><![CDATA[C#]]></category>

		<category><![CDATA[generics]]></category>

		<category><![CDATA[Nullable]]></category>

		<category><![CDATA[tryparse]]></category>

		<guid isPermaLink="false">http://hurtsmybrains.wordpress.com/2008/01/03/systemnullable-vs-tryparse/</guid>
		<description><![CDATA[I&#8217;ve been working on some code tonight and needed to use the trusty struct.TryParse methods available in the core framework.  Unfortunately, the built in TryParse methods choke on nullable types.  After a frightfully short google search I ran across a blog entry from Steve Michelotti describing his approach to writing his own TryParse object for nullable types.  [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I&#8217;ve been working on some code tonight and needed to use the trusty struct.TryParse methods available in the core framework.  Unfortunately, the built in TryParse methods choke on nullable types.  After a frightfully short google search I ran across a blog entry from <a target="_blank" href="http://geekswithblogs.net/michelotti/archive/2006/01/16/66015.aspx" title="TryParse for Nullable Types">Steve Michelotti</a> describing his approach to writing his own TryParse object for nullable types.  Its pretty sweet though it didn&#8217;t meet a specific need that I had, specifically the ability to have the result parameter have its value set to null in cases where the string passed in is in fact null (or empty).</p>
<p>I&#8217;ve modified his basic concept with an overloaded method that allows you to specify how the result parameter value will be set.  Passing true to the alwaysNull parameter will always set your value to null if the string sent to the function is null or empty (which is what I&#8217;m using for my code problem).  Conversely, passing false will result in the default behavior expected from the TryParse methods.</p>
<pre name="code" class="csharp">

public static class NullableParser {
    private delegate bool TryParseDelegate(string s, out T result) where T : struct;
    private static bool TryParseNullable(string value, out Nullable result, TryParseDelegate tryParse, bool alwaysNull) where T : struct {
        if(string.IsNullOrEmpty(value)) {
            if(alwaysNull) {
                result = null;
                return false;
            } else {
                result = default(T);
                return false;
            }
        }
        T tempResult;
        bool success = tryParse(value, out tempResult);
        result = tempResult;
        return success;
    }

    public static bool TryParse(string value, out DateTime? result, bool alwaysNull) {
        return TryParseNullable(value, out result, DateTime.TryParse, alwaysNull);
    }
    public static bool TryParse(string value, out DateTime? result) {
        return NullableParser.TryParse(value, out result, false);
    }
} 
</pre>
<p>Clearly this needs to have the rest of the native value type methods completed, i.e. TryParseInt, TryParseDouble, TryParseBoolean, etc. though it illustrates the basic concept well.</p>
<p>Enjoy!</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/hurtsmybrains.wordpress.com/8/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/hurtsmybrains.wordpress.com/8/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/hurtsmybrains.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/hurtsmybrains.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/hurtsmybrains.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/hurtsmybrains.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/hurtsmybrains.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/hurtsmybrains.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/hurtsmybrains.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/hurtsmybrains.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/hurtsmybrains.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/hurtsmybrains.wordpress.com/8/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hurtsmybrains.wordpress.com&blog=2425424&post=8&subd=hurtsmybrains&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://hurtsmybrains.wordpress.com/2008/01/03/systemnullable-vs-tryparse/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>