<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>Schwammy Says...</title>
    <link>http://www.blog.ingenuitynow.net/</link>
    <description>Whatever comes to mind.</description>
    <language>en-us</language>
    <copyright>Andrew Schwam</copyright>
    <lastBuildDate>Wed, 09 May 2012 01:52:49 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 1.9.6264.0</generator>
    <managingEditor>andy@ingenuitynow.net</managingEditor>
    <webMaster>andy@ingenuitynow.net</webMaster>
    <item>
      <trackback:ping>http://www.blog.ingenuitynow.net/Trackback.aspx?guid=58c6b3cb-b8e9-493d-b3f3-c68c76518fec</trackback:ping>
      <pingback:server>http://www.blog.ingenuitynow.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.blog.ingenuitynow.net/PermaLink,guid,58c6b3cb-b8e9-493d-b3f3-c68c76518fec.aspx</pingback:target>
      <dc:creator>Andrew Schwam</dc:creator>
      <wfw:comment>http://www.blog.ingenuitynow.net/CommentView,guid,58c6b3cb-b8e9-493d-b3f3-c68c76518fec.aspx</wfw:comment>
      <wfw:commentRss>http://www.blog.ingenuitynow.net/SyndicationService.asmx/GetEntryCommentsRss?guid=58c6b3cb-b8e9-493d-b3f3-c68c76518fec</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Today the Visual Studio team announced some changes to the look of Visual Studio 11.
You can read about it <a href="http://blogs.msdn.com/b/visualstudio/archive/2012/05/08/visual-studio-11-user-interface-updates-coming-in-rc.aspx" target="_blank">here</a>.
</p>
        <p>
When the Beta came out a little while back there was quite a lot of talk about the
new look for the UI. I wrote a <a href="http://www.blog.ingenuitynow.net/My+First+And+Second+Thoughts+On+Visual+Studio+11+Beta.aspx" target="_blank">blog
post</a> about it as well. Many people were pretty upset about the new “metro” look
to Visual Studio. I wasn’t completely in love with the new look at first myself. A
flood of complaints came in as people got their first look at the new skin to a familiar
tool. I think all the complaining was premature. As I stated in my blog post, once
I started using Visual Studio 11 I got used to it pretty quickly. I’ve been using
it a lot over the past month or so and I’ve even gotten to the point where I like
it more than VS 2010. However, I do think it was missing some color. Well, people
complained and Microsoft listened. I think that was pretty cool. Today the public
got a peek at the changes that have been put into the release candidate. I won’t bother
pasting images in, I think you should read about it on the <a href="http://blogs.msdn.com/b/visualstudio/archive/2012/05/08/visual-studio-11-user-interface-updates-coming-in-rc.aspx" target="_blank">Visual
Studio blog</a>. I really think that they achieved a nice balance, putting in some
color where needed to enhance the experience.
</p>
        <p>
I think it is time t move on from this topic. I’ll close with a few points:
</p>
        <ol>
          <li>
Visual Studio 11 has tons of great features. The new look is just on the surface.
People should play with it for a while and see what is inside!</li>
          <li>
Don’t be so quick to judge. I’ll admit, I had some doubts but I gave it a chance.
I think the designers made a few mistakes but they are fixing them. For instance,
the old icons were hard to read when they had borders around them. I’m glad this is
fixed. I’m glad they added some color back in to, it makes certain icons stand out
nicely. But when you give it some time you may find that these designers were also
right about of lot of their ideas. VS11 is quite easy to use.</li>
          <li>
It’s over. Stop complaining. Like many people, I don’t like the All Caps menus that
are in the latest refresh. SO WHAT? Is it really that big a deal? Is this really worth
switching over to Java and using Eclipse? Some people are actually talking like that
should be our response. Come on people, get a grip.</li>
        </ol>
        <img width="0" height="0" src="http://www.blog.ingenuitynow.net/aggbug.ashx?id=58c6b3cb-b8e9-493d-b3f3-c68c76518fec" />
      </body>
      <title>Visual Studio 11 gets some color back, now let&amp;rsquo;s move on</title>
      <guid isPermaLink="false">http://www.blog.ingenuitynow.net/PermaLink,guid,58c6b3cb-b8e9-493d-b3f3-c68c76518fec.aspx</guid>
      <link>http://www.blog.ingenuitynow.net/Visual+Studio+11+Gets+Some+Color+Back+Now+Letrsquos+Move+On.aspx</link>
      <pubDate>Wed, 09 May 2012 01:52:49 GMT</pubDate>
      <description>&lt;p&gt;
Today the Visual Studio team announced some changes to the look of Visual Studio 11.
You can read about it &lt;a href="http://blogs.msdn.com/b/visualstudio/archive/2012/05/08/visual-studio-11-user-interface-updates-coming-in-rc.aspx" target="_blank"&gt;here&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
When the Beta came out a little while back there was quite a lot of talk about the
new look for the UI. I wrote a &lt;a href="http://www.blog.ingenuitynow.net/My+First+And+Second+Thoughts+On+Visual+Studio+11+Beta.aspx" target="_blank"&gt;blog
post&lt;/a&gt; about it as well. Many people were pretty upset about the new “metro” look
to Visual Studio. I wasn’t completely in love with the new look at first myself. A
flood of complaints came in as people got their first look at the new skin to a familiar
tool. I think all the complaining was premature. As I stated in my blog post, once
I started using Visual Studio 11 I got used to it pretty quickly. I’ve been using
it a lot over the past month or so and I’ve even gotten to the point where I like
it more than VS 2010. However, I do think it was missing some color. Well, people
complained and Microsoft listened. I think that was pretty cool. Today the public
got a peek at the changes that have been put into the release candidate. I won’t bother
pasting images in, I think you should read about it on the &lt;a href="http://blogs.msdn.com/b/visualstudio/archive/2012/05/08/visual-studio-11-user-interface-updates-coming-in-rc.aspx" target="_blank"&gt;Visual
Studio blog&lt;/a&gt;. I really think that they achieved a nice balance, putting in some
color where needed to enhance the experience.
&lt;/p&gt;
&lt;p&gt;
I think it is time t move on from this topic. I’ll close with a few points:
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
Visual Studio 11 has tons of great features. The new look is just on the surface.
People should play with it for a while and see what is inside!&lt;/li&gt;
&lt;li&gt;
Don’t be so quick to judge. I’ll admit, I had some doubts but I gave it a chance.
I think the designers made a few mistakes but they are fixing them. For instance,
the old icons were hard to read when they had borders around them. I’m glad this is
fixed. I’m glad they added some color back in to, it makes certain icons stand out
nicely. But when you give it some time you may find that these designers were also
right about of lot of their ideas. VS11 is quite easy to use.&lt;/li&gt;
&lt;li&gt;
It’s over. Stop complaining. Like many people, I don’t like the All Caps menus that
are in the latest refresh. SO WHAT? Is it really that big a deal? Is this really worth
switching over to Java and using Eclipse? Some people are actually talking like that
should be our response. Come on people, get a grip.&lt;/li&gt;
&lt;/ol&gt;
&lt;img width="0" height="0" src="http://www.blog.ingenuitynow.net/aggbug.ashx?id=58c6b3cb-b8e9-493d-b3f3-c68c76518fec" /&gt;</description>
      <comments>http://www.blog.ingenuitynow.net/CommentView,guid,58c6b3cb-b8e9-493d-b3f3-c68c76518fec.aspx</comments>
      <category>.Net;C#;Visual Studio</category>
    </item>
    <item>
      <trackback:ping>http://www.blog.ingenuitynow.net/Trackback.aspx?guid=92f7588d-0b23-4a22-a6f1-81f93e29f330</trackback:ping>
      <pingback:server>http://www.blog.ingenuitynow.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.blog.ingenuitynow.net/PermaLink,guid,92f7588d-0b23-4a22-a6f1-81f93e29f330.aspx</pingback:target>
      <dc:creator>Andrew Schwam</dc:creator>
      <wfw:comment>http://www.blog.ingenuitynow.net/CommentView,guid,92f7588d-0b23-4a22-a6f1-81f93e29f330.aspx</wfw:comment>
      <wfw:commentRss>http://www.blog.ingenuitynow.net/SyndicationService.asmx/GetEntryCommentsRss?guid=92f7588d-0b23-4a22-a6f1-81f93e29f330</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
It seems like for forever I have been dealing with the problem of deploying software
and keeping the database updates synchronized at the same time. I’m sure you’ve been
there too. If you are developing software, you likely need database schema changes
from time to time (or much more often). If you are running a local copy of the database
for development (I like working like that), you can easily make the change on your
local SQL Server instance (or some other database product). But then you need all
of your teammates to update their database instances with the changes. Of course,
they may have changes to the schema as well. All that, plus sooner or later you will
need to deploy these changes to the test, staging or production database.
</p>
        <p>
Where I have worked we used a variety of techniques to accomplish this goal but it
has never been easy. Finally, Microsoft gives us Entity Framework Migrations! This
makes this situation very easy to deal with!
</p>
        <p>
Here are some steps to get started with Migrations. I was surprised with how easy
this is to use. To be fair, I haven’t pushed this technology much past the basics
but it is working quite nicely on my project so far. Also I’m using EF Code First
which is really cool but in this post, I won’t be explaining all of the parts of that.
I’ll mention the basic steps but if you want to learn more about the many features
of EF Code First, you’ll need to look elsewhere.
</p>
        <p>
Beware, I am running Visual Studio 11 Beta, .Net 4.5 Beta, Entity Framework 5 Beta.
You should be able to accomplish this stuff with earlier versions too.
</p>
        <h4>Step By Step Guide to Getting Started with Entity Framework Code First Migrations
