<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:blogChannel="http://backend.userland.com/blogChannelModule" xmlns:dc="http://purl.org/dc/elements/1.1/" 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:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" version="2.0">
  <channel>
    <title>Ryan Tomlinson</title>
    <description>Another opinionated developer</description>
    <link>http://www.ryantomlinson.com/</link>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <generator>BlogEngine.NET 2.0.0.36</generator>
    <language>en-US</language>
    <blogChannel:blogRoll>http://www.ryantomlinson.com/opml.axd</blogChannel:blogRoll>
    <blogChannel:blink>http://www.dotnetblogengine.net/syndication.axd</blogChannel:blink>
    <dc:creator>RyanTomlinson</dc:creator>
    <dc:title>Ryan Tomlinson</dc:title>
    <geo:lat>0.000000</geo:lat>
    <geo:long>0.000000</geo:long>
    <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/ryantomlinsonblog" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="ryantomlinsonblog" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
      <title>The best practice anti-pattern</title>
      <description>&lt;h2&gt;Follow The Leader&lt;/h2&gt;
&lt;p&gt;&lt;a href="http://www.ryantomlinson.com/image.axd?picture=followtheleader_1.jpg"&gt;&lt;img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="followtheleader" src="http://www.ryantomlinson.com/image.axd?picture=followtheleader_thumb_1.jpg" border="0" alt="followtheleader" width="314" height="288" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Software development is still in its infancy. When you consider other industries, such as manufacturing, writing software has a very short history. The word &amp;ldquo;software&amp;rdquo; was first used in print in 1958 and many of the software visionaries today are still alive. As a result we don&amp;rsquo;t have hundreds of years of research, guidelines and experience to have rigidity in our daily practices.&lt;/p&gt;
&lt;p&gt;As we learn and look to the evangelists and proposers of &lt;em&gt;best practice&lt;/em&gt; there stands the inevitability that many of us will play follow the leader and follow their gospel without forethought and questioning of WHY.&lt;/p&gt;
&lt;p&gt;Current trends, and there are many of them, such as development methodologies; TDD, BDD and DDD, practices such as unit testing and patterns e.g. inversion of control, dependency injection, repository pattern, have heavy focus at the minute and so they should. The problem comes when &lt;em&gt;best practice&lt;/em&gt; is followed and implemented without the reasoning, justification and understanding of why. In other industries early adoption is made more difficult by legislation and industry governance. That's not to say that early adoption is necessarily bad but in a rapidly changing market developers need to be aware of the pitfalls.&lt;/p&gt;
&lt;h2&gt;So what is the answer?&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Question everything. &lt;/strong&gt;Yes the repository pattern makes sense, but is it appropriate in your situation? WHY are you using it and what are the benefits? Consider the impact of alternative solutions.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Think ahead. &lt;/strong&gt;Be hype-agnostic and consider that your decision for adoption of a particular technology/framework/pattern has future impact. Consider product support in choosing a particular technology. Is this developed by a single person as a person project? Will it be dropped shortly down the line? How active is the community of support?&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Keep it simple.&lt;/strong&gt; Don't become an &lt;a href="http://www.joelonsoftware.com/articles/fog0000000018.html"&gt;architect astronaut&lt;/a&gt;. Don't spend forever architecting and adopting every pattern that is currently popular or that your &lt;a href="http://weblogs.asp.net/scottgu/"&gt;favorite Microsoft evangelist&lt;/a&gt; is touting. &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Of course there is never any guarantee. Even if a technology/framework is from a large organisation (read Microsoft) this does not mean that it is the right choice for you and it doesn't mean that it will continue to be supported.&lt;/p&gt;
&lt;p&gt;Speak to your fellow developers. Whether it be in your team, at a &lt;a href="http://www.nebytes.net/"&gt;local developer event&lt;/a&gt; or old colleagues. I find they usually throw up ideas that you haven't even considered and your products will usually be better for it.&lt;/p&gt;</description>
      <link>http://www.ryantomlinson.com/post/The-best-practice-anti-pattern.aspx</link>
      <comments>http://www.ryantomlinson.com/post/The-best-practice-anti-pattern.aspx#comment</comments>
      <guid>http://www.ryantomlinson.com/post.aspx?id=f6b45aba-7623-405f-aeae-76646117cfba</guid>
      <pubDate>Sun, 22 May 2011 06:56:00 +0900</pubDate>
      <dc:publisher>RTomlinson</dc:publisher>
      <pingback:server>http://www.ryantomlinson.com/pingback.axd</pingback:server>
      <pingback:target>http://www.ryantomlinson.com/post.aspx?id=f6b45aba-7623-405f-aeae-76646117cfba</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://www.ryantomlinson.com/trackback.axd?id=f6b45aba-7623-405f-aeae-76646117cfba</trackback:ping>
      <wfw:comment>http://www.ryantomlinson.com/post/The-best-practice-anti-pattern.aspx#comment</wfw:comment>
      <wfw:commentRss>http://www.ryantomlinson.com/syndication.axd?post=f6b45aba-7623-405f-aeae-76646117cfba</wfw:commentRss>
    </item>
    <item>
      <title>WP7 Tip #1: From TheNounProject to WP7 made simple.</title>
      <description>&lt;p&gt;This is the first in the series of WP7 tips that I picked up whilst developing StackO for Windows Phone 7. I have to say, that I am no Silverlight (or WP7) expert and there may be better ways to do certain things from what I write about in these posts, and if there are then I&amp;rsquo;d love to here them, so please leave comments. Hopefully, some of these tips will help you along a little quicker in getting your apps to market.&lt;/p&gt;
&lt;p&gt;The &lt;a href="http://TheNounProject.com"&gt;TheNounProject.com&lt;/a&gt; is an absolutely excellent resource for iconography. Their mission is to:&lt;/p&gt;
&lt;blockquote&gt;
&lt;h5&gt;"sharing, celebrating and enhancing the world's visual language".&lt;/h5&gt;
&lt;/blockquote&gt;
&lt;p&gt;There are over 500 icons there that fit perfectly with the metro style that the WP7 adopts providing visual metaphors to use throughout your application, absolutely free.&lt;/p&gt;
&lt;p&gt;These icons are downloaded as SVG&amp;rsquo;s and the WP7 ApplicationBar will only accept PNG images. In addition, you will most probably want these images to be themable.&lt;/p&gt;
&lt;p&gt;WP7 theming is pretty clever. If you use a PNG icon that has a transparent background and the image itself is completely white. Then if the dark theme is used your image will remain white, however, if you switch to the light theme then the image is changed automatically to black. This tutorial details the steps to take the SVG&amp;rsquo;s from TheNounProject and convert them to theme aware icons for WP7.&lt;/p&gt;
&lt;p&gt;Firstly, choose an appropriate image. For StackO, I used the &amp;ldquo;Eye&amp;rdquo; icon. &lt;a href="http://www.ryantomlinson.com/image.axd?picture=blackeye.png"&gt;&lt;img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="blackeye" src="http://www.ryantomlinson.com/image.axd?picture=blackeye_thumb.png" border="0" alt="blackeye" width="46" height="27" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Download the icon to somewhere local on your machine.&lt;/p&gt;
&lt;p&gt;Next you need to download and install &lt;a href="http://www.imagemagick.org/"&gt;ImageMagick&lt;/a&gt;. Again, there might be other ways to do this but this was the first solution I found.&lt;/p&gt;
&lt;p&gt;Open up a Command Prompt and navigate to the location of your SVG you downloaded. We are going to use the convert tool from ImageMagick to do the conversion, set the background to transparent, fill the image with white and resize it to 48px (the recommended image size for ApplicationIcons).&lt;/p&gt;
&lt;p&gt;Use the following command:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;convert -background none -fill white -resize 48 noun_project_388_1.svg whiteeye_42.png&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;a href="http://www.ryantomlinson.com/image.axd?picture=image.png"&gt;&lt;img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://www.ryantomlinson.com/image.axd?picture=image_thumb.png" border="0" alt="image" width="604" height="287" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The output is exactly what we want.&lt;a href="http://www.ryantomlinson.com/image.axd?picture=eye_white_42.png"&gt;&lt;img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="eye_white_42" src="http://www.ryantomlinson.com/image.axd?picture=eye_white_42_thumb.png" border="0" alt="eye_white_42" width="46" height="27" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Try it out. Add it to your project and set the IconUrl to the PNG. Now if you go into your WP7 Settings and change the theme from dark to light you will see that the icon is changed for you. Brilliant!&lt;/p&gt;</description>
      <link>http://www.ryantomlinson.com/post/WP7-Tip-1-From-TheNounProject-to-WP7-made-simple.aspx</link>
      <comments>http://www.ryantomlinson.com/post/WP7-Tip-1-From-TheNounProject-to-WP7-made-simple.aspx#comment</comments>
      <guid>http://www.ryantomlinson.com/post.aspx?id=3cf14d9b-635f-484d-909c-9a6395e1eea6</guid>
      <pubDate>Tue, 22 Feb 2011 22:26:00 +0900</pubDate>
      <category>Articles</category>
      <category>Tutorials</category>
      <dc:publisher>RTomlinson</dc:publisher>
      <pingback:server>http://www.ryantomlinson.com/pingback.axd</pingback:server>
      <pingback:target>http://www.ryantomlinson.com/post.aspx?id=3cf14d9b-635f-484d-909c-9a6395e1eea6</pingback:target>
      <slash:comments>1</slash:comments>
      <trackback:ping>http://www.ryantomlinson.com/trackback.axd?id=3cf14d9b-635f-484d-909c-9a6395e1eea6</trackback:ping>
      <wfw:comment>http://www.ryantomlinson.com/post/WP7-Tip-1-From-TheNounProject-to-WP7-made-simple.aspx#comment</wfw:comment>
      <wfw:commentRss>http://www.ryantomlinson.com/syndication.axd?post=3cf14d9b-635f-484d-909c-9a6395e1eea6</wfw:commentRss>
    </item>
    <item>
      <title>StackO: My First Windows Phone 7 App</title>
      <description>&lt;blockquote&gt;
