<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-8691068330397730091</id><updated>2010-06-09T09:06:50.859-04:00</updated><title type='text'>blog.jamesjones.name</title><subtitle type='html'>programming abroad</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://blog.jamesjones.name/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8691068330397730091/posts/default'/><link rel='alternate' type='text/html' href='http://blog.jamesjones.name/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>James</name><uri>http://www.blogger.com/profile/07743081202945582329</uri><email>james.russel.jones@gmail.com</email></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>10</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-8691068330397730091.post-4560473626028050343</id><published>2010-05-24T01:02:00.019-04:00</published><updated>2010-05-24T22:46:19.871-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Unit of Work'/><category scheme='http://www.blogger.com/atom/ns#' term='.NET'/><category scheme='http://www.blogger.com/atom/ns#' term='Repository'/><category scheme='http://www.blogger.com/atom/ns#' term='NHibernate'/><title type='text'>NHibernate Unit of Work Example</title><content type='html'>Several months ago, I blogged about &lt;a href="http://blog.jamesjones.name/2010/02/implementing-repository-pattern-with.html"&gt;implementing the Repository Pattern with NHibernate&lt;/a&gt;. The Repository Pattern functions as both a facade and an abstraction layer for your application's data access layer (DAL). The major drawback of this approach is that you're forced to disable lazy loading, which is a coveted feature of NHibernate. This spawned the creation of the Unit of Work pattern; essentially the Repository pattern implemented with session control.&lt;br /&gt;&lt;br /&gt;While many Unit of Work facades already exist, they all share the common problem of being nearly as complicated using NHibernate directly, which undermines the purpose of the facade pattern. To that end, I have developed a Unit of Work implementation for NHibernate that hits the sweet spot between functionality and simplicity. I'll use my classic scenario of monkeys and bananas to illustrate how one might use this particular implementation:&lt;br /&gt;&lt;br /&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; (var uow = &lt;span class="kwrd"&gt;new&lt;/span&gt; NHUnitOfWork(Properties.Settings.Default.DBConnStr))&lt;br /&gt;{&lt;br /&gt;    Monkey m = uow.Get&amp;lt;Monkey&amp;gt;(0);&lt;br /&gt;&lt;br /&gt;    m.NumberOfBananas++;&lt;br /&gt;&lt;br /&gt;    uow.Save(myObject);&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;This small snippet utilizes an atomic transaction with the database, which is essential when incrementing bananas in a database (remember race conditions!). This also solves the "lazy loading issue" with the Repository pattern, since all fields are accessible during the transaction. The transaction automatically begins when the "using" statement is executed, and the transaction commits at the end of the 'using' block (when NHUnitOfWork.Dispose() is called). No remembering to call "Initialize" or "Commit" functions - these are assumed. Simple.&lt;br /&gt;&lt;br /&gt;It's way past my bed time so I will upload the code tomorrow. Good night!&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Update:&lt;/b&gt; The code can be downloaded from the Google Code project&amp;nbsp;&lt;a href="http://code.google.com/p/nhibernate-unitofwork-example/"&gt;nhibernate-unitofwork-example&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8691068330397730091-4560473626028050343?l=blog.jamesjones.name' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.jamesjones.name/feeds/4560473626028050343/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.jamesjones.name/2010/05/nhibernate-unit-of-work-example.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8691068330397730091/posts/default/4560473626028050343'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8691068330397730091/posts/default/4560473626028050343'/><link rel='alternate' type='text/html' href='http://blog.jamesjones.name/2010/05/nhibernate-unit-of-work-example.html' title='NHibernate Unit of Work Example'/><author><name>James</name><uri>http://www.blogger.com/profile/07743081202945582329</uri><email>james.russel.jones@gmail.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='14897653130005070286'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8691068330397730091.post-39972332059619189</id><published>2010-02-25T08:43:00.002-05:00</published><updated>2010-05-21T00:33:12.712-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Visual Studio'/><title type='text'>Visual Studio 2010 Dark Color Theme</title><content type='html'>The bright default Visual Studio theme simply wasn't cutting it for me and my former Visual Studio 2005/2008 themes weren't converting nicely. I scoured the internet for a decent dark theme that would work with Visual Studio 2010 to no avail. Left to my own devices, I created this one from scratch. Check it out:&lt;br /&gt;&lt;br /&gt;C#:&lt;br /&gt;&lt;a href="http://1.bp.blogspot.com/_Xy29Qj1Kzis/S4WQqK7NsEI/AAAAAAAAADo/G5dsJdNnfX4/s1600-h/themess.PNG" imageanchor="1"&gt;&lt;img border="0" height="449" src="http://1.bp.blogspot.com/_Xy29Qj1Kzis/S4WQqK7NsEI/AAAAAAAAADo/G5dsJdNnfX4/s640/themess.PNG" width="640" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;ASP.NET / HTML:&lt;br /&gt;&lt;a href="http://2.bp.blogspot.com/_Xy29Qj1Kzis/S4WRzgUM18I/AAAAAAAAADw/d-Cchp_F6Fg/s1600-h/html.PNG" imageanchor="1"&gt;&lt;img border="0" height="172" src="http://2.bp.blogspot.com/_Xy29Qj1Kzis/S4WRzgUM18I/AAAAAAAAADw/d-Cchp_F6Fg/s640/html.PNG" width="640" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;JavaScript:&lt;br /&gt;&lt;a href="http://3.bp.blogspot.com/_Xy29Qj1Kzis/S4WR6JNnlYI/AAAAAAAAAD4/qYC_5oLSE1o/s1600-h/javascript.PNG" imageanchor="1"&gt;&lt;img border="0" height="252" src="http://3.bp.blogspot.com/_Xy29Qj1Kzis/S4WR6JNnlYI/AAAAAAAAAD4/qYC_5oLSE1o/s400/javascript.PNG" width="400" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;This theme is &lt;a href="http://visual-studio-2010-themes.googlecode.com/files/JamesJonesDarkTheme.zip"&gt;available for download&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8691068330397730091-39972332059619189?l=blog.jamesjones.name' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.jamesjones.name/feeds/39972332059619189/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.jamesjones.name/2010/02/visual-studio-2010-dark-color-theme.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8691068330397730091/posts/default/39972332059619189'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8691068330397730091/posts/default/39972332059619189'/><link rel='alternate' type='text/html' href='http://blog.jamesjones.name/2010/02/visual-studio-2010-dark-color-theme.html' title='Visual Studio 2010 Dark Color Theme'/><author><name>James</name><uri>http://www.blogger.com/profile/07743081202945582329</uri><email>james.russel.jones@gmail.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='14897653130005070286'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_Xy29Qj1Kzis/S4WQqK7NsEI/AAAAAAAAADo/G5dsJdNnfX4/s72-c/themess.PNG' height='72' width='72'/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8691068330397730091.post-5332538149065602435</id><published>2010-02-21T21:42:00.008-05:00</published><updated>2010-05-24T22:37:24.249-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='.NET'/><category scheme='http://www.blogger.com/atom/ns#' term='Repository'/><category scheme='http://www.blogger.com/atom/ns#' term='Pattern'/><category scheme='http://www.blogger.com/atom/ns#' term='NHibernate'/><title type='text'>Implementing the Repository Pattern with NHibernate</title><content type='html'>This blog post is a continuation from my &lt;a href="http://blog.jamesjones.name/2010/02/repository-pattern.html"&gt;previous post&lt;/a&gt;, which enumerates the merits of the Repository design pattern. Here, I'm going to show you a great way to implement the Repository pattern. Just to recap, the Repository Pattern is essentially this interface:&lt;br /&gt;&lt;br /&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;interface&lt;/span&gt; IRepository&amp;lt;T&amp;gt;&lt;br /&gt;{&lt;br /&gt;    T Get(&lt;span class="kwrd"&gt;object&lt;/span&gt; id);&lt;br /&gt;    &lt;span class="kwrd"&gt;void&lt;/span&gt; Save(T value&amp;gt;);&lt;br /&gt;    &lt;span class="kwrd"&gt;void&lt;/span&gt; Update(T value);&lt;br /&gt;    &lt;span class="kwrd"&gt;void&lt;/span&gt; Delete(T value);&lt;br /&gt;    IList&amp;lt;T&amp;gt; GetAll();&lt;br /&gt;}&lt;/pre&gt;&lt;b&gt;Note:&lt;/b&gt; The strength of this interface is its simplicity. Its Achilles' heel is that lazyloading will have to be disabled in order to reference associated objects. If this is a deal-breaker for you, check out the &lt;a href="http://blog.jamesjones.name/2010/05/nhibernate-unit-of-work-example.html"&gt;Unit of Work facade&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Now for the hard part: implementing the interface. We will be using NHibernate to accomplish this. Why NHibernate? NHibernate is one of the &lt;a href="http://stackoverflow.com/questions/662956/most-useful-free-net-libraries"&gt;most popular&lt;/a&gt; ORMs in existence, and for good reason.&lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;li&gt;It's open source.&lt;/li&gt;&lt;li&gt;It covers the object-relational&amp;nbsp;impedance&amp;nbsp;mismatch very well (support for inheritance/polymorphism/composition with configurable implementation).&lt;/li&gt;&lt;li&gt;You can generate the entire system database with one line of code.&lt;/li&gt;&lt;li&gt;Combined with FluentNHibernate, follows the&amp;nbsp;&lt;a href="http://en.wikipedia.org/wiki/Convention_over_configuration"&gt;convention over configuration&lt;/a&gt;&amp;nbsp;design paradigm.&lt;/li&gt;&lt;li&gt;It's very flexible in terms usability, offering you abstract/ease-of-use functionality or control of all fine-tuned minuté imaginable.&lt;/li&gt;&lt;/ol&gt;&lt;br /&gt;That being said, NHibernate is more than adequate for task at hand.&amp;nbsp;The example world that I'm going to model simply consists of monkeys and bananas, where monkeys can have multiple bananas, like so:&lt;br /&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Monkey&lt;br /&gt;{&lt;br /&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;virtual&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; Id { get; set; }&lt;br /&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;virtual&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Name { get; set; }&lt;br /&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;virtual&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; FlingsPoo { get; set; }&lt;br /&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;virtual&lt;/span&gt; IList&amp;lt;Banana&amp;gt; Bananas { get; set; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Banana&lt;br /&gt;{&lt;br /&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;virtual&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; Id { get; set; }&lt;br /&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;virtual&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Color { get; set; }&lt;br /&gt;}&lt;/pre&gt;NHibernate uses "mappings" to tie the classes to the database, and while it's possible to fulfill this example using FluentNHibernate &lt;a href="http://wiki.fluentnhibernate.org/Auto_mapping"&gt;auto mapping&lt;/a&gt;, most people prefer the control of the classic &lt;a href="http://wiki.fluentnhibernate.org/Fluent_mapping"&gt;Fluent mapping&lt;/a&gt; classes, so that's what we'll use.&lt;br /&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; MonkeyMap : ClassMap&amp;lt;Monkey&amp;gt;&lt;br /&gt;{&lt;br /&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; MonkeyMap()&lt;br /&gt;    {&lt;br /&gt;        Id(x =&amp;gt; x.Id);&lt;br /&gt;        Map(x =&amp;gt; x.Name);&lt;br /&gt;        Map(x =&amp;gt; x.FlingsPoo);&lt;br /&gt;        HasMany&amp;lt;Banana&amp;gt;(x =&amp;gt; x.Bananas)&lt;br /&gt;            .Not.LazyLoad();&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; BananaMap : ClassMap&amp;lt;Banana&amp;gt;&lt;br /&gt;{&lt;br /&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; BananaMap()&lt;br /&gt;    {&lt;br /&gt;        Id(x =&amp;gt; x.Id);&lt;br /&gt;        Map(x =&amp;gt; x.Color);&lt;br /&gt;    }&lt;br /&gt;}&lt;/pre&gt;That should take care of the database mapping. And now for the meat and potatoes:&lt;br /&gt;&lt;br /&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; NHibernateRepository&amp;lt;T&amp;gt; : IRepository&amp;lt;T&amp;gt; &lt;span class="kwrd"&gt;where&lt;/span&gt; T : &lt;span class="kwrd"&gt;class&lt;/span&gt;&lt;br /&gt;{&lt;br /&gt;    &lt;span class="kwrd"&gt;protected&lt;/span&gt; Configuration config;&lt;br /&gt;    &lt;span class="kwrd"&gt;protected&lt;/span&gt; ISessionFactory sessionFactory;&lt;br /&gt;&lt;br /&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; NHibernateRepository()&lt;br /&gt;    {&lt;br /&gt;        config = Fluently.Configure()&lt;br /&gt;            .Database(&lt;br /&gt;                MsSqlConfiguration&lt;br /&gt;                .MsSql2008&lt;br /&gt;                .ConnectionString(&lt;span class="str"&gt;@"Data Source=SQLEXPRESS;Initial Catalog=TestDB;Integrated Security=True"&lt;/span&gt;))&lt;br /&gt;                .Mappings(m =&amp;gt; m.FluentMappings.AddFromAssemblyOf&amp;lt;NHibernateRepository&amp;lt;T&amp;gt;&amp;gt;())&lt;br /&gt;            .BuildConfiguration();&lt;br /&gt;&lt;br /&gt;        sessionFactory = config.BuildSessionFactory();&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Save(T &lt;span class="kwrd"&gt;value&lt;/span&gt;)&lt;br /&gt;    {&lt;br /&gt;        &lt;span class="kwrd"&gt;using&lt;/span&gt; (var session = sessionFactory.OpenSession())&lt;br /&gt;        &lt;span class="kwrd"&gt;using&lt;/span&gt; (var transaction = session.BeginTransaction())&lt;br /&gt;        {&lt;br /&gt;            session.Save(&lt;span class="kwrd"&gt;value&lt;/span&gt;);&lt;br /&gt;            transaction.Commit();&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;That's really all there is to it. I leave Get/Update/Delete/GetAll out as an exercise for the reader to implement (Hint: they're almost exactly like Save). Change the connection string to point at your test database and we should be good to go. What are we waiting for? Let's put a monkey in the database!&lt;br /&gt;&lt;br /&gt;&lt;pre class="csharpcode"&gt;Monkey m = &lt;span class="kwrd"&gt;new&lt;/span&gt; Monkey() { Name = &lt;span class="str"&gt;"George"&lt;/span&gt;, FlingsPoo = &lt;span class="kwrd"&gt;true&lt;/span&gt; };&lt;br /&gt;IRepository&amp;lt;Monkey&amp;gt; mRepo = &lt;span class="kwrd"&gt;new&lt;/span&gt; NHibernateRepository&amp;lt;Monkey&amp;gt;();&lt;br /&gt;mRepo.Save(m);&lt;/pre&gt;I think this is enough for one blog post. The complete compilable project based off of this example can be found at the Google Code project&amp;nbsp;&lt;a href="http://code.google.com/p/nhibernate-repository-example/"&gt;nhibernate-repository-example&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8691068330397730091-5332538149065602435?l=blog.jamesjones.name' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.jamesjones.name/feeds/5332538149065602435/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.jamesjones.name/2010/02/implementing-repository-pattern-with.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8691068330397730091/posts/default/5332538149065602435'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8691068330397730091/posts/default/5332538149065602435'/><link rel='alternate' type='text/html' href='http://blog.jamesjones.name/2010/02/implementing-repository-pattern-with.html' title='Implementing the Repository Pattern with NHibernate'/><author><name>James</name><uri>http://www.blogger.com/profile/07743081202945582329</uri><email>james.russel.jones@gmail.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='14897653130005070286'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8691068330397730091.post-8756942130686000703</id><published>2010-02-19T11:13:00.004-05:00</published><updated>2010-04-20T10:01:00.594-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='.NET'/><category scheme='http://www.blogger.com/atom/ns#' term='Repository'/><category scheme='http://www.blogger.com/atom/ns#' term='Pattern'/><title type='text'>The Repository Pattern</title><content type='html'>If you're still writing SQL statements to persist your objects to/from your database, STOP!!! If you fall into this category, your code is likely unreadable by anyone other than yourself. And before you know it, even you won't be able to read your own code. Believe me, I know because I have felt this pain.&lt;br /&gt;&lt;br /&gt;In my experience, about 9/10 of database-driven applications could be vastly simplified by using a software pattern known as Repository.&lt;br /&gt;&lt;br /&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;interface&lt;/span&gt; IRepository&amp;lt;T&amp;gt;&lt;br /&gt;{&lt;br /&gt;    T Get(&lt;span class="kwrd"&gt;object&lt;/span&gt; id);&lt;br /&gt;    &lt;span class="kwrd"&gt;void&lt;/span&gt; Save(T value);&lt;br /&gt;    &lt;span class="kwrd"&gt;void&lt;/span&gt; Update(T value);&lt;br /&gt;    &lt;span class="kwrd"&gt;void&lt;/span&gt; Delete(T value);&lt;br /&gt;    IList&amp;lt;T&amp;gt; GetAll();&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;That's all there is to it. By using this interface as a gateway for getting objects to/from your database, you're able to completely decouple your system from the data access layer (DAL, for short). The advantages to this approach are twofold:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Your code is 500% more readable because the reader doesn't even have to THINK about the implementation details of your DAL.&lt;/li&gt;&lt;li&gt;You're able to easily swap out the DAL for a different implementation.&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;The implementation of the Repository pattern should be capable of reading the type of the object passed to it and then know how to fit the object into the database. Now, I suppose you could write a whole crapload of SQL to implement this interface OR you could use an ORM. I've found that NHibernate is a great way to implement the Repository pattern and that's what I'll be covering in my next blog post.&lt;br /&gt;&lt;br /&gt;Update: Here is the next blog post on &lt;a href="http://blog.jamesjones.name/2010/02/implementing-repository-pattern-with.html"&gt;Implementing the Repository Pattern with NHibernate&lt;/a&gt;.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8691068330397730091-8756942130686000703?l=blog.jamesjones.name' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.jamesjones.name/feeds/8756942130686000703/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.jamesjones.name/2010/02/repository-pattern.html#comment-form' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8691068330397730091/posts/default/8756942130686000703'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8691068330397730091/posts/default/8756942130686000703'/><link rel='alternate' type='text/html' href='http://blog.jamesjones.name/2010/02/repository-pattern.html' title='The Repository Pattern'/><author><name>James</name><uri>http://www.blogger.com/profile/07743081202945582329</uri><email>james.russel.jones@gmail.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='14897653130005070286'/></author><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8691068330397730091.post-4301421526190103063</id><published>2009-12-04T11:37:00.005-05:00</published><updated>2010-02-24T16:52:56.746-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='.NET'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><title type='text'>Filter a list of child objects from a list of parent objects</title><content type='html'>You have a list of generic parent objects consisting of various child objects. You want to filter out a list of a objects consisting of one of the child classes. Here's the code:&lt;br /&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;&lt;br /&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;class&lt;/span&gt; ChildObjectListFilterer&amp;lt;Tparent, Tchild&amp;gt;&lt;br /&gt;{&lt;br /&gt;    IList&amp;lt;Tparent&amp;gt; parentObjectList;&lt;br /&gt;&lt;br /&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; ChildObjectListFilterer(IList&amp;lt;Tparent&amp;gt; parentObjectList)&lt;br /&gt;    {&lt;br /&gt;        &lt;span class="kwrd"&gt;this&lt;/span&gt;.parentObjectList = parentObjectList;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; IList&amp;lt;Tchild&amp;gt; getChildObjects()&lt;br /&gt;    {&lt;br /&gt;        IList&amp;lt;Tchild&amp;gt; returnVal = &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;Tchild&amp;gt;();&lt;br /&gt;&lt;br /&gt;        &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (&lt;span class="kwrd"&gt;object&lt;/span&gt; o &lt;span class="kwrd"&gt;in&lt;/span&gt; parentObjectList)&lt;br /&gt;        {&lt;br /&gt;            &lt;span class="kwrd"&gt;if&lt;/span&gt; (o.GetType() == &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(Tchild))&lt;br /&gt;            {&lt;br /&gt;                returnVal.Add((Tchild)o);&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span class="kwrd"&gt;return&lt;/span&gt; returnVal;&lt;br /&gt;    }&lt;br /&gt;}&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8691068330397730091-4301421526190103063?l=blog.jamesjones.name' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.jamesjones.name/feeds/4301421526190103063/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.jamesjones.name/2009/12/filter-list-of-child-objects-from-list.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8691068330397730091/posts/default/4301421526190103063'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8691068330397730091/posts/default/4301421526190103063'/><link rel='alternate' type='text/html' href='http://blog.jamesjones.name/2009/12/filter-list-of-child-objects-from-list.html' title='Filter a list of child objects from a list of parent objects'/><author><name>James</name><uri>http://www.blogger.com/profile/07743081202945582329</uri><email>james.russel.jones@gmail.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='14897653130005070286'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8691068330397730091.post-3893091158956920786</id><published>2009-11-23T11:06:00.002-05:00</published><updated>2009-11-25T09:50:57.482-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='IIS'/><category scheme='http://www.blogger.com/atom/ns#' term='ASP.NET'/><title type='text'>How to disable browser caching in web.config</title><content type='html'>The title says it all. Here's the web.config snippet that will prevent all pages in your web app from being cached by the user's browser:&lt;br /&gt;&lt;br /&gt;&amp;lt;configuration&amp;gt;&lt;br /&gt;&amp;lt;system.webServer&amp;gt;&lt;br /&gt;&amp;lt;httpProtocol&amp;gt;&lt;br /&gt;&amp;lt;customHeaders&amp;gt;&lt;br /&gt;&amp;lt;add name="Cache-Control" value="no-cache" /&amp;gt;&lt;br /&gt;&amp;lt;add name="Pragma" value="no-cache" /&amp;gt;&lt;br /&gt;&amp;lt;add name="Expires" value="-1" /&amp;gt;&lt;br /&gt;&amp;lt;/customHeaders&amp;gt;&lt;br /&gt;&amp;lt;/httpProtocol&amp;gt;&lt;br /&gt;&amp;lt;/system.webServer&amp;gt;&lt;br /&gt;&amp;lt;/configuration&amp;gt;&lt;br /&gt;&lt;br /&gt;These headers will show up in the "HTTP Response Headers" section of IIS. If you're looking for an explanation why you need 3 name-value pairs, &lt;a href="http://support.microsoft.com/kb/234067"&gt;here's Microsoft's explanation&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8691068330397730091-3893091158956920786?l=blog.jamesjones.name' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.jamesjones.name/feeds/3893091158956920786/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.jamesjones.name/2009/11/how-to-disable-browser-caching-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8691068330397730091/posts/default/3893091158956920786'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8691068330397730091/posts/default/3893091158956920786'/><link rel='alternate' type='text/html' href='http://blog.jamesjones.name/2009/11/how-to-disable-browser-caching-in.html' title='How to disable browser caching in web.config'/><author><name>James</name><uri>http://www.blogger.com/profile/07743081202945582329</uri><email>james.russel.jones@gmail.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='14897653130005070286'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8691068330397730091.post-592136752672535054</id><published>2009-11-04T16:10:00.001-05:00</published><updated>2010-02-24T16:52:34.206-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Windows 7'/><category scheme='http://www.blogger.com/atom/ns#' term='Insanity'/><title type='text'>Creating a Default User Profile in Windows 7</title><content type='html'>Microsoft has given its users the &lt;a href="http://social.technet.microsoft.com/Forums/en/w7itprogeneral/thread/5a5d44b6-116a-4a21-bc64-53379218ecc6"&gt;virtual finger&lt;/a&gt; in respect to addressing a bug in Windows 7 that has been known of for at least 6 months as of the time of writing. Microsoft recently published a &lt;a href="http://support.microsoft.com/kb/973289"&gt;lengthy workaround&lt;/a&gt; to the issue, but most of us have lives and don't feel like jumping through hoops to achieve something that was easy to do since Windows NT.&lt;br /&gt;&lt;br /&gt;Here's the EASY workaround:&lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Download a little freeware program called "Windows Enabler 1.1" (Google it, and download it).&lt;/li&gt;&lt;li&gt;Log onto the target computer as a Standard User and set everything up as you want to appear for the default user.&lt;/li&gt;&lt;li&gt;Log out and log in as an Administrator.&lt;/li&gt;&lt;li&gt;Run Windows Enabler. (a little blue &amp;amp; white icon will show up in your system tray)&lt;/li&gt;&lt;li&gt;Right-click Computer -&amp;gt; Properties -&amp;gt; Advanced system settings (link)&lt;/li&gt;&lt;li&gt;Under the User Profiles section, click Settings... The User Profiles window will appear.&lt;/li&gt;&lt;li&gt;Select the profile that you set up for the default user.&lt;/li&gt;&lt;li&gt;Click on the Windows Enabler icon in your system tray. It should say "On".&lt;/li&gt;&lt;li&gt;Click the User Profiles window. &amp;nbsp;The Copy To... button should be enabled. Click it.&lt;/li&gt;&lt;li&gt;Click the Windows Enabler icon again to turn it off.&lt;/li&gt;&lt;li&gt;Under the "Permitted to use" section, hit Change and enter "Everyone" for the object name.&lt;/li&gt;&lt;li&gt;Under the "Copy profile to" section, paste this text into the text box "C:\Users\Default" (this assumes your base drive is C:\. Back up the Default folder if you're a scaredy cat.)&lt;/li&gt;&lt;li&gt;Click OK three times.&lt;/li&gt;&lt;/ol&gt;&lt;div&gt;Done. You should be good to go. Now, if only Microsoft could figure out a way to enable that button for us...&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8691068330397730091-592136752672535054?l=blog.jamesjones.name' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.jamesjones.name/feeds/592136752672535054/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.jamesjones.name/2009/11/creating-default-user-profile-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8691068330397730091/posts/default/592136752672535054'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8691068330397730091/posts/default/592136752672535054'/><link rel='alternate' type='text/html' href='http://blog.jamesjones.name/2009/11/creating-default-user-profile-in.html' title='Creating a Default User Profile in Windows 7'/><author><name>James</name><uri>http://www.blogger.com/profile/07743081202945582329</uri><email>james.russel.jones@gmail.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='14897653130005070286'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8691068330397730091.post-4629094955223337904</id><published>2009-10-01T15:50:00.005-04:00</published><updated>2010-02-24T16:52:34.207-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='IIS'/><category scheme='http://www.blogger.com/atom/ns#' term='WCF'/><category scheme='http://www.blogger.com/atom/ns#' term='Insanity'/><title type='text'>The type provided as the Service attribute value in the ServiceHost directive could not be found.</title><content type='html'>My WCF service on my dev server broke today after a build for seemingly no reason and the only thing it had to say for itself was "The type 'xxxxx', provided as the Service attribute value in the ServiceHost directive could not be found." I spent several hours permuting through the various changes I made earlier in the day trying to get the darn thing to work again until I exhausted nearly all possible combinations.&lt;br /&gt;&lt;br /&gt;Puzzled and on the brink of insanity, I decided to go into IIS and see if my Authentication settings have changed. Sure enough, my ASP.NET Impersonation that my WCF service required was somehow turned off.&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/_Xy29Qj1Kzis/SsUHcukeEmI/AAAAAAAAACs/Y57eMmIyNSc/s1600-h/Capture.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/_Xy29Qj1Kzis/SsUHcukeEmI/AAAAAAAAACs/Y57eMmIyNSc/s400/Capture.JPG" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;With the flick of a switch, everything started working again. I can only presume that the error was being caused because of a bad reference that crops up when turning off Impersonation. Sigh... If my employer only knew what I do all day...&lt;br /&gt;&lt;br /&gt;UPDATE:&lt;br /&gt;&lt;br /&gt;I turns out that my web.config was the culprit. &amp;nbsp;If impersonation is not enabled in web.config then it resets it in IIS each time you build out to the server. &amp;nbsp;This is the required code:&lt;br /&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;system.web&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;identity&lt;/span&gt; &lt;span class="attr"&gt;impersonate&lt;/span&gt;&lt;span class="kwrd"&gt;="true"&lt;/span&gt; &lt;span class="attr"&gt;userName&lt;/span&gt;&lt;span class="kwrd"&gt;=""&lt;/span&gt; &lt;span class="attr"&gt;password&lt;/span&gt;&lt;span class="kwrd"&gt;=""&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;system.web&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8691068330397730091-4629094955223337904?l=blog.jamesjones.name' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.jamesjones.name/feeds/4629094955223337904/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.jamesjones.name/2009/10/type-provided-as-service-attribute.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8691068330397730091/posts/default/4629094955223337904'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8691068330397730091/posts/default/4629094955223337904'/><link rel='alternate' type='text/html' href='http://blog.jamesjones.name/2009/10/type-provided-as-service-attribute.html' title='The type provided as the Service attribute value in the ServiceHost directive could not be found.'/><author><name>James</name><uri>http://www.blogger.com/profile/07743081202945582329</uri><email>james.russel.jones@gmail.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='14897653130005070286'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_Xy29Qj1Kzis/SsUHcukeEmI/AAAAAAAAACs/Y57eMmIyNSc/s72-c/Capture.JPG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8691068330397730091.post-1710514592183372660</id><published>2009-09-30T22:40:00.013-04:00</published><updated>2010-02-24T16:52:56.746-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='.NET'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><title type='text'>Generic Enum "Composed Of" Test</title><content type='html'>&lt;div class="separator" style="clear: both; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; text-align: left;"&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="color: red;"&gt;UPDATE&lt;/span&gt;&lt;span class="Apple-style-span" style="color: red;"&gt;:&lt;/span&gt;&lt;/b&gt; Microsoft will be offering &lt;a href="http://msdn.microsoft.com/en-us/library/system.enum.hasflag(VS.100,classic).aspx"&gt;a substitute&lt;/a&gt; for this method in .NET Framework 4, so you could say that this post is obsolete.&lt;/div&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; text-align: left;"&gt;I was working with Windows ACL permissions and I was attempting to find out whether a user had Read permissions to a file.&amp;nbsp;Permissions are represented in the form of an enum to something of this effect:&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/_Xy29Qj1Kzis/SsQSr-rCSoI/AAAAAAAAACk/D4pqYmRG7sU/s1600-h/Capture.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/_Xy29Qj1Kzis/SsQSr-rCSoI/AAAAAAAAACk/D4pqYmRG7sU/s320/Capture.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; text-align: left;"&gt;To further complicate things, Windows permissions are represented under 2 different enum classes, System.IO.FileAccess and System.Security.AccessControl.FileSystemRights. So, in order to persist these permissions to the database, I chose to also persist the respective enum class in the form of text, and then pull it back out of the database and perform Enum.Parse() on the text.&lt;/div&gt;&lt;div class="separator" style="clear: both; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; text-align: left;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: left;"&gt;Whenever a file had Modify permissions, there was no concise way of determining that this also implied the Read permission because I was dealing with the generic Enum class. As you can see, when you attempt bitwise operations on the Enum class, this is what you get:&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: left;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: left;"&gt;&lt;a href="http://1.bp.blogspot.com/_Xy29Qj1Kzis/S4GFo6mSu0I/AAAAAAAAADc/FlRKHHIf_UI/s1600-h/Capture.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="66" src="http://1.bp.blogspot.com/_Xy29Qj1Kzis/S4GFo6mSu0I/AAAAAAAAADc/FlRKHHIf_UI/s400/Capture.PNG" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: left;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: left;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: left;"&gt;&lt;b&gt;Error:&amp;nbsp;Operator '&amp;amp;' cannot be applied to operands of type 'System.Enum' and 'System.Enum'&lt;/b&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: left;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: left;"&gt;So, in order to get around this, I chose to cast the Enums to a type that I could use bitwise operations on, which lead me to generate this function:&lt;/div&gt;&lt;br /&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; EnumIsCompositeOf(Enum little, Enum big)&lt;br /&gt;{&lt;br /&gt;    &lt;span class="kwrd"&gt;if&lt;/span&gt; (!Type.Equals(little.GetType(), big.GetType()))&lt;br /&gt;        &lt;span class="kwrd"&gt;throw&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; ArgumentException(&lt;span class="str"&gt;"Enums must be of the same type."&lt;/span&gt;);&lt;br /&gt;&lt;br /&gt;    &lt;span class="kwrd"&gt;ulong&lt;/span&gt; littleVal;&lt;br /&gt;    &lt;span class="kwrd"&gt;ulong&lt;/span&gt; bigVal;&lt;br /&gt;&lt;br /&gt;    TypeCode typeCode = little.GetTypeCode();&lt;br /&gt;    &lt;span class="kwrd"&gt;switch&lt;/span&gt; (typeCode)&lt;br /&gt;    {&lt;br /&gt;        &lt;span class="kwrd"&gt;case&lt;/span&gt; TypeCode.Byte:&lt;br /&gt;        &lt;span class="kwrd"&gt;case&lt;/span&gt; TypeCode.UInt16:&lt;br /&gt;        &lt;span class="kwrd"&gt;case&lt;/span&gt; TypeCode.UInt32:&lt;br /&gt;        &lt;span class="kwrd"&gt;case&lt;/span&gt; TypeCode.UInt64:&lt;br /&gt;            littleVal = &lt;span class="kwrd"&gt;ulong&lt;/span&gt;.Parse(little.ToString(&lt;span class="str"&gt;"D"&lt;/span&gt;));&lt;br /&gt;            bigVal = &lt;span class="kwrd"&gt;ulong&lt;/span&gt;.Parse(big.ToString(&lt;span class="str"&gt;"D"&lt;/span&gt;));&lt;br /&gt;            &lt;span class="kwrd"&gt;break&lt;/span&gt;;&lt;br /&gt;        &lt;span class="kwrd"&gt;case&lt;/span&gt; TypeCode.SByte:&lt;br /&gt;        &lt;span class="kwrd"&gt;case&lt;/span&gt; TypeCode.Int16:&lt;br /&gt;        &lt;span class="kwrd"&gt;case&lt;/span&gt; TypeCode.Int32:&lt;br /&gt;        &lt;span class="kwrd"&gt;case&lt;/span&gt; TypeCode.Int64:&lt;br /&gt;            littleVal = (&lt;span class="kwrd"&gt;ulong&lt;/span&gt;)&lt;span class="kwrd"&gt;long&lt;/span&gt;.Parse(little.ToString(&lt;span class="str"&gt;"D"&lt;/span&gt;));&lt;br /&gt;            bigVal = (&lt;span class="kwrd"&gt;ulong&lt;/span&gt;)&lt;span class="kwrd"&gt;long&lt;/span&gt;.Parse(big.ToString(&lt;span class="str"&gt;"D"&lt;/span&gt;));&lt;br /&gt;            &lt;span class="kwrd"&gt;break&lt;/span&gt;;&lt;br /&gt;        &lt;span class="kwrd"&gt;default&lt;/span&gt;:&lt;br /&gt;            &lt;span class="kwrd"&gt;throw&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; ArgumentException(&lt;span class="str"&gt;"Enums are derived from an unknown type."&lt;/span&gt;);&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;span class="kwrd"&gt;ulong&lt;/span&gt; intersection = littleVal &amp;amp; bigVal;&lt;br /&gt;    &lt;span class="kwrd"&gt;return&lt;/span&gt; intersection == littleVal ? &lt;span class="kwrd"&gt;true&lt;/span&gt; : &lt;span class="kwrd"&gt;false&lt;/span&gt;;&lt;br /&gt;}&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8691068330397730091-1710514592183372660?l=blog.jamesjones.name' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.jamesjones.name/feeds/1710514592183372660/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.jamesjones.name/2009/09/generic-enum-composed-of-test.html#comment-form' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8691068330397730091/posts/default/1710514592183372660'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8691068330397730091/posts/default/1710514592183372660'/><link rel='alternate' type='text/html' href='http://blog.jamesjones.name/2009/09/generic-enum-composed-of-test.html' title='Generic Enum &quot;Composed Of&quot; Test'/><author><name>James</name><uri>http://www.blogger.com/profile/07743081202945582329</uri><email>james.russel.jones@gmail.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='14897653130005070286'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_Xy29Qj1Kzis/SsQSr-rCSoI/AAAAAAAAACk/D4pqYmRG7sU/s72-c/Capture.PNG' height='72' width='72'/><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8691068330397730091.post-107454686064044880</id><published>2009-09-12T20:12:00.012-04:00</published><updated>2010-02-24T16:51:56.275-05:00</updated><title type='text'>I guess blogs don't totally suck</title><content type='html'>&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/_Xy29Qj1Kzis/SqxX3nfzf6I/AAAAAAAAAAw/dAb8cgs_0Cs/s1600-h/blogs-none-of-us-is-as-dumb-as-all-of-us.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/_Xy29Qj1Kzis/SqxX3nfzf6I/AAAAAAAAAAw/dAb8cgs_0Cs/s400/blogs-none-of-us-is-as-dumb-as-all-of-us.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;I never thought that I would some day own a blog. &amp;nbsp;I mean, who gives a crap about what I think? &amp;nbsp;Hell, I don't even care about what I think. &amp;nbsp;In my mind, blogs were just a byproduct of babbling buffoons who ran out of humans to tolerated their rambling. &amp;nbsp;And, well, not much has changed. &amp;nbsp;But on to my point...&lt;br /&gt;&lt;br /&gt;As a software developer for a large company, I shamelessly&amp;nbsp;admit&amp;nbsp;that I "google" answers to problems probably upwards to 50 times per day. &amp;nbsp;When my employer used a web filter to block access to blogs I became handicapped. &amp;nbsp;Half of the time I tried to "google it," I was blocked. &amp;nbsp;Holy shit, my job just got a lot harder. &amp;nbsp;I suddenly realized that most of the valuable information I found online was actually &lt;i&gt;in a blog&lt;/i&gt;.&lt;br /&gt;&lt;br /&gt;From that point forward I took on a whole new stance on blogs. &amp;nbsp;Sure, 90% of blogs&amp;nbsp;are a waste of life, but my life would be a hell of a lot harder without that other 10%.&lt;br /&gt;&lt;br /&gt;I realized that I, too, possess valuable information that the rest of the world could use. &amp;nbsp;We all contain little random turds of useful knowledge that nobody else knows about - it's not necessarily stuff people want to read every day, but by posting it online you expose it to search engines and potentially billions of people. &lt;br /&gt;&lt;br /&gt;By creating this blog, I hope that I can give back to the world that has helped me so much over the years. &amp;nbsp;Here's to a blog that doesn't suck!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8691068330397730091-107454686064044880?l=blog.jamesjones.name' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.jamesjones.name/feeds/107454686064044880/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.jamesjones.name/2009/09/i-guess-blogs-dont-suck.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8691068330397730091/posts/default/107454686064044880'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8691068330397730091/posts/default/107454686064044880'/><link rel='alternate' type='text/html' href='http://blog.jamesjones.name/2009/09/i-guess-blogs-dont-suck.html' title='I guess blogs don&apos;t totally suck'/><author><name>James</name><uri>http://www.blogger.com/profile/07743081202945582329</uri><email>james.russel.jones@gmail.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='14897653130005070286'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_Xy29Qj1Kzis/SqxX3nfzf6I/AAAAAAAAAAw/dAb8cgs_0Cs/s72-c/blogs-none-of-us-is-as-dumb-as-all-of-us.jpg' height='72' width='72'/><thr:total>0</thr:total></entry></feed>