(in C#)
</h4>
        <ol>
          <li>
Create a new application. I’m working with a simple C# Console App. 
</li>
          <li>
Install Entity Framework. You can do this via the Nuget Package Manager UI or the
Package Manager Console. Again, I am using beta so I’ll need to use the console with
this command: <strong>PM&gt; install-package EntityFramework –includePreRelease</strong></li>
          <li>
I did get an error when I did that. I don’t recall getting that error in the past
but to resolve the error, I used the Add Reference Dialog and added a reference to
System.ComponentModel.DataAnnotations. Then I re-tried the console command and it
worked just fine. 
</li>
          <li>
After installing EntityFramework, my app.config looks like this: <pre class="csharpcode"><span class="kwrd">&lt;?</span><span class="html">xml</span><span class="attr">version</span><span class="kwrd">="1.0"</span><span class="attr">encoding</span><span class="kwrd">="utf-8"</span>?<span class="kwrd">&gt;</span><span class="kwrd">&lt;</span><span class="html">configuration</span><span class="kwrd">&gt;</span><span class="kwrd">&lt;</span><span class="html">configSections</span><span class="kwrd">&gt;</span><span class="kwrd">&lt;</span><span class="html">section</span><span class="attr">name</span><span class="kwrd">="entityFramework"</span><span class="attr">type</span><span class="kwrd">="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection,</span><br /><span class="kwrd"> EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"</span><span class="kwrd">/&gt;</span><span class="kwrd">&lt;/</span><span class="html">configSections</span><span class="kwrd">&gt;</span><span class="kwrd">&lt;</span><span class="html">startup</span><span class="kwrd">&gt;</span><span class="kwrd">&lt;</span><span class="html">supportedRuntime</span><span class="attr">version</span><span class="kwrd">="v4.0"</span><span class="attr">sku</span><span class="kwrd">=".NETFramework,Version=v4.5"</span><span class="kwrd">/&gt;</span><span class="kwrd">&lt;/</span><span class="html">startup</span><span class="kwrd">&gt;</span><span class="kwrd">&lt;</span><span class="html">entityFramework</span><span class="kwrd">&gt;</span><span class="kwrd">&lt;</span><span class="html">defaultConnectionFactory</span><span class="attr">type</span><span class="kwrd">="System.Data.Entity.Infrastructure.SqlConnectionFactory,
EntityFramework"</span><span class="kwrd">/&gt;</span><span class="kwrd">&lt;/</span><span class="html">entityFramework</span><span class="kwrd">&gt;</span><span class="kwrd">&lt;/</span><span class="html">configuration</span><span class="kwrd">&gt;</span></pre><style type="text/css">















.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style><blockquote><p>
Thanks NuGet!
</p></blockquote></li>
          <li>
Next we’ll need to create an entity that needs to be in our database. In my application,
I need a simple object to represent movies. <pre class="csharpcode"><span class="kwrd">public</span><span class="kwrd">class</span> Movie
{ <span class="kwrd">public</span><span class="kwrd">int</span> Id { get; set; } <span class="kwrd">public</span><span class="kwrd">string</span> Title
{ get; set; } <span class="kwrd">public</span><span class="kwrd">string</span> Year
{ get; set; } <span class="kwrd">public</span><span class="kwrd">string</span> Studio
{ get; set; } }</pre><style type="text/css">












.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style><blockquote><p>
You will note that I did NOT annotate this class with any attributes at all.
</p></blockquote></li>
          <li>
Next we’ll need to create our DbContext. It too is pretty simple. <pre class="csharpcode"><span class="kwrd">public</span><span class="kwrd">class</span> MovieContext
: DbContext { <span class="kwrd">public</span> DbSet&lt;Movie&gt; Movies { get; set;
} }</pre><style type="text/css">











.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style></li>
          <li>
Ok for this simple sample, my initial data schema is done. Since this is Code First
however, my database doesn’t actually exist yet. Let’s have Entity Framework create
it for us. To do so, we need to run our application. Before running it, just add this
code to the Main method of your console app. If your application doesn’t “use” the
DbContext, it won’t be generated. <pre class="csharpcode">    MovieContext context = <span class="kwrd">new</span> MovieContext(); <span class="kwrd">foreach</span>(var
movie <span class="kwrd">in</span> context.Movies) { }</pre><style type="text/css">










.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
Now just run the app. If you’ve got SqlServer Express installed, you will now have
a new database in there that looks like this:<a href="http://www.blog.ingenuitynow.net/content/binary/Windows-Live-Writer/Entity-Framework-Migrations-Where-have-y_1144C/image_2.png"><img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.blog.ingenuitynow.net/content/binary/Windows-Live-Writer/Entity-Framework-Migrations-Where-have-y_1144C/image_thumb.png" width="236" height="178" /></a><br />
Yes, the Id was automatically turned into a primary key. Sweet, huh? Code First Rocks! 
</li>
          <li>
Now we have a database and a schema but we haven’t used migrations yet! Let’s get
started with that. Back in the NuGet Package Manager Console, type this: <strong>PM&gt;
enable-Migrations</strong>  
</li>
          <li>
When you enable migrations, it will create a Migrations folder in your project with
two files. 
<ul><li>
201204190017084_InitialCreate.cs (your name will vary). This file contains the code
to create your database schema from scratch. In this case, there is only one table.
This will be important because after we do our next migration, we may need to roll
back to our initial design. 
</li><li>
Configuration.cs which is used for… you guessed it, configuration of Migrations. One
important setting is AutomaticMigrationsEnabled. With that set to true, EF will always
migrate your database when you run your application and it detects that your context
is out of sync with your db. 
</li><li>
Check out these files and you will see how simple this stuff is. Each migration contains
an Up() method and a Down() method. This enables you to migrate your database up and
down to any version! <pre class="csharpcode"><span class="kwrd">public</span><span class="kwrd">partial</span><span class="kwrd">class</span> InitialCreate
: DbMigration { <span class="kwrd">public</span><span class="kwrd">override</span><span class="kwrd">void</span> Up()
{ CreateTable( <span class="str">"Movies"</span>, c =&gt; <span class="kwrd">new</span> {
Id = c.Int(nullable: <span class="kwrd">false</span>, identity: <span class="kwrd">true</span>),
Title = c.String(), Year = c.String(), Studio = c.String(), }) .PrimaryKey(t =&gt;
t.Id); } <span class="kwrd">public</span><span class="kwrd">override</span><span class="kwrd">void</span> Down()
{ DropTable(<span class="str">"Movies"</span>); } }</pre><style type="text/css">









.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style></li></ul></li>
          <li>
Now we need to make a change: Add something to the Movie class, something like this:
public string Genre { get; set; } 
</li>
          <li>
Now if we run our application (remember that we do NOT have Automatic Migrations Enabled).
We’ll get an error:<a href="http://www.blog.ingenuitynow.net/content/binary/Windows-Live-Writer/Entity-Framework-Migrations-Where-have-y_1144C/image_6.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.blog.ingenuitynow.net/content/binary/Windows-Live-Writer/Entity-Framework-Migrations-Where-have-y_1144C/image_thumb_2.png" width="488" height="97" /></a><br />
In this case, that is perfect and just what we expected. 
</li>
          <li>
Back to the Package Manager Console: <strong>PM&gt; add-migration Genre </strong>That
command will create a new Migration file for us with just what we need: <pre class="csharpcode"><span class="kwrd">public</span><span class="kwrd">partial</span><span class="kwrd">class</span> Genre
: DbMigration { <span class="kwrd">public</span><span class="kwrd">override</span><span class="kwrd">void</span> Up()
{ AddColumn(<span class="str">"Movies"</span>, <span class="str">"Genre"</span>,
c =&gt; c.String()); } <span class="kwrd">public</span><span class="kwrd">override</span><span class="kwrd">void</span> Down()
{ DropColumn(<span class="str">"Movies"</span>, <span class="str">"Genre"</span>);
} }</pre><style type="text/css">








.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style></li>
          <li>
Next, this command in Package Manager Console: <strong>PM&gt; update-database </strong>You’ll
get some messages confirming the action. When I check my database I’ll see that the
new column was added just as I needed. I can now run my application successfully again.
Too bad my application doesn’t do anything. 
</li>
        </ol>
        <p>
Eventually, you will have multiple migrations in your project. If you need to revert
back to an old version of code, you can also revert back to an old version of the
schema by specifying which a target. In this example, I want to target the migration
named “InitialCreate”: <strong>update-database –TargetMigration InitialCreate</strong></p>
        <p>
To create scripts instead of actually updating your database, you can use a command
similar to this: <strong>update-database -Script -TargetMigration Genre</strong> These
scripts can be saved and used as part of your deployment process.
</p>
        <p>
Those are the basics of Entity Framework Migrations. I think you will find it is pretty
easy to use. For more information, I suggest you follow the <a href="http://blogs.msdn.com/b/adonet/" target="_blank">ADO.Net
Team Blog</a>.
</p>
        <p>
Download my sample solution: <a href="http://www.blog.ingenuitynow.net/content/binary/MigrationsDemo.zip" target="_blank">MigrationsDemo.zip</a></p>
        <img width="0" height="0" src="http://www.blog.ingenuitynow.net/aggbug.ashx?id=92f7588d-0b23-4a22-a6f1-81f93e29f330" />
      </body>
      <title>Entity Framework Code First Migrations: Where have you been all my life?</title>
      <guid isPermaLink="false">http://www.blog.ingenuitynow.net/PermaLink,guid,92f7588d-0b23-4a22-a6f1-81f93e29f330.aspx</guid>
      <link>http://www.blog.ingenuitynow.net/Entity+Framework+Code+First+Migrations+Where+Have+You+Been+All+My+Life.aspx</link>
      <pubDate>Thu, 19 Apr 2012 03:00:15 GMT</pubDate>
      <description>&lt;p&gt;
It seems like for forever I have been dealing with the problem of deploying software
and keeping the database updates synchronized at the same time. I’m sure you’ve been
there too. If you are developing software, you likely need database schema changes
from time to time (or much more often). If you are running a local copy of the database
for development (I like working like that), you can easily make the change on your
local SQL Server instance (or some other database product). But then you need all
of your teammates to update their database instances with the changes. Of course,
they may have changes to the schema as well. All that, plus sooner or later you will
need to deploy these changes to the test, staging or production database.
&lt;/p&gt;
&lt;p&gt;
Where I have worked we used a variety of techniques to accomplish this goal but it
has never been easy. Finally, Microsoft gives us Entity Framework Migrations! This
makes this situation very easy to deal with!
&lt;/p&gt;
&lt;p&gt;
Here are some steps to get started with Migrations. I was surprised with how easy
this is to use. To be fair, I haven’t pushed this technology much past the basics
but it is working quite nicely on my project so far. Also I’m using EF Code First
which is really cool but in this post, I won’t be explaining all of the parts of that.
I’ll mention the basic steps but if you want to learn more about the many features
of EF Code First, you’ll need to look elsewhere.
&lt;/p&gt;
&lt;p&gt;
Beware, I am running Visual Studio 11 Beta, .Net 4.5 Beta, Entity Framework 5 Beta.
You should be able to accomplish this stuff with earlier versions too.
&lt;/p&gt;
&lt;h4&gt;Step By Step Guide to Getting Started with Entity Framework Code First Migrations
(in C#)
&lt;/h4&gt;
&lt;ol&gt;
&lt;li&gt;
Create a new application. I’m working with a simple C# Console App. 
&lt;/li&gt;
&lt;li&gt;
Install Entity Framework. You can do this via the Nuget Package Manager UI or the
Package Manager Console. Again, I am using beta so I’ll need to use the console with
this command: &lt;strong&gt;PM&amp;gt; install-package EntityFramework –includePreRelease&lt;/strong&gt; 
&lt;/li&gt;
&lt;li&gt;
I did get an error when I did that. I don’t recall getting that error in the past
but to resolve the error, I used the Add Reference Dialog and added a reference to
System.ComponentModel.DataAnnotations. Then I re-tried the console command and it
worked just fine. 
&lt;/li&gt;
&lt;li&gt;
After installing EntityFramework, my app.config looks like this: &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;?&lt;/span&gt;&lt;span class="html"&gt;xml&lt;/span&gt; &lt;span class="attr"&gt;version&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;1.0&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;encoding&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;utf-8&amp;quot;&lt;/span&gt;?&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt; &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;configuration&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt; &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;configSections&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt; &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;section&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;entityFramework&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection,&lt;/span&gt;
&lt;br /&gt;
&lt;span class="kwrd"&gt; EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt; &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;configSections&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt; &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;startup&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt; &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;supportedRuntime&lt;/span&gt; &lt;span class="attr"&gt;version&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;v4.0&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;sku&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;.NETFramework,Version=v4.5&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt; &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;startup&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt; &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;entityFramework&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt; &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;defaultConnectionFactory&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;System.Data.Entity.Infrastructure.SqlConnectionFactory,
EntityFramework&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt; &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;entityFramework&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt; &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;configuration&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;















.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;
&lt;blockquote&gt; 
&lt;p&gt;
Thanks NuGet!
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;/li&gt;
&lt;li&gt;
Next we’ll need to create an entity that needs to be in our database. In my application,
I need a simple object to represent movies. &lt;pre class="csharpcode"&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Movie
{ &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; Id { get; set; } &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Title
{ get; set; } &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Year
{ get; set; } &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Studio
{ get; set; } }&lt;/pre&gt;
&lt;style type="text/css"&gt;












.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;
&lt;blockquote&gt; 
&lt;p&gt;
You will note that I did NOT annotate this class with any attributes at all.
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;/li&gt;
&lt;li&gt;
Next we’ll need to create our DbContext. It too is pretty simple. &lt;pre class="csharpcode"&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; MovieContext
: DbContext { &lt;span class="kwrd"&gt;public&lt;/span&gt; DbSet&amp;lt;Movie&amp;gt; Movies { get; set;
} }&lt;/pre&gt;
&lt;style type="text/css"&gt;











.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;
&lt;/li&gt;
&lt;li&gt;
Ok for this simple sample, my initial data schema is done. Since this is Code First
however, my database doesn’t actually exist yet. Let’s have Entity Framework create
it for us. To do so, we need to run our application. Before running it, just add this
code to the Main method of your console app. If your application doesn’t “use” the
DbContext, it won’t be generated. &lt;pre class="csharpcode"&gt;    MovieContext context = &lt;span class="kwrd"&gt;new&lt;/span&gt; MovieContext(); &lt;span class="kwrd"&gt;foreach&lt;/span&gt;(var
movie &lt;span class="kwrd"&gt;in&lt;/span&gt; context.Movies) { }&lt;/pre&gt;
&lt;style type="text/css"&gt;










.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;
Now just run the app. If you’ve got SqlServer Express installed, you will now have
a new database in there that looks like this:&lt;a href="http://www.blog.ingenuitynow.net/content/binary/Windows-Live-Writer/Entity-Framework-Migrations-Where-have-y_1144C/image_2.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.blog.ingenuitynow.net/content/binary/Windows-Live-Writer/Entity-Framework-Migrations-Where-have-y_1144C/image_thumb.png" width="236" height="178" /&gt;&lt;/a&gt; 
&lt;br /&gt;
Yes, the Id was automatically turned into a primary key. Sweet, huh? Code First Rocks! 
&lt;/li&gt;
&lt;li&gt;
Now we have a database and a schema but we haven’t used migrations yet! Let’s get
started with that. Back in the NuGet Package Manager Console, type this: &lt;strong&gt;PM&amp;gt;
enable-Migrations&lt;/strong&gt;&amp;#160; 
&lt;/li&gt;
&lt;li&gt;
When you enable migrations, it will create a Migrations folder in your project with
two files. 
&lt;ul&gt;
&lt;li&gt;
201204190017084_InitialCreate.cs (your name will vary). This file contains the code
to create your database schema from scratch. In this case, there is only one table.
This will be important because after we do our next migration, we may need to roll
back to our initial design. 
&lt;/li&gt;
&lt;li&gt;
Configuration.cs which is used for… you guessed it, configuration of Migrations. One
important setting is AutomaticMigrationsEnabled. With that set to true, EF will always
migrate your database when you run your application and it detects that your context
is out of sync with your db. 
&lt;/li&gt;
&lt;li&gt;
Check out these files and you will see how simple this stuff is. Each migration contains
an Up() method and a Down() method. This enables you to migrate your database up and
down to any version! &lt;pre class="csharpcode"&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;partial&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; InitialCreate
: DbMigration { &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Up()
{ CreateTable( &lt;span class="str"&gt;&amp;quot;Movies&amp;quot;&lt;/span&gt;, c =&amp;gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; {
Id = c.Int(nullable: &lt;span class="kwrd"&gt;false&lt;/span&gt;, identity: &lt;span class="kwrd"&gt;true&lt;/span&gt;),
Title = c.String(), Year = c.String(), Studio = c.String(), }) .PrimaryKey(t =&amp;gt;
t.Id); } &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Down()
{ DropTable(&lt;span class="str"&gt;&amp;quot;Movies&amp;quot;&lt;/span&gt;); } }&lt;/pre&gt;
&lt;style type="text/css"&gt;









.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
Now we need to make a change: Add something to the Movie class, something like this:
public string Genre { get; set; } 
&lt;/li&gt;
&lt;li&gt;
Now if we run our application (remember that we do NOT have Automatic Migrations Enabled).
We’ll get an error:&lt;a href="http://www.blog.ingenuitynow.net/content/binary/Windows-Live-Writer/Entity-Framework-Migrations-Where-have-y_1144C/image_6.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.blog.ingenuitynow.net/content/binary/Windows-Live-Writer/Entity-Framework-Migrations-Where-have-y_1144C/image_thumb_2.png" width="488" height="97" /&gt;&lt;/a&gt; 
&lt;br /&gt;
In this case, that is perfect and just what we expected. 
&lt;/li&gt;
&lt;li&gt;
Back to the Package Manager Console: &lt;strong&gt;PM&amp;gt; add-migration Genre &lt;/strong&gt;That
command will create a new Migration file for us with just what we need: &lt;pre class="csharpcode"&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;partial&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Genre
: DbMigration { &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Up()
{ AddColumn(&lt;span class="str"&gt;&amp;quot;Movies&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;Genre&amp;quot;&lt;/span&gt;,
c =&amp;gt; c.String()); } &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Down()
{ DropColumn(&lt;span class="str"&gt;&amp;quot;Movies&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;Genre&amp;quot;&lt;/span&gt;);
} }&lt;/pre&gt;
&lt;style type="text/css"&gt;








.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;
&lt;/li&gt;
&lt;li&gt;
Next, this command in Package Manager Console: &lt;strong&gt;PM&amp;gt; update-database &lt;/strong&gt;You’ll
get some messages confirming the action. When I check my database I’ll see that the
new column was added just as I needed. I can now run my application successfully again.
Too bad my application doesn’t do anything. 
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
Eventually, you will have multiple migrations in your project. If you need to revert
back to an old version of code, you can also revert back to an old version of the
schema by specifying which a target. In this example, I want to target the migration
named “InitialCreate”: &lt;strong&gt;update-database –TargetMigration InitialCreate&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
To create scripts instead of actually updating your database, you can use a command
similar to this: &lt;strong&gt;update-database -Script -TargetMigration Genre&lt;/strong&gt; These
scripts can be saved and used as part of your deployment process.
&lt;/p&gt;
&lt;p&gt;
Those are the basics of Entity Framework Migrations. I think you will find it is pretty
easy to use. For more information, I suggest you follow the &lt;a href="http://blogs.msdn.com/b/adonet/" target="_blank"&gt;ADO.Net
Team Blog&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
Download my sample solution: &lt;a href="http://www.blog.ingenuitynow.net/content/binary/MigrationsDemo.zip" target="_blank"&gt;MigrationsDemo.zip&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.blog.ingenuitynow.net/aggbug.ashx?id=92f7588d-0b23-4a22-a6f1-81f93e29f330" /&gt;</description>
      <comments>http://www.blog.ingenuitynow.net/CommentView,guid,92f7588d-0b23-4a22-a6f1-81f93e29f330.aspx</comments>
      <category>.Net;C#;Entity Framework;SQL Server</category>
    </item>
    <item>
      <trackback:ping>http://www.blog.ingenuitynow.net/Trackback.aspx?guid=653b8067-2c55-4386-b8c5-a9e279cfb474</trackback:ping>
      <pingback:server>http://www.blog.ingenuitynow.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.blog.ingenuitynow.net/PermaLink,guid,653b8067-2c55-4386-b8c5-a9e279cfb474.aspx</pingback:target>
      <dc:creator>Andrew Schwam</dc:creator>
      <wfw:comment>http://www.blog.ingenuitynow.net/CommentView,guid,653b8067-2c55-4386-b8c5-a9e279cfb474.aspx</wfw:comment>
      <wfw:commentRss>http://www.blog.ingenuitynow.net/SyndicationService.asmx/GetEntryCommentsRss?guid=653b8067-2c55-4386-b8c5-a9e279cfb474</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I’m a few weeks into a side project that I blogged about in a <a href="http://www.blog.ingenuitynow.net/Want+To+Learn+Some+New+Skills+Just+Write+It.aspx" target="_blank">previous
post</a>. I’m having a lot of fun (I’m such a geek) using a bunch of new stuff. Since <a href="http://www.microsoft.com/visualstudio/11/en-us" target="_blank">Visual
Studio 11</a> is at the center of all the work on the project, I thought I’d share
my first impressions on it. Of course, I’m using a Beta version of it. Really this
post is about my second thoughts since they are much more meaningful. Spoiler alert:
First impressions aren’t always the most important.
</p>
        <h4>My first thoughts
</h4>
        <p>
My first thoughts were pretty typical and can be summarized with one bullet:
</p>
        <ul>
          <li>
Colorless 
</li>
        </ul>
        <p>
That is pretty much what most people think when they see it for the first time. People
tend to ignore all of the improvements and new features and focus on the lack of color.
At first I found this lack of color to be somewhat distracting which is odd because
it is meant to have the opposite effect. I’ll be honest, I wasn’t thrilled with the
new look but I was quick to point out to some of my peers that we should give it some
time and get used to it.
</p>
        <h4>My Second Thoughts
</h4>
        <p>
Guess what? I got used to it… quickly. After using Visual Studio 11 for a couple of
hours, I quickly got used to the lack of color. It isn’t really that big a deal and
I think the VS team was on the right track by moving Visual Studio overall to the
background and making the code editor the focal point. Having said that, I still think
some color would be helpful. My last point on the overall lack of color is that it
isn’t 100% consistent. Some windows within VS11 still have color. And some plugins
use color too. That makes things a bit odd. I’m including a screenshot below. That’s
all for the color.
</p>
        <p>
          <a href="http://www.blog.ingenuitynow.net/content/binary/Windows-Live-Writer/My-First-and-Second-Thoughts-on-Visual-S_117D7/image_2.png">
            <img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.blog.ingenuitynow.net/content/binary/Windows-Live-Writer/My-First-and-Second-Thoughts-on-Visual-S_117D7/image_thumb.png" width="374" height="204" />
          </a>
        </p>
        <h4>Some features to note (this is by no means a comprehensive list, just some highlights):
</h4>
        <p>
So far, I think VS11 is an awesome development environment. I’ve been doing <a href="http://www.asp.net/mvc" target="_blank">MVC</a> development
within VS11 and the <strong>HTML, CSS, and JavaScript</strong><strong>support</strong> is
really nice. VS11 is now providing a lot of help for developers working in these areas.
I’ll also point out that I am using <a href="http://www.jetbrains.com/resharper/" target="_blank">ReSharper</a> (<a href="http://blogs.jetbrains.com/dotnet/2012/03/resharper-70-eap-visual-studio-11-beta-edition-is-nowopen/" target="_blank">v7
EAP for VS11</a>). I love ReSharper! Between VS11 and ReSharper, the web development
experience is awesome. I’ll be honest, I don’t always know which tool is providing
the various features!
</p>
        <p>
When developing web apps, we typically want to run/debug/test them in a variety of
browsers. It seems like Microsoft has figured out the IE is not the only browser in
town. So now we can use the <strong>Debug Target</strong> toolbar button. Just click
the typical “play” button or hit F5 to debug in which ever browser is selected: <a href="http://www.blog.ingenuitynow.net/content/binary/Windows-Live-Writer/My-First-and-Second-Thoughts-on-Visual-S_117D7/image_11.png"><img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.blog.ingenuitynow.net/content/binary/Windows-Live-Writer/My-First-and-Second-Thoughts-on-Visual-S_117D7/image_thumb_4.png" width="140" height="33" /></a> Or
you can use the drop down to chose a different target or change the default:
</p>
        <p>
          <a href="http://www.blog.ingenuitynow.net/content/binary/Windows-Live-Writer/My-First-and-Second-Thoughts-on-Visual-S_117D7/image_12.png">
            <img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.blog.ingenuitynow.net/content/binary/Windows-Live-Writer/My-First-and-Second-Thoughts-on-Visual-S_117D7/image_thumb_5.png" width="154" height="115" />
          </a>
        </p>
        <p>
I like the fact that the great features of the <strong>Solution Navigator</strong> (previously
part of the Productivity Power Tools) were combined into the Solution Explorer. Of
course, the <strong>Add Reference dialog</strong> is a huge improvement from the past,
that was also a feature from the Power Tools. 
</p>
        <p>
I’m also a huge fan in the <strong>reduction of items in the toolbars</strong>. I
think the VS team really nailed that part of the design as well. They took out all
but the most commonly used buttons from the toolbar – but only in the default configuration.
If there is a button or toolbar you like, just add it back in. That part is easy!
More importantly, we should all get used to the <strong>Quick Launch</strong> feature.
With that, we can just type the name of any command we want. No more hunting around
in the menus for seldom used actions!
</p>
        <p>
Another great feature is the <strong>Preview Tab</strong>. I’m surprised more people
aren’t talking about this one. This is pretty cool but I don’t think you can get the
full value of it until you experience it yourself. Think about all those times you
are debugging and you end up stepping into file after file after file. All those files
get opened up in the tab well. Eventually you get to the file you want in the debug
process. But when you are done you have a ton of open files. Not everyone is like
me, but I hate open files. I want my tab well to be as empty as possible. Preview
Tab to the rescue! With VS11, all of those files that you step through don’t open
up as normal files, they open in the Preview Tab. But Preview Tab only has one file
at a time. So each new file you step into replaces the old one and your environment
stays clutter free. And Preview Tab is pretty smart too. If you make a change to the
file it moves it into the normal tab well. You can also click a button in the tab
to “promote” the file to be a normally opened file. In this image you can see the
Preview Tab on the right, circled in blue.
</p>
        <p>
          <a href="http://www.blog.ingenuitynow.net/content/binary/Windows-Live-Writer/My-First-and-Second-Thoughts-on-Visual-S_117D7/image_4.png">
            <img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.blog.ingenuitynow.net/content/binary/Windows-Live-Writer/My-First-and-Second-Thoughts-on-Visual-S_117D7/image_thumb_1.png" width="595" height="63" />
          </a>
        </p>
        <br clear="all" />
        <p>
While it isn’t really new, I want to mention that the extensibility features of VS11
(and 2010 too) are really powerful and work so well and somewhat seamlessly. The <strong>Extension
Manager</strong> is really cool and with it I’m always adding tools to Visual Studio.
There are loads of great things to install. With VS2010 I hadn’t gotten to experience <strong><a href="http://nuget.org/" target="_blank">Nuget</a></strong> but
with the work I’m doing now in VS11 I am all over it. Nuget (or is it NuGet, or nuget?)
is providing all kinds of good stuff for my solution. Between VS11, the extensions
and nuget packages, I really feel empowered to create great solutions.
</p>
        <p>
There are lots of other great features, these are just the ones that came to mind
as I was writing. <a href="http://www.microsoft.com/visualstudio/11/en-us" target="_blank">Download
the Beta</a> and check it out for yourself!
</p>
        <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:46ec0143-cd7f-4198-9c7a-84a70a5652f5" class="wlWriterEditableSmartContent">del.icio.us
Tags: <a href="http://del.icio.us/popular/Visual+Studio+11" rel="tag">Visual Studio
11</a>,<a href="http://del.icio.us/popular/VS11" rel="tag">VS11</a>,<a href="http://del.icio.us/popular/asp.net+mvc" rel="tag">asp.net
mvc</a>,<a href="http://del.icio.us/popular/html" rel="tag">html</a>,<a href="http://del.icio.us/popular/css" rel="tag">css</a>,<a href="http://del.icio.us/popular/javascript" rel="tag">javascript</a>,<a href="http://del.icio.us/popular/nuget" rel="tag">nuget</a>,<a href="http://del.icio.us/popular/extension+manager" rel="tag">extension
manager</a></div>
        <img width="0" height="0" src="http://www.blog.ingenuitynow.net/aggbug.ashx?id=653b8067-2c55-4386-b8c5-a9e279cfb474" />
      </body>
      <title>My First and Second Thoughts on Visual Studio 11 (Beta)</title>
      <guid isPermaLink="false">http://www.blog.ingenuitynow.net/PermaLink,guid,653b8067-2c55-4386-b8c5-a9e279cfb474.aspx</guid>
      <link>http://www.blog.ingenuitynow.net/My+First+And+Second+Thoughts+On+Visual+Studio+11+Beta.aspx</link>
      <pubDate>Mon, 16 Apr 2012 00:45:21 GMT</pubDate>
      <description>&lt;p&gt;
I’m a few weeks into a side project that I blogged about in a &lt;a href="http://www.blog.ingenuitynow.net/Want+To+Learn+Some+New+Skills+Just+Write+It.aspx" target="_blank"&gt;previous
post&lt;/a&gt;. I’m having a lot of fun (I’m such a geek) using a bunch of new stuff. Since &lt;a href="http://www.microsoft.com/visualstudio/11/en-us" target="_blank"&gt;Visual
Studio 11&lt;/a&gt; is at the center of all the work on the project, I thought I’d share
my first impressions on it. Of course, I’m using a Beta version of it. Really this
post is about my second thoughts since they are much more meaningful. Spoiler alert:
First impressions aren’t always the most important.
&lt;/p&gt;
&lt;h4&gt;My first thoughts
&lt;/h4&gt;
&lt;p&gt;
My first thoughts were pretty typical and can be summarized with one bullet:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
Colorless 
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
That is pretty much what most people think when they see it for the first time. People
tend to ignore all of the improvements and new features and focus on the lack of color.
At first I found this lack of color to be somewhat distracting which is odd because
it is meant to have the opposite effect. I’ll be honest, I wasn’t thrilled with the
new look but I was quick to point out to some of my peers that we should give it some
time and get used to it.
&lt;/p&gt;
&lt;h4&gt;My Second Thoughts
&lt;/h4&gt;
&lt;p&gt;
Guess what? I got used to it… quickly. After using Visual Studio 11 for a couple of
hours, I quickly got used to the lack of color. It isn’t really that big a deal and
I think the VS team was on the right track by moving Visual Studio overall to the
background and making the code editor the focal point. Having said that, I still think
some color would be helpful. My last point on the overall lack of color is that it
isn’t 100% consistent. Some windows within VS11 still have color. And some plugins
use color too. That makes things a bit odd. I’m including a screenshot below. That’s
all for the color.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.blog.ingenuitynow.net/content/binary/Windows-Live-Writer/My-First-and-Second-Thoughts-on-Visual-S_117D7/image_2.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.blog.ingenuitynow.net/content/binary/Windows-Live-Writer/My-First-and-Second-Thoughts-on-Visual-S_117D7/image_thumb.png" width="374" height="204" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;h4&gt;Some features to note (this is by no means a comprehensive list, just some highlights):
&lt;/h4&gt;
&lt;p&gt;
So far, I think VS11 is an awesome development environment. I’ve been doing &lt;a href="http://www.asp.net/mvc" target="_blank"&gt;MVC&lt;/a&gt; development
within VS11 and the &lt;strong&gt;HTML, CSS, and JavaScript&lt;/strong&gt; &lt;strong&gt;support&lt;/strong&gt; is
really nice. VS11 is now providing a lot of help for developers working in these areas.
I’ll also point out that I am using &lt;a href="http://www.jetbrains.com/resharper/" target="_blank"&gt;ReSharper&lt;/a&gt; (&lt;a href="http://blogs.jetbrains.com/dotnet/2012/03/resharper-70-eap-visual-studio-11-beta-edition-is-nowopen/" target="_blank"&gt;v7
EAP for VS11&lt;/a&gt;). I love ReSharper! Between VS11 and ReSharper, the web development
experience is awesome. I’ll be honest, I don’t always know which tool is providing
the various features!
&lt;/p&gt;
&lt;p&gt;
When developing web apps, we typically want to run/debug/test them in a variety of
browsers. It seems like Microsoft has figured out the IE is not the only browser in
town. So now we can use the &lt;strong&gt;Debug Target&lt;/strong&gt; toolbar button. Just click
the typical “play” button or hit F5 to debug in which ever browser is selected: &lt;a href="http://www.blog.ingenuitynow.net/content/binary/Windows-Live-Writer/My-First-and-Second-Thoughts-on-Visual-S_117D7/image_11.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.blog.ingenuitynow.net/content/binary/Windows-Live-Writer/My-First-and-Second-Thoughts-on-Visual-S_117D7/image_thumb_4.png" width="140" height="33" /&gt;&lt;/a&gt; Or
you can use the drop down to chose a different target or change the default:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.blog.ingenuitynow.net/content/binary/Windows-Live-Writer/My-First-and-Second-Thoughts-on-Visual-S_117D7/image_12.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.blog.ingenuitynow.net/content/binary/Windows-Live-Writer/My-First-and-Second-Thoughts-on-Visual-S_117D7/image_thumb_5.png" width="154" height="115" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
I like the fact that the great features of the &lt;strong&gt;Solution Navigator&lt;/strong&gt; (previously
part of the Productivity Power Tools) were combined into the Solution Explorer. Of
course, the &lt;strong&gt;Add Reference dialog&lt;/strong&gt; is a huge improvement from the past,
that was also a feature from the Power Tools. 
&lt;/p&gt;
&lt;p&gt;
I’m also a huge fan in the &lt;strong&gt;reduction of items in the toolbars&lt;/strong&gt;. I
think the VS team really nailed that part of the design as well. They took out all
but the most commonly used buttons from the toolbar – but only in the default configuration.
If there is a button or toolbar you like, just add it back in. That part is easy!
More importantly, we should all get used to the &lt;strong&gt;Quick Launch&lt;/strong&gt; feature.
With that, we can just type the name of any command we want. No more hunting around
in the menus for seldom used actions!
&lt;/p&gt;
&lt;p&gt;
Another great feature is the &lt;strong&gt;Preview Tab&lt;/strong&gt;. I’m surprised more people
aren’t talking about this one. This is pretty cool but I don’t think you can get the
full value of it until you experience it yourself. Think about all those times you
are debugging and you end up stepping into file after file after file. All those files
get opened up in the tab well. Eventually you get to the file you want in the debug
process. But when you are done you have a ton of open files. Not everyone is like
me, but I hate open files. I want my tab well to be as empty as possible. Preview
Tab to the rescue! With VS11, all of those files that you step through don’t open
up as normal files, they open in the Preview Tab. But Preview Tab only has one file
at a time. So each new file you step into replaces the old one and your environment
stays clutter free. And Preview Tab is pretty smart too. If you make a change to the
file it moves it into the normal tab well. You can also click a button in the tab
to “promote” the file to be a normally opened file. In this image you can see the
Preview Tab on the right, circled in blue.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.blog.ingenuitynow.net/content/binary/Windows-Live-Writer/My-First-and-Second-Thoughts-on-Visual-S_117D7/image_4.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.blog.ingenuitynow.net/content/binary/Windows-Live-Writer/My-First-and-Second-Thoughts-on-Visual-S_117D7/image_thumb_1.png" width="595" height="63" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;br clear="all" /&gt;
&lt;p&gt;
While it isn’t really new, I want to mention that the extensibility features of VS11
(and 2010 too) are really powerful and work so well and somewhat seamlessly. The &lt;strong&gt;Extension
Manager&lt;/strong&gt; is really cool and with it I’m always adding tools to Visual Studio.
There are loads of great things to install. With VS2010 I hadn’t gotten to experience &lt;strong&gt;&lt;a href="http://nuget.org/" target="_blank"&gt;Nuget&lt;/a&gt;&lt;/strong&gt; but
with the work I’m doing now in VS11 I am all over it. Nuget (or is it NuGet, or nuget?)
is providing all kinds of good stuff for my solution. Between VS11, the extensions
and nuget packages, I really feel empowered to create great solutions.
&lt;/p&gt;
&lt;p&gt;
There are lots of other great features, these are just the ones that came to mind
as I was writing. &lt;a href="http://www.microsoft.com/visualstudio/11/en-us" target="_blank"&gt;Download
the Beta&lt;/a&gt; and check it out for yourself!
&lt;/p&gt;
&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:46ec0143-cd7f-4198-9c7a-84a70a5652f5" class="wlWriterEditableSmartContent"&gt;del.icio.us
Tags: &lt;a href="http://del.icio.us/popular/Visual+Studio+11" rel="tag"&gt;Visual Studio
11&lt;/a&gt;,&lt;a href="http://del.icio.us/popular/VS11" rel="tag"&gt;VS11&lt;/a&gt;,&lt;a href="http://del.icio.us/popular/asp.net+mvc" rel="tag"&gt;asp.net
mvc&lt;/a&gt;,&lt;a href="http://del.icio.us/popular/html" rel="tag"&gt;html&lt;/a&gt;,&lt;a href="http://del.icio.us/popular/css" rel="tag"&gt;css&lt;/a&gt;,&lt;a href="http://del.icio.us/popular/javascript" rel="tag"&gt;javascript&lt;/a&gt;,&lt;a href="http://del.icio.us/popular/nuget" rel="tag"&gt;nuget&lt;/a&gt;,&lt;a href="http://del.icio.us/popular/extension+manager" rel="tag"&gt;extension
manager&lt;/a&gt;
&lt;/div&gt;
&lt;img width="0" height="0" src="http://www.blog.ingenuitynow.net/aggbug.ashx?id=653b8067-2c55-4386-b8c5-a9e279cfb474" /&gt;</description>
      <comments>http://www.blog.ingenuitynow.net/CommentView,guid,653b8067-2c55-4386-b8c5-a9e279cfb474.aspx</comments>
      <category>.Net;asp.net mvc;C#;Visual Studio</category>
    </item>
    <item>
      <trackback:ping>http://www.blog.ingenuitynow.net/Trackback.aspx?guid=f4ca8a63-3acd-47a0-8e22-52beacb4589f</trackback:ping>
      <pingback:server>http://www.blog.ingenuitynow.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.blog.ingenuitynow.net/PermaLink,guid,f4ca8a63-3acd-47a0-8e22-52beacb4589f.aspx</pingback:target>
      <dc:creator>Andrew Schwam</dc:creator>
      <wfw:comment>http://www.blog.ingenuitynow.net/CommentView,guid,f4ca8a63-3acd-47a0-8e22-52beacb4589f.aspx</wfw:comment>
      <wfw:commentRss>http://www.blog.ingenuitynow.net/SyndicationService.asmx/GetEntryCommentsRss?guid=f4ca8a63-3acd-47a0-8e22-52beacb4589f</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
A lot of new stuff has been coming out from Microsoft lately. Couple that with all
the cool open source projects available for use and a developer can quickly get left
behind from all the new technology. I try to stay pretty current but there is some
new stuff that I’ve been wanting to use. I also wanted to brush up on some old skills
and even use some of the technologies I am experienced with in new ways. I decided
it was time to start a little project for myself. I’m often asked by developers about
how they can gain experience with new technology (or even old tech that is new to
them). My advice is that they should just write an application that uses the technology.
As a hiring manager, I’ll give serious consideration to that kind of experience, provided
it isn’t “hello world”. When I write an application like this, I treat it like a real
world production project. And if you are creating a web application you can have it
hosted and then it IS a real product. That should count as experience to a smart hiring
manager. So when you write these applications, try to follow all of the best practices,
use good standards, etc.
</p>
        <p>
In my case, I am writing an application that I hope will actually get some use. I’m
hoping to get some great blogging material out of this as well. I already have, but
now I need to find time to write about it. Anyway, figure out what you want to build
and then create a list of the things you want to learn. As you write the application,
you can just keep adding other technologies, frameworks or patterns in along the way. 
</p>
        <p>
Here is my list of things I’m using or will be using in my new pet project. Obviously
the beta stuff is brand new. And I’ve already got experience with MVC 2 (pre-Razor),
jQuery, HTML, CSS, etc. However, this stuff gets better and better all the time and
I like to stay on top of it. Working a few hours here and there for the past 2 weeks,
I’ve already included all of the items in blue in my project.
</p>
        <ul>
          <li>
            <font color="#0000ff">Visual Studio 11 (beta)</font>
          </li>
          <li>
            <font color="#0000ff">Entity Framework 5 (beta)</font>
          </li>
          <li>
            <font color="#0000ff">Entity Framework Code First</font>
          </li>
          <li>
            <font color="#0000ff">Entity Framework Migrations</font>
          </li>
          <li>
            <font color="#0000ff">ASP.Net MVC 4</font>
          </li>
          <li>
            <font color="#0000ff">Razor</font>
          </li>
          <li>
            <font color="#0000ff">HTML 5</font>
          </li>
          <li>
            <font color="#0000ff">jQuery</font>
          </li>
          <li>
            <font color="#0000ff">jQuery UI</font>
          </li>
          <li>
            <font color="#0000ff">Git</font>
          </li>
          <li>
            <font color="#0000ff">Open Authentication<!--EndFragment--></font>
          </li>
          <li>
            <font color="#0000ff">CSS3 &amp; Media Queries</font>
          </li>
          <li>
            <font color="#0000ff">HTML/CSS Grid Systems</font>
          </li>
          <li>
            <font color="#0000ff">NuGet</font>
          </li>
          <li>
            <font color="#0000ff">SEO Toolkit (Microsoft)<!--EndFragment--></font>
          </li>
          <li>
C# 4.5 (including Async) 
</li>
          <li>
SignalR 
</li>
          <li>
Azure 
</li>
          <li>
ASP.Net Web API 
</li>
          <li>
BootStrap (from Twitter) 
</li>
          <li>
Facebook Integration 
</li>
          <li>
Of course, <font color="#0000ff">Dependency Injection, Unit Testing</font>, and all
of the other stuff I put into any app I am deploying. 
</li>
        </ul>
        <p>
I’m writing this as a web application and creating a mobile version at the same time.
In addition, I plan to extend this to additional platforms. So my list continues:
</p>
        <ul>
          <li>
            <font color="#0000ff">Mobile Web</font>
          </li>
          <li>
WP7 
</li>
          <li>
Metro (Windows 8) 
</li>
        </ul>
        <img width="0" height="0" src="http://www.blog.ingenuitynow.net/aggbug.ashx?id=f4ca8a63-3acd-47a0-8e22-52beacb4589f" />
      </body>
      <title>Want to Learn Some New Skills? Just Write It!</title>
      <guid isPermaLink="false">http://www.blog.ingenuitynow.net/PermaLink,guid,f4ca8a63-3acd-47a0-8e22-52beacb4589f.aspx</guid>
      <link>http://www.blog.ingenuitynow.net/Want+To+Learn+Some+New+Skills+Just+Write+It.aspx</link>
      <pubDate>Thu, 12 Apr 2012 07:21:00 GMT</pubDate>
      <description>&lt;p&gt;
A lot of new stuff has been coming out from Microsoft lately. Couple that with all
the cool open source projects available for use and a developer can quickly get left
behind from all the new technology. I try to stay pretty current but there is some
new stuff that I’ve been wanting to use. I also wanted to brush up on some old skills
and even use some of the technologies I am experienced with in new ways. I decided
it was time to start a little project for myself. I’m often asked by developers about
how they can gain experience with new technology (or even old tech that is new to
them). My advice is that they should just write an application that uses the technology.
As a hiring manager, I’ll give serious consideration to that kind of experience, provided
it isn’t “hello world”. When I write an application like this, I treat it like a real
world production project. And if you are creating a web application you can have it
hosted and then it IS a real product. That should count as experience to a smart hiring
manager. So when you write these applications, try to follow all of the best practices,
use good standards, etc.
&lt;/p&gt;
&lt;p&gt;
In my case, I am writing an application that I hope will actually get some use. I’m
hoping to get some great blogging material out of this as well. I already have, but
now I need to find time to write about it. Anyway, figure out what you want to build
and then create a list of the things you want to learn. As you write the application,
you can just keep adding other technologies, frameworks or patterns in along the way. 
&lt;/p&gt;
&lt;p&gt;
Here is my list of things I’m using or will be using in my new pet project. Obviously
the beta stuff is brand new. And I’ve already got experience with MVC 2 (pre-Razor),
jQuery, HTML, CSS, etc. However, this stuff gets better and better all the time and
I like to stay on top of it. Working a few hours here and there for the past 2 weeks,
I’ve already included all of the items in blue in my project.
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;font color="#0000ff"&gt;Visual Studio 11 (beta)&lt;/font&gt; 
&lt;/li&gt;
&lt;li&gt;
&lt;font color="#0000ff"&gt;Entity Framework 5 (beta)&lt;/font&gt; 
&lt;/li&gt;
&lt;li&gt;
&lt;font color="#0000ff"&gt;Entity Framework Code First&lt;/font&gt; 
&lt;/li&gt;
&lt;li&gt;
&lt;font color="#0000ff"&gt;Entity Framework Migrations&lt;/font&gt; 
&lt;/li&gt;
&lt;li&gt;
&lt;font color="#0000ff"&gt;ASP.Net MVC 4&lt;/font&gt; 
&lt;/li&gt;
&lt;li&gt;
&lt;font color="#0000ff"&gt;Razor&lt;/font&gt; 
&lt;/li&gt;
&lt;li&gt;
&lt;font color="#0000ff"&gt;HTML 5&lt;/font&gt; 
&lt;/li&gt;
&lt;li&gt;
&lt;font color="#0000ff"&gt;jQuery&lt;/font&gt; 
&lt;/li&gt;
&lt;li&gt;
&lt;font color="#0000ff"&gt;jQuery UI&lt;/font&gt; 
&lt;/li&gt;
&lt;li&gt;
&lt;font color="#0000ff"&gt;Git&lt;/font&gt; 
&lt;/li&gt;
&lt;li&gt;
&lt;font color="#0000ff"&gt;Open Authentication&lt;!--EndFragment--&gt;&lt;/font&gt; 
&lt;/li&gt;
&lt;li&gt;
&lt;font color="#0000ff"&gt;CSS3 &amp;amp; Media Queries&lt;/font&gt; 
&lt;/li&gt;
&lt;li&gt;
&lt;font color="#0000ff"&gt;HTML/CSS Grid Systems&lt;/font&gt; 
&lt;/li&gt;
&lt;li&gt;
&lt;font color="#0000ff"&gt;NuGet&lt;/font&gt; 
&lt;/li&gt;
&lt;li&gt;
&lt;font color="#0000ff"&gt;SEO Toolkit (Microsoft)&lt;!--EndFragment--&gt;&lt;/font&gt; 
&lt;/li&gt;
&lt;li&gt;
C# 4.5 (including Async) 
&lt;/li&gt;
&lt;li&gt;
SignalR 
&lt;/li&gt;
&lt;li&gt;
Azure 
&lt;/li&gt;
&lt;li&gt;
ASP.Net Web API 
&lt;/li&gt;
&lt;li&gt;
BootStrap (from Twitter) 
&lt;/li&gt;
&lt;li&gt;
Facebook Integration 
&lt;/li&gt;
&lt;li&gt;
Of course, &lt;font color="#0000ff"&gt;Dependency Injection, Unit Testing&lt;/font&gt;, and all
of the other stuff I put into any app I am deploying. 
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
I’m writing this as a web application and creating a mobile version at the same time.
In addition, I plan to extend this to additional platforms. So my list continues:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;font color="#0000ff"&gt;Mobile Web&lt;/font&gt; 
&lt;/li&gt;
&lt;li&gt;
WP7 
&lt;/li&gt;
&lt;li&gt;
Metro (Windows 8) 
&lt;/li&gt;
&lt;/ul&gt;
&lt;img width="0" height="0" src="http://www.blog.ingenuitynow.net/aggbug.ashx?id=f4ca8a63-3acd-47a0-8e22-52beacb4589f" /&gt;</description>
      <comments>http://www.blog.ingenuitynow.net/CommentView,guid,f4ca8a63-3acd-47a0-8e22-52beacb4589f.aspx</comments>
      <category>.Net;asp.net mvc;C#;Visual Studio</category>
    </item>
    <item>
      <trackback:ping>http://www.blog.ingenuitynow.net/Trackback.aspx?guid=9cf23301-5ac2-4223-bc78-3595d9aa862d</trackback:ping>
      <pingback:server>http://www.blog.ingenuitynow.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.blog.ingenuitynow.net/PermaLink,guid,9cf23301-5ac2-4223-bc78-3595d9aa862d.aspx</pingback:target>
      <dc:creator>Andrew Schwam</dc:creator>
      <wfw:comment>http://www.blog.ingenuitynow.net/CommentView,guid,9cf23301-5ac2-4223-bc78-3595d9aa862d.aspx</wfw:comment>
      <wfw:commentRss>http://www.blog.ingenuitynow.net/SyndicationService.asmx/GetEntryCommentsRss?guid=9cf23301-5ac2-4223-bc78-3595d9aa862d</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Philly.Net recently had a very successful event called <a href="http://csharpenup2012.eventbrite.com/">CSharpenUp</a>.
We spent the day talking about some advanced topics for C# developers. We had 4 speakers
and 80+ attendees. The feedback was very positive, everyone learned a lot and had
fun too. If we can set it up, we’ll do the same event in the fall for those that missed
it.
</p>
        <p>
I’m still gathering code samples from the other presenters. But for now, here is mine:
</p>
        <p>
Code samples and slides for my LINQ session: <a href="http://www.blog.ingenuitynow.net/content/binary/CSharpenUp-LINQ.zip">Intro
to LINQ</a></p>
        <p>
Code samples and slides for my Unit Testing session: <a href="http://www.blog.ingenuitynow.net/content/binary/CSharpenUp-UnitTesting.zip">Unit
Testing Made Easy</a></p>
        <p>
Also, FYI we did try to record the sessions using Camtasia. Unfortunately, the mic
we used wasn’t that great. I’m trying to salvage mine but I may just re-record them.
</p>
        <img width="0" height="0" src="http://www.blog.ingenuitynow.net/aggbug.ashx?id=9cf23301-5ac2-4223-bc78-3595d9aa862d" />
      </body>
      <title>CSharpenUp Samples and Slides</title>
      <guid isPermaLink="false">http://www.blog.ingenuitynow.net/PermaLink,guid,9cf23301-5ac2-4223-bc78-3595d9aa862d.aspx</guid>
      <link>http://www.blog.ingenuitynow.net/CSharpenUp+Samples+And+Slides.aspx</link>
      <pubDate>Thu, 12 Apr 2012 06:38:00 GMT</pubDate>
      <description>&lt;p&gt;
Philly.Net recently had a very successful event called &lt;a href="http://csharpenup2012.eventbrite.com/"&gt;CSharpenUp&lt;/a&gt;.
We spent the day talking about some advanced topics for C# developers. We had 4 speakers
and 80+ attendees. The feedback was very positive, everyone learned a lot and had
fun too. If we can set it up, we’ll do the same event in the fall for those that missed
it.
&lt;/p&gt;
&lt;p&gt;
I’m still gathering code samples from the other presenters. But for now, here is mine:
&lt;/p&gt;
&lt;p&gt;
Code samples and slides for my LINQ session: &lt;a href="http://www.blog.ingenuitynow.net/content/binary/CSharpenUp-LINQ.zip"&gt;Intro
to LINQ&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
Code samples and slides for my Unit Testing session: &lt;a href="http://www.blog.ingenuitynow.net/content/binary/CSharpenUp-UnitTesting.zip"&gt;Unit
Testing Made Easy&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
Also, FYI we did try to record the sessions using Camtasia. Unfortunately, the mic
we used wasn’t that great. I’m trying to salvage mine but I may just re-record them.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.blog.ingenuitynow.net/aggbug.ashx?id=9cf23301-5ac2-4223-bc78-3595d9aa862d" /&gt;</description>
      <comments>http://www.blog.ingenuitynow.net/CommentView,guid,9cf23301-5ac2-4223-bc78-3595d9aa862d.aspx</comments>
      <category>.Net;C#;LINQ;MOQ;NUnit;Philly.Net;Unit Testing</category>
    </item>
    <item>
      <trackback:ping>http://www.blog.ingenuitynow.net/Trackback.aspx?guid=2d78a517-f103-4977-a3dd-b5ed8d770e29</trackback:ping>
      <pingback:server>http://www.blog.ingenuitynow.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.blog.ingenuitynow.net/PermaLink,guid,2d78a517-f103-4977-a3dd-b5ed8d770e29.aspx</pingback:target>
      <dc:creator>Andrew Schwam</dc:creator>
      <wfw:comment>http://www.blog.ingenuitynow.net/CommentView,guid,2d78a517-f103-4977-a3dd-b5ed8d770e29.aspx</wfw:comment>
      <wfw:commentRss>http://www.blog.ingenuitynow.net/SyndicationService.asmx/GetEntryCommentsRss?guid=2d78a517-f103-4977-a3dd-b5ed8d770e29</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
When I write code, one of my big concerns is how will I test it. I’ve learned that
when I see a static method, it is going to make things more complicated than I would
like. However, resolving that isn’t usually too difficult. Converting a string value
into an Enum is a perfect example. Of course, parsing the string may succeed or fail
and I need to know how my code will behave in either case, hence the reason for the
unit tests. 
</p>
        <p>
In order to make unit testing a bit easier, I wrote a simple class to help out. Basically,
this class “wraps” Enum.TryParse() and of course, implements and interface. I’m also
using some simple generics to make the casting a little prettier. Since I used an
interface, I can now using MOQ, RhinoMocks, or any other framework to mock my dependency
and control how it behaves.
</p>
        <p>
You may note that I didn’t call the methods Parse. Instead, I used the name Adapt.
That is just a naming convention of my current project so it made sense to be consistent.
Feel free to rename this as you wish :) 
</p>
        <p>
Here is the interface:
</p>
        <div class="csharpcode">
          <pre class="alt">
            <span class="kwrd">public</span>
            <span class="kwrd">interface</span> IStringToEnumAdapter</pre>
          <pre>{</pre>
          <pre class="alt">     T Adapt&lt;T&gt;(<span class="kwrd">string</span><span class="kwrd">value</span>) <span class="kwrd">where</span> T: <span class="kwrd">struct</span>;</pre>
          <pre>
            <span class="kwrd">bool</span> TryAdapt&lt;T&gt;(<span class="kwrd">string</span><span class="kwrd">value</span>, <span class="kwrd">out</span> T?
result) <span class="kwrd">where</span> T : <span class="kwrd">struct</span>;</pre>
          <pre class="alt">}</pre>
        </div>
        <style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
        <p>
You’ll probably notice that my generic constraint is <span class="kwrd">struct</span>.
That is because you can’t use Enum as a generic constraint. So struct is the best
I’ve got to work with. And considering we are doing parsing here, if you pass any
other stuct in, it is going to fail on the parse anyway. So I think it is pretty safe.
</p>
        <p>
Here is the implementation:
</p>
        <div class="csharpcode">
          <pre class="alt">
            <span class="kwrd">public</span>
            <span class="kwrd">class</span> StringToEnumAdapter
: IStringToEnumAdapter</pre>
          <pre>{</pre>
          <pre class="alt">
            <span class="kwrd">public</span> T Adapt&lt;T&gt;(<span class="kwrd">string</span><span class="kwrd">value</span>) <span class="kwrd">where</span> T
: <span class="kwrd">struct</span></pre>
          <pre>    {</pre>
          <pre class="alt">        T result;</pre>
          <pre>
          </pre>
          <pre class="alt">
            <span class="kwrd">bool</span> success = Enum.TryParse(<span class="kwrd">value</span>, <span class="kwrd">true</span>, <span class="kwrd">out</span> result);</pre>
          <pre> </pre>
          <pre class="alt">
            <span class="kwrd">if</span> (success)</pre>
          <pre>
            <span class="kwrd">return</span> result;</pre>
          <pre class="alt"> </pre>
          <pre>
            <span class="kwrd">throw</span>
            <span class="kwrd">new</span> InvalidEnumArgumentException(<span class="kwrd">string</span>.Format(<span class="str">"{0}
could not be converted to {1}"</span>, <span class="kwrd">value</span>, <span class="kwrd">typeof</span>(T).Name));</pre>
          <pre class="alt">    }</pre>
          <pre> </pre>
          <pre class="alt">
            <span class="kwrd">public</span>
            <span class="kwrd">bool</span> TryAdapt&lt;T&gt;(<span class="kwrd">string</span><span class="kwrd">value</span>, <span class="kwrd">out</span> T?
result) <span class="kwrd">where</span> T : <span class="kwrd">struct</span></pre>
          <pre>    {</pre>
          <pre class="alt">        T parsedValue;</pre>
          <pre>
            <span class="kwrd">bool</span> success = Enum.TryParse(<span class="kwrd">value</span>, <span class="kwrd">true</span>, <span class="kwrd">out</span> parsedValue);</pre>
          <pre class="alt"> </pre>
          <pre>        result = success ? parsedValue : (T?)<span class="kwrd">null</span>;</pre>
          <pre class="alt"> </pre>
          <pre>
            <span class="kwrd">return</span> success;</pre>
          <pre class="alt">    }</pre>
          <pre>}</pre>
        </div>
        <style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
        <p>
Guess what? It isn’t all that complicated right? If you are getting into testing,
you’ll soon find out that simple steps like this make life a lot easier.
</p>
        <p>
Click <a href="http://www.blog.ingenuitynow.net/content/binary/EnumParsing.zip">here
to download the class and unit tests</a> for it too.
</p>
        <img width="0" height="0" src="http://www.blog.ingenuitynow.net/aggbug.ashx?id=2d78a517-f103-4977-a3dd-b5ed8d770e29" />
      </body>
      <title>Unit Testable Enum Parsing with C#</title>
      <guid isPermaLink="false">http://www.blog.ingenuitynow.net/PermaLink,guid,2d78a517-f103-4977-a3dd-b5ed8d770e29.aspx</guid>
      <link>http://www.blog.ingenuitynow.net/Unit+Testable+Enum+Parsing+With+C.aspx</link>
      <pubDate>Thu, 12 Apr 2012 02:02:58 GMT</pubDate>
      <description>&lt;p&gt;
When I write code, one of my big concerns is how will I test it. I’ve learned that
when I see a static method, it is going to make things more complicated than I would
like. However, resolving that isn’t usually too difficult. Converting a string value
into an Enum is a perfect example. Of course, parsing the string may succeed or fail
and I need to know how my code will behave in either case, hence the reason for the
unit tests. 
&lt;/p&gt;
&lt;p&gt;
In order to make unit testing a bit easier, I wrote a simple class to help out. Basically,
this class “wraps” Enum.TryParse() and of course, implements and interface. I’m also
using some simple generics to make the casting a little prettier. Since I used an
interface, I can now using MOQ, RhinoMocks, or any other framework to mock my dependency
and control how it behaves.
&lt;/p&gt;
&lt;p&gt;
You may note that I didn’t call the methods Parse. Instead, I used the name Adapt.
That is just a naming convention of my current project so it made sense to be consistent.
Feel free to rename this as you wish :) 
&lt;/p&gt;
&lt;p&gt;
Here is the interface:
&lt;/p&gt;
&lt;div class="csharpcode"&gt;
&lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;interface&lt;/span&gt; IStringToEnumAdapter&lt;/pre&gt;
&lt;pre&gt;{&lt;/pre&gt;
&lt;pre class="alt"&gt;     T Adapt&amp;lt;T&amp;gt;(&lt;span class="kwrd"&gt;string&lt;/span&gt; &lt;span class="kwrd"&gt;value&lt;/span&gt;) &lt;span class="kwrd"&gt;where&lt;/span&gt; T: &lt;span class="kwrd"&gt;struct&lt;/span&gt;;&lt;/pre&gt;
&lt;pre&gt;     &lt;span class="kwrd"&gt;bool&lt;/span&gt; TryAdapt&amp;lt;T&amp;gt;(&lt;span class="kwrd"&gt;string&lt;/span&gt; &lt;span class="kwrd"&gt;value&lt;/span&gt;, &lt;span class="kwrd"&gt;out&lt;/span&gt; T?
result) &lt;span class="kwrd"&gt;where&lt;/span&gt; T : &lt;span class="kwrd"&gt;struct&lt;/span&gt;;&lt;/pre&gt;
&lt;pre class="alt"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;
&lt;p&gt;
You’ll probably notice that my generic constraint is &lt;span class="kwrd"&gt;struct&lt;/span&gt;.
That is because you can’t use Enum as a generic constraint. So struct is the best
I’ve got to work with. And considering we are doing parsing here, if you pass any
other stuct in, it is going to fail on the parse anyway. So I think it is pretty safe.
&lt;/p&gt;
&lt;p&gt;
Here is the implementation:
&lt;/p&gt;
&lt;div class="csharpcode"&gt;
&lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; StringToEnumAdapter
: IStringToEnumAdapter&lt;/pre&gt;
&lt;pre&gt;{&lt;/pre&gt;
&lt;pre class="alt"&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; T Adapt&amp;lt;T&amp;gt;(&lt;span class="kwrd"&gt;string&lt;/span&gt; &lt;span class="kwrd"&gt;value&lt;/span&gt;) &lt;span class="kwrd"&gt;where&lt;/span&gt; T
: &lt;span class="kwrd"&gt;struct&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;    {&lt;/pre&gt;
&lt;pre class="alt"&gt;        T result;&lt;/pre&gt;
&lt;pre&gt;        &lt;/pre&gt;
&lt;pre class="alt"&gt;        &lt;span class="kwrd"&gt;bool&lt;/span&gt; success = Enum.TryParse(&lt;span class="kwrd"&gt;value&lt;/span&gt;, &lt;span class="kwrd"&gt;true&lt;/span&gt;, &lt;span class="kwrd"&gt;out&lt;/span&gt; result);&lt;/pre&gt;
&lt;pre&gt;&amp;#160;&lt;/pre&gt;
&lt;pre class="alt"&gt;        &lt;span class="kwrd"&gt;if&lt;/span&gt; (success)&lt;/pre&gt;
&lt;pre&gt;            &lt;span class="kwrd"&gt;return&lt;/span&gt; result;&lt;/pre&gt;
&lt;pre class="alt"&gt;&amp;#160;&lt;/pre&gt;
&lt;pre&gt;        &lt;span class="kwrd"&gt;throw&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; InvalidEnumArgumentException(&lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(&lt;span class="str"&gt;&amp;quot;{0}
could not be converted to {1}&amp;quot;&lt;/span&gt;, &lt;span class="kwrd"&gt;value&lt;/span&gt;, &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(T).Name));&lt;/pre&gt;
&lt;pre class="alt"&gt;    }&lt;/pre&gt;
&lt;pre&gt;&amp;#160;&lt;/pre&gt;
&lt;pre class="alt"&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; TryAdapt&amp;lt;T&amp;gt;(&lt;span class="kwrd"&gt;string&lt;/span&gt; &lt;span class="kwrd"&gt;value&lt;/span&gt;, &lt;span class="kwrd"&gt;out&lt;/span&gt; T?
result) &lt;span class="kwrd"&gt;where&lt;/span&gt; T : &lt;span class="kwrd"&gt;struct&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;    {&lt;/pre&gt;
&lt;pre class="alt"&gt;        T parsedValue;&lt;/pre&gt;
&lt;pre&gt;        &lt;span class="kwrd"&gt;bool&lt;/span&gt; success = Enum.TryParse(&lt;span class="kwrd"&gt;value&lt;/span&gt;, &lt;span class="kwrd"&gt;true&lt;/span&gt;, &lt;span class="kwrd"&gt;out&lt;/span&gt; parsedValue);&lt;/pre&gt;
&lt;pre class="alt"&gt;&amp;#160;&lt;/pre&gt;
&lt;pre&gt;        result = success ? parsedValue : (T?)&lt;span class="kwrd"&gt;null&lt;/span&gt;;&lt;/pre&gt;
&lt;pre class="alt"&gt;&amp;#160;&lt;/pre&gt;
&lt;pre&gt;        &lt;span class="kwrd"&gt;return&lt;/span&gt; success;&lt;/pre&gt;
&lt;pre class="alt"&gt;    }&lt;/pre&gt;
&lt;pre&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;
&lt;p&gt;
Guess what? It isn’t all that complicated right? If you are getting into testing,
you’ll soon find out that simple steps like this make life a lot easier.
&lt;/p&gt;
&lt;p&gt;
Click &lt;a href="http://www.blog.ingenuitynow.net/content/binary/EnumParsing.zip"&gt;here
to download the class and unit tests&lt;/a&gt; for it too.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.blog.ingenuitynow.net/aggbug.ashx?id=2d78a517-f103-4977-a3dd-b5ed8d770e29" /&gt;</description>
      <comments>http://www.blog.ingenuitynow.net/CommentView,guid,2d78a517-f103-4977-a3dd-b5ed8d770e29.aspx</comments>
      <category>.Net;C#;MOQ;NUnit;Unit Testing</category>
    </item>
    <item>
      <trackback:ping>http://www.blog.ingenuitynow.net/Trackback.aspx?guid=7fe0cd86-5635-4173-8c0e-b02695ea652a</trackback:ping>
      <pingback:server>http://www.blog.ingenuitynow.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.blog.ingenuitynow.net/PermaLink,guid,7fe0cd86-5635-4173-8c0e-b02695ea652a.aspx</pingback:target>
      <dc:creator>Andrew Schwam</dc:creator>
      <wfw:comment>http://www.blog.ingenuitynow.net/CommentView,guid,7fe0cd86-5635-4173-8c0e-b02695ea652a.aspx</wfw:comment>
      <wfw:commentRss>http://www.blog.ingenuitynow.net/SyndicationService.asmx/GetEntryCommentsRss?guid=7fe0cd86-5635-4173-8c0e-b02695ea652a</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Tomorrow night I’m doing a demo at Philly.Net on AOP. It’s a pretty cool technology
that allows you to deal with cross cutting concerns in a pretty easy way. Write your
code once (code for exception handling, logging, security, etc.) in an Aspect. Then
you can easily reuse that same aspect throughout your application by simply decorating
methods with an attribute. 
</p>
        <p>
If you attended my demo, you may want the source code… <a href="http://www.blog.ingenuitynow.net/content/binary/AOPSample.Zip">here
it is</a>.
</p>
        <p>
If you are just curious, here is some sample code:
</p>
        <p>
A simple Trace Aspect:
</p>
        <pre class="code">
          <span style="color: blue">using </span>System; <span style="color: blue">using </span>System.Diagnostics; <span style="color: blue">using </span>PostSharp.Aspects; <span style="color: blue">namespace </span>AOPSample
{ [<span style="color: #2b91af">Serializable</span>] <span style="color: blue">public
sealed class </span><span style="color: #2b91af">TraceAttribute </span>: <span style="color: #2b91af">OnMethodBoundaryAspect </span>{ <span style="color: blue">public
override void </span>OnEntry(<span style="color: #2b91af">MethodExecutionArgs </span>args)
{ <span style="color: #2b91af">Trace</span>.WriteLine(<span style="color: blue">string</span>.Format(<span style="color: #a31515">"Entering </span><span style="color: #3cb371">{0}</span><span style="color: #a31515">.</span><span style="color: #3cb371">{1}</span><span style="color: #a31515">"</span>,
args.Method.DeclaringType.Name, args.Method.Name)); } <span style="color: blue">public
override void </span>OnExit(<span style="color: #2b91af">MethodExecutionArgs </span>args)
{ <span style="color: #2b91af">Trace</span>.WriteLine(<span style="color: blue">string</span>.Format(<span style="color: #a31515">"Leaving </span><span style="color: #3cb371">{0}</span><span style="color: #a31515">.</span><span style="color: #3cb371">{1}</span><span style="color: #a31515">"</span>,
args.Method.DeclaringType.Name, args.Method.Name)); } } } <font face="Verdana">I want
to write to the Trace log everytime DoSomething() gets called, so I decorate it with
the Trace attribute!:</font></pre>
        <pre class="code">
          <span style="color: blue">using </span>System; <span style="color: blue">namespace </span>AOPSample
{ <span style="color: blue">public class </span><span style="color: #2b91af">ServiceThatNeedsTracing </span>{
[<span style="color: #2b91af">Trace</span>] <span style="color: blue">public void </span>DoSomething()
{ <span style="color: green">//it doesn't matter what is here. </span>} } } <font face="Verdana">When
I run my application and call the DoSomething() method, I’ll get this in the Trace
Window:</font></pre>
        <pre class="code">Entering ServiceThatNeedsTracing.DoSomething
Leaving ServiceThatNeedsTracing.DoSomething</pre>
        <pre class="code">
          <font face="Verdana">Isn’t that easy?</font>
        </pre>
        <img width="0" height="0" src="http://www.blog.ingenuitynow.net/aggbug.ashx?id=7fe0cd86-5635-4173-8c0e-b02695ea652a" />
      </body>
      <title>Aspect Oriented Programming with C# and PostSharp</title>
      <guid isPermaLink="false">http://www.blog.ingenuitynow.net/PermaLink,guid,7fe0cd86-5635-4173-8c0e-b02695ea652a.aspx</guid>
      <link>http://www.blog.ingenuitynow.net/Aspect+Oriented+Programming+With+C+And+PostSharp.aspx</link>
      <pubDate>Wed, 15 Feb 2012 03:06:55 GMT</pubDate>
      <description>&lt;p&gt;
Tomorrow night I’m doing a demo at Philly.Net on AOP. It’s a pretty cool technology
that allows you to deal with cross cutting concerns in a pretty easy way. Write your
code once (code for exception handling, logging, security, etc.) in an Aspect. Then
you can easily reuse that same aspect throughout your application by simply decorating
methods with an attribute. 
&lt;/p&gt;
&lt;p&gt;
If you attended my demo, you may want the source code… &lt;a href="http://www.blog.ingenuitynow.net/content/binary/AOPSample.Zip"&gt;here
it is&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
If you are just curious, here is some sample code:
&lt;/p&gt;
&lt;p&gt;
A simple Trace Aspect:
&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;using &lt;/span&gt;System; &lt;span style="color: blue"&gt;using &lt;/span&gt;System.Diagnostics; &lt;span style="color: blue"&gt;using &lt;/span&gt;PostSharp.Aspects; &lt;span style="color: blue"&gt;namespace &lt;/span&gt;AOPSample
{ [&lt;span style="color: #2b91af"&gt;Serializable&lt;/span&gt;] &lt;span style="color: blue"&gt;public
sealed class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;TraceAttribute &lt;/span&gt;: &lt;span style="color: #2b91af"&gt;OnMethodBoundaryAspect &lt;/span&gt;{ &lt;span style="color: blue"&gt;public
override void &lt;/span&gt;OnEntry(&lt;span style="color: #2b91af"&gt;MethodExecutionArgs &lt;/span&gt;args)
{ &lt;span style="color: #2b91af"&gt;Trace&lt;/span&gt;.WriteLine(&lt;span style="color: blue"&gt;string&lt;/span&gt;.Format(&lt;span style="color: #a31515"&gt;&amp;quot;Entering &lt;/span&gt;&lt;span style="color: #3cb371"&gt;{0}&lt;/span&gt;&lt;span style="color: #a31515"&gt;.&lt;/span&gt;&lt;span style="color: #3cb371"&gt;{1}&lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;quot;&lt;/span&gt;,
args.Method.DeclaringType.Name, args.Method.Name)); } &lt;span style="color: blue"&gt;public
override void &lt;/span&gt;OnExit(&lt;span style="color: #2b91af"&gt;MethodExecutionArgs &lt;/span&gt;args)
{ &lt;span style="color: #2b91af"&gt;Trace&lt;/span&gt;.WriteLine(&lt;span style="color: blue"&gt;string&lt;/span&gt;.Format(&lt;span style="color: #a31515"&gt;&amp;quot;Leaving &lt;/span&gt;&lt;span style="color: #3cb371"&gt;{0}&lt;/span&gt;&lt;span style="color: #a31515"&gt;.&lt;/span&gt;&lt;span style="color: #3cb371"&gt;{1}&lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;quot;&lt;/span&gt;,
args.Method.DeclaringType.Name, args.Method.Name)); } } } &lt;font face="Verdana"&gt;I want
to write to the Trace log everytime DoSomething() gets called, so I decorate it with
the Trace attribute!:&lt;/font&gt;&lt;/pre&gt;
&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;using &lt;/span&gt;System; &lt;span style="color: blue"&gt;namespace &lt;/span&gt;AOPSample
{ &lt;span style="color: blue"&gt;public class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;ServiceThatNeedsTracing &lt;/span&gt;{
[&lt;span style="color: #2b91af"&gt;Trace&lt;/span&gt;] &lt;span style="color: blue"&gt;public void &lt;/span&gt;DoSomething()
{ &lt;span style="color: green"&gt;//it doesn't matter what is here. &lt;/span&gt;} } } &lt;font face="Verdana"&gt;When
I run my application and call the DoSomething() method, I’ll get this in the Trace
Window:&lt;/font&gt;&lt;/pre&gt;
&lt;pre class="code"&gt;Entering ServiceThatNeedsTracing.DoSomething
Leaving ServiceThatNeedsTracing.DoSomething&lt;/pre&gt;
&lt;pre class="code"&gt;&lt;font face="Verdana"&gt;Isn’t that easy?&lt;/font&gt;&lt;/pre&gt;
&lt;img width="0" height="0" src="http://www.blog.ingenuitynow.net/aggbug.ashx?id=7fe0cd86-5635-4173-8c0e-b02695ea652a" /&gt;</description>
      <comments>http://www.blog.ingenuitynow.net/CommentView,guid,7fe0cd86-5635-4173-8c0e-b02695ea652a.aspx</comments>
      <category>.Net;C#;Philly.Net</category>
    </item>
    <item>
      <trackback:ping>http://www.blog.ingenuitynow.net/Trackback.aspx?guid=e640a50f-9f93-4b0a-a150-c7f586d1833b</trackback:ping>
      <pingback:server>http://www.blog.ingenuitynow.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.blog.ingenuitynow.net/PermaLink,guid,e640a50f-9f93-4b0a-a150-c7f586d1833b.aspx</pingback:target>
      <dc:creator>Andrew Schwam</dc:creator>
      <wfw:comment>http://www.blog.ingenuitynow.net/CommentView,guid,e640a50f-9f93-4b0a-a150-c7f586d1833b.aspx</wfw:comment>
      <wfw:commentRss>http://www.blog.ingenuitynow.net/SyndicationService.asmx/GetEntryCommentsRss?guid=e640a50f-9f93-4b0a-a150-c7f586d1833b</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Linq is awesome and always makes tasks easier!  Here is a great tip that you
might not know about. 
</p>
        <p>
Today I needed to compare two generic lists… SequenceEqual() to the rescue. 
To show how it works, here is some sample code:
</p>
        <pre class="code">[<span style="color: #2b91af">Test</span>] <span style="color: blue">public
void </span>SuccessfullyMatchesTwoListsOfInts() { <span style="color: #2b91af">List</span>&lt;<span style="color: blue">int</span>&gt;
ints1 = <span style="color: blue">new </span><span style="color: #2b91af">List</span>&lt;<span style="color: blue">int</span>&gt;();
ints1.Add(1); ints1.Add(2); ints1.Add(3); <span style="color: #2b91af">List</span>&lt;<span style="color: blue">int</span>&gt;
ints2 = <span style="color: blue">new </span><span style="color: #2b91af">List</span>&lt;<span style="color: blue">int</span>&gt;();
ints2.Add(1); ints2.Add(2); ints2.Add(3); <span style="color: #2b91af">Assert</span>.That(ints1.SequenceEqual(ints2), <span style="color: #2b91af">Is</span>.True);
}</pre>
        <p>
SequenceEqual loops through the 2 lists and compares each item to make sure they match. 
Just for kicks I put it through the paces.  Here are some other unit tests that
I wrote.  This helps show what you can do:
</p>
        <pre class="code">
          <span style="color: blue">using </span>System.Collections.Generic; <span style="color: blue">using </span>System.Linq; <span style="color: blue">using </span>NUnit.Framework; <span style="color: blue">namespace </span>SequenceEqual
{ [<span style="color: #2b91af">TestFixture</span>] <span style="color: blue">public
class </span><span style="color: #2b91af">SequenceEqualTests </span>{ [<span style="color: #2b91af">Test</span>] <span style="color: blue">public
void </span>SuccessfullyMatchesTwoListsOfInts() { <span style="color: #2b91af">List</span>&lt;<span style="color: blue">int</span>&gt;
ints1 = <span style="color: blue">new </span><span style="color: #2b91af">List</span>&lt;<span style="color: blue">int</span>&gt;();
ints1.Add(1); ints1.Add(2); ints1.Add(3); <span style="color: #2b91af">List</span>&lt;<span style="color: blue">int</span>&gt;
ints2 = <span style="color: blue">new </span><span style="color: #2b91af">List</span>&lt;<span style="color: blue">int</span>&gt;();
ints2.Add(1); ints2.Add(2); ints2.Add(3); <span style="color: #2b91af">Assert</span>.That(ints1.SequenceEqual(ints2), <span style="color: #2b91af">Is</span>.True);
} [<span style="color: #2b91af">Test</span>] <span style="color: blue">public void </span>SuccessfullyFailsTwoListsOfInts()
{ <span style="color: green">// these two don't match! </span><span style="color: #2b91af">List</span>&lt;<span style="color: blue">int</span>&gt;
ints1 = <span style="color: blue">new </span><span style="color: #2b91af">List</span>&lt;<span style="color: blue">int</span>&gt;();
ints1.Add(1); ints1.Add(2); ints1.Add(3); <span style="color: #2b91af">List</span>&lt;<span style="color: blue">int</span>&gt;
ints2 = <span style="color: blue">new </span><span style="color: #2b91af">List</span>&lt;<span style="color: blue">int</span>&gt;();
ints2.Add(1); ints2.Add(4); ints2.Add(3); <span style="color: #2b91af">Assert</span>.That(ints1.SequenceEqual(ints2), <span style="color: #2b91af">Is</span>.False);
} [<span style="color: #2b91af">Test</span>] <span style="color: blue">public void </span>SuccessfullyFailsTwoListsOfIntsOutOfOrder()
{ <span style="color: green">// these two don't match. They have the same contents
but the order is changed. </span><span style="color: #2b91af">List</span>&lt;<span style="color: blue">int</span>&gt;
ints1 = <span style="color: blue">new </span><span style="color: #2b91af">List</span>&lt;<span style="color: blue">int</span>&gt;();
ints1.Add(3); ints1.Add(2); ints1.Add(1); <span style="color: #2b91af">List</span>&lt;<span style="color: blue">int</span>&gt;
ints2 = <span style="color: blue">new </span><span style="color: #2b91af">List</span>&lt;<span style="color: blue">int</span>&gt;();
ints2.Add(1); ints2.Add(2); ints2.Add(3); <span style="color: #2b91af">Assert</span>.That(ints1.SequenceEqual(ints2), <span style="color: #2b91af">Is</span>.False);
} [<span style="color: #2b91af">Test</span>] <span style="color: blue">public void </span>SuccessfullyFailsTwoListsOfStrings()
{ <span style="color: green">// these two lists of strings don't match </span><span style="color: #2b91af">List</span>&lt;<span style="color: blue">string</span>&gt;
strings1 = <span style="color: blue">new </span><span style="color: #2b91af">List</span>&lt;<span style="color: blue">string</span>&gt;();
strings1.Add(<span style="color: #a31515">"one"</span>); strings1.Add(<span style="color: #a31515">"two"</span>);
strings1.Add(<span style="color: #a31515">"three"</span>); <span style="color: #2b91af">List</span>&lt;<span style="color: blue">string</span>&gt;
strings2 = <span style="color: blue">new </span><span style="color: #2b91af">List</span>&lt;<span style="color: blue">string</span>&gt;();
strings2.Add(<span style="color: #a31515">"one"</span>); strings2.Add(<span style="color: #a31515">"lasjdflkajsdf"</span>);
strings2.Add(<span style="color: #a31515">"three"</span>); <span style="color: #2b91af">Assert</span>.That(strings1.SequenceEqual(strings2), <span style="color: #2b91af">Is</span>.False);
} [<span style="color: #2b91af">Test</span>] <span style="color: blue">public void </span>SuccessfullyMatchesTwoListsOfStrings()
{ <span style="color: green">// two matching lists of strings. </span><span style="color: #2b91af">List</span>&lt;<span style="color: blue">string</span>&gt;
strings1 = <span style="color: blue">new </span><span style="color: #2b91af">List</span>&lt;<span style="color: blue">string</span>&gt;();
strings1.Add(<span style="color: #a31515">"one"</span>); strings1.Add(<span style="color: #a31515">"two"</span>);
strings1.Add(<span style="color: #a31515">"three"</span>); <span style="color: #2b91af">List</span>&lt;<span style="color: blue">string</span>&gt;
strings2 = <span style="color: blue">new </span><span style="color: #2b91af">List</span>&lt;<span style="color: blue">string</span>&gt;();
strings2.Add(<span style="color: #a31515">"one"</span>); strings2.Add(<span style="color: #a31515">"two"</span>);
strings2.Add(<span style="color: #a31515">"three"</span>); <span style="color: #2b91af">Assert</span>.That(strings1.SequenceEqual(strings2), <span style="color: #2b91af">Is</span>.True);
} [<span style="color: #2b91af">Test</span>] <span style="color: blue">public void </span>SuccessfullyMatchesTwoListsOfObjects()
{ <span style="color: green">// works for objects too. </span><span style="color: #2b91af">List</span>&lt;<span style="color: #2b91af">TestObject</span>&gt;
objects1 = <span style="color: blue">new </span><span style="color: #2b91af">List</span>&lt;<span style="color: #2b91af">TestObject</span>&gt;();
objects1.Add(<span style="color: blue">new </span><span style="color: #2b91af">TestObject </span>{
Property1 = <span style="color: #a31515">"1" </span>}); objects1.Add(<span style="color: blue">new </span><span style="color: #2b91af">TestObject </span>{
Property1 = <span style="color: #a31515">"2" </span>}); objects1.Add(<span style="color: blue">new </span><span style="color: #2b91af">TestObject </span>{
Property1 = <span style="color: #a31515">"3" </span>}); <span style="color: #2b91af">Assert</span>.That(objects1.SequenceEqual(objects1), <span style="color: #2b91af">Is</span>.True);
} [<span style="color: #2b91af">Test</span>] <span style="color: blue">public void </span>SuccessfullyFailsTwoListsOfObjects()
{ <span style="color: green">// these two lists of objects may "look" the
same, but they aren't // the same object (reference equals!) </span><span style="color: #2b91af">List</span>&lt;<span style="color: #2b91af">TestObject</span>&gt;
objects1 = <span style="color: blue">new </span><span style="color: #2b91af">List</span>&lt;<span style="color: #2b91af">TestObject</span>&gt;();
objects1.Add(<span style="color: blue">new </span><span style="color: #2b91af">TestObject </span>{
Property1 = <span style="color: #a31515">"1" </span>}); objects1.Add(<span style="color: blue">new </span><span style="color: #2b91af">TestObject </span>{
Property1 = <span style="color: #a31515">"2" </span>}); objects1.Add(<span style="color: blue">new </span><span style="color: #2b91af">TestObject </span>{
Property1 = <span style="color: #a31515">"3" </span>}); <span style="color: #2b91af">List</span>&lt;<span style="color: #2b91af">TestObject</span>&gt;
objects2 = <span style="color: blue">new </span><span style="color: #2b91af">List</span>&lt;<span style="color: #2b91af">TestObject</span>&gt;();
objects2.Add(<span style="color: blue">new </span><span style="color: #2b91af">TestObject </span>{
Property1 = <span style="color: #a31515">"1" </span>}); objects2.Add(<span style="color: blue">new </span><span style="color: #2b91af">TestObject </span>{
Property1 = <span style="color: #a31515">"2" </span>}); objects2.Add(<span style="color: blue">new </span><span style="color: #2b91af">TestObject </span>{
Property1 = <span style="color: #a31515">"3" </span>}); <span style="color: #2b91af">Assert</span>.That(objects1.SequenceEqual(objects2), <span style="color: #2b91af">Is</span>.False);
} [<span style="color: #2b91af">Test</span>] <span style="color: blue">public void </span>SuccessfullyMatchesTwoListsOfObjectsWithCustomComparer()
{ <span style="color: green">// here I use a custom comparer to see if the // two
lists of objects have the same content. </span><span style="color: #2b91af">List</span>&lt;<span style="color: #2b91af">TestObject</span>&gt;
objects1 = <span style="color: blue">new </span><span style="color: #2b91af">List</span>&lt;<span style="color: #2b91af">TestObject</span>&gt;();
objects1.Add(<span style="color: blue">new </span><span style="color: #2b91af">TestObject </span>{
Property1 = <span style="color: #a31515">"1" </span>}); objects1.Add(<span style="color: blue">new </span><span style="color: #2b91af">TestObject </span>{
Property1 = <span style="color: #a31515">"2" </span>}); objects1.Add(<span style="color: blue">new </span><span style="color: #2b91af">TestObject </span>{
Property1 = <span style="color: #a31515">"3" </span>}); <span style="color: #2b91af">List</span>&lt;<span style="color: #2b91af">TestObject</span>&gt;
objects2 = <span style="color: blue">new </span><span style="color: #2b91af">List</span>&lt;<span style="color: #2b91af">TestObject</span>&gt;();
objects2.Add(<span style="color: blue">new </span><span style="color: #2b91af">TestObject </span>{
Property1 = <span style="color: #a31515">"1" </span>}); objects2.Add(<span style="color: blue">new </span><span style="color: #2b91af">TestObject </span>{
Property1 = <span style="color: #a31515">"2" </span>}); objects2.Add(<span style="color: blue">new </span><span style="color: #2b91af">TestObject </span>{
Property1 = <span style="color: #a31515">"3" </span>}); <span style="color: #2b91af">Assert</span>.That(objects1.SequenceEqual(objects2, <span style="color: blue">new </span><span style="color: #2b91af">TestObjectComparer</span>()), <span style="color: #2b91af">Is</span>.True);
} [<span style="color: #2b91af">Test</span>] <span style="color: blue">public void </span>SuccessfullyFailsTwoListsOfObjectsWithCustomComparer()
{ <span style="color: green">// making sure the custome comparer fails when they don't
match </span><span style="color: #2b91af">List</span>&lt;<span style="color: #2b91af">TestObject</span>&gt;
objects1 = <span style="color: blue">new </span><span style="color: #2b91af">List</span>&lt;<span style="color: #2b91af">TestObject</span>&gt;();
objects1.Add(<span style="color: blue">new </span><span style="color: #2b91af">TestObject </span>{
Property1 = <span style="color: #a31515">"1" </span>}); objects1.Add(<span style="color: blue">new </span><span style="color: #2b91af">TestObject </span>{
Property1 = <span style="color: #a31515">"2" </span>}); objects1.Add(<span style="color: blue">new </span><span style="color: #2b91af">TestObject </span>{
Property1 = <span style="color: #a31515">"3" </span>}); <span style="color: #2b91af">List</span>&lt;<span style="color: #2b91af">TestObject</span>&gt;
objects2 = <span style="color: blue">new </span><span style="color: #2b91af">List</span>&lt;<span style="color: #2b91af">TestObject</span>&gt;();
objects2.Add(<span style="color: blue">new </span><span style="color: #2b91af">TestObject </span>{
Property1 = <span style="color: #a31515">"1" </span>}); objects2.Add(<span style="color: blue">new </span><span style="color: #2b91af">TestObject </span>{
Property1 = <span style="color: #a31515">"asdfsadf" </span>}); objects2.Add(<span style="color: blue">new </span><span style="color: #2b91af">TestObject </span>{
Property1 = <span style="color: #a31515">"3" </span>}); <span style="color: #2b91af">Assert</span>.That(objects1.SequenceEqual(objects2, <span style="color: blue">new </span><span style="color: #2b91af">TestObjectComparer</span>()), <span style="color: #2b91af">Is</span>.False);
} } <span style="color: blue">public class </span><span style="color: #2b91af">TestObject </span>{ <span style="color: blue">public
string </span>Property1 { <span style="color: blue">get</span>; <span style="color: blue">set</span>;
} } <span style="color: blue">public class </span><span style="color: #2b91af">TestObjectComparer </span>:
IEqualityComparer&lt;<span style="color: #2b91af">TestObject</span>&gt; { <span style="color: blue">public
bool </span>Equals(<span style="color: #2b91af">TestObject </span>x, <span style="color: #2b91af">TestObject </span>y)
{ <span style="color: blue">return </span>(x.Property1 == y.Property1); } <span style="color: blue">public
int </span>GetHashCode(<span style="color: #2b91af">TestObject </span>obj) { <span style="color: blue">return </span>obj.GetHashCode();
} } }</pre>
        <p>
Today I needed to compare to generic lists. I guessed that Linq would provide a way
to do this and sure enough it did: SequenceEqual() to the rescue. To show how it work
</p>
        <img width="0" height="0" src="http://www.blog.ingenuitynow.net/aggbug.ashx?id=e640a50f-9f93-4b0a-a150-c7f586d1833b" />
      </body>
      <title>Using Linq to Compare Lists</title>
      <guid isPermaLink="false">http://www.blog.ingenuitynow.net/PermaLink,guid,e640a50f-9f93-4b0a-a150-c7f586d1833b.aspx</guid>
      <link>http://www.blog.ingenuitynow.net/Using+Linq+To+Compare+Lists.aspx</link>
      <pubDate>Thu, 05 Jan 2012 03:23:16 GMT</pubDate>
      <description>&lt;p&gt;
Linq is awesome and always makes tasks easier!&amp;#160; Here is a great tip that you
might not know about. 
&lt;/p&gt;
&lt;p&gt;
Today I needed to compare two generic lists… SequenceEqual() to the rescue.&amp;#160;
To show how it works, here is some sample code:
&lt;/p&gt;
&lt;pre class="code"&gt;[&lt;span style="color: #2b91af"&gt;Test&lt;/span&gt;] &lt;span style="color: blue"&gt;public
void &lt;/span&gt;SuccessfullyMatchesTwoListsOfInts() { &lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;int&lt;/span&gt;&amp;gt;
ints1 = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;int&lt;/span&gt;&amp;gt;();
ints1.Add(1); ints1.Add(2); ints1.Add(3); &lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;int&lt;/span&gt;&amp;gt;
ints2 = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;int&lt;/span&gt;&amp;gt;();
ints2.Add(1); ints2.Add(2); ints2.Add(3); &lt;span style="color: #2b91af"&gt;Assert&lt;/span&gt;.That(ints1.SequenceEqual(ints2), &lt;span style="color: #2b91af"&gt;Is&lt;/span&gt;.True);
}&lt;/pre&gt;
&lt;p&gt;
SequenceEqual loops through the 2 lists and compares each item to make sure they match.&amp;#160;
Just for kicks I put it through the paces.&amp;#160; Here are some other unit tests that
I wrote.&amp;#160; This helps show what you can do:
&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;using &lt;/span&gt;System.Collections.Generic; &lt;span style="color: blue"&gt;using &lt;/span&gt;System.Linq; &lt;span style="color: blue"&gt;using &lt;/span&gt;NUnit.Framework; &lt;span style="color: blue"&gt;namespace &lt;/span&gt;SequenceEqual
{ [&lt;span style="color: #2b91af"&gt;TestFixture&lt;/span&gt;] &lt;span style="color: blue"&gt;public
class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;SequenceEqualTests &lt;/span&gt;{ [&lt;span style="color: #2b91af"&gt;Test&lt;/span&gt;] &lt;span style="color: blue"&gt;public
void &lt;/span&gt;SuccessfullyMatchesTwoListsOfInts() { &lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;int&lt;/span&gt;&amp;gt;
ints1 = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;int&lt;/span&gt;&amp;gt;();
ints1.Add(1); ints1.Add(2); ints1.Add(3); &lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;int&lt;/span&gt;&amp;gt;
ints2 = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;int&lt;/span&gt;&amp;gt;();
ints2.Add(1); ints2.Add(2); ints2.Add(3); &lt;span style="color: #2b91af"&gt;Assert&lt;/span&gt;.That(ints1.SequenceEqual(ints2), &lt;span style="color: #2b91af"&gt;Is&lt;/span&gt;.True);
} [&lt;span style="color: #2b91af"&gt;Test&lt;/span&gt;] &lt;span style="color: blue"&gt;public void &lt;/span&gt;SuccessfullyFailsTwoListsOfInts()
{ &lt;span style="color: green"&gt;// these two don't match! &lt;/span&gt;&lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;int&lt;/span&gt;&amp;gt;
ints1 = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;int&lt;/span&gt;&amp;gt;();
ints1.Add(1); ints1.Add(2); ints1.Add(3); &lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;int&lt;/span&gt;&amp;gt;
ints2 = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;int&lt;/span&gt;&amp;gt;();
ints2.Add(1); ints2.Add(4); ints2.Add(3); &lt;span style="color: #2b91af"&gt;Assert&lt;/span&gt;.That(ints1.SequenceEqual(ints2), &lt;span style="color: #2b91af"&gt;Is&lt;/span&gt;.False);
} [&lt;span style="color: #2b91af"&gt;Test&lt;/span&gt;] &lt;span style="color: blue"&gt;public void &lt;/span&gt;SuccessfullyFailsTwoListsOfIntsOutOfOrder()
{ &lt;span style="color: green"&gt;// these two don't match. They have the same contents
but the order is changed. &lt;/span&gt;&lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;int&lt;/span&gt;&amp;gt;
ints1 = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;int&lt;/span&gt;&amp;gt;();
ints1.Add(3); ints1.Add(2); ints1.Add(1); &lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;int&lt;/span&gt;&amp;gt;
ints2 = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;int&lt;/span&gt;&amp;gt;();
ints2.Add(1); ints2.Add(2); ints2.Add(3); &lt;span style="color: #2b91af"&gt;Assert&lt;/span&gt;.That(ints1.SequenceEqual(ints2), &lt;span style="color: #2b91af"&gt;Is&lt;/span&gt;.False);
} [&lt;span style="color: #2b91af"&gt;Test&lt;/span&gt;] &lt;span style="color: blue"&gt;public void &lt;/span&gt;SuccessfullyFailsTwoListsOfStrings()
{ &lt;span style="color: green"&gt;// these two lists of strings don't match &lt;/span&gt;&lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;string&lt;/span&gt;&amp;gt;
strings1 = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;string&lt;/span&gt;&amp;gt;();
strings1.Add(&lt;span style="color: #a31515"&gt;&amp;quot;one&amp;quot;&lt;/span&gt;); strings1.Add(&lt;span style="color: #a31515"&gt;&amp;quot;two&amp;quot;&lt;/span&gt;);
strings1.Add(&lt;span style="color: #a31515"&gt;&amp;quot;three&amp;quot;&lt;/span&gt;); &lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;string&lt;/span&gt;&amp;gt;
strings2 = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;string&lt;/span&gt;&amp;gt;();
strings2.Add(&lt;span style="color: #a31515"&gt;&amp;quot;one&amp;quot;&lt;/span&gt;); strings2.Add(&lt;span style="color: #a31515"&gt;&amp;quot;lasjdflkajsdf&amp;quot;&lt;/span&gt;);
strings2.Add(&lt;span style="color: #a31515"&gt;&amp;quot;three&amp;quot;&lt;/span&gt;); &lt;span style="color: #2b91af"&gt;Assert&lt;/span&gt;.That(strings1.SequenceEqual(strings2), &lt;span style="color: #2b91af"&gt;Is&lt;/span&gt;.False);
} [&lt;span style="color: #2b91af"&gt;Test&lt;/span&gt;] &lt;span style="color: blue"&gt;public void &lt;/span&gt;SuccessfullyMatchesTwoListsOfStrings()
{ &lt;span style="color: green"&gt;// two matching lists of strings. &lt;/span&gt;&lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;string&lt;/span&gt;&amp;gt;
strings1 = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;string&lt;/span&gt;&amp;gt;();
strings1.Add(&lt;span style="color: #a31515"&gt;&amp;quot;one&amp;quot;&lt;/span&gt;); strings1.Add(&lt;span style="color: #a31515"&gt;&amp;quot;two&amp;quot;&lt;/span&gt;);
strings1.Add(&lt;span style="color: #a31515"&gt;&amp;quot;three&amp;quot;&lt;/span&gt;); &lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;string&lt;/span&gt;&amp;gt;
strings2 = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;string&lt;/span&gt;&amp;gt;();
strings2.Add(&lt;span style="color: #a31515"&gt;&amp;quot;one&amp;quot;&lt;/span&gt;); strings2.Add(&lt;span style="color: #a31515"&gt;&amp;quot;two&amp;quot;&lt;/span&gt;);
strings2.Add(&lt;span style="color: #a31515"&gt;&amp;quot;three&amp;quot;&lt;/span&gt;); &lt;span style="color: #2b91af"&gt;Assert&lt;/span&gt;.That(strings1.SequenceEqual(strings2), &lt;span style="color: #2b91af"&gt;Is&lt;/span&gt;.True);
} [&lt;span style="color: #2b91af"&gt;Test&lt;/span&gt;] &lt;span style="color: blue"&gt;public void &lt;/span&gt;SuccessfullyMatchesTwoListsOfObjects()
{ &lt;span style="color: green"&gt;// works for objects too. &lt;/span&gt;&lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;TestObject&lt;/span&gt;&amp;gt;
objects1 = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;TestObject&lt;/span&gt;&amp;gt;();
objects1.Add(&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;TestObject &lt;/span&gt;{
Property1 = &lt;span style="color: #a31515"&gt;&amp;quot;1&amp;quot; &lt;/span&gt;}); objects1.Add(&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;TestObject &lt;/span&gt;{
Property1 = &lt;span style="color: #a31515"&gt;&amp;quot;2&amp;quot; &lt;/span&gt;}); objects1.Add(&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;TestObject &lt;/span&gt;{
Property1 = &lt;span style="color: #a31515"&gt;&amp;quot;3&amp;quot; &lt;/span&gt;}); &lt;span style="color: #2b91af"&gt;Assert&lt;/span&gt;.That(objects1.SequenceEqual(objects1), &lt;span style="color: #2b91af"&gt;Is&lt;/span&gt;.True);
} [&lt;span style="color: #2b91af"&gt;Test&lt;/span&gt;] &lt;span style="color: blue"&gt;public void &lt;/span&gt;SuccessfullyFailsTwoListsOfObjects()
{ &lt;span style="color: green"&gt;// these two lists of objects may &amp;quot;look&amp;quot; the
same, but they aren't // the same object (reference equals!) &lt;/span&gt;&lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;TestObject&lt;/span&gt;&amp;gt;
objects1 = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;TestObject&lt;/span&gt;&amp;gt;();
objects1.Add(&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;TestObject &lt;/span&gt;{
Property1 = &lt;span style="color: #a31515"&gt;&amp;quot;1&amp;quot; &lt;/span&gt;}); objects1.Add(&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;TestObject &lt;/span&gt;{
Property1 = &lt;span style="color: #a31515"&gt;&amp;quot;2&amp;quot; &lt;/span&gt;}); objects1.Add(&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;TestObject &lt;/span&gt;{
Property1 = &lt;span style="color: #a31515"&gt;&amp;quot;3&amp;quot; &lt;/span&gt;}); &lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;TestObject&lt;/span&gt;&amp;gt;
objects2 = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;TestObject&lt;/span&gt;&amp;gt;();
objects2.Add(&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;TestObject &lt;/span&gt;{
Property1 = &lt;span style="color: #a31515"&gt;&amp;quot;1&amp;quot; &lt;/span&gt;}); objects2.Add(&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;TestObject &lt;/span&gt;{
Property1 = &lt;span style="color: #a31515"&gt;&amp;quot;2&amp;quot; &lt;/span&gt;}); objects2.Add(&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;TestObject &lt;/span&gt;{
Property1 = &lt;span style="color: #a31515"&gt;&amp;quot;3&amp;quot; &lt;/span&gt;}); &lt;span style="color: #2b91af"&gt;Assert&lt;/span&gt;.That(objects1.SequenceEqual(objects2), &lt;span style="color: #2b91af"&gt;Is&lt;/span&gt;.False);
} [&lt;span style="color: #2b91af"&gt;Test&lt;/span&gt;] &lt;span style="color: blue"&gt;public void &lt;/span&gt;SuccessfullyMatchesTwoListsOfObjectsWithCustomComparer()
{ &lt;span style="color: green"&gt;// here I use a custom comparer to see if the // two
lists of objects have the same content. &lt;/span&gt;&lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;TestObject&lt;/span&gt;&amp;gt;
objects1 = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;TestObject&lt;/span&gt;&amp;gt;();
objects1.Add(&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;TestObject &lt;/span&gt;{
Property1 = &lt;span style="color: #a31515"&gt;&amp;quot;1&amp;quot; &lt;/span&gt;}); objects1.Add(&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;TestObject &lt;/span&gt;{
Property1 = &lt;span style="color: #a31515"&gt;&amp;quot;2&amp;quot; &lt;/span&gt;}); objects1.Add(&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;TestObject &lt;/span&gt;{
Property1 = &lt;span style="color: #a31515"&gt;&amp;quot;3&amp;quot; &lt;/span&gt;}); &lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;TestObject&lt;/span&gt;&amp;gt;
objects2 = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;TestObject&lt;/span&gt;&amp;gt;();
objects2.Add(&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;TestObject &lt;/span&gt;{
Property1 = &lt;span style="color: #a31515"&gt;&amp;quot;1&amp;quot; &lt;/span&gt;}); objects2.Add(&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;TestObject &lt;/span&gt;{
Property1 = &lt;span style="color: #a31515"&gt;&amp;quot;2&amp;quot; &lt;/span&gt;}); objects2.Add(&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;TestObject &lt;/span&gt;{
Property1 = &lt;span style="color: #a31515"&gt;&amp;quot;3&amp;quot; &lt;/span&gt;}); &lt;span style="color: #2b91af"&gt;Assert&lt;/span&gt;.That(objects1.SequenceEqual(objects2, &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;TestObjectComparer&lt;/span&gt;()), &lt;span style="color: #2b91af"&gt;Is&lt;/span&gt;.True);
} [&lt;span style="color: #2b91af"&gt;Test&lt;/span&gt;] &lt;span style="color: blue"&gt;public void &lt;/span&gt;SuccessfullyFailsTwoListsOfObjectsWithCustomComparer()
{ &lt;span style="color: green"&gt;// making sure the custome comparer fails when they don't
match &lt;/span&gt;&lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;TestObject&lt;/span&gt;&amp;gt;
objects1 = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;TestObject&lt;/span&gt;&amp;gt;();
objects1.Add(&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;TestObject &lt;/span&gt;{
Property1 = &lt;span style="color: #a31515"&gt;&amp;quot;1&amp;quot; &lt;/span&gt;}); objects1.Add(&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;TestObject &lt;/span&gt;{
Property1 = &lt;span style="color: #a31515"&gt;&amp;quot;2&amp;quot; &lt;/span&gt;}); objects1.Add(&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;TestObject &lt;/span&gt;{
Property1 = &lt;span style="color: #a31515"&gt;&amp;quot;3&amp;quot; &lt;/span&gt;}); &lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;TestObject&lt;/span&gt;&amp;gt;
objects2 = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;TestObject&lt;/span&gt;&amp;gt;();
objects2.Add(&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;TestObject &lt;/span&gt;{
Property1 = &lt;span style="color: #a31515"&gt;&amp;quot;1&amp;quot; &lt;/span&gt;}); objects2.Add(&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;TestObject &lt;/span&gt;{
Property1 = &lt;span style="color: #a31515"&gt;&amp;quot;asdfsadf&amp;quot; &lt;/span&gt;}); objects2.Add(&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;TestObject &lt;/span&gt;{
Property1 = &lt;span style="color: #a31515"&gt;&amp;quot;3&amp;quot; &lt;/span&gt;}); &lt;span style="color: #2b91af"&gt;Assert&lt;/span&gt;.That(objects1.SequenceEqual(objects2, &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;TestObjectComparer&lt;/span&gt;()), &lt;span style="color: #2b91af"&gt;Is&lt;/span&gt;.False);
} } &lt;span style="color: blue"&gt;public class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;TestObject &lt;/span&gt;{ &lt;span style="color: blue"&gt;public
string &lt;/span&gt;Property1 { &lt;span style="color: blue"&gt;get&lt;/span&gt;; &lt;span style="color: blue"&gt;set&lt;/span&gt;;
} } &lt;span style="color: blue"&gt;public class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;TestObjectComparer &lt;/span&gt;:
IEqualityComparer&amp;lt;&lt;span style="color: #2b91af"&gt;TestObject&lt;/span&gt;&amp;gt; { &lt;span style="color: blue"&gt;public
bool &lt;/span&gt;Equals(&lt;span style="color: #2b91af"&gt;TestObject &lt;/span&gt;x, &lt;span style="color: #2b91af"&gt;TestObject &lt;/span&gt;y)
{ &lt;span style="color: blue"&gt;return &lt;/span&gt;(x.Property1 == y.Property1); } &lt;span style="color: blue"&gt;public
int &lt;/span&gt;GetHashCode(&lt;span style="color: #2b91af"&gt;TestObject &lt;/span&gt;obj) { &lt;span style="color: blue"&gt;return &lt;/span&gt;obj.GetHashCode();
} } }&lt;/pre&gt;
&lt;p&gt;
Today I needed to compare to generic lists. I guessed that Linq would provide a way
to do this and sure enough it did: SequenceEqual() to the rescue. To show how it work
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.blog.ingenuitynow.net/aggbug.ashx?id=e640a50f-9f93-4b0a-a150-c7f586d1833b" /&gt;</description>
      <comments>http://www.blog.ingenuitynow.net/CommentView,guid,e640a50f-9f93-4b0a-a150-c7f586d1833b.aspx</comments>
      <category>C#;LINQ;NUnit</category>
    </item>
    <item>
      <trackback:ping>http://www.blog.ingenuitynow.net/Trackback.aspx?guid=57f8aa3e-7b02-4a0c-845e-08b0fd9ff928</trackback:ping>
      <pingback:server>http://www.blog.ingenuitynow.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.blog.ingenuitynow.net/PermaLink,guid,57f8aa3e-7b02-4a0c-845e-08b0fd9ff928.aspx</pingback:target>
      <dc:creator>Andrew Schwam</dc:creator>
      <wfw:comment>http://www.blog.ingenuitynow.net/CommentView,guid,57f8aa3e-7b02-4a0c-845e-08b0fd9ff928.aspx</wfw:comment>
      <wfw:commentRss>http://www.blog.ingenuitynow.net/SyndicationService.asmx/GetEntryCommentsRss?guid=57f8aa3e-7b02-4a0c-845e-08b0fd9ff928</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I’m using <a href="http://www.jetbrains.com/teamcity/" target="_blank">TeamCity</a>,
MSBuild, and SVN together to do some pretty cool stuff around continuous integration
and automated builds.  It’s been working well, untouched, for well over a year! 
But all of a sudden my deployment process failed. Checking the logs with TeamCity,
I found this:
</p>
        <p>
[11:18:06]:   Error validating server certificate for 'https://[xxx].com:443': 
<br />
[11:18:06]:    - The certificate is not issued by a trusted authority.
Use the 
<br />
[11:18:06]:      fingerprint to validate the certificate
manually! 
<br />
[11:18:06]:   Certificate information: 
<br />
[11:18:06]:    - Hostname: [xxx] 
<br />
[11:18:06]:    - Valid: from Mon, 29 Mar 2010 17:44:04 GMT until Thu,
26 Mar 2020 17:44:04 GMT 
<br />
[11:18:06]:    - Issuer: [xxx] 
<br />
[11:18:06]:    - Fingerprint: [xxx] 
<br />
[11:18:06]:   (R)eject, accept (t)emporarily or accept (p)ermanently? svn:
OPTIONS of 'https://[xxx]': Server certificate verification failed: issuer is not
trusted (https://[xxx].com)
</p>
        <p>
The best part about this was that, for a change, this error message was very clear. 
Although I don’t know why the certificate failed.  Did it change or expire? 
Did one of the network guys make a change to something?  I didn’t really care. 
I just wanted to get my build working again.
</p>
        <p>
Here is the line of MSBuild Script that caused the issue: (I’m using the SVN stuff
from <a href="http://msbuildtasks.tigris.org/" target="_blank">MSBuild Community Tasks</a>)
</p>
        <p>
&lt;SvnClient Command="ls $(SvnRepository)/tags/$(BuildNumber) Username="$(SvnUserName)"
password="$(SvnPassword)" ContinueOnError="true"&gt; 
<br />
  &lt;Output TaskParameter="ExitCode" PropertyName="Value"/&gt; 
<br />
&lt;/SvnClient&gt;
</p>
        <p>
Since the Command of SvnClient accepts any SVN command (in other words, anything that
I can type at a command prompt), I searched the SVN Documentation.  It wasn’t
hard to find that I just needed to update to this: 
</p>
        <p>
&lt;SvnClient Command="ls $(SvnRepository)/tags/$(BuildNumber) <font style="background-color: #ffff00">--non-interactive
--trust-server-cert</font>" Username="$(SvnUserName)" password="$(SvnPassword)"
ContinueOnError="true"&gt; 
<br />
  &lt;Output TaskParameter="ExitCode" PropertyName="Value"/&gt; 
<br />
&lt;/SvnClient&gt;
</p>
        <p>
This worked great but my build still failed.  That is because I have other SVN
actions in my script and they don’t seem to know that I accepted the certificate.
However, my other tasks are not using the very generic and flexible SvnClient Command,
they are using tasks such as SvnCopy or SvnCommit, etc.  For instance: 
</p>
        <p>
&lt;SvnCopy SourcePath="$(SvnRepository)/$(SvnProjectLocation)/" 
<br />
    DestinationPath="$(SvnRepository)/tags/$(BuildNumber)" 
<br />
    Message="Auto-tagging Revision: $(BuildNumber)" 
<br />
    Username="$(SvnUserName)" password="$(SvnPassword)"
/&gt; 
<br /></p>
        <p>
So how could I tell SVN to accept the certificate.  I checked the MSBuild Community
Tasks documentation, took a guess and got lucky on the first try…sweet.  I added
this:
</p>
        <p>
    &lt;SvnCopy SourcePath="$(SvnRepository)/$(SvnProjectLocation)/" 
<br />
        DestinationPath="$(SvnRepository)/tags/$(BuildNumber)" 
<br />
        Message="Auto-tagging Revision: $(BuildNumber)" 
<br />
        Username="$(SvnUserName)" password="$(SvnPassword)" 
<br />
        <font style="background-color: #ffff00">Arguments="--non-interactive
--trust-server-cert"</font> /&gt;
</p>
        <p>
I added the Arguments to all of my other SVN Tasks in my script and it worked perfectly!
</p>
        <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:a2ba1be3-f0e6-44e9-b821-7a8bb2239b22" class="wlWriterEditableSmartContent">Technorati
Tags: <a href="http://technorati.com/tags/TeamCity" rel="tag">TeamCity</a>,<a href="http://technorati.com/tags/Subversion" rel="tag">Subversion</a>,<a href="http://technorati.com/tags/SVN" rel="tag">SVN</a>,<a href="http://technorati.com/tags/MSBuild+Community+Tasks" rel="tag">MSBuild
Community Tasks</a>,<a href="http://technorati.com/tags/Certificate" rel="tag">Certificate</a></div>
        <img width="0" height="0" src="http://www.blog.ingenuitynow.net/aggbug.ashx?id=57f8aa3e-7b02-4a0c-845e-08b0fd9ff928" />
      </body>
      <title>How to Accept a server certificate with MSBuild and SVN</title>
      <guid isPermaLink="false">http://www.blog.ingenuitynow.net/PermaLink,guid,57f8aa3e-7b02-4a0c-845e-08b0fd9ff928.aspx</guid>
      <link>http://www.blog.ingenuitynow.net/How+To+Accept+A+Server+Certificate+With+MSBuild+And+SVN.aspx</link>
      <pubDate>Fri, 09 Dec 2011 14:23:56 GMT</pubDate>
      <description>&lt;p&gt;
I’m using &lt;a href="http://www.jetbrains.com/teamcity/" target="_blank"&gt;TeamCity&lt;/a&gt;,
MSBuild, and SVN together to do some pretty cool stuff around continuous integration
and automated builds.&amp;#160; It’s been working well, untouched, for well over a year!&amp;#160;
But all of a sudden my deployment process failed. Checking the logs with TeamCity,
I found this:
&lt;/p&gt;
&lt;p&gt;
[11:18:06]:&amp;#160;&amp;#160; Error validating server certificate for 'https://[xxx].com:443': 
&lt;br /&gt;
[11:18:06]:&amp;#160;&amp;#160;&amp;#160; - The certificate is not issued by a trusted authority.
Use the 
&lt;br /&gt;
[11:18:06]:&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; fingerprint to validate the certificate
manually! 
&lt;br /&gt;
[11:18:06]:&amp;#160;&amp;#160; Certificate information: 
&lt;br /&gt;
[11:18:06]:&amp;#160;&amp;#160;&amp;#160; - Hostname: [xxx] 
&lt;br /&gt;
[11:18:06]:&amp;#160;&amp;#160;&amp;#160; - Valid: from Mon, 29 Mar 2010 17:44:04 GMT until Thu,
26 Mar 2020 17:44:04 GMT 
&lt;br /&gt;
[11:18:06]:&amp;#160;&amp;#160;&amp;#160; - Issuer: [xxx] 
&lt;br /&gt;
[11:18:06]:&amp;#160;&amp;#160;&amp;#160; - Fingerprint: [xxx] 
&lt;br /&gt;
[11:18:06]:&amp;#160;&amp;#160; (R)eject, accept (t)emporarily or accept (p)ermanently? svn:
OPTIONS of 'https://[xxx]': Server certificate verification failed: issuer is not
trusted (https://[xxx].com)
&lt;/p&gt;
&lt;p&gt;
The best part about this was that, for a change, this error message was very clear.&amp;#160;
Although I don’t know why the certificate failed.&amp;#160; Did it change or expire?&amp;#160;
Did one of the network guys make a change to something?&amp;#160; I didn’t really care.&amp;#160;
I just wanted to get my build working again.
&lt;/p&gt;
&lt;p&gt;
Here is the line of MSBuild Script that caused the issue: (I’m using the SVN stuff
from &lt;a href="http://msbuildtasks.tigris.org/" target="_blank"&gt;MSBuild Community Tasks&lt;/a&gt;)
&lt;/p&gt;
&lt;p&gt;
&amp;lt;SvnClient Command=&amp;quot;ls $(SvnRepository)/tags/$(BuildNumber) Username=&amp;quot;$(SvnUserName)&amp;quot;
password=&amp;quot;$(SvnPassword)&amp;quot; ContinueOnError=&amp;quot;true&amp;quot;&amp;gt; 
&lt;br /&gt;
&amp;#160; &amp;lt;Output TaskParameter=&amp;quot;ExitCode&amp;quot; PropertyName=&amp;quot;Value&amp;quot;/&amp;gt; 
&lt;br /&gt;
&amp;lt;/SvnClient&amp;gt;
&lt;/p&gt;
&lt;p&gt;
Since the Command of SvnClient accepts any SVN command (in other words, anything that
I can type at a command prompt), I searched the SVN Documentation.&amp;#160; It wasn’t
hard to find that I just needed to update to this: 
&lt;/p&gt;
&lt;p&gt;
&amp;lt;SvnClient Command=&amp;quot;ls $(SvnRepository)/tags/$(BuildNumber) &lt;font style="background-color: #ffff00"&gt;--non-interactive
--trust-server-cert&lt;/font&gt;&amp;quot; Username=&amp;quot;$(SvnUserName)&amp;quot; password=&amp;quot;$(SvnPassword)&amp;quot;
ContinueOnError=&amp;quot;true&amp;quot;&amp;gt; 
&lt;br /&gt;
&amp;#160; &amp;lt;Output TaskParameter=&amp;quot;ExitCode&amp;quot; PropertyName=&amp;quot;Value&amp;quot;/&amp;gt; 
&lt;br /&gt;
&amp;lt;/SvnClient&amp;gt;
&lt;/p&gt;
&lt;p&gt;
This worked great but my build still failed.&amp;#160; That is because I have other SVN
actions in my script and they don’t seem to know that I accepted the certificate.
However, my other tasks are not using the very generic and flexible SvnClient Command,
they are using tasks such as SvnCopy or SvnCommit, etc.&amp;#160; For instance: 
&lt;/p&gt;
&lt;p&gt;
&amp;lt;SvnCopy SourcePath=&amp;quot;$(SvnRepository)/$(SvnProjectLocation)/&amp;quot; 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160; DestinationPath=&amp;quot;$(SvnRepository)/tags/$(BuildNumber)&amp;quot; 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160; Message=&amp;quot;Auto-tagging Revision: $(BuildNumber)&amp;quot; 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160; Username=&amp;quot;$(SvnUserName)&amp;quot; password=&amp;quot;$(SvnPassword)&amp;quot;
/&amp;gt; 
&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;
So how could I tell SVN to accept the certificate.&amp;#160; I checked the MSBuild Community
Tasks documentation, took a guess and got lucky on the first try…sweet.&amp;#160; I added
this:
&lt;/p&gt;
&lt;p&gt;
&amp;#160;&amp;#160;&amp;#160; &amp;lt;SvnCopy SourcePath=&amp;quot;$(SvnRepository)/$(SvnProjectLocation)/&amp;quot; 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; DestinationPath=&amp;quot;$(SvnRepository)/tags/$(BuildNumber)&amp;quot; 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Message=&amp;quot;Auto-tagging Revision: $(BuildNumber)&amp;quot; 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Username=&amp;quot;$(SvnUserName)&amp;quot; password=&amp;quot;$(SvnPassword)&amp;quot; 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;font style="background-color: #ffff00"&gt;Arguments=&amp;quot;--non-interactive
--trust-server-cert&amp;quot;&lt;/font&gt; /&amp;gt;
&lt;/p&gt;
&lt;p&gt;
I added the Arguments to all of my other SVN Tasks in my script and it worked perfectly!
&lt;/p&gt;
&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:a2ba1be3-f0e6-44e9-b821-7a8bb2239b22" class="wlWriterEditableSmartContent"&gt;Technorati
Tags: &lt;a href="http://technorati.com/tags/TeamCity" rel="tag"&gt;TeamCity&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Subversion" rel="tag"&gt;Subversion&lt;/a&gt;,&lt;a href="http://technorati.com/tags/SVN" rel="tag"&gt;SVN&lt;/a&gt;,&lt;a href="http://technorati.com/tags/MSBuild+Community+Tasks" rel="tag"&gt;MSBuild
Community Tasks&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Certificate" rel="tag"&gt;Certificate&lt;/a&gt;
&lt;/div&gt;
&lt;img width="0" height="0" src="http://www.blog.ingenuitynow.net/aggbug.ashx?id=57f8aa3e-7b02-4a0c-845e-08b0fd9ff928" /&gt;</description>
      <comments>http://www.blog.ingenuitynow.net/CommentView,guid,57f8aa3e-7b02-4a0c-845e-08b0fd9ff928.aspx</comments>
      <category>MSBuild;Subversion</category>
    </item>
    <item>
      <trackback:ping>http://www.blog.ingenuitynow.net/Trackback.aspx?guid=646a5f43-0e3f-4e4b-a2f2-8347ef2b3f88</trackback:ping>
      <pingback:server>http://www.blog.ingenuitynow.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.blog.ingenuitynow.net/PermaLink,guid,646a5f43-0e3f-4e4b-a2f2-8347ef2b3f88.aspx</pingback:target>
      <dc:creator>Andrew Schwam</dc:creator>
      <wfw:comment>http://www.blog.ingenuitynow.net/CommentView,guid,646a5f43-0e3f-4e4b-a2f2-8347ef2b3f88.aspx</wfw:comment>
      <wfw:commentRss>http://www.blog.ingenuitynow.net/SyndicationService.asmx/GetEntryCommentsRss?guid=646a5f43-0e3f-4e4b-a2f2-8347ef2b3f88</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Last night I had the pleasure of presenting “Unit Testing Made Easy” at <a href="http://www.NoDeNUG.org" target="_blank">NoDeNUG</a> (Northern
Delaware .Net User Group).  I’ll be doing the same demo at <a href="http://codecamp.phillydotnet.org/2011-1/SitePages/Home.aspx" target="_blank">Philly.Net
Code Camp</a> next week.  The NoDeNUG crowd was great and asked good questions. 
That made the demo fun for me and I think it went very well.  I hope it goes
over great at Code Camp too.  
</p>
        <p>
I’m attaching a zip file containing my slides and Visual Studio Solution.  The
demo should work fine on it’s own, the references to <a href="http://nunit.org/" target="_blank">NUnit</a>, <a href="http://code.google.com/p/moq/" target="_blank">MOQ</a>,
and <a href="http://structuremap.net/structuremap/index.html" target="_blank">StructureMap</a> are
all included.  But if you don’t have VS2010 with Premium or Ultimate and Feature
Pack 2, the CodedUI (testing for Silverlight UIs) won’t work.  I hope it will
build and run ok though.  If not, let me know and I’ll upload the solution without
references to the Coded UI stuff.  Also, the demo uses a Silverlight application
for the front end.  If you don’t have the Silverlight tools set up, you can either
add them to Visual Studio, or simply exclude the Silverlight projects.  You’ll
still be able to run the services and the unit tests, even if you can’t see how the
UI looks.
</p>
        <p>
If you’ve just come across this and haven’t heard my presentation you have two options:
</p>
        <p>
1. Come to <a href="http://codecamp.phillydotnet.org/2011-1/SitePages/Home.aspx" target="_blank">Philly.Net
Code Camp</a> next week (April 9) and hear the presentation then!
</p>
        <p>
2. Just open the enclosed solution and have a look!  I’ve got sample code in
there to demonstrate using Dependency Injection to make services easier to unit test,
sample unit tests, and sample tests using mocking of dependencies.  I’m coding
my tests with <a href="http://www.nunit.org/" target="_blank">NUnit</a>, using <a href="http://structuremap.net/structuremap/index.html" target="_blank">StructureMap</a> for
my IOC, and <a href="http://code.google.com/p/moq/" target="_blank">MOQ</a> as my
mocking framework.
</p>
        <p>
Here is the code:  <a href="http://www.blog.ingenuitynow.net/content/binary/UnitTestingMadeEasy.zip" target="_blank">UnitTestingMadeEasy.zip</a></p>
        <p>
Again, if you have any problems with the solution, let me know and I’ll upload a copy
without the Coded UI, or even without the Silverlight part.
</p>
        <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:37d3ba7b-9df2-4da8-853f-f3fcc46ba52f" class="wlWriterEditableSmartContent">Technorati
Tags: <a href="http://technorati.com/tags/Unit+Test" rel="tag">Unit Test</a>,<a href="http://technorati.com/tags/C%23" rel="tag">C#</a>,<a href="http://technorati.com/tags/Dependency+Injection" rel="tag">Dependency
Injection</a>,<a href="http://technorati.com/tags/Mocking" rel="tag">Mocking</a>,<a href="http://technorati.com/tags/IOC" rel="tag">IOC</a></div>
        <img width="0" height="0" src="http://www.blog.ingenuitynow.net/aggbug.ashx?id=646a5f43-0e3f-4e4b-a2f2-8347ef2b3f88" />
      </body>
      <title>Unit Testing Made Easy Demo</title>
      <guid isPermaLink="false">http://www.blog.ingenuitynow.net/PermaLink,guid,646a5f43-0e3f-4e4b-a2f2-8347ef2b3f88.aspx</guid>
      <link>http://www.blog.ingenuitynow.net/Unit+Testing+Made+Easy+Demo.aspx</link>
      <pubDate>Sat, 02 Apr 2011 00:51:28 GMT</pubDate>
      <description>&lt;p&gt;
Last night I had the pleasure of presenting “Unit Testing Made Easy” at &lt;a href="http://www.NoDeNUG.org" target="_blank"&gt;NoDeNUG&lt;/a&gt; (Northern
Delaware .Net User Group).&amp;#160; I’ll be doing the same demo at &lt;a href="http://codecamp.phillydotnet.org/2011-1/SitePages/Home.aspx" target="_blank"&gt;Philly.Net
Code Camp&lt;/a&gt; next week.&amp;#160; The NoDeNUG crowd was great and asked good questions.&amp;#160;
That made the demo fun for me and I think it went very well.&amp;#160; I hope it goes
over great at Code Camp too.&amp;#160; 
&lt;/p&gt;
&lt;p&gt;
I’m attaching a zip file containing my slides and Visual Studio Solution.&amp;#160; The
demo should work fine on it’s own, the references to &lt;a href="http://nunit.org/" target="_blank"&gt;NUnit&lt;/a&gt;, &lt;a href="http://code.google.com/p/moq/" target="_blank"&gt;MOQ&lt;/a&gt;,
and &lt;a href="http://structuremap.net/structuremap/index.html" target="_blank"&gt;StructureMap&lt;/a&gt; are
all included.&amp;#160; But if you don’t have VS2010 with Premium or Ultimate and Feature
Pack 2, the CodedUI (testing for Silverlight UIs) won’t work.&amp;#160; I hope it will
build and run ok though.&amp;#160; If not, let me know and I’ll upload the solution without
references to the Coded UI stuff.&amp;#160; Also, the demo uses a Silverlight application
for the front end.&amp;#160; If you don’t have the Silverlight tools set up, you can either
add them to Visual Studio, or simply exclude the Silverlight projects.&amp;#160; You’ll
still be able to run the services and the unit tests, even if you can’t see how the
UI looks.
&lt;/p&gt;
&lt;p&gt;
If you’ve just come across this and haven’t heard my presentation you have two options:
&lt;/p&gt;
&lt;p&gt;
1. Come to &lt;a href="http://codecamp.phillydotnet.org/2011-1/SitePages/Home.aspx" target="_blank"&gt;Philly.Net
Code Camp&lt;/a&gt; next week (April 9) and hear the presentation then!
&lt;/p&gt;
&lt;p&gt;
2. Just open the enclosed solution and have a look!&amp;#160; I’ve got sample code in
there to demonstrate using Dependency Injection to make services easier to unit test,
sample unit tests, and sample tests using mocking of dependencies.&amp;#160; I’m coding
my tests with &lt;a href="http://www.nunit.org/" target="_blank"&gt;NUnit&lt;/a&gt;, using &lt;a href="http://structuremap.net/structuremap/index.html" target="_blank"&gt;StructureMap&lt;/a&gt; for
my IOC, and &lt;a href="http://code.google.com/p/moq/" target="_blank"&gt;MOQ&lt;/a&gt; as my
mocking framework.
&lt;/p&gt;
&lt;p&gt;
Here is the code:&amp;#160; &lt;a href="http://www.blog.ingenuitynow.net/content/binary/UnitTestingMadeEasy.zip" target="_blank"&gt;UnitTestingMadeEasy.zip&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
Again, if you have any problems with the solution, let me know and I’ll upload a copy
without the Coded UI, or even without the Silverlight part.
&lt;/p&gt;
&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:37d3ba7b-9df2-4da8-853f-f3fcc46ba52f" class="wlWriterEditableSmartContent"&gt;Technorati
Tags: &lt;a href="http://technorati.com/tags/Unit+Test" rel="tag"&gt;Unit Test&lt;/a&gt;,&lt;a href="http://technorati.com/tags/C%23" rel="tag"&gt;C#&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Dependency+Injection" rel="tag"&gt;Dependency
Injection&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Mocking" rel="tag"&gt;Mocking&lt;/a&gt;,&lt;a href="http://technorati.com/tags/IOC" rel="tag"&gt;IOC&lt;/a&gt;
&lt;/div&gt;
&lt;img width="0" height="0" src="http://www.blog.ingenuitynow.net/aggbug.ashx?id=646a5f43-0e3f-4e4b-a2f2-8347ef2b3f88" /&gt;</description>
      <comments>http://www.blog.ingenuitynow.net/CommentView,guid,646a5f43-0e3f-4e4b-a2f2-8347ef2b3f88.aspx</comments>
      <category>.Net;C#;MOQ;MVVM;NoDeNUG.org;NUnit;Philly.Net;Silverlight;Unit Testing</category>
    </item>
    <item>
      <trackback:ping>http://www.blog.ingenuitynow.net/Trackback.aspx?guid=fc89dc0e-1ede-4121-b9df-4ed2af551da7</trackback:ping>
      <pingback:server>http://www.blog.ingenuitynow.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.blog.ingenuitynow.net/PermaLink,guid,fc89dc0e-1ede-4121-b9df-4ed2af551da7.aspx</pingback:target>
      <dc:creator>Andrew Schwam</dc:creator>
      <wfw:comment>http://www.blog.ingenuitynow.net/CommentView,guid,fc89dc0e-1ede-4121-b9df-4ed2af551da7.aspx</wfw:comment>
      <wfw:commentRss>http://www.blog.ingenuitynow.net/SyndicationService.asmx/GetEntryCommentsRss?guid=fc89dc0e-1ede-4121-b9df-4ed2af551da7</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
In a previous post I wrote about some tips for creating WP7 apps which included using
the CameraCaptureTask.  A reader responded, asking how to save the picture. 
So I figured I’d write a more detailed response with some samples.
</p>
        <p>
In this post I’ll show 3 easy sample:
</p>
        <ol>
          <li>
How to simply use the camera and display a photo.</li>
          <li>
How to save an image to IsolatedStorage (and change the size of the photo too!)</li>
          <li>
How to save an image to the phone’s media library.</li>
        </ol>
        <p>
All of these are pretty simple.  I’m sure once you get started you can easily
modify this code to do more creative things.  
</p>
        <p>
First, you’ll need to define a CameraCaptureTask.  You should always do so as
a class level variable.   You should also wire up the Completed handler
in the constructor  These steps are important for dealing with application tombstoning. 
For more on this, <a href="http://msdn.microsoft.com/en-us/library/ff769543(v=VS.92).aspx" target="_blank">please
read this article</a>.
</p>
        <pre class="code">
          <span style="color: blue">private </span>
          <span style="color: #2b91af">CameraCaptureTask </span>_cameraCaptureTask; <span style="color: blue">public </span>MainPage()
{ InitializeComponent(); _cameraCaptureTask = <span style="color: blue">new </span><span style="color: #2b91af">CameraCaptureTask</span>();
_cameraCaptureTask.Completed += CameraCaptureTaskCompleted; }</pre>
        <h4>How to simply use the camera and display a photo:
</h4>
        <pre class="code">
          <font face="Verdana">You’ll need to kick off the camera task, I’m
using a button. </font>
        </pre>
        <pre class="code">
          <span style="color: blue">private void </span>SimpleTest_Click(<span style="color: blue">object </span>sender, <span style="color: #2b91af">EventArgs </span>e)
{ <span style="color: blue">try </span>{ _cameraCaptureTask.Show(); } <span style="color: blue">catch </span>(<span style="color: #2b91af">InvalidOperationException </span>ex)
{ <span style="color: green">// Catch the exception, but no handling is necessary. </span>}
} <font face="Verdana">In my XAML, I’ve defined an Image named MainImage</font></pre>
        <pre class="code">
          <span style="color: blue">&lt;</span>
          <span style="color: #a31515">Image </span>
          <span style="color: red">x</span>
          <span style="color: blue">:</span>
          <span style="color: red">Name</span>
          <span style="color: blue">="MainImage" </span>
          <span style="color: blue">/&gt; </span>
        </pre>
        <p>
Now when the CameraCaptureTask is complete, just bind the results of the task to the
Image as I’m doing here:
</p>
        <pre class="code">
          <span style="color: blue">void </span>CameraCaptureTaskCompleted(<span style="color: blue">object </span>sender, <span style="color: #2b91af">PhotoResult </span>e)
{ <span style="color: blue">if </span>(e.TaskResult == <span style="color: #2b91af">TaskResult</span>.OK)
{ <span style="color: green">//simply use the picture. </span><span style="color: #2b91af">BitmapImage </span>bitmapImage
= <span style="color: blue">new </span><span style="color: #2b91af">BitmapImage</span>();
bitmapImage.SetSource(e.ChosenPhoto); MainImage.Source = bitmapImage; } } <font face="Verdana">Easy,
right?</font></pre>
        <h4>How to save an image to IsolatedStorage (and change the size of the photo too!)
</h4>
        <p>
In this case I want to save the image to IsolatedStorage.  In addition, the app
I was creating didn’t need full size images.  So I figured, why waste space in
the user’s IsolatedStorage?  So I use a WritableBitmap and change the size of
the image.  You’ll notice that after I save the image, I read it back and bind
the results to another image named SmallerImage.  That’s just to prove that saving
it really worked!
</p>
        <pre class="code">
          <span style="color: blue">void </span>CameraCaptureTaskCompleted(<span style="color: blue">object </span>sender, <span style="color: #2b91af">PhotoResult </span>e)
{ <span style="color: blue">if </span>(e.TaskResult == <span style="color: #2b91af">TaskResult</span>.OK)
{ <span style="color: green">//here I save the image to Isolated Storage. Also I am
changing the size of it to not waste space! </span><span style="color: #2b91af">WriteableBitmap </span>writeableBitmap
= <span style="color: blue">new </span><span style="color: #2b91af">WriteableBitmap</span>(200,
200); writeableBitmap.LoadJpeg(e.ChosenPhoto); <span style="color: blue">string </span>imageFolder
= <span style="color: #a31515">"Images"</span>; <span style="color: blue">string </span>imageFileName
= <span style="color: #a31515">"TestImage.jpg"</span>; <span style="color: blue">using </span>(<span style="color: blue">var </span>isoFile
= <span style="color: #2b91af">IsolatedStorageFile</span>.GetUserStoreForApplication())
{ <span style="color: blue">if </span>(!isoFile.DirectoryExists(imageFolder)) { isoFile.CreateDirectory(imageFolder);
} <span style="color: blue">string </span>filePath = <span style="color: #2b91af">Path</span>.Combine(imageFolder,
imageFileName); <span style="color: blue">using </span>(<span style="color: blue">var </span>stream
= isoFile.CreateFile(filePath)) { writeableBitmap.SaveJpeg(stream, writeableBitmap.PixelWidth,
writeableBitmap.PixelHeight, 0, 100); } } <span style="color: green">//now read the
image back from storage to show it worked... </span><span style="color: #2b91af">BitmapImage </span>imageFromStorage
= <span style="color: blue">new </span><span style="color: #2b91af">BitmapImage</span>(); <span style="color: blue">using </span>(<span style="color: blue">var </span>isoFile
= <span style="color: #2b91af">IsolatedStorageFile</span>.GetUserStoreForApplication())
{ <span style="color: blue">string </span>filePath = <span style="color: #2b91af">Path</span>.Combine(imageFolder,
imageFileName); <span style="color: blue">using </span>(<span style="color: blue">var </span>imageStream
= isoFile.OpenFile( filePath, <span style="color: #2b91af">FileMode</span>.Open, <span style="color: #2b91af">FileAccess</span>.Read))
{ imageFromStorage.SetSource(imageStream); } } SmallerImage.Source = imageFromStorage;
} }</pre>
        <h4>How to save an image to the phone’s media library.
</h4>
        <p>
This one is pretty easy too.  Just remember to add a reference to Microsoft.Xna.Framework
or you can’t access the Media Library. Also, you’ll need this using statement:
</p>
        <pre class="code">
          <span style="color: blue">using </span>Microsoft.Xna.Framework.Media;</pre>
        <pre class="code">
          <span style="color: blue">void </span>CameraCaptureTaskForSavingToLibraryCompleted(<span style="color: blue">object </span>sender, <span style="color: #2b91af">PhotoResult </span>e)
{ <span style="color: blue">byte</span>[] imageBits = <span style="color: blue">new
byte</span>[(<span style="color: blue">int</span>)e.ChosenPhoto.Length]; e.ChosenPhoto.Read(imageBits,
0, imageBits.Length); e.ChosenPhoto.Seek(0, <span style="color: #2b91af">SeekOrigin</span>.Begin); <span style="color: #2b91af">MediaLibrary </span>library
= <span style="color: blue">new </span><span style="color: #2b91af">MediaLibrary</span>();
library.SavePicture(<span style="color: #a31515">"TestPhoto"</span>, imageBits);
}</pre>
        <p>
Hopefully you’ll see that using this feature is pretty easy.
</p>
        <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:84358b34-61cc-4043-a532-4cb12a6a6657" class="wlWriterEditableSmartContent">Technorati
Tags: <a href="http://technorati.com/tags/WP7" rel="tag">WP7</a>,<a href="http://technorati.com/tags/Windows+Phone+7" rel="tag">Windows
Phone 7</a>,<a href="http://technorati.com/tags/CameraCaptureTask" rel="tag">CameraCaptureTask</a>,<a href="http://technorati.com/tags/IsolatedStorage" rel="tag">IsolatedStorage</a>,<a href="http://technorati.com/tags/MediaLibrary" rel="tag">MediaLibrary</a></div>
        <img width="0" height="0" src="http://www.blog.ingenuitynow.net/aggbug.ashx?id=fc89dc0e-1ede-4121-b9df-4ed2af551da7" />
      </body>
      <title>WP7 Tip: Using the CameraCaptureTask for Windows Phone 7</title>
      <guid isPermaLink="false">http://www.blog.ingenuitynow.net/PermaLink,guid,fc89dc0e-1ede-4121-b9df-4ed2af551da7.aspx</guid>
      <link>http://www.blog.ingenuitynow.net/WP7+Tip+Using+The+CameraCaptureTask+For+Windows+Phone+7.aspx</link>
      <pubDate>Mon, 27 Dec 2010 04:10:27 GMT</pubDate>
      <description>&lt;p&gt;
In a previous post I wrote about some tips for creating WP7 apps which included using
the CameraCaptureTask.&amp;#160; A reader responded, asking how to save the picture.&amp;#160;
So I figured I’d write a more detailed response with some samples.
&lt;/p&gt;
&lt;p&gt;
In this post I’ll show 3 easy sample:
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
How to simply use the camera and display a photo.&lt;/li&gt;
&lt;li&gt;
How to save an image to IsolatedStorage (and change the size of the photo too!)&lt;/li&gt;
&lt;li&gt;
How to save an image to the phone’s media library.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
All of these are pretty simple.&amp;#160; I’m sure once you get started you can easily
modify this code to do more creative things.&amp;#160; 
&lt;/p&gt;
&lt;p&gt;
First, you’ll need to define a CameraCaptureTask.&amp;#160; You should always do so as
a class level variable.&amp;#160;&amp;#160; You should also wire up the Completed handler
in the constructor&amp;#160; These steps are important for dealing with application tombstoning.&amp;#160;
For more on this, &lt;a href="http://msdn.microsoft.com/en-us/library/ff769543(v=VS.92).aspx" target="_blank"&gt;please
read this article&lt;/a&gt;.
&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;private &lt;/span&gt;&lt;span style="color: #2b91af"&gt;CameraCaptureTask &lt;/span&gt;_cameraCaptureTask; &lt;span style="color: blue"&gt;public &lt;/span&gt;MainPage()
{ InitializeComponent(); _cameraCaptureTask = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;CameraCaptureTask&lt;/span&gt;();
_cameraCaptureTask.Completed += CameraCaptureTaskCompleted; }&lt;/pre&gt;
&lt;h4&gt;How to simply use the camera and display a photo:
&lt;/h4&gt;
&lt;pre class="code"&gt;&lt;font face="Verdana"&gt;You’ll need to kick off the camera task, I’m
using a button. &lt;/font&gt;&lt;/pre&gt;
&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;private void &lt;/span&gt;SimpleTest_Click(&lt;span style="color: blue"&gt;object &lt;/span&gt;sender, &lt;span style="color: #2b91af"&gt;EventArgs &lt;/span&gt;e)
{ &lt;span style="color: blue"&gt;try &lt;/span&gt;{ _cameraCaptureTask.Show(); } &lt;span style="color: blue"&gt;catch &lt;/span&gt;(&lt;span style="color: #2b91af"&gt;InvalidOperationException &lt;/span&gt;ex)
{ &lt;span style="color: green"&gt;// Catch the exception, but no handling is necessary. &lt;/span&gt;}
} &lt;font face="Verdana"&gt;In my XAML, I’ve defined an Image named MainImage&lt;/font&gt;&lt;/pre&gt;
&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Image &lt;/span&gt;&lt;span style="color: red"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;Name&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;MainImage&amp;quot; &lt;/span&gt;&lt;span style="color: blue"&gt;/&amp;gt; &lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;
Now when the CameraCaptureTask is complete, just bind the results of the task to the
Image as I’m doing here:
&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;void &lt;/span&gt;CameraCaptureTaskCompleted(&lt;span style="color: blue"&gt;object &lt;/span&gt;sender, &lt;span style="color: #2b91af"&gt;PhotoResult &lt;/span&gt;e)
{ &lt;span style="color: blue"&gt;if &lt;/span&gt;(e.TaskResult == &lt;span style="color: #2b91af"&gt;TaskResult&lt;/span&gt;.OK)
{ &lt;span style="color: green"&gt;//simply use the picture. &lt;/span&gt;&lt;span style="color: #2b91af"&gt;BitmapImage &lt;/span&gt;bitmapImage
= &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;BitmapImage&lt;/span&gt;();
bitmapImage.SetSource(e.ChosenPhoto); MainImage.Source = bitmapImage; } } &lt;font face="Verdana"&gt;Easy,
right?&lt;/font&gt;&lt;/pre&gt;
&lt;h4&gt;How to save an image to IsolatedStorage (and change the size of the photo too!)
&lt;/h4&gt;
&lt;p&gt;
In this case I want to save the image to IsolatedStorage.&amp;#160; In addition, the app
I was creating didn’t need full size images.&amp;#160; So I figured, why waste space in
the user’s IsolatedStorage?&amp;#160; So I use a WritableBitmap and change the size of
the image.&amp;#160; You’ll notice that after I save the image, I read it back and bind
the results to another image named SmallerImage.&amp;#160; That’s just to prove that saving
it really worked!
&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;void &lt;/span&gt;CameraCaptureTaskCompleted(&lt;span style="color: blue"&gt;object &lt;/span&gt;sender, &lt;span style="color: #2b91af"&gt;PhotoResult &lt;/span&gt;e)
{ &lt;span style="color: blue"&gt;if &lt;/span&gt;(e.TaskResult == &lt;span style="color: #2b91af"&gt;TaskResult&lt;/span&gt;.OK)
{ &lt;span style="color: green"&gt;//here I save the image to Isolated Storage. Also I am
changing the size of it to not waste space! &lt;/span&gt;&lt;span style="color: #2b91af"&gt;WriteableBitmap &lt;/span&gt;writeableBitmap
= &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;WriteableBitmap&lt;/span&gt;(200,
200); writeableBitmap.LoadJpeg(e.ChosenPhoto); &lt;span style="color: blue"&gt;string &lt;/span&gt;imageFolder
= &lt;span style="color: #a31515"&gt;&amp;quot;Images&amp;quot;&lt;/span&gt;; &lt;span style="color: blue"&gt;string &lt;/span&gt;imageFileName
= &lt;span style="color: #a31515"&gt;&amp;quot;TestImage.jpg&amp;quot;&lt;/span&gt;; &lt;span style="color: blue"&gt;using &lt;/span&gt;(&lt;span style="color: blue"&gt;var &lt;/span&gt;isoFile
= &lt;span style="color: #2b91af"&gt;IsolatedStorageFile&lt;/span&gt;.GetUserStoreForApplication())
{ &lt;span style="color: blue"&gt;if &lt;/span&gt;(!isoFile.DirectoryExists(imageFolder)) { isoFile.CreateDirectory(imageFolder);
} &lt;span style="color: blue"&gt;string &lt;/span&gt;filePath = &lt;span style="color: #2b91af"&gt;Path&lt;/span&gt;.Combine(imageFolder,
imageFileName); &lt;span style="color: blue"&gt;using &lt;/span&gt;(&lt;span style="color: blue"&gt;var &lt;/span&gt;stream
= isoFile.CreateFile(filePath)) { writeableBitmap.SaveJpeg(stream, writeableBitmap.PixelWidth,
writeableBitmap.PixelHeight, 0, 100); } } &lt;span style="color: green"&gt;//now read the
image back from storage to show it worked... &lt;/span&gt;&lt;span style="color: #2b91af"&gt;BitmapImage &lt;/span&gt;imageFromStorage
= &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;BitmapImage&lt;/span&gt;(); &lt;span style="color: blue"&gt;using &lt;/span&gt;(&lt;span style="color: blue"&gt;var &lt;/span&gt;isoFile
= &lt;span style="color: #2b91af"&gt;IsolatedStorageFile&lt;/span&gt;.GetUserStoreForApplication())
{ &lt;span style="color: blue"&gt;string &lt;/span&gt;filePath = &lt;span style="color: #2b91af"&gt;Path&lt;/span&gt;.Combine(imageFolder,
imageFileName); &lt;span style="color: blue"&gt;using &lt;/span&gt;(&lt;span style="color: blue"&gt;var &lt;/span&gt;imageStream
= isoFile.OpenFile( filePath, &lt;span style="color: #2b91af"&gt;FileMode&lt;/span&gt;.Open, &lt;span style="color: #2b91af"&gt;FileAccess&lt;/span&gt;.Read))
{ imageFromStorage.SetSource(imageStream); } } SmallerImage.Source = imageFromStorage;
} }&lt;/pre&gt;
&lt;h4&gt;How to save an image to the phone’s media library.
&lt;/h4&gt;
&lt;p&gt;
This one is pretty easy too.&amp;#160; Just remember to add a reference to Microsoft.Xna.Framework
or you can’t access the Media Library. Also, you’ll need this using statement:
&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;using &lt;/span&gt;Microsoft.Xna.Framework.Media;&lt;/pre&gt;
&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;void &lt;/span&gt;CameraCaptureTaskForSavingToLibraryCompleted(&lt;span style="color: blue"&gt;object &lt;/span&gt;sender, &lt;span style="color: #2b91af"&gt;PhotoResult &lt;/span&gt;e)
{ &lt;span style="color: blue"&gt;byte&lt;/span&gt;[] imageBits = &lt;span style="color: blue"&gt;new
byte&lt;/span&gt;[(&lt;span style="color: blue"&gt;int&lt;/span&gt;)e.ChosenPhoto.Length]; e.ChosenPhoto.Read(imageBits,
0, imageBits.Length); e.ChosenPhoto.Seek(0, &lt;span style="color: #2b91af"&gt;SeekOrigin&lt;/span&gt;.Begin); &lt;span style="color: #2b91af"&gt;MediaLibrary &lt;/span&gt;library
= &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;MediaLibrary&lt;/span&gt;();
library.SavePicture(&lt;span style="color: #a31515"&gt;&amp;quot;TestPhoto&amp;quot;&lt;/span&gt;, imageBits);
}&lt;/pre&gt;
&lt;p&gt;
Hopefully you’ll see that using this feature is pretty easy.
&lt;/p&gt;
&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:84358b34-61cc-4043-a532-4cb12a6a6657" class="wlWriterEditableSmartContent"&gt;Technorati
Tags: &lt;a href="http://technorati.com/tags/WP7" rel="tag"&gt;WP7&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Windows+Phone+7" rel="tag"&gt;Windows
Phone 7&lt;/a&gt;,&lt;a href="http://technorati.com/tags/CameraCaptureTask" rel="tag"&gt;CameraCaptureTask&lt;/a&gt;,&lt;a href="http://technorati.com/tags/IsolatedStorage" rel="tag"&gt;IsolatedStorage&lt;/a&gt;,&lt;a href="http://technorati.com/tags/MediaLibrary" rel="tag"&gt;MediaLibrary&lt;/a&gt;
&lt;/div&gt;
&lt;img width="0" height="0" src="http://www.blog.ingenuitynow.net/aggbug.ashx?id=fc89dc0e-1ede-4121-b9df-4ed2af551da7" /&gt;</description>
      <comments>http://www.blog.ingenuitynow.net/CommentView,guid,fc89dc0e-1ede-4121-b9df-4ed2af551da7.aspx</comments>
      <category>.Net;C#;Silverlight;Windows Phone 7</category>
    </item>
    <item>
      <trackback:ping>http://www.blog.ingenuitynow.net/Trackback.aspx?guid=aa822965-c412-4eca-b0d8-189d1268dc0a</trackback:ping>
      <pingback:server>http://www.blog.ingenuitynow.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.blog.ingenuitynow.net/PermaLink,guid,aa822965-c412-4eca-b0d8-189d1268dc0a.aspx</pingback:target>
      <dc:creator>Andrew Schwam</dc:creator>
      <wfw:comment>http://www.blog.ingenuitynow.net/CommentView,guid,aa822965-c412-4eca-b0d8-189d1268dc0a.aspx</wfw:comment>
      <wfw:commentRss>http://www.blog.ingenuitynow.net/SyndicationService.asmx/GetEntryCommentsRss?guid=aa822965-c412-4eca-b0d8-189d1268dc0a</wfw:commentRss>
      <slash:comments>7</slash:comments>
      <title>Windows Phone 7 Application Development Tips</title>
      <guid isPermaLink="false">http://www.blog.ingenuitynow.net/PermaLink,guid,aa822965-c412-4eca-b0d8-189d1268dc0a.aspx</guid>
      <link>http://www.blog.ingenuitynow.net/Windows+Phone+7+Application+Development+Tips.aspx</link>
      <pubDate>Wed, 17 Nov 2010 03:53:00 GMT</pubDate>
      <description>&lt;p&gt;
I recently started writing my first Windows Phone 7 Application.&amp;#160; I was shocked
at how easy it was to get started although I’ll admit that has a lot to do with my
existing knowledge of Silverlight.&amp;#160; If you don’t know Silverlight, now is a great
time to learn it.&amp;#160; You can write apps for the web, desktop, and Windows Phone
7 too!&amp;#160; 
&lt;/p&gt;
&lt;p&gt;
As I wrote my application, I compiled a list of tips to share.&amp;#160; I spent a bunch
of time tracking some of these down or figuring them out.&amp;#160; I hope this will be
helpful to other people.&amp;#160; Plus, I’ll use this as a reference for myself when
I create my next app! 
&lt;/p&gt;
&lt;p&gt;
Here you go.&amp;#160; The first two are pretty basic, but worth mentioning.
&lt;/p&gt;
&lt;h3&gt;Tip:&amp;#160; Go For It!
&lt;/h3&gt;
&lt;p&gt;
The best advice is to install the tools and try it out for yourself.&amp;#160; If you
create an application from one of the templates (you’ll get them after you install
the tools for Visual Studio) you find that the templates themselves are a great learning
tool.&amp;#160; Some include samples for styling, data binding, design time data binding,
navigation, and more!&amp;#160; I recommend trying each of the templates out.
&lt;/p&gt;
&lt;h3&gt;Tip: Install the Free Tools
&lt;/h3&gt;
&lt;p&gt;
This isn’t really a tip.&amp;#160; You can’t create apps without doing this!&amp;#160; Visit
the &lt;a href="http://create.msdn.com/en-us/home/getting_started" target="_blank"&gt;App
Hub&lt;/a&gt; to download the free tools.&amp;#160; You get all this for free: VS 2010 Express,
the Windows Phone Emulator, Expression Blend for Windows Phone, and more!&amp;#160; Also,
don’t forget to install &lt;a href="http://silverlight.codeplex.com/releases/view/55034" target="_blank"&gt;Silverlight
for Windows Phone Toolkit&lt;/a&gt; from the CodePlex site.&amp;#160; It includes some additional
controls that are great like AutoCompleteBox, ContextMenu, GestureListener and more!&amp;#160;
By the way, when you are at the App Hub, check out all the great learning resources.&amp;#160;
By the way, you should keep in mind that Windows Phone 7 is a subset of Silverlight
3!&amp;#160; That means that most features of 3 are there but not all.&amp;#160; And Silverlight
4 features are obviously not included.
&lt;/p&gt;
&lt;h3&gt;Tip: Using the Software Input Panel
&lt;/h3&gt;
&lt;p&gt;
The Software Input Panel (SIP) is the “on screen” keyboard that users use to key in
data.&amp;#160; It’s pretty cool and has some great features.&amp;#160; First, you don’t need
to turn it on.&amp;#160; If you include a TextBox in your app, when it gets focus the
SIP will appear.&amp;#160; But there are many versions of the SIP and you can easily configure
which one appears by setting the InputScope property of your TextBox.&amp;#160; You can
get a full list of the options &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.input.inputscopenamevalue(VS.95).aspx" target="_blank"&gt;here&lt;/a&gt;.&amp;#160;
If you want users to enter numbers, set InputScope to Digits.&amp;#160; For email address
entry, try EmailNameOrAddress and the keyboard will include the @ sign.&amp;#160; Some
choices are more subtle.&amp;#160; Choosing AddressCountryName may seem like the typical
keyboard but the first letter typed will be capitalized, remaining character will
be lower case.&amp;#160; There are many cool and smart features like that.&amp;#160; Also,
options like Text or Chat will include word suggestions!&amp;#160; Here are some code
samples and screen shots:
&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;TextBox &lt;/span&gt;&lt;span style="color: red"&gt;InputScope&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;EmailNameOrAddress&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Height&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;75&amp;quot;
/&amp;gt; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;TextBox &lt;/span&gt;&lt;span style="color: red"&gt;InputScope&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Text&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Height&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;75&amp;quot;
/&amp;gt; &lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;
&lt;a href="http://www.blog.ingenuitynow.net/content/binary/Windows-Live-Writer/dfcf1ff1a700_13347/image_2.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.blog.ingenuitynow.net/content/binary/Windows-Live-Writer/dfcf1ff1a700_13347/image_thumb.png" width="190" height="244" /&gt;&lt;/a&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;a href="http://www.blog.ingenuitynow.net/content/binary/Windows-Live-Writer/dfcf1ff1a700_13347/image_4.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.blog.ingenuitynow.net/content/binary/Windows-Live-Writer/dfcf1ff1a700_13347/image_thumb_1.png" width="226" height="244" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
The first screenshot is the SIP when the EmailNameOrAddress version has focus.&amp;#160;
In the second screen shot (TextBox InputScope set to Text), I typed a few letters
and you can see the word suggestions!
&lt;/p&gt;
&lt;h3&gt;Tip:&amp;#160; Orientation
&lt;/h3&gt;
&lt;p&gt;
If you want your application to support both portrait and landscape mode (when the
user tilts the phone over), you need to set up each page’s SupportedOrientations property
to do so as follows.&amp;#160; Set the default value in the Orientation property.
&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;phone&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;PhoneApplicationPage &lt;/span&gt;&lt;span style="color: red"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;Class&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;WindowsPhoneApplication1.MainPage&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;xmlns&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;xmlns&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;xmlns&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;phone&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;xmlns&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;shell&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;xmlns&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;d&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;http://schemas.microsoft.com/expression/blend/2008&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;xmlns&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;mc&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;http://schemas.openxmlformats.org/markup-compatibility/2006&amp;quot; &lt;/span&gt;&lt;span style="color: blue"&gt; &lt;/span&gt;&lt;font style="background-color: #ffff00"&gt;&lt;span style="color: red"&gt;SupportedOrientations&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;PortraitOrLandscape&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Orientation&lt;/span&gt;&lt;/font&gt;&lt;span style="color: blue"&gt;&lt;font style="background-color: #ffff00"&gt;=&amp;quot;Portrait&amp;quot;&lt;/font&gt; &lt;/span&gt;&lt;/pre&gt;
&lt;h3&gt;Tip: UI Design
&lt;/h3&gt;
&lt;p&gt;
First, you should check out the &lt;a href="http://go.microsoft.com/fwlink/?LinkID=200145" target="_blank"&gt;UI
Design and Interaction Guide&lt;/a&gt; for tips on how to properly design and style the
look and feel of your application.&amp;#160; Also, you should try to use the standard
styles provided when you create an application.&amp;#160; Setting the style in this way
will give your application a consistent look.&amp;#160; Here are a few samples:
&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;TextBlock &lt;/span&gt;&lt;span style="color: red"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;Name&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;ApplicationTitle&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Text&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Demo&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Style&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;StaticResource &lt;/span&gt;&lt;span style="color: red"&gt;PhoneTextNormalStyle&lt;/span&gt;&lt;span style="color: blue"&gt;}&amp;quot;/&amp;gt;
&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;TextBlock &lt;/span&gt;&lt;span style="color: red"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;Name&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;PageTitle&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Text&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;first
page&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Style&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;StaticResource &lt;/span&gt;&lt;span style="color: red"&gt;PhoneTextTitle1Style&lt;/span&gt;&lt;span style="color: blue"&gt;}&amp;quot;/&amp;gt; &lt;/span&gt;&lt;/pre&gt;
&lt;h3&gt;Tip: Using Isolated Storage
&lt;/h3&gt;
&lt;p&gt;
For simple values, you can easily get in and out of IsolatedStorageSettings.ApplicationSettings
(Dictionary&lt;string  , Object&gt;
). For more complex data, you can put it into IsolatedStorage.&amp;#160; Since there is
no database available in Wp7, one common approach to saving data is to simple serialize
your model and save it as a file.&amp;#160; To do so, make sure you mark all of your Model’s
classes with the attribute DataContract and make sure the properties have the DataMember
attribute.&amp;#160; Here’s a sample class called ListOfStuff as well as the methods I
use to read/write it to/from IsolatedStorage: 
&lt;/p&gt;
&lt;pre class="code"&gt;[&lt;span style="color: #2b91af"&gt;DataContract&lt;/span&gt;] &lt;span style="color: blue"&gt;public
class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;ListOfStuff &lt;/span&gt;: &lt;span style="color: #2b91af"&gt;Observable &lt;/span&gt;{
[&lt;span style="color: #2b91af"&gt;DataMember&lt;/span&gt;] &lt;span style="color: blue"&gt;public
string &lt;/span&gt;Title { &lt;span style="color: blue"&gt;get &lt;/span&gt;{ &lt;span style="color: blue"&gt;return &lt;/span&gt;_title;
} &lt;span style="color: blue"&gt;set &lt;/span&gt;{ &lt;span style="color: blue"&gt;if &lt;/span&gt;(_title
!= &lt;span style="color: blue"&gt;value&lt;/span&gt;) { _title = &lt;span style="color: blue"&gt;value&lt;/span&gt;;
NotifyPropertyChanged(&lt;span style="color: #a31515"&gt;&amp;quot;Title&amp;quot;&lt;/span&gt;); } }
} &lt;span style="color: blue"&gt;private string &lt;/span&gt;_title; [&lt;span style="color: #2b91af"&gt;DataMember&lt;/span&gt;] &lt;span style="color: blue"&gt;public &lt;/span&gt;&lt;span style="color: #2b91af"&gt;ObservableCollection&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;ListCategory&lt;/span&gt;&amp;gt;
Categories { &lt;span style="color: blue"&gt;get &lt;/span&gt;{ &lt;span style="color: blue"&gt;return &lt;/span&gt;_categories;
} &lt;span style="color: blue"&gt;set &lt;/span&gt;{ &lt;span style="color: blue"&gt;if &lt;/span&gt;(_categories
!= &lt;span style="color: blue"&gt;value&lt;/span&gt;) { _categories = &lt;span style="color: blue"&gt;value&lt;/span&gt;;
NotifyPropertyChanged(&lt;span style="color: #a31515"&gt;&amp;quot;Categories&amp;quot;&lt;/span&gt;);
} } } &lt;span style="color: blue"&gt;private &lt;/span&gt;&lt;span style="color: #2b91af"&gt;ObservableCollection&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;ListCategory&lt;/span&gt;&amp;gt;
_categories = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;ObservableCollection&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;ListCategory&lt;/span&gt;&amp;gt;();
}&lt;/pre&gt;
&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;public static void &lt;/span&gt;SaveToFile(&lt;span style="color: #2b91af"&gt;ListOfStuff &lt;/span&gt;listOfStuff)
{ &lt;span style="color: blue"&gt;using &lt;/span&gt;(&lt;span style="color: #2b91af"&gt;IsolatedStorageFile &lt;/span&gt;isolatedStorageFile
= &lt;span style="color: #2b91af"&gt;IsolatedStorageFile&lt;/span&gt;.GetUserStoreForApplication())
{ &lt;span style="color: blue"&gt;using &lt;/span&gt;(&lt;span style="color: #2b91af"&gt;IsolatedStorageFileStream &lt;/span&gt;stream
= &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;IsolatedStorageFileStream&lt;/span&gt;(&lt;span style="color: blue"&gt;string&lt;/span&gt;.Format(&lt;span style="color: #a31515"&gt;&amp;quot;{0}.dat&amp;quot;&lt;/span&gt;,
listOfStuff.Title), &lt;span style="color: #2b91af"&gt;FileMode&lt;/span&gt;.Create, isolatedStorageFile))
{ &lt;span style="color: #2b91af"&gt;DataContractSerializer &lt;/span&gt;serializer = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;DataContractSerializer&lt;/span&gt;(&lt;span style="color: blue"&gt;typeof&lt;/span&gt;(&lt;span style="color: #2b91af"&gt;ListOfStuff&lt;/span&gt;));
serializer.WriteObject(stream, listOfStuff); } } } &lt;span style="color: blue"&gt;public
static &lt;/span&gt;&lt;span style="color: #2b91af"&gt;ListOfStuff &lt;/span&gt;LoadFromFile(&lt;span style="color: blue"&gt;string &lt;/span&gt;listName)
{ &lt;span style="color: #2b91af"&gt;ListOfStuff &lt;/span&gt;listOfStuff = &lt;span style="color: blue"&gt;null&lt;/span&gt;; &lt;span style="color: blue"&gt;using &lt;/span&gt;(&lt;span style="color: #2b91af"&gt;IsolatedStorageFile &lt;/span&gt;isf
= &lt;span style="color: #2b91af"&gt;IsolatedStorageFile&lt;/span&gt;.GetUserStoreForApplication())
{ &lt;span style="color: blue"&gt;using &lt;/span&gt;(&lt;span style="color: #2b91af"&gt;IsolatedStorageFileStream &lt;/span&gt;stream
= &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;IsolatedStorageFileStream&lt;/span&gt;(&lt;span style="color: blue"&gt;string&lt;/span&gt;.Format(&lt;span style="color: #a31515"&gt;&amp;quot;{0}.dat&amp;quot;&lt;/span&gt;,
listName), &lt;span style="color: #2b91af"&gt;FileMode&lt;/span&gt;.OpenOrCreate, isf)) { &lt;span style="color: blue"&gt;if &lt;/span&gt;(stream.Length
&amp;gt; 0) { &lt;span style="color: #2b91af"&gt;DataContractSerializer &lt;/span&gt;serializer = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;DataContractSerializer&lt;/span&gt;(&lt;span style="color: blue"&gt;typeof&lt;/span&gt;(&lt;span style="color: #2b91af"&gt;ListOfStuff&lt;/span&gt;));
listOfStuff = serializer.ReadObject(stream) &lt;span style="color: blue"&gt;as &lt;/span&gt;&lt;span style="color: #2b91af"&gt;ListOfStuff&lt;/span&gt;;
} } } &lt;span style="color: blue"&gt;return &lt;/span&gt;listOfStuff; }&lt;/pre&gt;
&lt;h3&gt;Tip: Using the Phone’s Camera
&lt;/h3&gt;
&lt;p&gt;
Using the phone couldn’t be simpler, just use the CameraCaptureTask as follows:
&lt;/p&gt;
&lt;p&gt;
&lt;em&gt;**NOTE: As reader Andy Wilkinson pointed out in a comment to this post, I’m not
following best practices here.&amp;#160; The way I declare my CameraCaptureTask could
lead to problems with tombstoning.&amp;#160; He points out a &lt;/em&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ff769543(v=VS.92).aspx" target="_blank"&gt;&lt;em&gt;nice
article on MSDN&lt;/em&gt;&lt;/a&gt;&lt;em&gt; that explains the proper use, please read it &lt;/em&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ff769543(v=VS.92).aspx" target="_blank"&gt;&lt;em&gt;here&lt;/em&gt;&lt;/a&gt;&lt;em&gt;.&amp;#160;
Thanks, Andy, for the assistance!&lt;/em&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;em&gt;**Another Note:&amp;#160; Another user asked about saving the results of the CameraCaptureTask.&amp;#160;
So I’ve written another post that you may find useful.&amp;#160; Please check it out &lt;a href="http://www.blog.ingenuitynow.net/WP7+Tip+Using+The+CameraCaptureTask+For+Windows+Phone+7.aspx" target="_blank"&gt;here&lt;/a&gt;.&lt;/em&gt;
&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;private void &lt;/span&gt;Camera_Click(&lt;span style="color: blue"&gt;object &lt;/span&gt;sender, &lt;span style="color: #2b91af"&gt;RoutedEventArgs &lt;/span&gt;e)
{ &lt;span style="color: #2b91af"&gt;CameraCaptureTask &lt;/span&gt;cameraCaptureTask = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;CameraCaptureTask&lt;/span&gt;();
cameraCaptureTask.Completed += cameraCaptureTask_Completed; cameraCaptureTask.Show();
} &lt;font face="Verdana"&gt;After the picture is taken, you can access it later, as a Stream.
You can assign it to an Image, save it, or do whatever you want.&lt;/font&gt;&lt;/pre&gt;
&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;void &lt;/span&gt;cameraCaptureTask_Completed(&lt;span style="color: blue"&gt;object &lt;/span&gt;sender, &lt;span style="color: #2b91af"&gt;PhotoResult &lt;/span&gt;e)
{ &lt;span style="color: blue"&gt;var &lt;/span&gt;photoStream = e.ChosenPhoto; }&lt;/pre&gt;
&lt;h3&gt;Tip: Using Gestures
&lt;/h3&gt;
&lt;p&gt;
Of course, you want your application to react when users use common phone Gestures
such as Flick, Pinch, Hold, etc.&amp;#160; Doing so is easy too!&amp;#160; The Silverlight
Toolkit for Windows Phone (mentioned in second tip above) provides the GestureListener
that you will need.&amp;#160; You can see how simple it is to wire up in the following
example. In this case, I want the user to be able to hold their finger down on an
image to go to “edit mode” where a description TextBox will appear.&amp;#160; In the NoteHold()
method (not shown), you can imaging all I need to do is set the description TextBox
to be visible.
&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Image &lt;/span&gt;&lt;span style="color: red"&gt;Source&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;Binding &lt;/span&gt;&lt;span style="color: red"&gt;Image&lt;/span&gt;&lt;span style="color: blue"&gt;}&amp;quot;&amp;gt;
&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;ToolkitControls&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;GestureService.GestureListener&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;ToolkitControls&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;GestureListener &lt;/span&gt;&lt;span style="color: red"&gt;Hold&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;NoteHold&amp;quot;
/&amp;gt; &amp;lt;/&amp;lt; span&amp;gt;&lt;span style="color: #a31515"&gt;ToolkitControls&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;GestureService.GestureListener&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;/&amp;lt; span&amp;gt;&lt;span style="color: #a31515"&gt;Image&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt; &lt;/span&gt;
&lt;/pre&gt;
&lt;p&gt;
Now go start creating apps!
&lt;/p&gt;
&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:03401b9b-262a-4072-9d73-5efe6f4cca93" class="wlWriterEditableSmartContent"&gt;Technorati
Tags: &lt;a href="http://technorati.com/tags/Windows+Phone+7" rel="tag"&gt;Windows Phone
7&lt;/a&gt;,&lt;a href="http://technorati.com/tags/IsolatedStorage" rel="tag"&gt;IsolatedStorage&lt;/a&gt;,&lt;a href="http://technorati.com/tags/CameraCaptureTask" rel="tag"&gt;CameraCaptureTask&lt;/a&gt;,&lt;a href="http://technorati.com/tags/GestureListener" rel="tag"&gt;GestureListener&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Software+Input+Panel" rel="tag"&gt;Software
Input Panel&lt;/a&gt;,&lt;a href="http://technorati.com/tags/WP7" rel="tag"&gt;WP7&lt;/a&gt;
&lt;/div&gt;
&lt;img width="0" height="0" src="http://www.blog.ingenuitynow.net/aggbug.ashx?id=aa822965-c412-4eca-b0d8-189d1268dc0a" /&gt;</description>
      <comments>http://www.blog.ingenuitynow.net/CommentView,guid,aa822965-c412-4eca-b0d8-189d1268dc0a.aspx</comments>
      <category>.Net;C#;Silverlight;Windows 7</category>
    </item>
  </channel>
</rss>
