<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Paul Rohde</title>
	
	<link>http://www.paulrohde.com</link>
	<description>Photographer, Developer, Graphic Designer</description>
	<lastBuildDate>Fri, 05 Feb 2010 02:12:48 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/paulrohdecom" /><feedburner:info uri="paulrohdecom" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:feedFlare href="http://add.my.yahoo.com/rss?url=http%3A%2F%2Ffeeds.feedburner.com%2Fpaulrohdecom" src="http://us.i1.yimg.com/us.yimg.com/i/us/my/addtomyyahoo4.gif">Subscribe with My Yahoo!</feedburner:feedFlare><feedburner:feedFlare href="http://www.newsgator.com/ngs/subscriber/subext.aspx?url=http%3A%2F%2Ffeeds.feedburner.com%2Fpaulrohdecom" src="http://www.newsgator.com/images/ngsub1.gif">Subscribe with NewsGator</feedburner:feedFlare><feedburner:feedFlare href="http://feeds.my.aol.com/add.jsp?url=http%3A%2F%2Ffeeds.feedburner.com%2Fpaulrohdecom" src="http://o.aolcdn.com/favorites.my.aol.com/webmaster/ffclient/webroot/locale/en-US/images/myAOLButtonSmall.gif">Subscribe with My AOL</feedburner:feedFlare><feedburner:feedFlare href="http://www.bloglines.com/sub/http://feeds.feedburner.com/paulrohdecom" src="http://www.bloglines.com/images/sub_modern11.gif">Subscribe with Bloglines</feedburner:feedFlare><feedburner:feedFlare href="http://www.netvibes.com/subscribe.php?url=http%3A%2F%2Ffeeds.feedburner.com%2Fpaulrohdecom" src="http://www.netvibes.com/img/add2netvibes.gif">Subscribe with Netvibes</feedburner:feedFlare><feedburner:feedFlare href="http://fusion.google.com/add?feedurl=http%3A%2F%2Ffeeds.feedburner.com%2Fpaulrohdecom" src="http://buttons.googlesyndication.com/fusion/add.gif">Subscribe with Google</feedburner:feedFlare><feedburner:feedFlare href="http://www.pageflakes.com/subscribe.aspx?url=http%3A%2F%2Ffeeds.feedburner.com%2Fpaulrohdecom" src="http://www.pageflakes.com/ImageFile.ashx?instanceId=Static_4&amp;fileName=ATP_blu_91x17.gif">Subscribe with Pageflakes</feedburner:feedFlare><feedburner:feedFlare href="http://www.plusmo.com/add?url=http%3A%2F%2Ffeeds.feedburner.com%2Fpaulrohdecom" src="http://plusmo.com/res/graphics/fbplusmo.gif">Subscribe with Plusmo</feedburner:feedFlare><feedburner:feedFlare href="http://www.thefreedictionary.com/_/hp/AddRSS.aspx?http%3A%2F%2Ffeeds.feedburner.com%2Fpaulrohdecom" src="http://img.tfd.com/hp/addToTheFreeDictionary.gif">Subscribe with The Free Dictionary</feedburner:feedFlare><feedburner:feedFlare href="http://www.bitty.com/manual/?contenttype=rssfeed&amp;contentvalue=http%3A%2F%2Ffeeds.feedburner.com%2Fpaulrohdecom" src="http://www.bitty.com/img/bittychicklet_91x17.gif">Subscribe with Bitty Browser</feedburner:feedFlare><feedburner:feedFlare href="http://www.newsalloy.com/?rss=http%3A%2F%2Ffeeds.feedburner.com%2Fpaulrohdecom" src="http://www.newsalloy.com/subrss3.gif">Subscribe with NewsAlloy</feedburner:feedFlare><feedburner:feedFlare href="http://www.live.com/?add=http%3A%2F%2Ffeeds.feedburner.com%2Fpaulrohdecom" src="http://tkfiles.storage.msn.com/x1piYkpqHC_35nIp1gLE68-wvzLZO8iXl_JMledmJQXP-XTBOLfmQv4zhj4MhcWEJh_GtoBIiAl1Mjh-ndp9k47If7hTaFno0mxW9_i3p_5qQw">Subscribe with Live.com</feedburner:feedFlare><feedburner:feedFlare href="http://mix.excite.eu/add?feedurl=http%3A%2F%2Ffeeds.feedburner.com%2Fpaulrohdecom" src="http://image.excite.co.uk/mix/addtomix.gif">Subscribe with Excite MIX</feedburner:feedFlare><feedburner:feedFlare href="http://www.yourminis.com/subscribe.aspx?u=http%3A%2F%2Ffeeds.feedburner.com%2Fpaulrohdecom" src="http://www.yourminis.com/images/addtoyourminisbadge.gif">Subscribe with Yourminis.com</feedburner:feedFlare><feedburner:feedFlare href="http://download.attensa.com/app/get_attensa.html?feedurl=http%3A%2F%2Ffeeds.feedburner.com%2Fpaulrohdecom" src="http://www.attensa.com/blogs/attensa/WindowsLiveWriter/BadgeredintoBadges_10C02/attensa_feed_button5.gif">Subscribe with Attensa for Outlook</feedburner:feedFlare><feedburner:feedFlare href="http://www.webwag.com/wwgthis.php?url=http%3A%2F%2Ffeeds.feedburner.com%2Fpaulrohdecom" src="http://www.webwag.com/images/wwgthis.gif">Subscribe with Webwag</feedburner:feedFlare><feedburner:feedFlare href="http://hub.netomat.net/account/account.autoSubscribe.jspa?urls=http%3A%2F%2Ffeeds.feedburner.com%2Fpaulrohdecom" src="http://www.netomat.net/blogger/images/icon_netomat_feedbutton.gif">Subscribe with netomat Hub</feedburner:feedFlare><feedburner:feedFlare href="http://www.podcastready.com/oneclick_bookmark.php?url=http%3A%2F%2Ffeeds.feedburner.com%2Fpaulrohdecom" src="http://www.podcastready.com/images/podcastready_button.gif">Subscribe with Podcast Ready</feedburner:feedFlare><feedburner:feedFlare href="http://www.flurry.com/pushRssFeed.do?r=fb&amp;url=http%3A%2F%2Ffeeds.feedburner.com%2Fpaulrohdecom" src="http://www.flurry.com/images/flurry_rss_logo2.gif">Subscribe with Flurry</feedburner:feedFlare><feedburner:feedFlare href="http://www.wikio.com/subscribe?url=http%3A%2F%2Ffeeds.feedburner.com%2Fpaulrohdecom" src="http://www.wikio.com/shared/img/add2wikio.gif">Subscribe with Wikio</feedburner:feedFlare><feedburner:feedFlare href="http://www.dailyrotation.com/index.php?feed=http%3A%2F%2Ffeeds.feedburner.com%2Fpaulrohdecom" src="http://www.dailyrotation.com/rss-dr2.gif">Subscribe with Daily Rotation</feedburner:feedFlare><item>
		<title>The Evolution of Generics in C# 4.0</title>
		<link>http://feedproxy.google.com/~r/paulrohdecom/~3/0j3qLhR0wMs/</link>
		<comments>http://www.paulrohde.com/the-evolution-of-generics-in-c-4-0/#comments</comments>
		<pubDate>Fri, 05 Feb 2010 02:12:48 +0000</pubDate>
		<dc:creator>Paul Rohde</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Arrays]]></category>
		<category><![CDATA[Assignment Compatability]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Collections]]></category>
		<category><![CDATA[Contravariance]]></category>
		<category><![CDATA[Covariance]]></category>
		<category><![CDATA[Generics]]></category>
		<category><![CDATA[Inheritance]]></category>
		<category><![CDATA[Invariant]]></category>
		<category><![CDATA[microsoft]]></category>
		<category><![CDATA[Type Safety]]></category>

		<guid isPermaLink="false">http://www.paulrohde.com/?p=1253</guid>
		<description><![CDATA[Before I begin, let me point out that I'm primarily writing this post to solidify my own understanding of the new generic structures and put it into my own words, there are already some great posts that already explain this in much greater depth and detail: (Generic Variance in C# 4.0 by Discord &#38; Rhyme, [...]]]></description>
			<content:encoded><![CDATA[<p>Before I begin, let me point out that I'm primarily writing this post to solidify my own understanding of the new generic structures and put it into my own words, there are already some great posts that already explain this in much greater depth and detail: (<a href="http://kohari.org/2008/10/28/generic-variance-in-c-40/">Generic Variance in C# 4.0</a> by <a href="http://kohari.org/">Discord &amp; Rhyme</a>, <a href="http://blogs.msdn.com/ericlippert/archive/2009/11/30/what-s-the-difference-between-covariance-and-assignment-compatibility.aspx">What's the difference between covariance and assignment compatibility?</a> By <a href="http://blogs.msdn.com/ericlippert">Eric Lippert</a>)</p>

<p>So that being said, let start off with the problem that generics solve in the first place. (If you have a good understanding, you can jump to the new features in C# 4.0)</p>

<h4>C# Prior to 2.0</h4>
<p>Lets say I have the following class hierarchy:</p>
<div style="line-height: normal;background-color:#f8f8f8; border: 1px solid #aaaaaa; padding: 5px;">
<pre class="csharp">    <span style="color: #0600FF;">public</span> abstract <span style="color: #FF0000;">class</span> Fruit <span style="color: #000000;">&#123;</span> <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> Apple : Fruit <span style="color: #000000;">&#123;</span> <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> Orange : Fruit <span style="color: #000000;">&#123;</span> <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> FruitBasket
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">public</span> Fruit<span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> Fruit <span style="color: #000000;">&#123;</span> get; set; <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> Tree
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">public</span> Fruit<span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> PickFruit<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            Fruit<span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> daFruit = <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Fruit<span style="color: #000000;">&#91;</span><span style="color: #FF0000;">2</span><span style="color: #000000;">&#93;</span>;
            daFruit<span style="color: #000000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #000000;">&#93;</span> = <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Apple<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
            daFruit<span style="color: #000000;">&#91;</span><span style="color: #FF0000;">1</span><span style="color: #000000;">&#93;</span> = <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Orange<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
            <span style="color: #0600FF;">return</span> daFruit;
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span></pre>
</div>
<p>We have a hierarchy of objects, a base Fruit class, an Apple class, which is a Fruit, and an Orange class, which is also a Fruit. In addition, we have a FruitBasket which has an enumerable of Fruit, and a Tree which I can "PickFruit()" from.</p>

<p>Now, lets say I want to have an instance of a fruit basket, however, I also want another one that deals with only Oranges (I don't want it to even be possible to put apples in the basket) so that I can make orange juice, apples just ruin a good glass of orange juice. I have two possibilities, I can create another fruit basket and ASSUME that I only put oranges in, or I create another classes that only allows oranges to be inserted in. Because I decide that I want the compiler to absolutely not allow apples in with the oranges, I now have to create a new class:</p>
<div style="line-height: normal;background-color:#f8f8f8; border: 1px solid #aaaaaa; padding: 5px;">
<pre class="csharp">    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> OrangeBasket
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">public</span> Oranges<span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> Oranges <span style="color: #000000;">&#123;</span> get; set; <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span></pre>
</div>
</p>Or if I now want to have a basket that holds potatoes, I have to build <em>another </em>class:</p>
<div style="line-height: normal;background-color:#f8f8f8; border: 1px solid #aaaaaa; padding: 5px;">
<pre class="csharp">    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> PotatoBasket
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">public</span> Potato<span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> Potatos <span style="color: #000000;">&#123;</span> get; set; <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span></pre>
</div>
<p>Right. Pattern. We are repeatedly creating virtually identical objects that simply contain other objects or that apply some sort of processing to those specific elements, all because we want the consumer (the person that is using this object) to be able to put an specifically typed object in and get a specifically typed object out, without having to cast it.</p>
<h4>C# 2.0 - 3.5</h4>
</p>With the release of C# 2.0 Microsoft introduced this concept of "generics" in programming. It allows programmers to create generalized algorithms that take and receive specific objects, store or process them, and return them, without knowing the creator of the object being worked on or knowing specific type. C# 2.0 also included a number of generic collections and interfaces that implemented these features, the most useful in my mind being the generic IEnumerable&lt;T&gt; interface. This now allows us to rewrite our basket class like follows:</p>
<div style="line-height: normal;background-color:#f8f8f8; border: 1px solid #aaaaaa; padding: 5px;"><pre class="csharp">    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> Basket&lt;T&gt;
    <span style="color: #000000;">&#123;</span>
        IEnumerable&lt;T&gt; Contents<span style="color: #000000;">&#123;</span> get; set; <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span></pre></div>
<p>Now, instead of having a PotatoBasket, a FruitBasket, and a OrangeBasket we can replace it like so while still using the same class:</p>
<div style="line-height: normal;background-color:#f8f8f8; border: 1px solid #aaaaaa; padding: 5px;">
<pre class="csharp">    Basket&lt;Potato&gt;
    Basket&lt;Fruit&gt;
    Basket&lt;Orange&gt;</pre>
</div>
<p>And our Tree class now becomes:</p>
<div style="line-height: normal;background-color:#f8f8f8; border: 1px solid #aaaaaa; padding: 5px;">
<pre class="csharp">    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> Tree
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">public</span> IEnumerable&lt;Fruit&gt; PickFruit<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            yield <span style="color: #0600FF;">return</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Apple<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
            yield <span style="color: #0600FF;">return</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Orange<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span></pre>
</div>
</p>So now, we have a Basket of Potatos, a Basket of Fruit, and a Basket of Oranges. Yet, we didn't have to duplicate the classes, and any the implementations still preserves type safety.</p>

<p>This is where it gets… Interesting.</p>

<p>Lets say I have an instance of a Tree class, and an instance of my Basket&lt;Fruit&gt; class. Now, it’s simple to do an assignment like this:</p>
<div style="line-height: normal;background-color:#f8f8f8; border: 1px solid #aaaaaa; padding: 5px;">
<pre class="csharp">    var fruitBasket = <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Basket&lt;Fruit&gt;<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
    var Tree = <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Tree<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
    fruitBasket.<span style="color: #0000FF;">Contents</span> = tree.<span style="color: #0000FF;">PickFruit</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;</pre>
</div>
</p>BUT if I have a tree that has a PickApples() method like this:</p>
<div style="line-height: normal;background-color:#f8f8f8; border: 1px solid #aaaaaa; padding: 5px;">
<pre class="csharp">    <span style="color: #0600FF;">public</span> IEnumerable&lt;Apples&gt; PickApples<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        yield <span style="color: #0600FF;">return</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Apple<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
        yield <span style="color: #0600FF;">return</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Apple<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
        yield <span style="color: #0600FF;">return</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Apple<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
    <span style="color: #000000;">&#125;</span></pre>
</div>
<p>And I attempt to do the same assignment as before but with the PickApples() method instead, C# 3.5 will not compile it because the generic parameters are not the same:</p>
<div style="line-height: normal;background-color:#f8f8f8; border: 1px solid #aaaaaa; padding: 5px;">
<pre class="csharp">    var fruitBasket = <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Basket&lt;Fruit&gt;<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
    var Tree = <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Tree<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
    fruitBasket.<span style="color: #0000FF;">Contents</span> = tree.<span style="color: #0000FF;">PickApples</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;</pre>
</div>
<p>That sucks. Why?</p>

<p>The reason has to do with the relationships of types, covariance / contra-variance / invariance (Erick Lipperts post on the difference between covariance and assignment compatibility is a much better source for it's relation with mathematics and type hierarchies). With versions prior to 4.0 the C# compiler does NOT allow generics of one type to be assigned to generics of another type. Thus, an IEnumerable&lt;Apple&gt; cannot be assigned to a variable of IEnumerable&lt;Fruit&gt;. But lets say we were allowed to do this, why would it be a problem? Lets say I have an IList&lt;Fruit&gt; and an IList&lt;Apple&gt;; it <em>seems</em> to make perfect sense that I could so the following assignment:</p>
<div style="line-height: normal;background-color:#f8f8f8; border: 1px  solid #aaaaaa; padding: 5px;">
<pre class="csharp">    var fruitList = <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> List&lt;Fruit&gt;<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
    var appleList = <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> List&lt;Apple&gt;<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
    fruitList = appleList;</pre>
</div>
<p>Right?</p>

<p>Wrong.</p>

<p>This assignment would actually be plausable for IEnumerable&lt;T&gt; because IEnumerable&lt;T&gt; is immutable, it can not change, there's no way to "Insert" a new element into an IEnumerable. However, with an IList&lt;T&gt; it defines an Add(T item) method. An IList<T> can be altered. In the previous example, if I were to take fruitList and look at the Add method in intellisense, it would show that I can insert any object that is a fruit into the add method of the fruitList, however, fruitlist isn't technically a list of fruits anymore given this senario, its a pointer to a List&lt;Apple&gt;. So in this flawed example, I could now call fruitList.Add(new Orange()); which would now be a <em>runtime</em> error because I can't insert an Orange into a List&lt;Apple&gt;. Bad. (In C# however, there is an edge case where this sort of error can occur with arrays. For instance, if you have a object[] objarray = new string[10]; you can then assign a fruit to one of the slots and cause a runtime exception. For more detail on this, see Erick Lipperts post on <a href="http://blogs.msdn.com/ericlippert/archive/2007/10/17/covariance-and-contravariance-in-c-part-two-array-covariance.aspx">Covariance and Contravariance in C# arrays</a>) So we have two things that should be solved. We know that there are certain situations where IEnumerable&lt;X&gt; should be assignable to IEnumerable&lt;T&gt;, specifically when X is a subclass of T, but we also realize that something like IList&lt;X&gt; should not be assignable to a variable of IList&lt;T&gt;.</p>
<h4>C# 4.0</h4>

<p>Enter variance modifiers for generic types that have now been introduced in C# 4.0.</p>

<strong>out</strong> and <strong>in</strong>.

<p>First, these can only be applied to generic type parameters of interfaces and delegates, <strong>in</strong> can only be applied to generic parameters that are contra-variant or invariant valid, and <strong>out </strong> can only be applied to generic parameters that are co-variant or invariant valid.</p>

<p>Gulp.</p>

<p>First, invariance, contra-variance, and covariance. In terms of types, if I have T1 and T2, those types are Invariant if they are the same type. For instance, a Fruit and a Fruit are invariant, a Fruit and an Apple is not invariant even though a Fruit variable can hold an Apple object.</p>

<p>Co-variant is where the inheritance chains are kept, if I have T1 and T2, the <strong>projection</strong> of T1 to T2 is covariant if T2 is lower in the inheritance chain than T1. For instance, a Fruit to Apple is Co-variant because Apple is an instance of Fruit.</p>

<p>Contra-variant is where the inheritance chain is reversed, if I have T1 and T2, the <strong>projection</strong> of T1 to T2 is contra-variant if T2 is higher up the inheritance chain than T1. For instance, an Apple to Fruit is contra-variant because Apple is an instance of Fruit, the relationship is reversed, flipped.</p>

<p>So, it allows me to do the following in C# 4.0 with the new variant structure:</p>
<div style="line-height: normal;background-color:#f8f8f8; border: 1px solid #aaaaaa; padding: 5px;">
<pre class="csharp">    var fruitBasket = <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Basket&lt;Fruit&gt;<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
    var Tree = <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Tree<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
    fruitBasket.<span style="color: #0000FF;">Contents</span> = tree.<span style="color: #0000FF;">PickApples</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;</pre>
</div>
<p>Because IEnumerable is defined as follows:</p>
<div style="line-height: normal;background-color:#f8f8f8; border: 1px solid #aaaaaa; padding: 5px;">
<pre class="csharp">    IEnumerable&lt;out T&gt; <span style="color: #000000;">&#123;</span> <span style="color: #008080; font-style: italic;">/* .. */</span> <span style="color: #000000;">&#125;</span></pre>
</div>
<p>Remembering that out is co-variant because it can return the item or a subclass of that item, in this case PickApples() is returning an IEnumerable<T> that is lower in the inheritance chain than the variable it's being assigned to (by lower, I mean that its a subclass, or sub-sub..n class of the other object)</p>

<p>To demonstrate a class with contra-variance with an <strong>in</strong> parameter, lets say we have an interface and classes like so:</p>
<div style="line-height: normal;background-color:#f8f8f8; border: 1px solid #aaaaaa; padding: 5px;">
<pre class="csharp">    IPieMaker&lt;in T&gt; where T : Fruit
    <span style="color: #000000;">&#123;</span>
        Pie MakePie<span style="color: #000000;">&#40;</span>IEnumerable&lt;T&gt; fruits<span style="color: #000000;">&#41;</span>;
    <span style="color: #000000;">&#125;</span>
&nbsp;
    ApplePieMaker : IPieMaker&lt;Apple&gt; <span style="color: #000000;">&#123;</span> <span style="color: #008080; font-style: italic;">/* ... Some implementation ...*/</span> <span style="color: #000000;">&#125;</span>
    FruitPieMaker : IPieMaker&lt;Fruit&gt; <span style="color: #000000;">&#123;</span> <span style="color: #008080; font-style: italic;">/* ... Some implementation ...*/</span> <span style="color: #000000;">&#125;</span></pre>
</div>
<p>Now, because the input parameter is contra-variant, I can have a variable declaration like so:</p>
<div style="line-height: normal;background-color:#f8f8f8; border: 1px solid #aaaaaa; padding: 5px;">
<pre class="csharp">    IPieMaker&lt;Apple&gt; applePieMaker = <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> FruitPieMaker<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;</pre>
</div>
<p>Wait. Seem odd? Because T is not specifying what Pie we are making only what is put IN to make the pie, I can put apples into a FruitPieMaker. It’s contra-variant.</p>

<p>Try and wrap you head around that :)</p>

<p><em>Note: There's a good possibility that I didn't accurately describe the terms covariance and contra-variance in relation to mathematical projection and ordering, corrections and better descriptions are greatly appreciated.</em></p>

<h4>Additional Links:</h4>
<ul>
	<li>Discord &amp; Rhyme: <a href="http://kohari.org/2008/10/28/generic-variance-in-c-40/">http://kohari.org/2008/10/28/generic-variance-in-c-40/</a></li>
	<li>Erick Lippert: <a href="http://blogs.msdn.com/ericlippert">http://blogs.msdn.com/ericlippert</a></li>
	<li>Eric Lipperts Blog posts on the subject: <a href="http://blogs.msdn.com/ericlippert/archive/tags/Covariance+and+Contravariance/default.aspx">http://blogs.msdn.com/ericlippert/archive/tags/Covariance+and+Contravariance/default.aspx</a></li>
	<li>Specific Posts by Eric Lippert:
<ul>
	<li><a href="http://blogs.msdn.com/ericlippert/archive/2009/11/30/what-s-the-difference-between-covariance-and-assignment-compatibility.aspx">http://blogs.msdn.com/ericlippert/archive/2009/11/30/what-s-the-difference-between-covariance-and-assignment-compatibility.aspx</a></li>
	<li><a href="http://blogs.msdn.com/ericlippert/archive/2007/11/02/covariance-and-contravariance-in-c-part-nine-breaking-changes.aspx">http://blogs.msdn.com/ericlippert/archive/2007/11/02/covariance-and-contravariance-in-c-part-nine-breaking-changes.aspx</a></li>
	<li><a href="http://blogs.msdn.com/ericlippert/archive/2007/10/17/covariance-and-contravariance-in-c-part-two-array-covariance.aspx">http://blogs.msdn.com/ericlippert/archive/2007/10/17/covariance-and-contravariance-in-c-part-two-array-covariance.aspx</a></li>
	<li><a href="http://blogs.msdn.com/ericlippert/archive/2009/09/21/why-do-ref-and-out-parameters-not-allow-type-variation.aspx">http://blogs.msdn.com/ericlippert/archive/2009/09/21/why-do-ref-and-out-parameters-not-allow-type-variation.aspx</a></li>
</ul>
</li>
	<li>Future of C#: <a href="http://code.msdn.microsoft.com/csharpfuture">http://code.msdn.microsoft.com/csharpfuture</a></li>
</ul><img src="http://feeds.feedburner.com/~r/paulrohdecom/~4/0j3qLhR0wMs" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.paulrohde.com/the-evolution-of-generics-in-c-4-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.paulrohde.com/the-evolution-of-generics-in-c-4-0/</feedburner:origLink></item>
		<item>
		<title>New Toys</title>
		<link>http://feedproxy.google.com/~r/paulrohdecom/~3/ODJue10j7qQ/</link>
		<comments>http://www.paulrohde.com/new-toys/#comments</comments>
		<pubDate>Thu, 03 Dec 2009 06:42:37 +0000</pubDate>
		<dc:creator>Paul Rohde</dc:creator>
				<category><![CDATA[Life]]></category>
		<category><![CDATA[Photography]]></category>
		<category><![CDATA[5D Mk II]]></category>
		<category><![CDATA[camera]]></category>
		<category><![CDATA[Canon]]></category>
		<category><![CDATA[Canon 5D Mk II]]></category>
		<category><![CDATA[First Shot]]></category>
		<category><![CDATA[Portrait]]></category>
		<category><![CDATA[utah]]></category>

		<guid isPermaLink="false">http://www.paulrohde.com/?p=1244</guid>
		<description><![CDATA[As some of you may (Or may not) know, I&#8217;ve been saving up and finally bought myself a new 5D Mk II Camera while I was out in Utah! And so, I present to you the first picture taken with this awesome new piece of precision equipment:


I&#8217;m going to have so much fun with this [...]]]></description>
			<content:encoded><![CDATA[<p>As some of you may (Or may not) know, I&#8217;ve been saving up and finally bought myself a new 5D Mk II Camera while I was out in Utah! And so, I present to you the first picture taken with this awesome new piece of precision equipment:</p>
<p><a href="http://www.paulrohde.com/wordpress/wp-content/uploads/2009/12/20091111_PaulRohde_5DMkIIShot1_IMG_0001.jpg" rel="lightbox"><img src="http://www.paulrohde.com/wordpress/wp-content/uploads/2009/12/20091111_PaulRohde_5DMkIIShot1_IMG_0001.jpg" alt="20091111_PaulRohde_5DMkIIShot1_IMG_0001" title="20091111_PaulRohde_5DMkIIShot1_IMG_0001" width="800" height="533" class="alignnone size-full wp-image-1245" /></a></p>
<p><br style="clear: both;" /></p>
<p>I&#8217;m going to have so much fun with this thing, watch out!</p>
<p>- Paul Rohde</p>
<img src="http://feeds.feedburner.com/~r/paulrohdecom/~4/ODJue10j7qQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.paulrohde.com/new-toys/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.paulrohde.com/new-toys/</feedburner:origLink></item>
		<item>
		<title>Native Glass Windows with WPF in Windows 7 / Vista</title>
		<link>http://feedproxy.google.com/~r/paulrohdecom/~3/Qipvi8Z7ek0/</link>
		<comments>http://www.paulrohde.com/native-glass-with-wpf/#comments</comments>
		<pubDate>Tue, 01 Dec 2009 03:43:25 +0000</pubDate>
		<dc:creator>Paul Rohde</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Aero]]></category>
		<category><![CDATA[Desktop Window Manager]]></category>
		<category><![CDATA[DLLImport]]></category>
		<category><![CDATA[glass]]></category>
		<category><![CDATA[InterKnowlogy]]></category>
		<category><![CDATA[RECESS]]></category>
		<category><![CDATA[vista]]></category>
		<category><![CDATA[Windows 7]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://www.paulrohde.com/?p=1227</guid>
		<description><![CDATA[One of the awesome benefits of working at InterKnowlogy is that we get time to do what we call RECESS:  Research and Experimental Coding to Enhance Software Skills. It&#8217;s a 4 hour time span where we can work on interesting technologies to enhance, grow, and keep up on the latest technologies and methodologies. It [...]]]></description>
			<content:encoded><![CDATA[<p>One of the awesome benefits of working at <a href="http://www.interknowlogy.com">InterKnowlogy</a> is that we get time to do what we call RECESS:  <strong>R</strong>esearch and <strong>E</strong>xperimental <strong>C</strong>oding to <strong>E</strong>nhance <strong>S</strong>oftware <strong>S</strong>kills. It&#8217;s a 4 hour time span where we can work on interesting technologies to enhance, grow, and keep up on the latest technologies and methodologies. It keeps us sharp, interested, and many of our demos have come from these short code jams.</p>
<p>Over the past few weeks I&#8217;ve wanted to figure out how to add or extend glass into my application like you see in Word (2010 preview):</p>
<p><a href="http://www.paulrohde.com/wordpress/wp-content/uploads/2009/11/Glass.PNG" rel="lightbox"><img src="http://www.paulrohde.com/wordpress/wp-content/uploads/2009/11/Glass.PNG" alt="Glass" title="Glass" width="279" height="76" class="alignnone size-full wp-image-1228" /></a></p>
<p>As you can see, the whole title bar area is seamlessly integrated into the look and feel of windows, it feels native, its got that cool semi-transparent blur-the-background effect and everything. So come RECESS I did some research and pieced together what you&#8217;d need to get an effect like this.</p>
<div style="line-height: normal;background-color:#f8f8f8; border: 1px solid #aaaaaa; padding: 5px;">
<h5>DesktopWindowManagerAPI.cs</h5>
<pre class="csharp">&nbsp;
<span style="color: #0600FF;">using</span> <span style="color: #000000;">System</span>.<span style="color: #0000FF;">Runtime</span>.<span style="color: #0000FF;">InteropServices</span>;
<span style="color: #0600FF;">using</span> <span style="color: #000000;">System</span>.<span style="color: #0000FF;">Windows</span>;
<span style="color: #0600FF;">using</span> <span style="color: #000000;">System</span>.<span style="color: #0000FF;">Windows</span>.<span style="color: #0000FF;">Interop</span>;
<span style="color: #0600FF;">using</span> <span style="color: #000000;">System</span>.<span style="color: #0000FF;">Windows</span>.<span style="color: #0000FF;">Media</span>;
<span style="color: #0600FF;">using</span> Codelogic.<span style="color: #0000FF;">Windows</span>.<span style="color: #0000FF;">Native</span>.<span style="color: #0000FF;">APIManagedExceptions</span>;
&nbsp;
<span style="color: #0600FF;">namespace</span> Codelogic.<span style="color: #0000FF;">Windows</span>.<span style="color: #0000FF;">Native</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">class</span> DesktopWindowManagerAPI
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">void</span> AllGlassWindow<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span> Window window<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            ExtendFrameIntoClientArea<span style="color: #000000;">&#40;</span>window, <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Thickness<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">-1</span><span style="color: #000000;">&#41;</span>, <span style="color: #0600FF;">false</span><span style="color: #000000;">&#41;</span>;
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">void</span> ExtendFrameIntoClientArea<span style="color: #000000;">&#40;</span>Window window, Thickness thickness<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            ExtendFrameIntoClientArea<span style="color: #000000;">&#40;</span>window, thickness, <span style="color: #0600FF;">false</span><span style="color: #000000;">&#41;</span>;
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">void</span> ExtendFrameIntoClientArea<span style="color: #000000;">&#40;</span>Window window, Thickness thickness, <span style="color: #FF0000;">bool</span> exceptionOnFail<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            var compEnabled = IsCompositionEnabled<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>exceptionOnFail &amp;&amp; !compEnabled<span style="color: #000000;">&#41;</span>
                <span style="color: #0600FF;">throw</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> DWMNotEnabledException<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>exceptionOnFail &amp;&amp; !window.<span style="color: #0000FF;">IsInitialized</span><span style="color: #000000;">&#41;</span>
                <span style="color: #0600FF;">throw</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> WindowNotLoadedException<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>!compEnabled<span style="color: #000000;">&#41;</span> <span style="color: #0600FF;">return</span>;
&nbsp;
            var margins = thickness.<span style="color: #0000FF;">ToDWMMargins</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
            var windowPointer = <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> WindowInteropHelper<span style="color: #000000;">&#40;</span>window<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Handle</span>;
&nbsp;
            <span style="color: #008080; font-style: italic;">//convert the background to nondrawing</span>
            var mainWindowHwnd = HwndSource.<span style="color: #0000FF;">FromHwnd</span><span style="color: #000000;">&#40;</span>windowPointer<span style="color: #000000;">&#41;</span>;
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>mainWindowHwnd != <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
                mainWindowHwnd.<span style="color: #0000FF;">CompositionTarget</span>.<span style="color: #0000FF;">BackgroundColor</span> = Color.<span style="color: #0000FF;">FromArgb</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">0</span>, <span style="color: #FF0000;">0</span>, <span style="color: #FF0000;">0</span>, <span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span>;
&nbsp;
            <span style="color: #0600FF;">try</span>
            <span style="color: #000000;">&#123;</span>
                DwmExtendFrameIntoClientArea<span style="color: #000000;">&#40;</span>windowPointer, <span style="color: #0600FF;">ref</span> margins<span style="color: #000000;">&#41;</span>;
            <span style="color: #000000;">&#125;</span>
            <span style="color: #0600FF;">catch</span> <span style="color: #000000;">&#40;</span>DllNotFoundException<span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                window.<span style="color: #0000FF;">Background</span> = Brushes.<span style="color: #0000FF;">White</span>;
            <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">bool</span> IsCompositionEnabled<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">try</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #0600FF;">return</span> DwmIsCompositionEnabled<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
            <span style="color: #000000;">&#125;</span>
            <span style="color: #0600FF;">catch</span> <span style="color: #000000;">&#40;</span>DllNotFoundException<span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #0600FF;">return</span> <span style="color: #0600FF;">false</span>;
            <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #008080;">#region WPF to Native</span>
&nbsp;
        <span style="color: #0600FF;">private</span> <span style="color: #0600FF;">static</span> DWMMargins ToDWMMargins<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span> Thickness t<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            var rtrn = <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> DWMMargins<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
            rtrn.<span style="color: #0000FF;">Top</span> = <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span><span style="color: #000000;">&#41;</span>t.<span style="color: #0000FF;">Top</span>;
            rtrn.<span style="color: #0000FF;">Bottom</span> = <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span><span style="color: #000000;">&#41;</span>t.<span style="color: #0000FF;">Bottom</span>;
            rtrn.<span style="color: #0000FF;">Left</span> = <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span><span style="color: #000000;">&#41;</span>t.<span style="color: #0000FF;">Left</span>;
            rtrn.<span style="color: #0000FF;">Right</span> = <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span><span style="color: #000000;">&#41;</span>t.<span style="color: #0000FF;">Right</span>;
&nbsp;
            <span style="color: #0600FF;">return</span> rtrn;
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #008080;">#endregion</span>
&nbsp;
        <span style="color: #008080;">#region Native Interop</span>
&nbsp;
        <span style="color: #000000;">&#91;</span>StructLayout<span style="color: #000000;">&#40;</span>LayoutKind.<span style="color: #0000FF;">Sequential</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #0600FF;">private</span> <span style="color: #FF0000;">struct</span> DWMMargins
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">int</span> Left;
            <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">int</span> Right;
            <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">int</span> Top;
            <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">int</span> Bottom;
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// Extends an hwind's frame into the client area by the specified margins.</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;hwnd&quot;&gt;Integer pointer to the window to change the glass area on.&lt;/param&gt;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;margins&quot;&gt;Margins, what to set each side to&lt;/param&gt;</span>
        <span style="color: #000000;">&#91;</span>DllImport<span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;dwmapi.dll&quot;</span>, PreserveSig = <span style="color: #0600FF;">false</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #0600FF;">private</span> <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">extern</span> <span style="color: #0600FF;">void</span> DwmExtendFrameIntoClientArea<span style="color: #000000;">&#40;</span>IntPtr hwnd, <span style="color: #0600FF;">ref</span> DWMMargins margins<span style="color: #000000;">&#41;</span>;
&nbsp;
        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// Checks to see if the Desktop window manager is enabled.</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #000000;">&#91;</span>DllImport<span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;dwmapi.dll&quot;</span>, PreserveSig = <span style="color: #0600FF;">false</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #0600FF;">private</span> <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">extern</span> <span style="color: #FF0000;">bool</span> DwmIsCompositionEnabled<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
        <span style="color: #008080;">#endregion</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;</pre>
</div>
<p>Alright, lets begin breaking this down.</p>
<div style="line-height: normal;background-color:#f8f8f8; border: 1px solid #aaaaaa; padding: 5px;">
<h5>DesktopWindowManagerAPI.cs</h5>
<pre class="csharp">&nbsp;
        <span style="color: #000000;">&#91;</span>StructLayout<span style="color: #000000;">&#40;</span>LayoutKind.<span style="color: #0000FF;">Sequential</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #0600FF;">private</span> <span style="color: #FF0000;">struct</span> DWMMargins
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">int</span> Left;
            <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">int</span> Right;
            <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">int</span> Top;
            <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">int</span> Bottom;
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #000000;">&#91;</span>DllImport<span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;dwmapi.dll&quot;</span>, PreserveSig = <span style="color: #0600FF;">false</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #0600FF;">private</span> <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">extern</span> <span style="color: #0600FF;">void</span> DwmExtendFrameIntoClientArea<span style="color: #000000;">&#40;</span>IntPtr hwnd, <span style="color: #0600FF;">ref</span> DWMMargins margins<span style="color: #000000;">&#41;</span>;
&nbsp;
        <span style="color: #000000;">&#91;</span>DllImport<span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;dwmapi.dll&quot;</span>, PreserveSig = <span style="color: #0600FF;">false</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #0600FF;">private</span> <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">extern</span> <span style="color: #FF0000;">bool</span> DwmIsCompositionEnabled<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;</pre>
</div>
<p>First, Windows 7 and Vista provide us with the <a  href="http://en.wikipedia.org/wiki/Desktop_Window_Manager">Desktop Window Manager</a> which was first included in Vista and continues on into Windows 7, it manages all the cool graphical windowing and effects you see in those operating systems. It also gives us an API dll to access these all the features, including many that are unavailable in WPF. </p>
<p>The first declaration you see sets up the data type that the DLL uses internally to represent Left, Right, Top, and Bottom glass margins. The others are pointers to unmanaged (non .NET) methods in the DLL. <em>DwmExtendFrameIntoClientArea</em> is the method that allows me to adjust how far in the glass extends in to the client drawable area, and DwmIsCompositionEnabled tells me if Aero Glass is enabled.</p>
<div style="line-height: normal;background-color:#f8f8f8; border: 1px solid #aaaaaa; padding: 5px;">
<h5>DesktopWindowManagerAPI.cs</h5>
<pre class="csharp">&nbsp;
        <span style="color: #0600FF;">private</span> <span style="color: #0600FF;">static</span> DWMMargins ToDWMMargins<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span> Thickness t<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            var rtrn = <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> DWMMargins<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
            rtrn.<span style="color: #0000FF;">Top</span> = <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span><span style="color: #000000;">&#41;</span>t.<span style="color: #0000FF;">Top</span>;
            rtrn.<span style="color: #0000FF;">Bottom</span> = <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span><span style="color: #000000;">&#41;</span>t.<span style="color: #0000FF;">Bottom</span>;
            rtrn.<span style="color: #0000FF;">Left</span> = <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span><span style="color: #000000;">&#41;</span>t.<span style="color: #0000FF;">Left</span>;
            rtrn.<span style="color: #0000FF;">Right</span> = <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span><span style="color: #000000;">&#41;</span>t.<span style="color: #0000FF;">Right</span>;
&nbsp;
            <span style="color: #0600FF;">return</span> rtrn;
        <span style="color: #000000;">&#125;</span>
&nbsp;</pre>
</div>
<p>A simple extension method (denoted by the &#8216;this&#8217; in front of the Thickness t, it allows me to write the declaration as though the method were part of the Thickness class, so if I have a thickness variable <em>thick</em> I could convert it to a </em>DWMMargins</em> type by writing <em>var margins = thick.ToDWMMargins();</em>) it converts a WPF Thickness object to the internal DWMMargins struct.</p>
<div style="line-height: normal;background-color:#f8f8f8; border: 1px solid #aaaaaa; padding: 5px;">
<h5>DesktopWindowManagerAPI.cs</h5>
<pre class="csharp">&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">void</span> ExtendFrameIntoClientArea<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span> Window window, Thickness thickness<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            ExtendFrameIntoClientArea<span style="color: #000000;">&#40;</span>window, thickness, <span style="color: #0600FF;">false</span><span style="color: #000000;">&#41;</span>;
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">void</span> ExtendFrameIntoClientArea<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span> Window window, Thickness thickness, <span style="color: #FF0000;">bool</span> exceptionOnFail<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            var compEnabled = IsCompositionEnabled<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>exceptionOnFail &amp;&amp; !compEnabled<span style="color: #000000;">&#41;</span>
                <span style="color: #0600FF;">throw</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> DWMNotEnabledException<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>exceptionOnFail &amp;&amp; !window.<span style="color: #0000FF;">IsInitialized</span><span style="color: #000000;">&#41;</span>
                <span style="color: #0600FF;">throw</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> WindowNotLoadedException<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>!compEnabled<span style="color: #000000;">&#41;</span> <span style="color: #0600FF;">return</span>;
&nbsp;
            var margins = thickness.<span style="color: #0000FF;">ToDWMMargins</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
            var windowPointer = <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> WindowInteropHelper<span style="color: #000000;">&#40;</span>window<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Handle</span>;
&nbsp;
            <span style="color: #008080; font-style: italic;">//convert the background to nondrawing</span>
            var mainWindowHwnd = HwndSource.<span style="color: #0000FF;">FromHwnd</span><span style="color: #000000;">&#40;</span>windowPointer<span style="color: #000000;">&#41;</span>;
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>mainWindowHwnd != <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
                mainWindowHwnd.<span style="color: #0000FF;">CompositionTarget</span>.<span style="color: #0000FF;">BackgroundColor</span> = Color.<span style="color: #0000FF;">FromArgb</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">0</span>, <span style="color: #FF0000;">0</span>, <span style="color: #FF0000;">0</span>, <span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span>;
&nbsp;
            <span style="color: #0600FF;">try</span>
            <span style="color: #000000;">&#123;</span>
                DwmExtendFrameIntoClientArea<span style="color: #000000;">&#40;</span>windowPointer, <span style="color: #0600FF;">ref</span> margins<span style="color: #000000;">&#41;</span>;
            <span style="color: #000000;">&#125;</span>
            <span style="color: #0600FF;">catch</span> <span style="color: #000000;">&#40;</span>DllNotFoundException<span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                window.<span style="color: #0000FF;">Background</span> = Brushes.<span style="color: #0000FF;">White</span>;
            <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">bool</span> IsCompositionEnabled<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">try</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #0600FF;">return</span> DwmIsCompositionEnabled<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
            <span style="color: #000000;">&#125;</span>
            <span style="color: #0600FF;">catch</span> <span style="color: #000000;">&#40;</span>DllNotFoundException<span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #0600FF;">return</span> <span style="color: #0600FF;">false</span>;
            <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;</pre>
</div>
<p>Finally I wrapped native methods with .NET versions that take a more useful WPF Window class and WPF Thickness class for the ExtendFrameIntoClientArea method. Internally it checks to make sure the window is initialized and that Desktop Composition is enabled, gets the integer pointer to the window, resets the background, and then calls the native method to extend the glass into the drawable (client) area of the window. Two custom classes not shown are the DWMNotEnabledException class and the WindowNotLoadedException class, which are thrown if something goes wrong.</p>
<p>That&#8217;s all well and good, but wouldn&#8217;t it be nice if we didn&#8217;t have to worry about all these calls to this custom DesktopWindowManagerAPI class and could just set how much we wanted the glass to extend into the client area? Or bind it to something so that the glass area expands or contracts when a value changes?</p>
<p>I thought so:</p>
<div style="line-height: normal;background-color:#f8f8f8; border: 1px solid #aaaaaa; padding: 5px;">
<h5>GlassWindow.cs</h5>
<pre class="csharp">&nbsp;
<span style="color: #0600FF;">using</span> <span style="color: #000000;">System</span>.<span style="color: #0000FF;">Windows</span>;
<span style="color: #0600FF;">using</span> Codelogic.<span style="color: #0000FF;">Windows</span>.<span style="color: #0000FF;">Native</span>;
&nbsp;
<span style="color: #0600FF;">namespace</span> Codelogic.<span style="color: #0000FF;">Controls</span>.<span style="color: #0000FF;">WPF</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> GlassWindow : Window
    <span style="color: #000000;">&#123;</span>
         <span style="color: #008080;">#region Glass Thickness Dependency Property</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">readonly</span> DependencyProperty GlassThicknessProperty = DependencyProperty.<span style="color: #0000FF;">Register</span><span style="color: #000000;">&#40;</span>
            <span style="color: #808080;">&quot;GlassThickness&quot;</span>, <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #000000;">&#40;</span>Thickness<span style="color: #000000;">&#41;</span>, <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #000000;">&#40;</span>GlassWindow<span style="color: #000000;">&#41;</span>, <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> PropertyMetadata<span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Thickness<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">0</span>, <span style="color: #FF0000;">0</span>, <span style="color: #FF0000;">0</span>, <span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span>, GlassThicknessChanged<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
        <span style="color: #008080; font-style: italic;">//when the thickness changes, apply the change to the window.</span>
        <span style="color: #0600FF;">private</span> <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">void</span> GlassThicknessChanged<span style="color: #000000;">&#40;</span>DependencyObject d, DependencyPropertyChangedEventArgs e<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>GlassWindow<span style="color: #000000;">&#41;</span>d<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">UpdateGlassState</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// Local property for Glass thickness.</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #0600FF;">public</span> Thickness GlassThickness
        <span style="color: #000000;">&#123;</span>
            get <span style="color: #000000;">&#123;</span> <span style="color: #0600FF;">return</span> <span style="color: #000000;">&#40;</span>Thickness<span style="color: #000000;">&#41;</span>GetValue<span style="color: #000000;">&#40;</span>GlassThicknessProperty<span style="color: #000000;">&#41;</span>; <span style="color: #000000;">&#125;</span>
            set <span style="color: #000000;">&#123;</span> SetValue<span style="color: #000000;">&#40;</span>GlassThicknessProperty, value<span style="color: #000000;">&#41;</span>; <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">readonly</span> DependencyProperty IsAllGlassProperty = DependencyProperty.<span style="color: #0000FF;">Register</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;IsAllGlass&quot;</span>,
                                                                                                   <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">bool</span><span style="color: #000000;">&#41;</span>,
                                                                                                   <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #000000;">&#40;</span>GlassWindow<span style="color: #000000;">&#41;</span>,
                                                                                                   <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> PropertyMetadata<span style="color: #000000;">&#40;</span>
                                                                                                       OnIsAllGlassChanged<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
        <span style="color: #0600FF;">private</span> <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">void</span> OnIsAllGlassChanged<span style="color: #000000;">&#40;</span>DependencyObject d, DependencyPropertyChangedEventArgs e<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>GlassWindow<span style="color: #000000;">&#41;</span>d<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">UpdateGlassState</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">bool</span> IsAllGlass
        <span style="color: #000000;">&#123;</span>
            get <span style="color: #000000;">&#123;</span> <span style="color: #0600FF;">return</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">bool</span><span style="color: #000000;">&#41;</span>GetValue<span style="color: #000000;">&#40;</span>IsAllGlassProperty<span style="color: #000000;">&#41;</span>; <span style="color: #000000;">&#125;</span>
            set <span style="color: #000000;">&#123;</span> SetValue<span style="color: #000000;">&#40;</span>IsAllGlassProperty, value<span style="color: #000000;">&#41;</span>; <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">private</span> <span style="color: #0600FF;">void</span> UpdateGlassState<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>!IsInitialized<span style="color: #000000;">&#41;</span> <span style="color: #0600FF;">return</span>;
&nbsp;
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>IsAllGlass<span style="color: #000000;">&#41;</span>
                <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">AllGlassWindow</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
            <span style="color: #0600FF;">else</span>
                <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">ExtendFrameIntoClientArea</span><span style="color: #000000;">&#40;</span>GlassThickness<span style="color: #000000;">&#41;</span>;
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">static</span> GlassWindow<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            DefaultStyleKeyProperty.<span style="color: #0000FF;">OverrideMetadata</span><span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #000000;">&#40;</span>GlassWindow<span style="color: #000000;">&#41;</span>, <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> FrameworkPropertyMetadata<span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #000000;">&#40;</span>GlassWindow<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">override</span> <span style="color: #0600FF;">void</span> OnSourceInitialized<span style="color: #000000;">&#40;</span>EventArgs e<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">base</span>.<span style="color: #0000FF;">OnSourceInitialized</span><span style="color: #000000;">&#40;</span>e<span style="color: #000000;">&#41;</span>;
            UpdateGlassState<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;</pre>
</div>
<p>Alright, this class creates a WPF Window subclass, adds a dependency property for GlassThickness and a change handler that internally calls the DesktopWindowManagerAPI.ExtendFrameIntoClientArea if the window is loaded or attaches an event handler if the window is not loaded. Now all you have to do is change your window class over to a GlassWindow class, set the thickness and you rock and roll!</p>
<div style="line-height: normal;background-color:#f8f8f8; border: 1px solid #aaaaaa; padding: 5px;">
<h5>GlassDemoWindow.cs</h5>
<pre class="xml">&nbsp;
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;WPF:GlassWindow</span> <span style="color: #000066;">x:Class</span>=<span style="color: #ff0000;">&quot;Codelogic.Controls.WPF.Demo.GlassDemoWindow&quot;</span>
    <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;</span>
    <span style="color: #000066;">xmlns:x</span>=<span style="color: #ff0000;">&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;</span>
    <span style="color: #000066;">xmlns:WPF</span>=<span style="color: #ff0000;">&quot;clr-namespace:Codelogic.Controls.WPF;assembly=Codelogic.Controls.WPF&quot;</span>
    <span style="color: #000066;">Title</span>=<span style="color: #ff0000;">&quot;Glass Window Demo&quot;</span>
    <span style="color: #000066;">Height</span>=<span style="color: #ff0000;">&quot;300&quot;</span>
    <span style="color: #000066;">Width</span>=<span style="color: #ff0000;">&quot;300&quot;</span>
    <span style="color: #000066;">GlassThickness</span>=<span style="color: #ff0000;">&quot;10000&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;Grid<span style="font-weight: bold; color: black;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;InkCanvas</span> <span style="color: #000066;">HorizontalAlignment</span>=<span style="color: #ff0000;">&quot;Stretch&quot;</span> <span style="color: #000066;">VerticalAlignment</span>=<span style="color: #ff0000;">&quot;Stretch&quot;</span> <span style="color: #000066;">Background</span>=<span style="color: #ff0000;">&quot;Transparent&quot;</span> <span style="font-weight: bold; color: black;">/&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/Grid<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/WPF:GlassWindow<span style="font-weight: bold; color: black;">&gt;</span></span></span>
&nbsp;</pre>
</div>
<p><a href="http://www.paulrohde.com/wordpress/wp-content/uploads/2009/11/Glass-Ink.PNG" rel="lightbox"><img src="http://www.paulrohde.com/wordpress/wp-content/uploads/2009/11/Glass-Ink.PNG" alt="Glass Ink" title="Glass Ink" width="565" height="211" class="alignnone size-full wp-image-1235" /></a></p>
<p>Something I have not yet done that I would like to do is figure out how to add functional buttons into the title-bar of an application. If you remember the Microsoft Word snippet from above there&#8217;s save / undo / redo buttons in the title bar. But that will have to be a later post.</p>
<p>Hope someone enjoyed my Glassy exploration,</p>
<p><strong>Updates:</strong></p>
<ul>
<li><em>2 Dec 2009</em>
<ul>
<li>Changed ExtendFrameIntoClientArea to check to see if window.IsInitialized instead of window.IsLoaded</li>
<li>Updated GlassWindow to override OnSourceInitialized instead of adding an event handler for Loaded</li>
<li>Added in a method that turns the entire client area into glass by setting the margins to -1.</li>
<li>Changed Glass Window to have a Boolean Dependency property to turn it all glass.</li>
</ul>
</li>
</ul>
<p>- Paul Rohde</p>
<img src="http://feeds.feedburner.com/~r/paulrohdecom/~4/Qipvi8Z7ek0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.paulrohde.com/native-glass-with-wpf/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.paulrohde.com/native-glass-with-wpf/</feedburner:origLink></item>
		<item>
		<title>My Neumont Educational History Part II</title>
		<link>http://feedproxy.google.com/~r/paulrohdecom/~3/bfm8KRcRGnU/</link>
		<comments>http://www.paulrohde.com/my-neumont-educational-history-part-ii/#comments</comments>
		<pubDate>Sat, 17 Oct 2009 00:03:28 +0000</pubDate>
		<dc:creator>Paul Rohde</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Life]]></category>
		<category><![CDATA[Administration]]></category>
		<category><![CDATA[Campus]]></category>
		<category><![CDATA[Classes]]></category>
		<category><![CDATA[College Campus]]></category>
		<category><![CDATA[College Mail]]></category>
		<category><![CDATA[Culture]]></category>
		<category><![CDATA[Education]]></category>
		<category><![CDATA[Financial Aid]]></category>
		<category><![CDATA[Geek]]></category>
		<category><![CDATA[Guideance]]></category>
		<category><![CDATA[Help]]></category>
		<category><![CDATA[Loans]]></category>
		<category><![CDATA[neumont]]></category>
		<category><![CDATA[Neumont University]]></category>
		<category><![CDATA[News]]></category>
		<category><![CDATA[Perspective]]></category>
		<category><![CDATA[school]]></category>
		<category><![CDATA[Student]]></category>
		<category><![CDATA[University]]></category>

		<guid isPermaLink="false">http://www.paulrohde.com/?p=1219</guid>
		<description><![CDATA[After the great response I got from my previous post on my Neumont Educational History (http://www.paulrohde.com/my-neumont-educational-history/) Several e-mail, comments, and questions later, I&#8217;ve decided it&#8217;s time for a batch of Q &#038; A to answer additional questions.  I recently received an e-mail from a student that had found my website through the Neumont website, [...]]]></description>
			<content:encoded><![CDATA[<p>After the great response I got from my previous post on my Neumont Educational History (<a href="http://www.paulrohde.com/my-neumont-educational-history/">http://www.paulrohde.com/my-neumont-educational-history/</a>) Several e-mail, comments, and questions later, I&#8217;ve decided it&#8217;s time for a batch of Q &#038; A to answer additional questions.  I recently received an e-mail from a student that had found my website through the <a href="http://www.neumont.edu">Neumont website</a>, I feel it sums up many of the questions I have been asked since my previous post:</p>
<div style="line-height: normal;background-color:#f8f8f8; border: 1px solid #aaaaaa; padding: 10px 30px 15px 30px;">
<p>Mr. Rohde,</p>
<p>I am currently a high school senior at <em>[omitted]</em>. I am currently in the process of searching for colleges, and Neumont has presented itself to me as being a very unique school for computer science. Programming has been my passion since a very young age, and I hope to go to a college that has a reputable computer science program. While on the Neumont website, I happened to stumble across your blog. To be completely honest with you, your website blew me away. Your fusion of stylistic art and coding are breathtaking- I hope to one day be able to create the same sort of digital art that you have.</p>
<p>That said, I had a few questions regarding Neumont that can only be answered by an alumni. Neumont strikes me as being almost a technical school due to the nature of its program, and although the 2 year degree is definitely a bonus, I do wonder if they cut out the more &#8220;traditional&#8221; topics thus harming what would otherwise be a well-rounded education. Do you believe that they sacrificed subjects, or were classes such as literature unnecessary because they did not feed into a science degree? I also read on your blog that you debated between Neumont and Winona; were you considering any other schools at that point? How did you hear about Neumont?</p>
<p>Regarding Neumont&#8217;s atmosphere, I read about the classes that you took, but you did not particularly go into detail about the campus life. What did you like about Neumont? Were there any glaring drawbacks? How was the food?<br />
       Lastly, the administration and cost. I have read from various sources that the administration was difficult to come in contact with; especially the financial aid officers. I&#8217;m not sure as to their accuracy, so I figured a former student would be a prime source of information. Secondly, were you offered much of a financial aid package? Ultimately, my college decision depends largely on a financial aid package, and information surrounding how Neumont goes about choosing how to distribute their money is rather vague. Do you believe that Neumont was affordable? Do you still have any debts? Do they have an unduly high interest rate?</p>
<p>Since Neumont is a fairly new school with a small population, articles regarding Neumont are few and far between. As such, I believe that a former student&#8217;s opinion on the matter would be greatly influential in my decision. Any input that you could give me would be greatly appreciated.</p>
<p>Thank you for your time,</p>
<p>- Steven</p>
</div>
<p>First, many thanks for the awesome comments about the site, its one of those ongoing projects that is continually evolving and changing, so its appreciated when someone does enjoy it.</p>
<h4>Neumont is not round.</h4>
<p>Ok. Sentimental comments aside, let me do the best I can to answer your questions. Since I am a Neumont Alumni, do keep in mind that the school has been evolving over the past several years and that there have been many alterations to the main program since I started (Cohort 15, July 2007). So take what I say with a grain of salt. Get in touch with one of the Neumont Reps if you haven&#8217;t already since they *should* be able to answer more direct questions about the current state of the school and the primary CS degree program. </p>
<p>From my experience, Neumont is a very technical school, it has one degree (There was previously a business masters degree program at the school, but that has been put on hold and may or may not re-emerge), and it is very geared towards graduating high quality and hopefully well rounded CS students. Because the program is so tightly geared toward CS there are some areas and classes that I personally felt were lacking. For instance, I really wish that the mathematics program went further, by the time I started at Neumont I had already completed Calculus II at WSU (<a href="http://www.winona.edu">Winona State University</a>) and was beyond the current mathematics courses offered at Neumont. In addition, they do lack some of the general classes that form the basis for other fields of study: Chemistry, higher level Mathmatics, Physics, History, Literature, Art(To be fair, they did have an introduction photography class, and the last two quarters when I was leaving they were adding in a digital media concentration with courses that are more artistically bent). Part of my own draw away from Neumont was the fact that I wouldn&#8217;t have the opportunity to grow in some of these other areas, I love photography, art, the more classical sciences, and there&#8217;s a part of me that really does miss not having more time to explore those other subjects for my own personal interest.</p>
<p>The question about well rounded-ness really boils down to this: Why are you going to school? If your goal is to get a degree, get a full time job in business software development, I honestly cannot recommend a better school. However, if your not sure you want to do business software, if your not sure you want to even DO software, or if your not passionate enough to pursue and devote yourself to it for the two and a half years it&#8217;ll take to get through the program, Neumont is probably not the place for you.</p>
<h4>Hearing about Neumont</h4>
<p>I first heard about Neumont sometime after taking my ACT a year early and getting piles of junk mail from colleges talking about the &#8216;college decision&#8217; I would be making over the next year.</p>
<p>Right.</p>
<p>After two years of highschool at a private school I returned to being officially &#8216;home schooled&#8217; after my sophomore year, enrolled in WSU via the PSEO Program (Post Secondary Education Option, basically, if your a good enough student and would like to take classes at the local college the state will pay for the tuition and books), and then spent the following year and a half taking a full load of college classes (plus two side classes at an online school the year I started). Sometime within that college span I began receiving mail from Neumont, glanced and discarded most of it into the large bin of college spam. After receiving several more mailings I did some research, ended up being contacted by a Neumont rep, and was invited to attend their &#8216;Geek Weekend&#8217; where they flew out potential new students that were interested in the school along with a parent or guardian to visit, meet some of the students, etc&#8230; That trip was the turning point in my decision making process. During my time at WSU I was actively taking some <acronym title="Computer Science">CS</acronym> classes, most of them in Java, most little console algorithm type problems and one cool little robotics project near the end in one of my classes. After a year and a half of WSU, and having had several years of my own personal experience doing web, C++, Visual Basic, Dark Basic, building several of my own small games, and working as a student programmer at WSU doing C#, ASP.NET, and Sharepoint development, I was completely outmatched by students in their second quarter at Neumont (6 months into the program) that I met that weekend. That was cool.</p>
<p>Yes, it was a hard decision, I had a good job for where I was, I could have continued at WSU, graduated with a lot of current job experience (Read: ~4 years if I had graduated from WSU), but it wouldn&#8217;t have challenged me as much or pushed me as far as I am today.</p>
<h4>The Campus</h4>
<p>First of all, Neumont is not a normal school. They are located in an office building that&#8217;s been converted into the University as it is today. In fact, there are other companies that have offices in the same building, at least when I was there. Since I&#8217;ve been there they&#8217;ve made some additions and changes to the building, there&#8217;s now a new computer lab complete with iMacs, the common area has a pool table and a large screen TV that students will bring in and hook up their 360, Wii, or PS3 to and play games. The school does have a reasonable catering service during lunch on school days, but nothing like a normal cafeteria.  When I was leaving they were experimented with having another place come in on Fridays, so I&#8217;m not entirely sure as to the state of the school provided food. From what I&#8217;ve experienced however, most students will eventually move away from the catered food and get something nearby (which is what I eventually did), there is a Zupas across the the street and a coffee shop within walking distance, and there&#8217;s quite a few additional places a short drive away.</p>
<p>The campus &#8220;Housing&#8221; is two sets of apartments, one set is at The Falls at Hunters Pointe, the other is Sterling Village in South Jordan, both are about a 20 minute walk from the school (although most people tend take the shuttle or carpool). I was only in student housing for a year, when I first moved in, one of my roommates was also just moving in and the other was close to graduating. During second quarter after the senior in our house moved out we got a new freshman, who ended up moving out without telling any of us before the end of the quarter&#8230; Anyhow, after that first ~10 months a friend of mine and two other guy&#8217;s rented a 4 bedroom 3 story house for about what we were paying in student housing, so, I ditched Neumont housing and moved.  As far as rules and regulations go for student housing (Yes, they are regulated) they aren&#8217;t too bad, you do need to keep the apartment clean and they do have inspections. You also can&#8217;t bring weapons into the apartment (no paintball guns, swords, non-kitchen-knives, etc&#8230;).</p>
<p>As far as &#8216;life on campus&#8217; goes you have lots and lots of geeked out guys (And about a 50:1 guy to girl ratio) that live life on Mountain Dew, Guitar Hero, WoW, and DotA. They are the stereotype, and you will find them on almost every non Neumont campus you visit, but you&#8217;ll find a much higher concentration than you would elsewhere. However, there are many people there that really do take what they&#8217;re doing seriously, and are already well rounded individuals. I was never that &#8216;involved&#8217; in the geek culture. It&#8217;s cool, I like parts of it, I&#8217;ve rocked my share of Guitar Hero and Rock Band, and played my hours of Counter Strike. Still, I spent a lot of my time outside of Neumont towards the end of my time there. Most of who I considered my &#8216;good&#8217; friends were up at the University of Utah and were <em>not</em> CompSci majors. I was involved in the photographic community, I did several photowalks, met lots of photographers and models, made some good friends there. I was involved in a church (Gateway Community Church), and had several friends through that. The community is out there, but you have to go to it, it&#8217;s not going to drop into your lap as much as it would at a &#8220;normal&#8221; University.</p>
<p>If you make good friends, keep in touch, work hard, help and teach others (not just giving answers), and really strive to be a personable, well rounded individual, you will be fine.  The homework can be hard, and there are ALWAYS group projects that you&#8217;re in and will be working on. It&#8217;ll force you to deal with and work with other people and figure out how to make things work. From personal experience, it&#8217;s exactly what you&#8217;ll be doing in the real world.</p>
<h4>Administration and Cost</h4>
<p>I&#8217;m probably not the best person to answer a lot of these questions, but I&#8217;ll do what I can. Administration from my experience hasn&#8217;t been that difficult to get in touch with, I was always able to go to people and figure out what I needed when I needed it. However, I do know that in the past, people have had issues, specifically with tracking graduation credits.  There was (or is) a student written program that allows you to track your progress towards graduation that I used, and it worked well. However, I would also go in and talk directly with the student advisers on a regular basis and verify that I was doing things correctly. There have been several occasions where people have been 1-2 credits short because they thought they were taking enough credits but didn&#8217;t take the time to go and check with advisers each quarter&#8230;</p>
<p>As far as finances go, I was able to get my loans through the Department of Education and Sallie Mae with my parents as co-signers on those loans. With the economy having tanked, and quite possibly still in the tank, I&#8217;m not sure how difficult it will be to get financing, it&#8217;ll really depend on your situation. I was lucky enough to not have to worry about it much or have deal with the financial aid department at school. I do know that if I had not received loans or financing, I would have had a VERY difficult (if not impossible) time going to Neumont. Again, this is where I would get a Rep, ask very specific, very direct questions. Make sure they give you an answer, that&#8217;s what their job is.</p>
<p>Was Neumont affordable? I made it through. I will be able to pay it off with my current job over the next ~3 years, and my interest rate seems rather standard as far as student loans go.</p>
<p>Was it a lot? Yes.</p>
<p>Was it worth it? For the field I&#8217;m in, Yes. For the contacts I made, the experience I gained, Yes.</p>
<h4>Wrap Up</h4>
<p>Neumont is a great school, for business software development. For what the school is and at the time I went through the program, I don&#8217;t know of any other degree program that could trump it. It does have a very narrow focus, it&#8217;s hard, it&#8217;ll make you learn, and you&#8217;ll be better for it. Like any school, you only get out of it what you put into it and there will always be people that don&#8217;t care, don&#8217;t work, fail out, and complain to all ends of the earth about how it&#8217;s the university&#8217;s fault or how this or that caused them to _____. Fill in the blank.</p>
<p>Work hard, do your best and you&#8217;ll be fine wherever you&#8217;re at.</p>
<p>If anyone has any questions, feel free to leave a comment, call me, send me an e-mail, I&#8217;ll do my best to get back to you when I can.</p>
<p>- Paul Rohde</p>
<p><em>Note: The opinions presented here are my own and do not in any way represent the opinion or position of my Employer or that of Neumont University.</em></p>
<img src="http://feeds.feedburner.com/~r/paulrohdecom/~4/bfm8KRcRGnU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.paulrohde.com/my-neumont-educational-history-part-ii/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://www.paulrohde.com/my-neumont-educational-history-part-ii/</feedburner:origLink></item>
		<item>
		<title>Why I Shoot.</title>
		<link>http://feedproxy.google.com/~r/paulrohdecom/~3/sCOa8yaRrGc/</link>
		<comments>http://www.paulrohde.com/why-i-shoot/#comments</comments>
		<pubDate>Fri, 02 Oct 2009 06:55:47 +0000</pubDate>
		<dc:creator>Paul Rohde</dc:creator>
				<category><![CDATA[Photography]]></category>
		<category><![CDATA[accountant]]></category>
		<category><![CDATA[chris]]></category>
		<category><![CDATA[photo]]></category>
		<category><![CDATA[Portrait]]></category>
		<category><![CDATA[project 54]]></category>

		<guid isPermaLink="false">http://www.paulrohde.com/?p=1212</guid>
		<description><![CDATA[Why do I shoot?
It&#8217;s a question I often ask myself, and the answer has changed over the years, but I think it boils down to the challenge of creating. With photography there&#8217;s no limits, no end to the creative exploration, there&#8217;s always new ways to improve and better yourself.  With the recent project I&#8217;ve [...]]]></description>
			<content:encoded><![CDATA[<p>Why do I shoot?</p>
<p>It&#8217;s a question I often ask myself, and the answer has changed over the years, but I think it boils down to the challenge of creating. With photography there&#8217;s no limits, no end to the creative exploration, there&#8217;s always new ways to improve and better yourself.  With the recent project I&#8217;ve started (Which you should take a look at here: <a href="http://www.project54.net">http://www.project54.net</a>) to take 50 pictures of 50 people over 50 days with a 50 mm lens I&#8217;ve realized two things: I&#8217;m becoming more comfortable around people with my photography (asking them to do this or that and to let me shoot their picture), and I&#8217;m shooting much than just the images for my project.  Since moving out here to California I&#8217;ve slowed down and I really forgot the passion I do have for photography. It&#8217;s images like these from people that have never modeled or done any sort of photography before that make want to keep shooting.</p>
<p>So for your viewing pleasure, Chris the Accountant:</p>
<p><a href="http://www.flickr.com/photos/paulrohde/3973994748/" title="Project 54 - Day 16" target="_blank" class="flickr-image alignleft"><img src="http://farm3.static.flickr.com/2425/3973994748_6d36efd71d_o.jpg" alt="Project 54 - Day 16" class=""  /></a></p>
<p><br style="clear: both;" /></p>
<p>- Paul Rohde</p>
<img src="http://feeds.feedburner.com/~r/paulrohdecom/~4/sCOa8yaRrGc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.paulrohde.com/why-i-shoot/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.paulrohde.com/why-i-shoot/</feedburner:origLink></item>
		<item>
		<title>New Twitter Theme</title>
		<link>http://feedproxy.google.com/~r/paulrohdecom/~3/LXcLSnirXd8/</link>
		<comments>http://www.paulrohde.com/new-twitter-theme/#comments</comments>
		<pubDate>Sun, 27 Sep 2009 23:14:26 +0000</pubDate>
		<dc:creator>Paul Rohde</dc:creator>
				<category><![CDATA[Graphic Design]]></category>
		<category><![CDATA[Life]]></category>
		<category><![CDATA[Photography]]></category>
		<category><![CDATA[black and white]]></category>
		<category><![CDATA[Paul]]></category>
		<category><![CDATA[Paul Rohde]]></category>
		<category><![CDATA[Portrait]]></category>
		<category><![CDATA[Self Portrait]]></category>
		<category><![CDATA[Theme]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://www.paulrohde.com/?p=1202</guid>
		<description><![CDATA[Every now again you just get the bug to do something. 
Like taking self portraits. 
And updating your twitter theme.


- Paul Rohde
]]></description>
			<content:encoded><![CDATA[<p>Every now again you just get the bug to do something. </p>
<p>Like taking self portraits. </p>
<p>And updating your twitter theme.</p>
<p><a href="http://www.flickr.com/photos/paulrohde/3960671394/" title="New Twitter Theme '09" target="_blank" class="flickr-image alignleft"><img src="http://farm3.static.flickr.com/2456/3960671394_12549ca247_o.jpg" alt="New Twitter Theme '09" class=""  /></a></p>
<p><br style="clear: both;" /></p>
<p>- Paul Rohde</p>
<img src="http://feeds.feedburner.com/~r/paulrohdecom/~4/LXcLSnirXd8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.paulrohde.com/new-twitter-theme/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.paulrohde.com/new-twitter-theme/</feedburner:origLink></item>
		<item>
		<title>I have MMS.</title>
		<link>http://feedproxy.google.com/~r/paulrohdecom/~3/1BWvEzYuZYA/</link>
		<comments>http://www.paulrohde.com/i-have-mms/#comments</comments>
		<pubDate>Fri, 25 Sep 2009 20:21:06 +0000</pubDate>
		<dc:creator>Paul Rohde</dc:creator>
				<category><![CDATA[Life]]></category>
		<category><![CDATA[Photography]]></category>

		<guid isPermaLink="false">http://www.paulrohde.com/?p=1198</guid>
		<description><![CDATA[Finally, AT&#038;T made their fashionably late entrance for the iPhone into the world of Multimedia Messaging Services, finally no more log-into-a-website-via-a-phone-web-browsers-with-an-autogenerated-username-and-password-to-see-pictures. Finally, I can stop banging my head against the wall when someone sends me a MMS!


- Paul Rohde
]]></description>
			<content:encoded><![CDATA[<p>Finally, AT&#038;T made their fashionably late entrance for the iPhone into the world of Multimedia Messaging Services, finally no more log-into-a-website-via-a-phone-web-browsers-with-an-autogenerated-username-and-password-to-see-pictures. Finally, I can stop banging my head against the wall when someone sends me a MMS!</p>
<p><a href="http://www.flickr.com/photos/paulrohde/3954188988/" title="I have MMS." target="_blank" class="flickr-image alignleft"><img src="http://farm3.static.flickr.com/2568/3954188988_78a82d285f.jpg" alt="I have MMS." class=""  /></a></p>
<p><br style="clear: both;" /></p>
<p>- Paul Rohde</p>
<img src="http://feeds.feedburner.com/~r/paulrohdecom/~4/1BWvEzYuZYA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.paulrohde.com/i-have-mms/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.paulrohde.com/i-have-mms/</feedburner:origLink></item>
	</channel>
</rss>