&lt;h2&gt;&lt;br /&gt;UPDATE: For support and feedback go to &lt;a href="http://stacko.uservoice.com"&gt;http://stacko.uservoice.com&lt;/a&gt;&lt;/h2&gt;
&lt;/blockquote&gt;
&lt;h2&gt;&lt;br /&gt;Background to the app&lt;/h2&gt;
&lt;p&gt;I started, about a week ago, messing around with Silverlight for Windows Phone 7, having no experience with Silverlight what-so-ever. After having my HTC HD7 for almost a month now I wanted a project to start on that would give me exposure to the WP7 platform. The reason for this is twofold. Firstly, the mobile development market is absolutely flying at the minute (not surprising given that the mobile market has already taken over the PC market in sales) and I don&amp;rsquo;t want to be left behind, having spent the last 4 years developing for the web. Secondly, my main focus this year is on new learning. Not that I&amp;rsquo;m not learning constantly, as developers do pretty much every day, but learning outside my remit at work and away from the web.&lt;/p&gt;
&lt;p&gt;I spend a lot of time on the &lt;a href="http://stackexchange.com/"&gt;StackExchange&lt;/a&gt; family of sites and &lt;a href="http://stackoverflow.com/"&gt;StackOveflow&lt;/a&gt; in particular. I even browsed the &lt;a href="http://stackoverflow.com/"&gt;Stackoverflow&lt;/a&gt; site for common issues and requests to come up with an idea. After a little research I realised that &lt;a href="http://stackoverflow.com/"&gt;Stackoverflow&lt;/a&gt; itself had an API and so did the other &lt;a href="http://stackexchange.com/"&gt;StackExchange&lt;/a&gt; family of sites. Then I came across a &lt;a href="http://stackapps.com/questions/1676/stackoverflow-as-an-app-on-windows-mobile-6-5-and-windows-phone-7"&gt;post by lfoust&lt;/a&gt; showing some screenshots of a mockup for a &lt;a href="http://stackexchange.com/"&gt;StackExchange&lt;/a&gt; client for WP7 and discovered that he had actually implemented a superb &lt;a href="http://stacky.codeplex.com/"&gt;C# API wrapper&lt;/a&gt; for &lt;a href="http://stackexchange.com/"&gt;StackExchange&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;I set out developing an app using the mockups displayed on this post.&lt;/p&gt;
&lt;h2&gt;What does it do?&lt;/h2&gt;
&lt;p&gt;The apps main features are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Browse latest &lt;strong&gt;Voted&lt;/strong&gt;, &lt;strong&gt;Featured&lt;/strong&gt; and &lt;strong&gt;Hot&lt;/strong&gt; questions &lt;/li&gt;
&lt;li&gt;Browse top users by &lt;strong&gt;Reputation&lt;/strong&gt; and &lt;strong&gt;Latest &lt;/strong&gt;users &lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Search &lt;/strong&gt;for &lt;strong&gt;Questions&lt;/strong&gt; &lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Search &lt;/strong&gt;for &lt;strong&gt;Users&lt;/strong&gt; &lt;/li&gt;
&lt;li&gt;View questions and answers, including associated tags and view, vote and score counts. &lt;/li&gt;
&lt;li&gt;View user information and achievements &lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;span style="font-size: small;"&gt;Watch questions and add/remove them from your watched list&lt;/span&gt;&lt;/strong&gt; &lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;What does it look like?&lt;/h2&gt;
&lt;p&gt;&lt;a href="http://www.ryantomlinson.com/image.axd?picture=StackO-Home.png"&gt;&lt;img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="StackO-Home" src="http://www.ryantomlinson.com/image.axd?picture=StackO-Home_thumb.png" border="0" alt="StackO-Home" width="212" height="350" /&gt;&lt;/a&gt;&lt;a href="http://www.ryantomlinson.com/image.axd?picture=StackO-Browser.png"&gt;&lt;img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="StackO-Browser" src="http://www.ryantomlinson.com/image.axd?picture=StackO-Browser_thumb.png" border="0" alt="StackO-Browser" width="208" height="344" /&gt;&lt;/a&gt;&lt;a href="http://www.ryantomlinson.com/image.axd?picture=StackO-Questions.png"&gt;&lt;img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="StackO-Questions" src="http://www.ryantomlinson.com/image.axd?picture=StackO-Questions_thumb.png" border="0" alt="StackO-Questions" width="210" height="347" /&gt;&lt;/a&gt;&lt;a href="http://www.ryantomlinson.com/image.axd?picture=StackO-QuestionItem.png"&gt;&lt;img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="StackO-QuestionItem" src="http://www.ryantomlinson.com/image.axd?picture=StackO-QuestionItem_thumb.png" border="0" alt="StackO-QuestionItem" width="210" height="348" /&gt;&lt;/a&gt;&lt;a href="http://www.ryantomlinson.com/image.axd?picture=StackO-Users.png"&gt;&lt;img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="StackO-Users" src="http://www.ryantomlinson.com/image.axd?picture=StackO-Users_thumb.png" border="0" alt="StackO-Users" width="210" height="347" /&gt;&lt;/a&gt;&lt;a href="http://www.ryantomlinson.com/image.axd?picture=StackO-UserInfo.png"&gt;&lt;img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="StackO-UserInfo" src="http://www.ryantomlinson.com/image.axd?picture=StackO-UserInfo_thumb.png" border="0" alt="StackO-UserInfo" width="209" height="346" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;What I learned?&lt;/h2&gt;
&lt;p&gt;The learning curve for this project was quite steep, having originally only limited exposure to Silverlight and the Windows Mobile 7 platform in particular. A lot went into the development of this app and below is a summary of the main learning outcomes:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The WP7 ecosystem: Windows Mobile 7 is a superb platform to develop on and Microsoft have done a great job in supplying some exceptional tools to develop with. That said there are a lot of controls missing and a lot of things that I don&amp;rsquo;t like. One example in particular is the WP7 Marketplace is still not great when it comes to categorizing apps and searching them. That said, people have to remember that it is still very early days for WP7 and Microsoft have a lot of resource going into improving it. Things will improve and these days Mircrosoft are getting really good at listening to consumer feedback and community driven development. &lt;/li&gt;
&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Model_View_ViewModel"&gt;MVVM&lt;/a&gt;: As with any new development it is very easy to just want to &amp;ldquo;knock something up&amp;rdquo;. I spent a lot of time doing the research so that I didn&amp;rsquo;t just do that. That mind set usually results in huge problems and a monolothic application. Separation of concerns and reducing coupling is very important and in doing so the results are a more solid app.       &lt;br /&gt;If you&amp;rsquo;re going to do any Silvelight/WPF development you need to have a good understanding of &lt;a href="http://en.wikipedia.org/wiki/Model_View_ViewModel"&gt;MVVM&lt;/a&gt;. There are frameworks out there such as &lt;a href="http://mvvmlight.codeplex.com/"&gt;MVVM Light&lt;/a&gt; but I decided to go with a simple implementation without the help of an &lt;a href="http://en.wikipedia.org/wiki/Model_View_ViewModel"&gt;MVVM&lt;/a&gt; framework. The cons of this (to which I found out) is that I had to do a lot of the wiring up myself, that I&amp;rsquo;m sure the framework would have provided me. &lt;/li&gt;
&lt;li&gt;Databinding: The databinding model in Silverlight is immense. It&amp;rsquo;s very powerful and works great with MVVM. Once you master databinding you will understand the benefits of &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.data.ivalueconverter.aspx"&gt;IValueConverter&lt;/a&gt; and the ability to manipulate data whilst databinding to your controls. &lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;StackO (the very well-thought out name &lt;img class="wlEmoticon wlEmoticon-smile" style="border-style: none;" src="http://www.ryantomlinson.com/image.axd?picture=wlEmoticon-smile.png" alt="Smile" /&gt;) is far from complete. There are lots of features I would like to continue to develop and improve. I want a lot of that to come from the community. I intentionally left out a lot of features in the hope that they will be requested. If you have a Windows Phone 7 device I would really appreciate you downloading it and giving it a go and providing any feedback you can (good or bad). It&amp;rsquo;s &lt;strong&gt;&lt;span style="font-size: large;"&gt;completely FREE!&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;</description>
      <link>http://www.ryantomlinson.com/post/StackO-My-First-Windows-Phone-7-App.aspx</link>
      <comments>http://www.ryantomlinson.com/post/StackO-My-First-Windows-Phone-7-App.aspx#comment</comments>
      <guid>http://www.ryantomlinson.com/post.aspx?id=93562063-6cd9-4199-8ec0-d6e1c2785ab5</guid>
      <pubDate>Sun, 20 Feb 2011 02:55:00 +0900</pubDate>
      <category>Articles</category>
      <dc:publisher>RTomlinson</dc:publisher>
      <pingback:server>http://www.ryantomlinson.com/pingback.axd</pingback:server>
      <pingback:target>http://www.ryantomlinson.com/post.aspx?id=93562063-6cd9-4199-8ec0-d6e1c2785ab5</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://www.ryantomlinson.com/trackback.axd?id=93562063-6cd9-4199-8ec0-d6e1c2785ab5</trackback:ping>
      <wfw:comment>http://www.ryantomlinson.com/post/StackO-My-First-Windows-Phone-7-App.aspx#comment</wfw:comment>
      <wfw:commentRss>http://www.ryantomlinson.com/syndication.axd?post=93562063-6cd9-4199-8ec0-d6e1c2785ab5</wfw:commentRss>
    </item>
    <item>
      <title>Silverlight: Databinding visibility property to boolean</title>
      <description>&lt;p&gt;Very simple one here, but one that may not seem completely obvious to those new to &lt;a href="http://www.silverlight.net/"&gt;Silverlight&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;The Scenario&lt;/h2&gt;
