<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>IIrrelevant - AOP</title>
    <link>http://www.milkcarton.com/blog/</link>
    <description>Irrelevant musings about software development</description>
    <language>en-us</language>
    <copyright>Dan Morphis</copyright>
    <lastBuildDate>Mon, 26 Nov 2007 05:37:23 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.3.9074.18820</generator>
    <managingEditor>blog@milkcarton.com</managingEditor>
    <webMaster>blog@milkcarton.com</webMaster>
    <item>
      <trackback:ping>http://www.milkcarton.com/blog/Trackback.aspx?guid=aa751f74-30f0-4d38-aaf7-36e2c75ea382</trackback:ping>
      <pingback:server>http://www.milkcarton.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.milkcarton.com/blog/PermaLink,guid,aa751f74-30f0-4d38-aaf7-36e2c75ea382.aspx</pingback:target>
      <dc:creator>Dan Morphis</dc:creator>
      <wfw:comment>http://www.milkcarton.com/blog/CommentView,guid,aa751f74-30f0-4d38-aaf7-36e2c75ea382.aspx</wfw:comment>
      <wfw:commentRss>http://www.milkcarton.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=aa751f74-30f0-4d38-aaf7-36e2c75ea382</wfw:commentRss>
      <slash:comments>3</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <h3>Background Information
</h3>
        <p>
Aspect Oriented Programming has been on my list of things to read up on for almost
a year now.  It likely would have stayed on my list of things to do well into
the future if it hadn't been for a recent <a href="http://www.dotnetrocks.com/">.NET
Rocks</a> episode.  I can't recall if it was the <a href="http://www.dotnetrocks.com/default.aspx?showNum=289">Pablo
Castro on Astoria</a>, or the <a href="http://www.dotnetrocks.com/default.aspx?showNum=290">Tim
Sneath and Ian Ellison</a> show, but one of them off-hand mentioned <a href="http://www.postsharp.org/">PostSharp</a>. 
As I usually do when links are thrown about on the show, I scribbled it on my hand
for later review. <b>Update</b><a href="http://www.dotnetrocks.com/default.aspx?showNum=298">DNR
just released a show with Gael Fraiteur of PostSharp</a> fame!<br /></p>
        <p>
Once I got to the PostSharp site, I found their <a href="http://www.postsharp.org/documentation/simple-trace-aspect-tutorial">sample
video on creating a trace AOP attribute</a>.  They had me hooked.  I wasn't
so much interested in doing a logging or trace attribute, but was more interested
in doing a few validation attributes.  More specifically a NotNullAttribute.
</p>
        <h3>The Problem
</h3>
        <p>
