<?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>JSEDLAK &#187; .NET Framework</title>
	<atom:link href="http://jsedlak.org/tag/net-framework/feed/" rel="self" type="application/rss+xml" />
	<link>http://jsedlak.org</link>
	<description></description>
	<lastBuildDate>Wed, 01 Sep 2010 00:44:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>A Letter To Microsoft: On Framework Design</title>
		<link>http://jsedlak.org/2009/10/02/a-letter-to-microsoft-on-framework-design/</link>
		<comments>http://jsedlak.org/2009/10/02/a-letter-to-microsoft-on-framework-design/#comments</comments>
		<pubDate>Sat, 03 Oct 2009 01:23:06 +0000</pubDate>
		<dc:creator>John Sedlak</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[.NET 4.0]]></category>
		<category><![CDATA[.NET Framework]]></category>

		<guid isPermaLink="false">http://jsedlak.com/?p=220</guid>
		<description><![CDATA[Rather than writing an actual letter, which would do no good, I have chosen to write this post with the idea that as an MVP I should lead and teach by example. One of the most important design principles that factor into designing a framework is that of dependency hierarchies. In less fancy terms it [...]]]></description>
			<content:encoded><![CDATA[<p>Rather than writing an actual letter, which would do no good, I have chosen to write this post with the idea that as an MVP I should lead and teach by example. One of the most important design principles that factor into designing a framework is that of dependency hierarchies. In less fancy terms it simply means what classes implement what interfaces and where these things are maintained in the framework. Recently I placed a suggestion on <a href="http://connect.microsoft.com">Connect</a> to <a href="https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=488607&#038;wa=wsignin1.0">Move INotifyCollectionChanged to System.dll</a> so that more projects that do not require WindowsBase.dll (WPF) could use the functionality. Fortunately for .NET developers everywhere the suggestion was taken (although I won&#8217;t claim sole responsibility) and the move is happening.</p>
<p>This post is about the reasons for such a move, and such reasons are incredibly basic to realize. Consider a platform other than Windows whether it be Linux, Windows Mobile, the Xbox 360 or even the Zune HD. Now think about how you would write a framework that supports some of (or all) these platforms and consider the problem of developing a class that implements something like INotifyCollectionChanged. The problem, of course, is that not all the platforms have access to WindowsBase.dll. Thus the developers come to a crossroads: either recreate the functionality for the platforms or don&#8217;t implement the functionality.</p>
<p>While that may not seem too unreasonable a dilemma, the problem is that Microsoft implemented functionality in a branched assembly that really has no dependency on any classes or interfaces within that assembly. Here the principle is simple: when possible, move functionality up the assembly hierarchy so as to reduce cross dependencies. In layman&#8217;s terms, by moving the INotifyCollectionChanged interface to System.dll, many more projects can take advantage of it without requiring any sort of platform dependent code. And here it is important to remember that one of the original goals of .NET was to enable true cross platform development.</p>
<p>To say that this case is the only one of its kind would be ignorant. The scary thing is that I don&#8217;t think anyone actually has a list of where these mistakes exist and what can be done about them. Even scarier than that is the fact that Microsoft is making these mistakes. Consider the following which further demonstrates this point.</p>
<p>While helping someone today with a few questions on the System.Reflection namespace, a point was made about how odd it is to compare generic types. When you have a generic class such as <i>Nullable&lt;T&gt;</i> you cannot do something as simple as <i>if(foo is Nullable)</i> because the generic parameter can make a difference. While this isn&#8217;t too much of a problem, Microsoft <span style="text-decoration: line-through;">later</span> also developed the System.Data assembly and included an interface called <i>INullable</i> within this assembly under the <a href="http://msdn.microsoft.com/en-us/library/system.data.sqltypes.aspx">System.Data.SqlTypes namespace</a>. This, like INotifyCollectionChanged, constricts the use of this interface to only assemblies that reference System.Data.dll. Furthermore, the interface contains a single boolean property and has not a single dependency on anything within the System.data assembly.</p>
<p>The problem and its solution should be obvious: move INullable to the System namespace in System.dll and make <i>Nullable&lt;T&gt;</i> implement it. This allows developers to easily check whether or not a type represents a nullable type while not creating a single problem in the entire framework&#8217;s design. Furthermore it would allow developers to treat System.Nullable and System.Data.SqlTypes.* as the same types which can come in handy.</p>
<p><b>Update:</b> I added a suggestion on Connect for <a href="https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=495607">moving INullable to System.dll</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://jsedlak.org/2009/10/02/a-letter-to-microsoft-on-framework-design/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Difference Between System.* and Microsoft.*</title>
		<link>http://jsedlak.org/2008/11/16/difference-between-system-and-microsoft/</link>
		<comments>http://jsedlak.org/2008/11/16/difference-between-system-and-microsoft/#comments</comments>
		<pubDate>Sun, 16 Nov 2008 08:39:45 +0000</pubDate>
		<dc:creator>John Sedlak</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[.NET Framework]]></category>

		<guid isPermaLink="false">http://jsedlak.com/?p=138</guid>
		<description><![CDATA[Scott Hanselman has been on a roll lately with his posts and twits. Today he writes &#8220;Question to .NET Programmers: what is the difference between the System.* and Microsoft.* namespaces?&#8221; This is an important question and one that I can&#8217;t say I truly know the answer too. I had always assumed it was based on [...]]]></description>
			<content:encoded><![CDATA[<p>Scott Hanselman has been on a roll lately with his posts and twits. Today <a href="http://twitter.com/shanselman/status/1007844464">he writes</a> &#8220;Question to .NET Programmers: what is the difference between the System.* and Microsoft.* namespaces?&#8221;</p>
<p>This is an important question and one that I can&#8217;t say I truly know the answer too. I had always assumed it was based on either the idea that System.* was part of the <em>core</em> framework where as Microsoft.* was for Microsoft specific functionality. For instance, it would be expected that much or all of the System.* functionality would be replicated on many other platforms where as Microsoft.* would not. </p>
<p>Certainly this is true for the very basic feature set such as the common types but it is not true for System.Windows.Forms. Which begs the question that I always wondered: why is Windows.Forms where it is? I always expected it to be in Microsoft.Windows.Forms as it is a Windows specific implementation based on many of the Win32 controls.</p>
]]></content:encoded>
			<wfw:commentRss>http://jsedlak.org/2008/11/16/difference-between-system-and-microsoft/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Restoring LocalUserAppDataPath in WPF</title>
		<link>http://jsedlak.org/2008/08/29/restoring-localuserappdatapath-in-wpf/</link>
		<comments>http://jsedlak.org/2008/08/29/restoring-localuserappdatapath-in-wpf/#comments</comments>
		<pubDate>Fri, 29 Aug 2008 21:54:16 +0000</pubDate>
		<dc:creator>John Sedlak</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[.NET Framework]]></category>

		<guid isPermaLink="false">http://jso.fg.com/?p=376</guid>
		<description><![CDATA[With the arrival of .NET 3.5 and consequently WPF applications, Microsoft has done away with the old Application WinForms class. No longer can you call Application.LocalUserAppDataPath to get where the user&#8217;s files are stored. To restore this functionality as well as add a bit more, I have tapped into an uncommon resource: extension methods. Let&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>With the arrival of .NET 3.5 and consequently WPF applications, Microsoft has done away with the old Application WinForms class. No longer can you call Application.LocalUserAppDataPath to get where the user&#8217;s files are stored. To restore this functionality as well as add a bit more, I have tapped into an uncommon resource: extension methods. Let&#8217;s dig a little deeper, shall we?</p>
<p><span id="more-376"></span></p>
<p><b>Note:</b> You should not rely on this for accessing local data stores. Microsoft has done away with this method for a reason and relying on it in the future can cause problems.</p>
<p>The first thing we need to do is be able to get the Company Name from the assembly. Inside of a blank static class, add the following functions. I have named my class <i>ApplicationExtensions</i>.</p>
<p>Fortunately the company name is kept in an attribute:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p376code4'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p3764"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
</pre></td><td class="code" id="p376code4"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">string</span> GetCompanyName<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> Assembly assembly<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #6666cc; font-weight: bold;">string</span> name <span style="color: #008000;">=</span> <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Empty</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #6666cc; font-weight: bold;">object</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> attributes <span style="color: #008000;">=</span> assembly<span style="color: #008000;">.</span><span style="color: #0000FF;">GetCustomAttributes</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">typeof</span><span style="color: #008000;">&#40;</span>AssemblyCompanyAttribute<span style="color: #008000;">&#41;</span>, <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>attributes <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span> <span style="color: #008000;">&amp;&amp;</span> attributes<span style="color: #008000;">.</span><span style="color: #0000FF;">Length</span> <span style="color: #008000;">&gt;</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        AssemblyCompanyAttribute aca <span style="color: #008000;">=</span> attributes<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#93;</span> <span style="color: #0600FF; font-weight: bold;">as</span> AssemblyCompanyAttribute<span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>aca <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            name <span style="color: #008000;">=</span> aca<span style="color: #008000;">.</span><span style="color: #0000FF;">Company</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">return</span> name<span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>Note my lack of any formal error handling. I will leave this up to you to handle. For now, returning an empty string will do. Next up, we need to be able to format the version number:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p376code5'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p3765"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code" id="p376code5"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">string</span> GetFormattedVersion<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> Assembly assembly<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #6666cc; font-weight: bold;">string</span> version <span style="color: #008000;">=</span> <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Empty</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">try</span><span style="color: #008000;">&#123;</span>
        Version assemblyVersion <span style="color: #008000;">=</span> assembly<span style="color: #008000;">.</span><span style="color: #0000FF;">GetName</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Version</span><span style="color: #008000;">;</span>
&nbsp;
        version <span style="color: #008000;">=</span> <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Format</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;{0}.{1}.{2}.{3}&quot;</span>,
            assemblyVersion<span style="color: #008000;">.</span><span style="color: #0000FF;">Major</span>,
            assemblyVersion<span style="color: #008000;">.</span><span style="color: #0000FF;">Minor</span>,
            assemblyVersion<span style="color: #008000;">.</span><span style="color: #0000FF;">Build</span>,
            assemblyVersion<span style="color: #008000;">.</span><span style="color: #0000FF;">Revision</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
    <span style="color: #0600FF; font-weight: bold;">catch</span><span style="color: #008000;">&#123;</span><span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">return</span> version<span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>And finally, the LocalUserDataPath:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p376code6'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p3766"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
</pre></td><td class="code" id="p376code6"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">string</span> GetLocalUserAppDataPath<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> Application application<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #6666cc; font-weight: bold;">string</span> path <span style="color: #008000;">=</span> <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Empty</span><span style="color: #008000;">;</span>
&nbsp;
    Assembly assembly <span style="color: #008000;">=</span> Assembly<span style="color: #008000;">.</span><span style="color: #0000FF;">GetEntryAssembly</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>assembly <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        path <span style="color: #008000;">=</span> Path<span style="color: #008000;">.</span><span style="color: #0000FF;">Combine</span><span style="color: #008000;">&#40;</span>
            Environment<span style="color: #008000;">.</span><span style="color: #0000FF;">GetFolderPath</span><span style="color: #008000;">&#40;</span>Environment<span style="color: #008000;">.</span><span style="color: #0000FF;">SpecialFolder</span><span style="color: #008000;">.</span><span style="color: #0000FF;">LocalApplicationData</span><span style="color: #008000;">&#41;</span>,
            Path<span style="color: #008000;">.</span><span style="color: #0000FF;">Combine</span><span style="color: #008000;">&#40;</span>
                Path<span style="color: #008000;">.</span><span style="color: #0000FF;">Combine</span><span style="color: #008000;">&#40;</span>
                    assembly<span style="color: #008000;">.</span><span style="color: #0000FF;">GetCompanyName</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>,
                    assembly<span style="color: #008000;">.</span><span style="color: #0000FF;">GetName</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">&#41;</span>,
                assembly<span style="color: #008000;">.</span><span style="color: #0000FF;">GetFormattedVersion</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
                <span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">return</span> path<span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://jsedlak.org/2008/08/29/restoring-localuserappdatapath-in-wpf/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