&lt;p&gt;A very common scenario in &lt;a href="http://www.silverlight.net/"&gt;Silverlight &lt;/a&gt;is to databing the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.visibility.aspx"&gt;visibility &lt;/a&gt;of a control to a boolean value in your code. At first you may think you can just do inline binding as normal:&lt;/p&gt;
&lt;p&gt;&amp;lt;Image Source="AnImage.png" Visibility="{Binding Accepted}" /&amp;gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.ryantomlinson.com/image.axd?picture=2011%2f2%2fquestion_answer.png" alt="" /&gt;&lt;/p&gt;
&lt;p&gt;Today I was trying to do similar with a new project I'm working on. A StackExchange (&lt;a href="http://stackoverflow.com/"&gt;StackOverflow&lt;/a&gt; family of sites) application for Windows Phone 7 that brings the popular family of sites to the mobile. In particular I was trying to indicate which answer in particular was the correct one. To do this I used the Image control (as above) to display a green tick icon, similar to that on the &lt;a href="http://stackoverflow.com/"&gt;StackOverflow website&lt;/a&gt; and bind the Accepted property to controls it's visibility.&lt;/p&gt;
&lt;h2&gt;The Solution&lt;br /&gt;&lt;/h2&gt;
&lt;p&gt;Unfortunately the visibility property is of type &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.visibility.aspx"&gt;System.Windows.Visibility&lt;/a&gt;. Therefore we need to implement IValueConverter to take our boolean property and convert that to System.Windows.Visibility. You can then add this &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.data.ivalueconverter.aspx"&gt;IValueConverter &lt;/a&gt;implementation to your XAML as a resource and specify the converter as a part of the binding process in your XAML.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt; &lt;!-- .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; } --&gt;&lt;/p&gt;
&lt;div class="csharpcode"&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; VisibilityConverter : IValueConverter&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;    {&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;object&lt;/span&gt; Convert(&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;            &lt;span class="kwrd"&gt;object&lt;/span&gt; &lt;span class="kwrd"&gt;value&lt;/span&gt;,&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;            Type targetType,&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;            &lt;span class="kwrd"&gt;object&lt;/span&gt; parameter,&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;            CultureInfo culture)&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;        {&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt;            &lt;span class="kwrd"&gt;bool&lt;/span&gt; visibility = (&lt;span class="kwrd"&gt;bool&lt;/span&gt;)&lt;span class="kwrd"&gt;value&lt;/span&gt;;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  10:  &lt;/span&gt;            &lt;span class="kwrd"&gt;return&lt;/span&gt; visibility ? Visibility.Visible : Visibility.Collapsed;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  11:  &lt;/span&gt;        }&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  12:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  13:  &lt;/span&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;object&lt;/span&gt; ConvertBack(&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  14:  &lt;/span&gt;            &lt;span class="kwrd"&gt;object&lt;/span&gt; &lt;span class="kwrd"&gt;value&lt;/span&gt;,&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  15:  &lt;/span&gt;            Type targetType,&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  16:  &lt;/span&gt;            &lt;span class="kwrd"&gt;object&lt;/span&gt; parameter,&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  17:  &lt;/span&gt;            CultureInfo culture)&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  18:  &lt;/span&gt;        {&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  19:  &lt;/span&gt;            Visibility visibility = (Visibility)&lt;span class="kwrd"&gt;value&lt;/span&gt;;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  20:  &lt;/span&gt;            &lt;span class="kwrd"&gt;return&lt;/span&gt; (visibility == Visibility.Visible);&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  21:  &lt;/span&gt;        }&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  22:  &lt;/span&gt;    }&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;And the XAML:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt; &lt;!-- .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; } --&gt;&lt;/p&gt;
&lt;div class="csharpcode"&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&amp;lt;helpers:VisibilityConverter x:Key=&lt;span class="str"&gt;"VisibilityConverter"&lt;/span&gt;&amp;gt;&amp;lt;/helpers:VisibilityConverter&amp;gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt; &lt;!-- .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; } --&gt;&lt;/p&gt;
&lt;div class="csharpcode"&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&amp;lt;Image Source=&lt;span class="str"&gt;"/Images/Icons/correct_answer.png"&lt;/span&gt; Visibility=&lt;span class="str"&gt;"{Binding Accepted, Converter={StaticResource VisibilityConverter}}"&lt;/span&gt;&amp;gt;&amp;lt;/Image&amp;gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Again it may seem a little obvious but I hope this comes in handy for those new to Silverlight databinding.&lt;/p&gt;</description>
      <link>http://www.ryantomlinson.com/post/Silverlight-Databinding-visibility-property-to-boolean.aspx</link>
      <comments>http://www.ryantomlinson.com/post/Silverlight-Databinding-visibility-property-to-boolean.aspx#comment</comments>
      <guid>http://www.ryantomlinson.com/post.aspx?id=52057914-9666-4d7d-ba14-2572a7b6e5ea</guid>
      <pubDate>Fri, 11 Feb 2011 23:02:00 +0900</pubDate>
      <category>Articles</category>
      <category>Tutorials</category>
      <dc:publisher>RTomlinson</dc:publisher>
      <pingback:server>http://www.ryantomlinson.com/pingback.axd</pingback:server>
      <pingback:target>http://www.ryantomlinson.com/post.aspx?id=52057914-9666-4d7d-ba14-2572a7b6e5ea</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://www.ryantomlinson.com/trackback.axd?id=52057914-9666-4d7d-ba14-2572a7b6e5ea</trackback:ping>
      <wfw:comment>http://www.ryantomlinson.com/post/Silverlight-Databinding-visibility-property-to-boolean.aspx#comment</wfw:comment>
      <wfw:commentRss>http://www.ryantomlinson.com/syndication.axd?post=52057914-9666-4d7d-ba14-2572a7b6e5ea</wfw:commentRss>
    </item>
    <item>
      <title>An introduction to Code Contracts in .NET 4.0</title>
      <description>&lt;p&gt;.NET 4.0 sees the introduction of &lt;a href="http://msdn.microsoft.com/en-us/devlabs/dd491992.aspx"&gt;Code Contracts&lt;/a&gt;. Code Contracts allow the developer to specify rules and &lt;em&gt;"assumptions on your code in the form of pre-conditions, post-conditions and object invariants"&lt;/em&gt; (in the words of &lt;a href="http://msdn.microsoft.com/en-us/devlabs/default.aspx"&gt;DevLabs&lt;/a&gt;). What this means in real terms is that we are able to apply contractual rules to methods or properties where typically we would have applied other input sanitizing methods.&lt;/p&gt;