What got me interested in doing the NotNullAttribute was thinking back to how many
times in our code base we would have something like this:
</p>
        <pre>
          <div class="wlWriterSmartContent" id="57F11A72-B0E5-49c7-9094-E3A15BD5B5E7:412e8b34-6570-4246-b54c-2d1eec69d82e" style="margin: 0px; padding: 0px; display: inline; float: none;" contenteditable="false">
            <pre style="overflow: auto; background-color: rgb(255, 255, 128);">
              <div>
                <!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
                <span style="color: rgb(0, 128, 128);"> 1</span>
                <span style="color: rgb(0, 0, 255);">public</span>
                <span style="color: rgb(0, 0, 0);">
                </span>
                <span style="color: rgb(0, 0, 255);">void</span>
                <span style="color: rgb(0, 0, 0);"> AddUser(Organization
org, User user) </span>
                <span style="color: rgb(0, 128, 128);"> 2</span>
                <span style="color: rgb(0, 0, 0);">{ </span>
                <span style="color: rgb(0, 128, 128);"> 3</span>
                <span style="color: rgb(0, 0, 0);">
                </span>
                <span style="color: rgb(0, 0, 255);">if</span>
                <span style="color: rgb(0, 0, 0);"> (org </span>
                <span style="color: rgb(0, 0, 0);">==</span>
                <span style="color: rgb(0, 0, 0);">
                </span>
                <span style="color: rgb(0, 0, 255);">null</span>
                <span style="color: rgb(0, 0, 0);">) </span>
                <span style="color: rgb(0, 128, 128);"> 4</span>
                <span style="color: rgb(0, 0, 0);">
                </span>
                <span style="color: rgb(0, 0, 255);">throw</span>
                <span style="color: rgb(0, 0, 0);">
                </span>
                <span style="color: rgb(0, 0, 255);">new</span>
                <span style="color: rgb(0, 0, 0);"> ArgumentNullException(</span>
                <span style="color: rgb(128, 0, 0);">"</span>
                <span style="color: rgb(128, 0, 0);">org</span>
                <span style="color: rgb(128, 0, 0);">"</span>
                <span style="color: rgb(0, 0, 0);">); </span>
                <span style="color: rgb(0, 128, 128);"> 5</span>
                <span style="color: rgb(0, 0, 0);">
                </span>
                <span style="color: rgb(0, 0, 255);">if</span>
                <span style="color: rgb(0, 0, 0);"> (user </span>
                <span style="color: rgb(0, 0, 0);">==</span>
                <span style="color: rgb(0, 0, 0);">
                </span>
                <span style="color: rgb(0, 0, 255);">null</span>
                <span style="color: rgb(0, 0, 0);">) </span>
                <span style="color: rgb(0, 128, 128);"> 6</span>
                <span style="color: rgb(0, 0, 0);">
                </span>
                <span style="color: rgb(0, 0, 255);">throw</span>
                <span style="color: rgb(0, 0, 0);">
                </span>
                <span style="color: rgb(0, 0, 255);">new</span>
                <span style="color: rgb(0, 0, 0);"> ArgumentNullException(</span>
                <span style="color: rgb(128, 0, 0);">"</span>
                <span style="color: rgb(128, 0, 0);">user</span>
                <span style="color: rgb(128, 0, 0);">"</span>
                <span style="color: rgb(0, 0, 0);">); </span>
                <span style="color: rgb(0, 128, 128);"> 7</span>
                <span style="color: rgb(0, 0, 0);">
                </span>
                <span style="color: rgb(0, 128, 128);"> 8</span>
                <span style="color: rgb(0, 0, 0);"> org.AddUser(user); </span>
                <span style="color: rgb(0, 128, 128);"> 9</span>
                <span style="color: rgb(0, 0, 0);"> _ordDal.Save(org); </span>
                <span style="color: rgb(0, 128, 128);">10</span>
                <span style="color: rgb(0, 0, 0);">}</span>
              </div>
            </pre>
            <!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com -->
          </div>
        </pre>
        <p>
        </p>
        <p>
Granted this is a somewhat short method, but we have methods which take 6 parameters,
and only 2 actual lines of code.  That's 12 lines of code taken up for argument
checking, and 2 lines of code.  That would put our crap to code ratio at 6/1.
</p>
        <h3>The Solution
</h3>
        <p>
Wouldn't it be much nicer if you could do something like this:
</p>
        <p>
        </p>
        <div class="wlWriterSmartContent" id="57F11A72-B0E5-49c7-9094-E3A15BD5B5E7:b14b6321-8fde-41c3-a4c5-e50fc4fd2847" style="margin: 0px; padding: 0px; display: inline; float: none;" contenteditable="false">
          <pre style="overflow: auto; background-color: rgb(255, 255, 128);">
            <div>
              <!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
              <span style="color: rgb(0, 128, 128);">1</span>
              <span style="color: rgb(0, 0, 255);">public</span>
              <span style="color: rgb(0, 0, 0);">
              </span>
              <span style="color: rgb(0, 0, 255);">void</span>
              <span style="color: rgb(0, 0, 0);"> AddUser([NotNull]
Organization org, [NotNull] User user) </span>
              <span style="color: rgb(0, 128, 128);">2</span>
              <span style="color: rgb(0, 0, 0);">{ </span>
              <span style="color: rgb(0, 128, 128);">3</span>
              <span style="color: rgb(0, 0, 0);"> org.AddUser(user); </span>
              <span style="color: rgb(0, 128, 128);">4</span>
              <span style="color: rgb(0, 0, 0);"> _ordDal.Save(org); </span>
              <span style="color: rgb(0, 128, 128);">5</span>
              <span style="color: rgb(0, 0, 0);">}</span>
            </div>
          </pre>
          <!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com -->
        </div>
        <p>
        </p>
        <p>
 
</p>
        <p>
PostSharp is almost there to let you write code just like that.  Currently, there
is no support for an OnParameterAspectBoundaryAttribute in PostSharp, so we have to
do things just slightly differently:
</p>
        <p>
        </p>
        <div class="wlWriterSmartContent" id="57F11A72-B0E5-49c7-9094-E3A15BD5B5E7:497ca957-7091-4b07-84f7-3f49ed150dad" style="margin: 0px; padding: 0px; display: inline; float: none;" contenteditable="false">
          <pre style="overflow: auto; background-color: rgb(255, 255, 128);">
            <div>
              <!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
              <span style="color: rgb(0, 0, 0);">[NotNullHelper] </span>
              <span style="color: rgb(0, 0, 255);">public</span>
              <span style="color: rgb(0, 0, 0);">
              </span>
              <span style="color: rgb(0, 0, 255);">void</span>
              <span style="color: rgb(0, 0, 0);"> AddUser([NotNull]
Organization org, [NotNull] User user) { org.AddUser(user); _ordDal.Save(org); }</span>
            </div>
          </pre>
          <!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com -->
        </div>
        <p>
        </p>
        <p>