&lt;p&gt;Take, for example, an SMS messaging application where we have a dispatching service class. This class is responsible for sending out messages and contains a single &lt;em&gt;Send &lt;/em&gt;method. A pre-condition to this method may be that the message length can only be 140 characters (as is typically the case). Code Contracts allows us to design our object and specify this contract as a condition to the method.&lt;/p&gt;
&lt;p&gt;There are three ways to utilise this feature.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Runtime Code Checking - Your code will be modified with the contracts at runtime and allows for runtime results.&lt;/li&gt;
&lt;li&gt;Static Code Analysis - A static checker that can check broken conditions and violations.&lt;/li&gt;
&lt;li&gt;Document Generation - Although I haven't used this facility, it is able to generate XML documentation.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;I start by creating an interface for my message dispatcher that contains my single Send method.&lt;/p&gt;
&lt;p&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt; &lt;!-- .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; } --&gt;&lt;/p&gt;
&lt;div class="csharpcode"&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Diagnostics.Contracts;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;&lt;span class="kwrd"&gt;namespace&lt;/span&gt; CodeContractsFirstLook.Contracts&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;{&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;    [ContractClass(&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(MessageDispatcherServiceContract))]&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;interface&lt;/span&gt; IMessageDispatcherService&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;    {&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;        &lt;span class="kwrd"&gt;bool&lt;/span&gt; Send(IMessage message);&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt;    }&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  10:  &lt;/span&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;As you can see this dispatcher service interface is attributed with the &lt;strong&gt;ConcreteClass&lt;/strong&gt; attribute that is part of the &lt;strong&gt;System.Diagnostics.Contracts&lt;/strong&gt; namespace. This tells the checker which contract class applies to the concrete class that implements this interface. Let's see what the contract class (&lt;strong&gt;MessageDispatcherServiceContract&lt;/strong&gt;) looks like:&lt;/p&gt;
&lt;p&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt; &lt;!-- .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; } --&gt;&lt;/p&gt;
&lt;div class="csharpcode"&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Diagnostics.Contracts;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;&lt;span class="kwrd"&gt;namespace&lt;/span&gt; CodeContractsFirstLook.Contracts&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;{&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;    [ContractClassFor(&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(IMessageDispatcherService))]&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;sealed&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; MessageDispatcherServiceContract : IMessageDispatcherService&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;    {&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;        &lt;span class="kwrd"&gt;bool&lt;/span&gt; IMessageDispatcherService.Send(IMessage message)&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt;        {&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  10:  &lt;/span&gt;            Contract.Requires(message.messageBody.Length &amp;lt; 140);&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  11:  &lt;/span&gt;            &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;default&lt;/span&gt;(&lt;span class="kwrd"&gt;bool&lt;/span&gt;);&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  12:  &lt;/span&gt;        }&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  13:  &lt;/span&gt;    }&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  14:  &lt;/span&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Here the contract is specified on line 10. What we are saying here is that whenever a class implements the &lt;strong&gt;IMessageDispatcherService&lt;/strong&gt; interface and the &lt;strong&gt;Send&lt;/strong&gt; method is called we are going to evaluate the &lt;strong&gt;Requires&lt;/strong&gt; method as a pre-condition to the method. In this case the condition is that the message body is less than 140 characters in length.&lt;/p&gt;
&lt;p&gt;By default we must return something where the method siganture has a return type, otherwise our code won't compile. Here, I use the &lt;strong&gt;default&lt;/strong&gt; keyword to return the default for the type bool.&lt;/p&gt;
&lt;p&gt;Now let's take a look at the actual &lt;strong&gt;MessageDispatcherService&lt;/strong&gt; that implements the &lt;strong&gt;IMessageDispatcherService &lt;/strong&gt;interface and therefore will execute our interface contract:&lt;/p&gt;
&lt;p&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt; &lt;!-- .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; } --&gt;&lt;/p&gt;
&lt;div class="csharpcode"&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; CodeContractsFirstLook.Contracts;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;&lt;span class="kwrd"&gt;namespace&lt;/span&gt; CodeContractsFirstLook&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;{&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; MessageDispatcherService : IMessageDispatcherService&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;    {&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; Send(IMessage message)&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;        {&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt;            &lt;span class="rem"&gt;// It doesn't matter what we do here&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  10:  &lt;/span&gt;            &lt;span class="rem"&gt;// Our Contracts will be executed&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  11:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  12:  &lt;/span&gt;            &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;true&lt;/span&gt;;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  13:  &lt;/span&gt;        }&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  14:  &lt;/span&gt;    }&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  15:  &lt;/span&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;As our interface has a contract associated with it, whenever the method above is executed our contract code will execute to evaluate the message body length. We can test this code works with a simple console application.&lt;/p&gt;
&lt;p&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt; &lt;!-- .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; } --&gt;&lt;/p&gt;
&lt;div class="csharpcode"&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; CodeContractsFirstLook.Messaging;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; CodeContractsFirstLook;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;&lt;span class="kwrd"&gt;namespace&lt;/span&gt; ConsoleApplication1&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;{&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;    &lt;span class="kwrd"&gt;class&lt;/span&gt; Program&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;    {&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt;        &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Main(&lt;span class="kwrd"&gt;string&lt;/span&gt;[] args)&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  10:  &lt;/span&gt;        {&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  11:  &lt;/span&gt;            var message = &lt;span class="kwrd"&gt;new&lt;/span&gt; SmsMessage();&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  12:  &lt;/span&gt;            var messageDispatcher = &lt;span class="kwrd"&gt;new&lt;/span&gt; MessageDispatcherService();&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  13:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  14:  &lt;/span&gt;            message.messageBody = &lt;span class="str"&gt;"This will certainly pass"&lt;/span&gt;;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  15:  &lt;/span&gt;            Console.WriteLine(&lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(&lt;span class="str"&gt;"Was message dispatching successful? {0} "&lt;/span&gt;, &lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  16:  &lt;/span&gt;                messageDispatcher.Send(message)));&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  17:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  18:  &lt;/span&gt;            message.messageBody = &lt;span class="str"&gt;"A very long message that surely must be over one hundred and forty characters by now...surely! Let me copy and paste into word to do a character count....a yes....we're good!"&lt;/span&gt;;         &lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  19:  &lt;/span&gt;            Console.WriteLine(&lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(&lt;span class="str"&gt;"Was message dispatching successful? {0} "&lt;/span&gt;, &lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  20:  &lt;/span&gt;                messageDispatcher.Send(message)));&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  21:  &lt;/span&gt;        }&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  22:  &lt;/span&gt;    }&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  23:  &lt;/span&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;h2&gt;Conclusion&lt;br /&gt;&lt;/h2&gt;
&lt;p&gt;In this post I've covered a very simplified overview of Code Contracts and a basic introduction as to how you can use the .NET 4.0 &lt;strong&gt;System.Diagnostics.Contracts&lt;/strong&gt; to specify pre-conditions on methods, specifically using interface contracts.&lt;/p&gt;
&lt;p&gt;This is very much the tip of the iceberg when it comes to the subject of Code Contracts.&lt;/p&gt;
&lt;p&gt;One of the biggest benefits is the ability to ensure loose coupling of contracts from class code through interface contracts and the "Design-By-Contract" pattern seems a much neater implementation than the normal input sanitization/exception throwing mechanism that we typically deal with day-to-day.&lt;/p&gt;
&lt;h2&gt;What you need to get started&lt;/h2&gt;
&lt;p&gt;To get started you will need to &lt;a href="http://msdn.microsoft.com/en-us/devlabs/dd491992.aspx"&gt;download the Code Contracts project from DevLabs&lt;/a&gt;. This will add a "Code Contracts" panel to your projects &lt;strong&gt;properties&lt;/strong&gt; (right-click on your project in Visual Studio and go to Properties). In order to perform runtime checks you will need to select the "Perform Runtime Contract Checking" option (see below):&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.ryantomlinson.com/image.axd?picture=2010%2f8%2fCodeContracts-blog.png" alt="" /&gt;&lt;/p&gt;
&lt;h2&gt;Want to know more?&lt;/h2&gt;
&lt;p&gt;&lt;a href="http://www.developer.com/net/article.php/3836626/Understanding-and-Benefiting-from-Code-Contracts-in-NET-40.htm"&gt;http://www.developer.com/net/article.php/3836626/Understanding-and-Benefiting-from-Code-Contracts-in-NET-40.htm&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.cauldwell.net/patrick/blog/CodeContracts.aspx"&gt;http://www.cauldwell.net/patrick/blog/CodeContracts.aspx&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/b/bclteam/archive/2008/11/11/introduction-to-code-contracts-melitta-andersen.aspx"&gt;http://blogs.msdn.com/b/bclteam/archive/2008/11/11/introduction-to-code-contracts-melitta-andersen.aspx&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://msdn.microsoft.com/en-us/devlabs/dd491992.aspx"&gt;http://msdn.microsoft.com/en-us/devlabs/dd491992.aspx&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Download my solution code sample:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.ryantomlinson.com/file.axd?file=2010%2f8%2fCodeContractsFirstLook.zip"&gt;CodeContractsFirstLook.zip (66.36 kb)&lt;/a&gt;&lt;/p&gt;</description>
      <link>http://www.ryantomlinson.com/post/An-introduction-to-Code-Contracts-in-NET-40.aspx</link>
      <comments>http://www.ryantomlinson.com/post/An-introduction-to-Code-Contracts-in-NET-40.aspx#comment</comments>
      <guid>http://www.ryantomlinson.com/post.aspx?id=822dda64-2d2e-47b7-874d-ab0fa17f7c69</guid>
      <pubDate>Thu, 19 Aug 2010 20:49:00 +0900</pubDate>
      <category>Articles</category>
      <category>Labs</category>
      <dc:publisher>RTomlinson</dc:publisher>
      <pingback:server>http://www.ryantomlinson.com/pingback.axd</pingback:server>
      <pingback:target>http://www.ryantomlinson.com/post.aspx?id=822dda64-2d2e-47b7-874d-ab0fa17f7c69</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://www.ryantomlinson.com/trackback.axd?id=822dda64-2d2e-47b7-874d-ab0fa17f7c69</trackback:ping>
      <wfw:comment>http://www.ryantomlinson.com/post/An-introduction-to-Code-Contracts-in-NET-40.aspx#comment</wfw:comment>
      <wfw:commentRss>http://www.ryantomlinson.com/syndication.axd?post=822dda64-2d2e-47b7-874d-ab0fa17f7c69</wfw:commentRss>
    </item>
    <item>
      <title>Notify your customers of your product updates!</title>
      <description>&lt;p&gt;Every web app business should have a continual process of marketing their product. As with agile software development, digital marketing should be a iterative process to find out what is and isn't working and the same goes for user experience design. Your customers are using your products for a reason. Whether they like  using them is a different matter altogether, but they are using them. Continual improvement, however, can only happen if you listen to the feedback from your customers.&lt;/p&gt;
&lt;p&gt;Too many web app companies simply make an internal decision and release products/features before moving on to the next new feature and take it that not hearing a word about their new features can only mean that "it hasn't broken yet".&lt;/p&gt;
&lt;h1&gt;Be proactive and preemptive&lt;br /&gt;&lt;/h1&gt;
&lt;p&gt;Customers that are using your web apps, whether manager or not, will eventually lose interest if they aren't engaged or more importantly are hindered.&lt;/p&gt;
&lt;p&gt;Make sure that they are aware of new features. Get their feedback and get it early. Make sure they know what is coming before it arrives. Provide screen shots, video walk throughs and help site documentation so that they aren't left stranded on the inevitable release.&lt;/p&gt;
&lt;p&gt;We provide maintenance release notifications in our web app for every release cycle. This is a simple lightbox notification message that informs the user of the forthcoming release and what to expect with regards to new features/products. Once the user has seen the notification when they log in, they are no longer informed of the message and therefore is unobtrusive for the user.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://www.ryantomlinson.com/image.axd?picture=2010%2f7%2fMaintenanceRelease-4.2.1.3-trim.png" alt="" /&gt;&lt;/p&gt;</description>
      <link>http://www.ryantomlinson.com/post/Notify-your-customers-of-your-product-updates!.aspx</link>
      <comments>http://www.ryantomlinson.com/post/Notify-your-customers-of-your-product-updates!.aspx#comment</comments>
      <guid>http://www.ryantomlinson.com/post.aspx?id=741cd21c-a7e6-4290-98cd-b1d8b7946647</guid>
      <pubDate>Wed, 21 Jul 2010 00:19:00 +0900</pubDate>
      <category>Articles</category>
      <dc:publisher>RTomlinson</dc:publisher>
      <pingback:server>http://www.ryantomlinson.com/pingback.axd</pingback:server>
      <pingback:target>http://www.ryantomlinson.com/post.aspx?id=741cd21c-a7e6-4290-98cd-b1d8b7946647</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://www.ryantomlinson.com/trackback.axd?id=741cd21c-a7e6-4290-98cd-b1d8b7946647</trackback:ping>
      <wfw:comment>http://www.ryantomlinson.com/post/Notify-your-customers-of-your-product-updates!.aspx#comment</wfw:comment>
      <wfw:commentRss>http://www.ryantomlinson.com/syndication.axd?post=741cd21c-a7e6-4290-98cd-b1d8b7946647</wfw:commentRss>
    </item>
    <item>
      <title>True data paging the Telerik RadGrid</title>
      <description>&lt;p&gt;The &lt;a href="http://www.telerik.com/"&gt;Telerik&lt;/a&gt; RadGrid is a great grid component for .NET developers and I can't recommend it, or the rest of the ASP.NET controls from Telerik, highly enough. The control has a vast amount of options, from drag and drop columns, filtering, templating and hierarchical databinding. Go and check out the demo's on their &lt;a href="http://demos.telerik.com/aspnet-ajax/grid/examples/overview/defaultcs.aspx"&gt;demo website&lt;/a&gt;. This post will cover setting up the data access for true data paging as well as hooking into the appropriate server side events&lt;/p&gt;
&lt;p&gt;The grid can handle 300,000 rows with in-memory databinding, according to the Telerik website. When you potentially reach this upper limit and beyond you want to look at true data paging of results SQL Server side, which is made even more easier in SQL Server 2005 and later using Common Table Expressions. This is the most efficient way of data paging within SQL by supplying a page number and a page size to work out the record set to retrieve, improving website response time and saving memory allocation. See an example below:&lt;/p&gt;
&lt;p&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;CREATE&lt;/span&gt; &lt;span class="kwrd"&gt;PROCEDURE&lt;/span&gt; [dbo].[Web_Accounts_Get]
    @CompanyID &lt;span class="kwrd"&gt;int&lt;/span&gt;,
    @PageSize &lt;span class="kwrd"&gt;int&lt;/span&gt; = 10,
    @PageNumber &lt;span class="kwrd"&gt;int&lt;/span&gt; = 1
&lt;span class="kwrd"&gt;AS&lt;/span&gt;
&lt;span class="kwrd"&gt;BEGIN&lt;/span&gt;
    &lt;span class="kwrd"&gt;SET&lt;/span&gt; NOCOUNT &lt;span class="kwrd"&gt;ON&lt;/span&gt;;

    &lt;span class="kwrd"&gt;DECLARE&lt;/span&gt; @PageRecordStart &lt;span class="kwrd"&gt;INT&lt;/span&gt;
    &lt;span class="kwrd"&gt;DECLARE&lt;/span&gt; @PageRecordEnd &lt;span class="kwrd"&gt;INT&lt;/span&gt;

    &lt;span class="kwrd"&gt;SET&lt;/span&gt; @PageRecordStart = ((@PageNumber - 1 ) * @PageSize) + 1
    &lt;span class="kwrd"&gt;SET&lt;/span&gt; @PageRecordEnd = @PageNumber * @PageSize 


    ;&lt;span class="kwrd"&gt;WITH&lt;/span&gt; Accounts_Page &lt;span class="kwrd"&gt;AS&lt;/span&gt;
    (
        &lt;span class="kwrd"&gt;SELECT&lt;/span&gt; Row_Number() &lt;span class="kwrd"&gt;OVER&lt;/span&gt; (&lt;span class="kwrd"&gt;ORDER&lt;/span&gt; &lt;span class="kwrd"&gt;BY&lt;/span&gt; [AccountName]) &lt;span class="kwrd"&gt;AS&lt;/span&gt; RowNo
            ,[Id]
          ,[CompanyID]
          ,[AccountID]
          ,[AccountName]
          ,[PostCode]
          ,[AccountTypeID]
          ,[DateUpdated]
          ,[DateAdded]
        &lt;span class="kwrd"&gt;FROM&lt;/span&gt; [dbo].[tblAccount] &lt;span class="kwrd"&gt;WITH&lt;/span&gt; (NOLOCK)
        &lt;span class="kwrd"&gt;WHERE&lt;/span&gt; [CompanyID] = @CompanyID
    )
    &lt;span class="kwrd"&gt;SELECT&lt;/span&gt; ,[Id]
          ,[CompanyID]
          ,[AccountID]
          ,[AccountName]
          ,[PostCode]
          ,[AccountTypeID]
          ,[DateUpdated]
          ,[DateAdded]
    &lt;span class="kwrd"&gt;FROM&lt;/span&gt; Accounts_Page
    &lt;span class="kwrd"&gt;WHERE&lt;/span&gt; RowNo &lt;span class="kwrd"&gt;BETWEEN&lt;/span&gt; @PageRecordStart &lt;span class="kwrd"&gt;and&lt;/span&gt; @PageRecordEnd 
    &lt;span class="kwrd"&gt;ORDER&lt;/span&gt; &lt;span class="kwrd"&gt;BY&lt;/span&gt; RowNo &lt;span class="kwrd"&gt;ASC&lt;/span&gt;;

&lt;span class="kwrd"&gt;END&lt;/span&gt;
&lt;/pre&gt;
&lt;p&gt;The Telerik RadGrid exposes an OnNeedDataSource event that you can hook into to provide data access to bind to the grid. Here I use the RadGrid's CurrentPageIndex and PageSize properties to pass to my data access for our SQL CTE.&lt;/p&gt;
&lt;p&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;&lt;/p&gt;
&lt;pre class="csharpcode"&gt;        &lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; rdgrdAccounts_OnNeedDataSource(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, GridNeedDataSourceEventArgs e)
        {
            &lt;span class="kwrd"&gt;int&lt;/span&gt; startRowIndex = rdgrdAccounts.CurrentPageIndex + 1;
            &lt;span class="kwrd"&gt;int&lt;/span&gt; maximumRows = rdgrdAccounts.PageSize;

            rdgrdAccounts.VirtualItemCount = Account.CountForFilters(CompanyId, filters);
            rdgrdAccounts.DataSource = Account.GetAccounts(CompanyId, maximumRows, startRowIndex);
            
        }&lt;/pre&gt;
&lt;p&gt;In the next post I will cover allowing multiple checkbox selection of rows when using true data paging.&lt;/p&gt;</description>
      <link>http://www.ryantomlinson.com/post/True-data-paging-the-Telerik-RadGrid.aspx</link>
      <comments>http://www.ryantomlinson.com/post/True-data-paging-the-Telerik-RadGrid.aspx#comment</comments>
      <guid>http://www.ryantomlinson.com/post.aspx?id=8a5f9e13-1f30-4b71-98da-99269c44bcbc</guid>
      <pubDate>Tue, 15 Jun 2010 22:15:00 +0900</pubDate>
      <category>Articles</category>
      <category>Tutorials</category>
      <dc:publisher>RTomlinson</dc:publisher>
      <pingback:server>http://www.ryantomlinson.com/pingback.axd</pingback:server>
      <pingback:target>http://www.ryantomlinson.com/post.aspx?id=8a5f9e13-1f30-4b71-98da-99269c44bcbc</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://www.ryantomlinson.com/trackback.axd?id=8a5f9e13-1f30-4b71-98da-99269c44bcbc</trackback:ping>
      <wfw:comment>http://www.ryantomlinson.com/post/True-data-paging-the-Telerik-RadGrid.aspx#comment</wfw:comment>
      <wfw:commentRss>http://www.ryantomlinson.com/syndication.axd?post=8a5f9e13-1f30-4b71-98da-99269c44bcbc</wfw:commentRss>
    </item>
    <item>
      <title>Databinding child controls in an ASP.NET composite control.</title>
      <description>&lt;p&gt;Today I spent a stupid amount of time trying to resolve an issue that had me banging my head off the desk. To save anyone else from the sheer frustration I thought I would write about it to hopefully save anyone else from wasting their time.&lt;/p&gt;
&lt;p&gt;I began writing a custom composite control that contained a dropdownlist. This dropdownlist required data binding to a list of business objects. Simple and common scenario. I would then databind the dropdownlist to the control in the page behind (see code sample below).&lt;/p&gt;
&lt;p&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;&lt;/p&gt;
&lt;div class="csharpcode"&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Web;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Web.UI.WebControls;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.ComponentModel;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;&lt;span class="kwrd"&gt;namespace&lt;/span&gt; SSControls&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;{&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; MapControl : CompositeControl&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt;    {&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  10:  &lt;/span&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; MapControl() { }&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  11:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  12:  &lt;/span&gt;        DropDownList _ddlAccountTypes = &lt;span class="kwrd"&gt;new&lt;/span&gt; DropDownList();&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  13:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  14:  &lt;/span&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; DropDownList AccountTypes&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  15:  &lt;/span&gt;        {&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  16:  &lt;/span&gt;           get&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  17:  &lt;/span&gt;           {&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  18:  &lt;/span&gt;               &lt;span class="kwrd"&gt;return&lt;/span&gt; _ddlAccountTypes;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  19:  &lt;/span&gt;           }&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  20:  &lt;/span&gt;        }&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  21:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  22:  &lt;/span&gt;        &lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; CreateChildControls()&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  23:  &lt;/span&gt;        {&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  24:  &lt;/span&gt;            Controls.Add(_ddlAccountTypes);&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  25:  &lt;/span&gt;        }&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  26:  &lt;/span&gt;    }&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  27:  &lt;/span&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;&lt;/p&gt;
&lt;div class="csharpcode"&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; AccountMap : System.Web.UI.Page&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;{&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;    &lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Page_Load(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, EventArgs e)&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;    {&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;      &lt;span class="kwrd"&gt;if&lt;/span&gt; (!IsPostBack)&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;      {&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;          mapControl.AccountTypes.DataSource = Accounts.GetAccounts(123);&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;          mapControl.AccountTypes.DataBind();&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt;      }&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  10:  &lt;/span&gt;    }&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  11:  &lt;/span&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;As simple as it sounds whenever a postback was issued the data in the dropdownlist was lost. Now the first thought of any developer is probably that this is either a ViewState issue or a databinding issue.&lt;/p&gt;
&lt;p&gt;Let's think about what happens when we perform data binding on a composite control. The benefit of inheriting from CompositeControl is that child controls have their ViewState automatically tracked and we don't have to go through the pain of the whole IPostBackEventHandler complexity and the loading and saving of ViewState.&lt;/p&gt;
&lt;p&gt;So why do we lose our data upon postback? The problem is that ViewState is only tracked once it has been added to the Controls collection in the CreateChildControls() method. Therefore if we call DataBind() on a child control before it is added to the Controls collection then the ViewState is not being tracked. The result of this (apart from a massive headache) is that when we issue a postback we lose the ViewState information from out dropdownlist.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The solution? As painful as it is for me to say, make sure that you data bind after your child control has been added to the controls collection, as follows:&lt;/p&gt;
&lt;p&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;&lt;/p&gt;
&lt;div class="csharpcode"&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Web;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Web.UI.WebControls;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.ComponentModel;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;&lt;span class="kwrd"&gt;namespace&lt;/span&gt; SSControls&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;{&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; MapControl : CompositeControl&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt;    {&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  10:  &lt;/span&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; MapControl() { }&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  11:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  12:  &lt;/span&gt;        DropDownList _ddlAccountTypes = &lt;span class="kwrd"&gt;new&lt;/span&gt; DropDownList();&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  13:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  14:  &lt;/span&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; DropDownList AccountTypes&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  15:  &lt;/span&gt;        {&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  16:  &lt;/span&gt;           get&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  17:  &lt;/span&gt;           {&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  18:  &lt;/span&gt;               &lt;span class="kwrd"&gt;return&lt;/span&gt; _ddlAccountTypes;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  19:  &lt;/span&gt;           }&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  20:  &lt;/span&gt;        }&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  21:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  22:  &lt;/span&gt;        &lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; CreateChildControls()&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  23:  &lt;/span&gt;        {&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  24:  &lt;/span&gt;            Controls.Add(_ddlAccountTypes);&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  25:  &lt;/span&gt;            &lt;span class="kwrd"&gt;if&lt;/span&gt; (!Page.IsPostBack)&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  26:  &lt;/span&gt;                _ddlAccountTypes.DataBind();&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  27:  &lt;/span&gt;        }&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  28:  &lt;/span&gt;    }&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  29:  &lt;/span&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;&lt;/p&gt;
&lt;div class="csharpcode"&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; AccountMap : System.Web.UI.Page&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;{&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;    &lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Page_Load(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, EventArgs e)&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;    {&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;      &lt;span class="kwrd"&gt;if&lt;/span&gt; (!IsPostBack)&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;      {&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;          mapControl.AccountTypes.DataSource = Accounts.GetAccounts(123);&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;      }&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt;    }&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt;  10:  &lt;/span&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Now when a postback is issued your dropdownlist will have it's values tracked in ViewState and you will not lose data.&lt;/p&gt;</description>
      <link>http://www.ryantomlinson.com/post/Databinding-child-controls-in-an-ASPNET-composite-control.aspx</link>
      <comments>http://www.ryantomlinson.com/post/Databinding-child-controls-in-an-ASPNET-composite-control.aspx#comment</comments>
      <guid>http://www.ryantomlinson.com/post.aspx?id=c7625f7f-6834-4a1a-90a1-b7911191e5ca</guid>
      <pubDate>Thu, 07 Jan 2010 07:07:00 +0900</pubDate>
      <category>Articles</category>
      <dc:publisher>RTomlinson</dc:publisher>
      <pingback:server>http://www.ryantomlinson.com/pingback.axd</pingback:server>
      <pingback:target>http://www.ryantomlinson.com/post.aspx?id=c7625f7f-6834-4a1a-90a1-b7911191e5ca</pingback:target>
      <slash:comments>6</slash:comments>
      <trackback:ping>http://www.ryantomlinson.com/trackback.axd?id=c7625f7f-6834-4a1a-90a1-b7911191e5ca</trackback:ping>
      <wfw:comment>http://www.ryantomlinson.com/post/Databinding-child-controls-in-an-ASPNET-composite-control.aspx#comment</wfw:comment>
      <wfw:commentRss>http://www.ryantomlinson.com/syndication.axd?post=c7625f7f-6834-4a1a-90a1-b7911191e5ca</wfw:commentRss>
    </item>
    <item>
      <title>Using generics to specify return types.</title>
      <description>&lt;p&gt;Let me start by saying that I absolutely HATE Session in ASP.NET. In fact...no I don't...what I mean is that I HATE improper use of Session and I specifically hate when it's used randomly as a poor design choice, typically by insanely aweful developers, you know who you are!&lt;/p&gt;
&lt;p&gt;I have in the past designed, and stole, session manager helper classes. Today I was playing around with the idea of returning a strongly typed object from session using a single static helper method. Hardly a life changing post but hopefully someone, somewhere might find it interesting/useful.&lt;/p&gt;
&lt;p&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt; &lt;!-- .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; } --&gt;&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; SessionManager
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; T GetSessionValue&amp;lt;T&amp;gt;(&lt;span class="kwrd"&gt;string&lt;/span&gt; key, HttpContext context) &lt;span class="kwrd"&gt;where&lt;/span&gt; T : &lt;span class="kwrd"&gt;class&lt;/span&gt;
    {
        &lt;span class="kwrd"&gt;return&lt;/span&gt; context.Session[key] &lt;span class="kwrd"&gt;as&lt;/span&gt; T;
    }
}&lt;/pre&gt;
&lt;p&gt;The c# compiler will complain if you return "as T" without a class or method level type constraint. Hence the need for "where T : class".&lt;/p&gt;
&lt;p&gt;And its use?&lt;/p&gt;
&lt;p&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt; &lt;!-- .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; } --&gt;&lt;/p&gt;
&lt;pre class="csharpcode"&gt;SessionManager.GetSessionValue&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;(&lt;span class="str"&gt;"Username"&lt;/span&gt;, Context);&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description>
      <link>http://www.ryantomlinson.com/post/Using-generics-to-specify-return-types.aspx</link>
      <comments>http://www.ryantomlinson.com/post/Using-generics-to-specify-return-types.aspx#comment</comments>
      <guid>http://www.ryantomlinson.com/post.aspx?id=e3064e34-4b95-428c-8ae6-f15384e908d1</guid>
      <pubDate>Wed, 09 Sep 2009 02:01:00 +0900</pubDate>
      <category>Articles</category>
      <category>Labs</category>
      <dc:publisher>RTomlinson</dc:publisher>
      <pingback:server>http://www.ryantomlinson.com/pingback.axd</pingback:server>
      <pingback:target>http://www.ryantomlinson.com/post.aspx?id=e3064e34-4b95-428c-8ae6-f15384e908d1</pingback:target>
      <slash:comments>1</slash:comments>
      <trackback:ping>http://www.ryantomlinson.com/trackback.axd?id=e3064e34-4b95-428c-8ae6-f15384e908d1</trackback:ping>
      <wfw:comment>http://www.ryantomlinson.com/post/Using-generics-to-specify-return-types.aspx#comment</wfw:comment>
      <wfw:commentRss>http://www.ryantomlinson.com/syndication.axd?post=e3064e34-4b95-428c-8ae6-f15384e908d1</wfw:commentRss>
    </item>
    <item>
      <title>An Enterprise Authorization Framework: Part 3 - Dynamic Permissions Discovery</title>
      <description>&lt;p&gt;In &lt;a title="Part 1 Introduction" href="http://ryantomlinson.com/post/An-Enterprise-Authorization-Framework-Part-1-Introduction.aspx"&gt;Part 1&lt;/a&gt; and &lt;a title="Part 2 - Why Rhino Security is the shit" href="http://ryantomlinson.com/post/An-Enterprise-Authorization-Framework-Part-2-Why-Rhino-Security-is-the-shit.aspx"&gt;Part 2&lt;/a&gt; I covered how I went about building an authorization framework using Rhino Security. I am now going to cover how to integrate this into your domain model (business objects) and how we can use dynamic discovery for permission registration and database persistence.&lt;/p&gt;
&lt;p&gt;In essence what I am saying here is that given the scenario whereby we have a domain object (lets use that of a Company business object, for example) we could state what available permissions that object could have. This post will therefore cover:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Defining permissions at an object level&lt;/li&gt;
&lt;li&gt;The ability to register those permissions in the database&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Defining Object Permissions&lt;/h2&gt;
&lt;p&gt;Having considered various implementations, I finally decided to go with an attribute based approach. The attribute requires the operation that you want access control over and to what level of granularity. For example, given the flexibility of the Rhino Security implementation we can use the operation convention of /BUSINESSOBJECT/OPERATION or /BUSINESSOBJECT/METHOD/OPERATION OR /BUSINESSOBJECT/PROPERTY/OPERATION.&lt;/p&gt;
&lt;p&gt;In reality this would result in the following examples:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;/Company/Add&lt;/li&gt;
&lt;li&gt;/Company/Delete&lt;/li&gt;
&lt;li&gt;/User/UserName/Set&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;As you can see this attribute (ACL) used below, it takes as a parameter, the operation and an enum that states what type of permission it is.&lt;/div&gt;
&lt;p&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt; &lt;!-- .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; } --&gt;&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;namespace&lt;/span&gt; MyApp.Core
{
    [ACL(&lt;span class="str"&gt;"/User/Add"&lt;/span&gt;, &lt;span class="str"&gt;"Restrict the ability to add new users"&lt;/span&gt;, ACLType.ObjectLevel)]
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; User : Entity, IUser
    {
        &lt;span class="kwrd"&gt;private&lt;/span&gt; IAuthorizationRepository _authRepo;
        &lt;span class="kwrd"&gt;protected&lt;/span&gt; User(IAuthorizationRepository authRepo) 
        {
            _authRepo = authRepo;
        }

        &lt;span class="kwrd"&gt;public&lt;/span&gt; User() 
        {
            _authRepo = ResolveType.Of&amp;lt;IAuthorizationRepository&amp;gt;();
        }

        [Length(6, 512)]
        [NotNullNotEmpty]
        &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; UserName { get; set; }

        [Length(6, 512)]
        [NotNullNotEmpty]
        &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; Password { get; set; }&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;Dynamic Permissions Discovery&lt;/h2&gt;
&lt;p&gt;Having created an attribute to apply the required information to an object we can use reflection to discover all of our permissions. Those permissions that have not been registered in the database can then be registered and any that no longer exist can be marked accordingly. The way that I implemented this was run this discovery in the Application_Start event of the Global.asax. Therefore whenever we start our application this process takes place and the overhead of some pretty heavy reflection is less of an issue.&lt;/p&gt;
&lt;p&gt;This process, although sounding quote complex, is actually very very simple. I call a static Discover method that uses relflection to reflect the assembly, find those objects that the ACLAttribute has been applied to, checks whether that object is registered and if not then registers it.&lt;/p&gt;
&lt;p&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt; &lt;!-- .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; } --&gt;&lt;/p&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;void&lt;/span&gt; Discover(Castle.Windsor.IWindsorContainer Container)
{
  Assembly asm = Assembly.Load(&lt;span class="str"&gt;"MyApp.Core"&lt;/span&gt;);

  Type[] types = asm.GetTypes();

  Type securityPermission = asm.GetType(&lt;span class="str"&gt;"MyApp.Core.Security.ACLAttribute"&lt;/span&gt;, &lt;span class="kwrd"&gt;false&lt;/span&gt;);
  PropertyInfo operation = securityPermission.GetProperty(&lt;span class="str"&gt;"Operation"&lt;/span&gt;);
  RegisterAssemblyTypes(Container, types, securityPermission, operation);
}

&lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; RegisterAssemblyTypes(Castle.Windsor.IWindsorContainer Container, Type[] types, Type securityPermission, PropertyInfo operation)
{
  &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (Type t &lt;span class="kwrd"&gt;in&lt;/span&gt; types)
  {
    &lt;span class="kwrd"&gt;object&lt;/span&gt;[] objs = t.GetCustomAttributes(securityPermission, &lt;span class="kwrd"&gt;false&lt;/span&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; objs)
    {
      &lt;span class="kwrd"&gt;if&lt;/span&gt; (!Registered(operation.GetValue(o, &lt;span class="kwrd"&gt;null&lt;/span&gt;).ToString(), Container))
      {
        Register(operation.GetValue(o, &lt;span class="kwrd"&gt;null&lt;/span&gt;).ToString(), Container);
      }
    }
  }
}&lt;/pre&gt;
&lt;p&gt;This implementation works very well. It involves minimal work work the developer. When a new permission is required it simply means adding an attribute to the appropriate business object. This permission will then be automatically registered and will be visible within the permissions section of the application, allowing the administrator to associate a particular user with that permission to allow or deny the operation.&lt;/p&gt;
&lt;p&gt;In the next post I will detail the how I implemented this using some nice jQuery iPhone checkboxes on top of the standard ASP.NET checkbox control.&lt;/p&gt;</description>
      <link>http://www.ryantomlinson.com/post/An-Enterprise-Authorization-Framework-Part-3-Dynamic-Permissions-Discovery.aspx</link>
      <comments>http://www.ryantomlinson.com/post/An-Enterprise-Authorization-Framework-Part-3-Dynamic-Permissions-Discovery.aspx#comment</comments>
      <guid>http://www.ryantomlinson.com/post.aspx?id=c2aecc7f-2c5c-4a23-8933-c74a92b50c6d</guid>
      <pubDate>Thu, 03 Sep 2009 18:58:00 +0900</pubDate>
      <category>Articles</category>
      <category>Tutorials</category>
      <dc:publisher>RTomlinson</dc:publisher>
      <pingback:server>http://www.ryantomlinson.com/pingback.axd</pingback:server>
      <pingback:target>http://www.ryantomlinson.com/post.aspx?id=c2aecc7f-2c5c-4a23-8933-c74a92b50c6d</pingback:target>
      <slash:comments>10</slash:comments>
      <trackback:ping>http://www.ryantomlinson.com/trackback.axd?id=c2aecc7f-2c5c-4a23-8933-c74a92b50c6d</trackback:ping>
      <wfw:comment>http://www.ryantomlinson.com/post/An-Enterprise-Authorization-Framework-Part-3-Dynamic-Permissions-Discovery.aspx#comment</wfw:comment>
      <wfw:commentRss>http://www.ryantomlinson.com/syndication.axd?post=c2aecc7f-2c5c-4a23-8933-c74a92b50c6d</wfw:commentRss>
    </item>
  </channel>
</rss>