We have to have a helper class were all the actual code lives.
</p>
        <h3>How PostSharp Works
</h3>
        <p>
PostSharp works by weaving all your AOP attributes with your source code after the
compiler compiles your code.  This <a href="http://www.codeproject.com/useritems/ps-custom-attributes-2.asp">article
by Gael Fraiteur describes in more detail how the PostSharp process works</a>. 
After the code is post-compiled by PostSharp, you end up with something very ugly
that looks like this:
</p>
        <p>
        </p>
        <div class="wlWriterSmartContent" id="57F11A72-B0E5-49c7-9094-E3A15BD5B5E7:ec455986-ad9f-4f97-aeba-2727cc90f106" style="margin: 0px; padding: 0px; display: inline; float: none;" contenteditable="false">
          <pre style="overflow: auto; background-color: rgb(255, 255, 128);">
            <div>
              <!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
              <span style="color: rgb(0, 0, 255);">public</span>
              <span style="color: rgb(0, 0, 0);">
              </span>
              <span style="color: rgb(0, 0, 255);">void</span>
              <span style="color: rgb(0, 0, 0);"> AddUser([NotNull]
Organization org, [NotNull] User user) { MethodExecutionEventArgs </span>
              <span style="color: rgb(0, 0, 0);">~</span>
              <span style="color: rgb(0, 0, 0);">laosEventArgs</span>
              <span style="color: rgb(0, 0, 0);">~</span>
              <span style="color: rgb(128, 0, 128);">2</span>
              <span style="color: rgb(0, 0, 0);">; </span>
              <span style="color: rgb(0, 0, 255);">try</span>
              <span style="color: rgb(0, 0, 0);"> { </span>
              <span style="color: rgb(0, 0, 255);">object</span>
              <span style="color: rgb(0, 0, 0);">[] </span>
              <span style="color: rgb(0, 0, 0);">~</span>
              <span style="color: rgb(0, 0, 0);">arguments</span>
              <span style="color: rgb(0, 0, 0);">~</span>
              <span style="color: rgb(128, 0, 128);">1</span>
              <span style="color: rgb(0, 0, 0);">
              </span>
              <span style="color: rgb(0, 0, 0);">=</span>
              <span style="color: rgb(0, 0, 0);">
              </span>
              <span style="color: rgb(0, 0, 255);">new</span>
              <span style="color: rgb(0, 0, 0);">
              </span>
              <span style="color: rgb(0, 0, 255);">object</span>
              <span style="color: rgb(0, 0, 0);">[]
{ org, user }; </span>
              <span style="color: rgb(0, 0, 0);">~</span>
              <span style="color: rgb(0, 0, 0);">laosEventArgs</span>
              <span style="color: rgb(0, 0, 0);">~</span>
              <span style="color: rgb(128, 0, 128);">2</span>
              <span style="color: rgb(0, 0, 0);">
              </span>
              <span style="color: rgb(0, 0, 0);">=</span>
              <span style="color: rgb(0, 0, 0);">
              </span>
              <span style="color: rgb(0, 0, 255);">new</span>
              <span style="color: rgb(0, 0, 0);"> MethodExecutionEventArgs(methodof(OrgManager.AddUser,
OrgManager), </span>
              <span style="color: rgb(0, 0, 255);">this</span>
              <span style="color: rgb(0, 0, 0);">, </span>
              <span style="color: rgb(0, 0, 0);">~</span>
              <span style="color: rgb(0, 0, 0);">arguments</span>
              <span style="color: rgb(0, 0, 0);">~</span>
              <span style="color: rgb(128, 0, 128);">1</span>
              <span style="color: rgb(0, 0, 0);">); </span>
              <span style="color: rgb(0, 0, 0);">~</span>
              <span style="color: rgb(0, 0, 0);">PostSharp</span>
              <span style="color: rgb(0, 0, 0);">~</span>
              <span style="color: rgb(0, 0, 0);">Laos</span>
              <span style="color: rgb(0, 0, 0);">~</span>
              <span style="color: rgb(0, 0, 0);">Implementation.NotNullHelperAttribute</span>
              <span style="color: rgb(0, 0, 0);">~</span>
              <span style="color: rgb(128, 0, 128);">3</span>
              <span style="color: rgb(0, 0, 0);">.OnEntry(</span>
              <span style="color: rgb(0, 0, 0);">~</span>
              <span style="color: rgb(0, 0, 0);">laosEventArgs</span>
              <span style="color: rgb(0, 0, 0);">~</span>
              <span style="color: rgb(128, 0, 128);">2</span>
              <span style="color: rgb(0, 0, 0);">); </span>
              <span style="color: rgb(0, 0, 255);">if</span>
              <span style="color: rgb(0, 0, 0);"> (</span>
              <span style="color: rgb(0, 0, 0);">~</span>
              <span style="color: rgb(0, 0, 0);">laosEventArgs</span>
              <span style="color: rgb(0, 0, 0);">~</span>
              <span style="color: rgb(128, 0, 128);">2</span>
              <span style="color: rgb(0, 0, 0);">.FlowBehavior </span>
              <span style="color: rgb(0, 0, 0);">!=</span>
              <span style="color: rgb(0, 0, 0);"> FlowBehavior.Return)
{ org.AddUser(user); _orgDal.Save(org); </span>
              <span style="color: rgb(0, 0, 0);">~</span>
              <span style="color: rgb(0, 0, 0);">PostSharp</span>
              <span style="color: rgb(0, 0, 0);">~</span>
              <span style="color: rgb(0, 0, 0);">Laos</span>
              <span style="color: rgb(0, 0, 0);">~</span>
              <span style="color: rgb(0, 0, 0);">Implementation.NotNullHelperAttribute</span>
              <span style="color: rgb(0, 0, 0);">~</span>
              <span style="color: rgb(128, 0, 128);">3</span>
              <span style="color: rgb(0, 0, 0);">.OnSuccess(</span>
              <span style="color: rgb(0, 0, 0);">~</span>
              <span style="color: rgb(0, 0, 0);">laosEventArgs</span>
              <span style="color: rgb(0, 0, 0);">~</span>
              <span style="color: rgb(128, 0, 128);">2</span>
              <span style="color: rgb(0, 0, 0);">);
} } </span>
              <span style="color: rgb(0, 0, 255);">catch</span>
              <span style="color: rgb(0, 0, 0);"> (Exception </span>
              <span style="color: rgb(0, 0, 0);">~</span>
              <span style="color: rgb(0, 0, 0);">exception</span>
              <span style="color: rgb(0, 0, 0);">~</span>
              <span style="color: rgb(128, 0, 128);">0</span>
              <span style="color: rgb(0, 0, 0);">)
{ </span>
              <span style="color: rgb(0, 0, 0);">~</span>
              <span style="color: rgb(0, 0, 0);">laosEventArgs</span>
              <span style="color: rgb(0, 0, 0);">~</span>
              <span style="color: rgb(128, 0, 128);">2</span>
              <span style="color: rgb(0, 0, 0);">.Exception </span>
              <span style="color: rgb(0, 0, 0);">=</span>
              <span style="color: rgb(0, 0, 0);">
              </span>
              <span style="color: rgb(0, 0, 0);">~</span>
              <span style="color: rgb(0, 0, 0);">exception</span>
              <span style="color: rgb(0, 0, 0);">~</span>
              <span style="color: rgb(128, 0, 128);">0</span>
              <span style="color: rgb(0, 0, 0);">; </span>
              <span style="color: rgb(0, 0, 0);">~</span>
              <span style="color: rgb(0, 0, 0);">PostSharp</span>
              <span style="color: rgb(0, 0, 0);">~</span>
              <span style="color: rgb(0, 0, 0);">Laos</span>
              <span style="color: rgb(0, 0, 0);">~</span>
              <span style="color: rgb(0, 0, 0);">Implementation.NotNullHelperAttribute</span>
              <span style="color: rgb(0, 0, 0);">~</span>
              <span style="color: rgb(128, 0, 128);">3</span>
              <span style="color: rgb(0, 0, 0);">.OnException(</span>
              <span style="color: rgb(0, 0, 0);">~</span>
              <span style="color: rgb(0, 0, 0);">laosEventArgs</span>
              <span style="color: rgb(0, 0, 0);">~</span>
              <span style="color: rgb(128, 0, 128);">2</span>
              <span style="color: rgb(0, 0, 0);">); </span>
              <span style="color: rgb(0, 0, 255);">switch</span>
              <span style="color: rgb(0, 0, 0);"> (</span>
              <span style="color: rgb(0, 0, 0);">~</span>
              <span style="color: rgb(0, 0, 0);">laosEventArgs</span>
              <span style="color: rgb(0, 0, 0);">~</span>
              <span style="color: rgb(128, 0, 128);">2</span>
              <span style="color: rgb(0, 0, 0);">.FlowBehavior)
{ </span>
              <span style="color: rgb(0, 0, 255);">case</span>
              <span style="color: rgb(0, 0, 0);"> FlowBehavior.Continue: </span>
              <span style="color: rgb(0, 0, 255);">case</span>
              <span style="color: rgb(0, 0, 0);"> FlowBehavior.Return: </span>
              <span style="color: rgb(0, 0, 255);">return</span>
              <span style="color: rgb(0, 0, 0);">;
} </span>
              <span style="color: rgb(0, 0, 255);">throw</span>
              <span style="color: rgb(0, 0, 0);">;
} </span>
              <span style="color: rgb(0, 0, 255);">finally</span>
              <span style="color: rgb(0, 0, 0);"> { </span>
              <span style="color: rgb(0, 0, 0);">~</span>
              <span style="color: rgb(0, 0, 0);">PostSharp</span>
              <span style="color: rgb(0, 0, 0);">~</span>
              <span style="color: rgb(0, 0, 0);">Laos</span>
              <span style="color: rgb(0, 0, 0);">~</span>
              <span style="color: rgb(0, 0, 0);">Implementation.NotNullHelperAttribute</span>
              <span style="color: rgb(0, 0, 0);">~</span>
              <span style="color: rgb(128, 0, 128);">3</span>
              <span style="color: rgb(0, 0, 0);">.OnExit(</span>
              <span style="color: rgb(0, 0, 0);">~</span>
              <span style="color: rgb(0, 0, 0);">laosEventArgs</span>
              <span style="color: rgb(0, 0, 0);">~</span>
              <span style="color: rgb(128, 0, 128);">2</span>
              <span style="color: rgb(0, 0, 0);">);
} }</span>
            </div>
          </pre>
          <!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com -->
        </div>
        <p>
        </p>
        <p>
I don't know about you, but I would have one HELL of a time trying to debug this,
thankfully PostSharp touches up the PDB files, so when your debugging, you only see
and debug the source code you've written, both your attribute, and your business logic.
</p>
        <h3>The Drawbacks
</h3>
        <p>
PostSharp modifies your code! Well, not directly, but it is still modifying your code
(as seen above), but thankfully it touches up the PDB files so all the mess under
the hood is hidden from you.
</p>
        <h3>Conclusion
</h3>
        <p>
This is but one of the many things you can do with AOP and PostSharp.  Next up,
I plan to write some validation attributes.  Look for those in the next few weeks. 
In the mean time, <a href="http://www.milkcarton.com/blog/content/binary/NotNullAttribute.cs.txt">download
the source code for the NotNullAttribute</a>.
</p>
        <p>
I'm sorry if this post looks terrible in your feed reader, I still haven't been able
to figure out why the code looks terrible.  If anyone has any suggestions, let
me know.  I'm using DasBlogCE as my blog engine.
</p>
        <a href="http://www.dotnetkicks.com/kick/?url=http://www.milkcarton.com/blog/2007/11/26/Decrapify+Your+Code+Base+With+AOP+Using+PostSharp.aspx">
          <img alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://www.milkcarton.com/blog/2007/11/26/Decrapify+Your+Code+Base+With+AOP+Using+PostSharp.aspx" border="0" />
        </a>
        <img width="0" height="0" src="http://www.milkcarton.com/blog/aggbug.ashx?id=aa751f74-30f0-4d38-aaf7-36e2c75ea382" />
      </body>
      <title>De-crapify your code base with AOP using PostSharp</title>
      <guid isPermaLink="false">http://www.milkcarton.com/blog/PermaLink,guid,aa751f74-30f0-4d38-aaf7-36e2c75ea382.aspx</guid>
      <link>http://www.milkcarton.com/blog/2007/11/26/Decrapify+Your+Code+Base+With+AOP+Using+PostSharp.aspx</link>
      <pubDate>Mon, 26 Nov 2007 05:37:23 GMT</pubDate>
      <description>&lt;h3&gt;Background Information
&lt;/h3&gt;
&lt;p&gt;
Aspect Oriented Programming has been on my list of things to read up on for almost
a year now.&amp;nbsp; It likely would have stayed on my list of things to do well into
the future if it hadn't been for a recent &lt;a href="http://www.dotnetrocks.com/"&gt;.NET
Rocks&lt;/a&gt;&amp;nbsp;episode.&amp;nbsp; I can't recall if it was the &lt;a href="http://www.dotnetrocks.com/default.aspx?showNum=289"&gt;Pablo
Castro on Astoria&lt;/a&gt;, or the &lt;a href="http://www.dotnetrocks.com/default.aspx?showNum=290"&gt;Tim
Sneath and Ian Ellison&lt;/a&gt;&amp;nbsp;show, but one of them off-hand mentioned &lt;a href="http://www.postsharp.org/"&gt;PostSharp&lt;/a&gt;.&amp;nbsp;
As I usually do when links are thrown about on the show, I scribbled it on my hand
for later review. &lt;b&gt;Update&lt;/b&gt; &lt;a href="http://www.dotnetrocks.com/default.aspx?showNum=298"&gt;DNR
just released a show with Gael Fraiteur of PostSharp&lt;/a&gt; fame!&lt;br&gt;
&lt;/p&gt;
&lt;p&gt;
Once I got to the PostSharp site, I found their &lt;a href="http://www.postsharp.org/documentation/simple-trace-aspect-tutorial"&gt;sample
video on creating a trace AOP attribute&lt;/a&gt;.&amp;nbsp; They had me hooked.&amp;nbsp; I wasn't
so much interested in doing a logging or trace attribute, but was more interested
in doing a few validation attributes.&amp;nbsp; More specifically a NotNullAttribute.
&lt;/p&gt;
&lt;h3&gt;The Problem
&lt;/h3&gt;
&lt;p&gt;
What got me interested in doing the NotNullAttribute was thinking back to how many
times in our code base we would have something like this:
&lt;/p&gt;
&lt;pre&gt;
&lt;div class="wlWriterSmartContent" id="57F11A72-B0E5-49c7-9094-E3A15BD5B5E7:412e8b34-6570-4246-b54c-2d1eec69d82e" style="margin: 0px; padding: 0px; display: inline; float: none;" contenteditable="false"&gt;&lt;pre style="overflow: auto; background-color: rgb(255, 255, 128);"&gt;
&lt;div&gt;
&lt;!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--&gt;&lt;span style="color: rgb(0, 128, 128);"&gt; 1&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; AddUser(Organization
org, User user) &lt;/span&gt;&lt;span style="color: rgb(0, 128, 128);"&gt; 2&lt;/span&gt; &lt;span style="color: rgb(0, 0, 0);"&gt;{ &lt;/span&gt;&lt;span style="color: rgb(0, 128, 128);"&gt; 3&lt;/span&gt; &lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; (org &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;==&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;) &lt;/span&gt;&lt;span style="color: rgb(0, 128, 128);"&gt; 4&lt;/span&gt; &lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;throw&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; ArgumentNullException(&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;"&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;org&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;); &lt;/span&gt;&lt;span style="color: rgb(0, 128, 128);"&gt; 5&lt;/span&gt; &lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; (user &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;==&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;) &lt;/span&gt;&lt;span style="color: rgb(0, 128, 128);"&gt; 6&lt;/span&gt; &lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;throw&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; ArgumentNullException(&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;"&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;user&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;); &lt;/span&gt;&lt;span style="color: rgb(0, 128, 128);"&gt; 7&lt;/span&gt; &lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 128, 128);"&gt; 8&lt;/span&gt; &lt;span style="color: rgb(0, 0, 0);"&gt; org.AddUser(user); &lt;/span&gt;&lt;span style="color: rgb(0, 128, 128);"&gt; 9&lt;/span&gt; &lt;span style="color: rgb(0, 0, 0);"&gt; _ordDal.Save(org); &lt;/span&gt;&lt;span style="color: rgb(0, 128, 128);"&gt;10&lt;/span&gt; &lt;span style="color: rgb(0, 0, 0);"&gt;}&lt;/span&gt;
&lt;/div&gt;
&lt;/pre&gt;
&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;
&lt;/div&gt;
&lt;/pre&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
Granted this is a somewhat short method, but we have methods which take 6 parameters,
and only 2 actual&amp;nbsp;lines of code.&amp;nbsp; That's 12 lines of code taken up for argument
checking, and 2 lines of code.&amp;nbsp; That would put our crap to code ratio at 6/1.
&lt;/p&gt;
&lt;h3&gt;The Solution
&lt;/h3&gt;
&lt;p&gt;
Wouldn't it be much nicer if you could do something like this:
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;div class="wlWriterSmartContent" id="57F11A72-B0E5-49c7-9094-E3A15BD5B5E7:b14b6321-8fde-41c3-a4c5-e50fc4fd2847" style="margin: 0px; padding: 0px; display: inline; float: none;" contenteditable="false"&gt;&lt;pre style="overflow: auto; background-color: rgb(255, 255, 128);"&gt;
&lt;div&gt;
&lt;!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--&gt;&lt;span style="color: rgb(0, 128, 128);"&gt;1&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; AddUser([NotNull]
Organization org, [NotNull] User user) &lt;/span&gt;&lt;span style="color: rgb(0, 128, 128);"&gt;2&lt;/span&gt; &lt;span style="color: rgb(0, 0, 0);"&gt;{ &lt;/span&gt;&lt;span style="color: rgb(0, 128, 128);"&gt;3&lt;/span&gt; &lt;span style="color: rgb(0, 0, 0);"&gt; org.AddUser(user); &lt;/span&gt;&lt;span style="color: rgb(0, 128, 128);"&gt;4&lt;/span&gt; &lt;span style="color: rgb(0, 0, 0);"&gt; _ordDal.Save(org); &lt;/span&gt;&lt;span style="color: rgb(0, 128, 128);"&gt;5&lt;/span&gt; &lt;span style="color: rgb(0, 0, 0);"&gt;}&lt;/span&gt;
&lt;/div&gt;
&lt;/pre&gt;
&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
PostSharp is almost there to let you write code just like that.&amp;nbsp; Currently, there
is no support for an OnParameterAspectBoundaryAttribute in PostSharp, so we have to
do things just slightly differently:
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;div class="wlWriterSmartContent" id="57F11A72-B0E5-49c7-9094-E3A15BD5B5E7:497ca957-7091-4b07-84f7-3f49ed150dad" style="margin: 0px; padding: 0px; display: inline; float: none;" contenteditable="false"&gt;&lt;pre style="overflow: auto; background-color: rgb(255, 255, 128);"&gt;
&lt;div&gt;
&lt;!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;[NotNullHelper] &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; AddUser([NotNull]
Organization org, [NotNull] User user) { org.AddUser(user); _ordDal.Save(org); }&lt;/span&gt;
&lt;/div&gt;
&lt;/pre&gt;
&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
We have to have a helper class were all the actual code lives.
&lt;/p&gt;
&lt;h3&gt;How&amp;nbsp;PostSharp Works
&lt;/h3&gt;
&lt;p&gt;
PostSharp works by weaving all your AOP attributes with your source code after the
compiler compiles your code.&amp;nbsp; This &lt;a href="http://www.codeproject.com/useritems/ps-custom-attributes-2.asp"&gt;article
by Gael Fraiteur describes in more detail how the PostSharp process works&lt;/a&gt;.&amp;nbsp;
After the code is post-compiled by PostSharp, you end up with something very ugly
that looks like this:
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;div class="wlWriterSmartContent" id="57F11A72-B0E5-49c7-9094-E3A15BD5B5E7:ec455986-ad9f-4f97-aeba-2727cc90f106" style="margin: 0px; padding: 0px; display: inline; float: none;" contenteditable="false"&gt;&lt;pre style="overflow: auto; background-color: rgb(255, 255, 128);"&gt;
&lt;div&gt;
&lt;!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; AddUser([NotNull]
Organization org, [NotNull] User user) { MethodExecutionEventArgs &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;~&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;laosEventArgs&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;~&lt;/span&gt;&lt;span style="color: rgb(128, 0, 128);"&gt;2&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;try&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; { &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;object&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;[] &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;~&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;arguments&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;~&lt;/span&gt;&lt;span style="color: rgb(128, 0, 128);"&gt;1&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;object&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;[]
{ org, user }; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;~&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;laosEventArgs&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;~&lt;/span&gt;&lt;span style="color: rgb(128, 0, 128);"&gt;2&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; MethodExecutionEventArgs(methodof(OrgManager.AddUser,
OrgManager), &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;this&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;~&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;arguments&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;~&lt;/span&gt;&lt;span style="color: rgb(128, 0, 128);"&gt;1&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;); &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;~&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;PostSharp&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;~&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;Laos&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;~&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;Implementation.NotNullHelperAttribute&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;~&lt;/span&gt;&lt;span style="color: rgb(128, 0, 128);"&gt;3&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;.OnEntry(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;~&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;laosEventArgs&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;~&lt;/span&gt;&lt;span style="color: rgb(128, 0, 128);"&gt;2&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;); &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; (&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;~&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;laosEventArgs&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;~&lt;/span&gt;&lt;span style="color: rgb(128, 0, 128);"&gt;2&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;.FlowBehavior &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;!=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; FlowBehavior.Return)
{ org.AddUser(user); _orgDal.Save(org); &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;~&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;PostSharp&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;~&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;Laos&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;~&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;Implementation.NotNullHelperAttribute&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;~&lt;/span&gt;&lt;span style="color: rgb(128, 0, 128);"&gt;3&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;.OnSuccess(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;~&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;laosEventArgs&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;~&lt;/span&gt;&lt;span style="color: rgb(128, 0, 128);"&gt;2&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;);
} } &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;catch&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; (Exception &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;~&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;exception&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;~&lt;/span&gt;&lt;span style="color: rgb(128, 0, 128);"&gt;0&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)
{ &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;~&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;laosEventArgs&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;~&lt;/span&gt;&lt;span style="color: rgb(128, 0, 128);"&gt;2&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;.Exception &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;~&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;exception&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;~&lt;/span&gt;&lt;span style="color: rgb(128, 0, 128);"&gt;0&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;~&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;PostSharp&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;~&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;Laos&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;~&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;Implementation.NotNullHelperAttribute&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;~&lt;/span&gt;&lt;span style="color: rgb(128, 0, 128);"&gt;3&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;.OnException(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;~&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;laosEventArgs&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;~&lt;/span&gt;&lt;span style="color: rgb(128, 0, 128);"&gt;2&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;); &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;switch&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; (&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;~&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;laosEventArgs&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;~&lt;/span&gt;&lt;span style="color: rgb(128, 0, 128);"&gt;2&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;.FlowBehavior)
{ &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;case&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; FlowBehavior.Continue: &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;case&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; FlowBehavior.Return: &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;;
} &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;throw&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;;
} &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;finally&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; { &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;~&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;PostSharp&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;~&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;Laos&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;~&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;Implementation.NotNullHelperAttribute&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;~&lt;/span&gt;&lt;span style="color: rgb(128, 0, 128);"&gt;3&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;.OnExit(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;~&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;laosEventArgs&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;~&lt;/span&gt;&lt;span style="color: rgb(128, 0, 128);"&gt;2&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;);
} }&lt;/span&gt;
&lt;/div&gt;
&lt;/pre&gt;
&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
I don't know about you, but I would have&amp;nbsp;one HELL of a time trying to debug this,
thankfully PostSharp touches up the PDB files, so when your debugging, you only see
and debug the source code you've written, both your attribute, and your business logic.
&lt;/p&gt;
&lt;h3&gt;The Drawbacks
&lt;/h3&gt;
&lt;p&gt;
PostSharp modifies your code! Well, not directly, but it is still modifying your code
(as seen above), but thankfully it touches up the PDB files so all the mess under
the hood is hidden from you.
&lt;/p&gt;
&lt;h3&gt;Conclusion
&lt;/h3&gt;
&lt;p&gt;
This is but one of the many things you can do with AOP and PostSharp.&amp;nbsp; Next up,
I plan to write some validation attributes.&amp;nbsp; Look for those in the next few weeks.&amp;nbsp;
In the mean time, &lt;a href="http://www.milkcarton.com/blog/content/binary/NotNullAttribute.cs.txt"&gt;download
the source code for the NotNullAttribute&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
I'm sorry if this post looks terrible in your feed reader, I still haven't been able
to figure out why the code looks terrible.&amp;nbsp; If anyone has any suggestions, let
me know.&amp;nbsp; I'm using DasBlogCE as my blog engine.
&lt;/p&gt;
&lt;a href="http://www.dotnetkicks.com/kick/?url=http://www.milkcarton.com/blog/2007/11/26/Decrapify+Your+Code+Base+With+AOP+Using+PostSharp.aspx"&gt;&lt;img alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://www.milkcarton.com/blog/2007/11/26/Decrapify+Your+Code+Base+With+AOP+Using+PostSharp.aspx" border="0"&gt;&lt;/a&gt;&lt;img width="0" height="0" src="http://www.milkcarton.com/blog/aggbug.ashx?id=aa751f74-30f0-4d38-aaf7-36e2c75ea382" /&gt;</description>
      <comments>http://www.milkcarton.com/blog/CommentView,guid,aa751f74-30f0-4d38-aaf7-36e2c75ea382.aspx</comments>
      <category>.NET</category>
      <category>AOP</category>
      <category>C#</category>
      <category>PostSharp</category>
    </item>
  </channel>
</rss>