<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: static reflection &#8211; Method Guards</title>
	<atom:link href="http://jonfuller.codingtomusic.com/2008/12/11/static-reflection-method-guards/feed/" rel="self" type="application/rss+xml" />
	<link>http://jonfuller.codingtomusic.com/2008/12/11/static-reflection-method-guards/</link>
	<description></description>
	<lastBuildDate>Tue, 29 Jun 2010 19:28:27 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
	<item>
		<title>By: Des</title>
		<link>http://jonfuller.codingtomusic.com/2008/12/11/static-reflection-method-guards/comment-page-1/#comment-361</link>
		<dc:creator>Des</dc:creator>
		<pubDate>Tue, 02 Feb 2010 22:52:09 +0000</pubDate>
		<guid isPermaLink="false">http://jonfuller.codingtomusic.com/2008/12/11/static-reflection-method-guards/#comment-361</guid>
		<description>Excellent work getting this far however I did note that one failing was when calling Guard.IsNull with a string with a value of null it throws a NullReferenceException because of the fact that the default value T is String.Empty.   

One way to handle this scenario would be to use reflection and Reflect on expr.Compile().Target.Globals[0].Value which happens to contain information on the given expression including the argument name, value and type however this does seem to defeat the whole purpose.

Example test code that produces the above results:

[Test]
        public void ShouldThrowArgumentNullExceptionWhenGivenStringWithNullValue()
        {
            const string rootDirectory = null;
            const string serverName = null;
            var server = new WebServer();
            
            TestUtilities.Assert.ThrowsExactly(
                () =&gt; server.BootstrapServer(0, rootDirectory, serverName));
        }</description>
		<content:encoded><![CDATA[<p>Excellent work getting this far however I did note that one failing was when calling Guard.IsNull with a string with a value of null it throws a NullReferenceException because of the fact that the default value T is String.Empty.   </p>
<p>One way to handle this scenario would be to use reflection and Reflect on expr.Compile().Target.Globals[0].Value which happens to contain information on the given expression including the argument name, value and type however this does seem to defeat the whole purpose.</p>
<p>Example test code that produces the above results:</p>
<p>[Test]<br />
        public void ShouldThrowArgumentNullExceptionWhenGivenStringWithNullValue()<br />
        {<br />
            const string rootDirectory = null;<br />
            const string serverName = null;<br />
            var server = new WebServer();</p>
<p>            TestUtilities.Assert.ThrowsExactly(<br />
                () =&gt; server.BootstrapServer(0, rootDirectory, serverName));<br />
        }</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jon</title>
		<link>http://jonfuller.codingtomusic.com/2008/12/11/static-reflection-method-guards/comment-page-1/#comment-270</link>
		<dc:creator>jon</dc:creator>
		<pubDate>Thu, 24 Sep 2009 18:30:44 +0000</pubDate>
		<guid isPermaLink="false">http://jonfuller.codingtomusic.com/2008/12/11/static-reflection-method-guards/#comment-270</guid>
		<description>That is a great idea, but I don&#039;t think you have access to that level of meta information in C#.  Please correct me if I&#039;m wrong (anyone).

This is sort of doing something similar to what you said though.  You&#039;re not actually passing in a lambda (although it does indeed look like one)... in reality you&#039;re passing an Expression (just a piece of code) that gets analyzed and validated inside the validator.</description>
		<content:encoded><![CDATA[<p>That is a great idea, but I don&#8217;t think you have access to that level of meta information in C#.  Please correct me if I&#8217;m wrong (anyone).</p>
<p>This is sort of doing something similar to what you said though.  You&#8217;re not actually passing in a lambda (although it does indeed look like one)&#8230; in reality you&#8217;re passing an Expression (just a piece of code) that gets analyzed and validated inside the validator.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jason</title>
		<link>http://jonfuller.codingtomusic.com/2008/12/11/static-reflection-method-guards/comment-page-1/#comment-269</link>
		<dc:creator>Jason</dc:creator>
		<pubDate>Thu, 24 Sep 2009 15:12:11 +0000</pubDate>
		<guid isPermaLink="false">http://jonfuller.codingtomusic.com/2008/12/11/static-reflection-method-guards/#comment-269</guid>
		<description>I find this concept interesting, and wonder if it can be taken one step further. Instead of passing in a lambda of the parameter, is there a way to pass in a reference to the current function&#039;s param array, and validate them?</description>
		<content:encoded><![CDATA[<p>I find this concept interesting, and wonder if it can be taken one step further. Instead of passing in a lambda of the parameter, is there a way to pass in a reference to the current function&#8217;s param array, and validate them?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Elegant, appealing parameter validation syntax in C# 3.0 &#171; Blog of Charlie Flowers in Atlanta</title>
		<link>http://jonfuller.codingtomusic.com/2008/12/11/static-reflection-method-guards/comment-page-1/#comment-233</link>
		<dc:creator>Elegant, appealing parameter validation syntax in C# 3.0 &#171; Blog of Charlie Flowers in Atlanta</dc:creator>
		<pubDate>Thu, 02 Apr 2009 03:25:38 +0000</pubDate>
		<guid isPermaLink="false">http://jonfuller.codingtomusic.com/2008/12/11/static-reflection-method-guards/#comment-233</guid>
		<description>[...] Elegant, appealing parameter validation syntax in C#&#160;3.0 Filed under: Uncategorized &#8212; charlieflowers @ 7:21 am   This is a VERY cool trick that leads to much improved syntax for parameter validation in C# 3.0. (Kudos to Jon Fuller). [...]</description>
		<content:encoded><![CDATA[<p>[...] Elegant, appealing parameter validation syntax in C#&nbsp;3.0 Filed under: Uncategorized &#8212; charlieflowers @ 7:21 am   This is a VERY cool trick that leads to much improved syntax for parameter validation in C# 3.0. (Kudos to Jon Fuller). [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Charlie Flowers</title>
		<link>http://jonfuller.codingtomusic.com/2008/12/11/static-reflection-method-guards/comment-page-1/#comment-232</link>
		<dc:creator>Charlie Flowers</dc:creator>
		<pubDate>Thu, 02 Apr 2009 03:20:15 +0000</pubDate>
		<guid isPermaLink="false">http://jonfuller.codingtomusic.com/2008/12/11/static-reflection-method-guards/#comment-232</guid>
		<description>Jon, I love this! I wanted exactly this, but didn&#039;t expect it to be possible in C#. Thanks. I blogged about this here: http://charlieflowers.wordpress.com/2009/04/01/elegant-appealing-parameter-validation-syntax-in-c-30/?preview=true&amp;preview_id=33&amp;preview_nonce=ac886be15c</description>
		<content:encoded><![CDATA[<p>Jon, I love this! I wanted exactly this, but didn&#8217;t expect it to be possible in C#. Thanks. I blogged about this here: <a href="http://charlieflowers.wordpress.com/2009/04/01/elegant-appealing-parameter-validation-syntax-in-c-30/?preview=true&amp;preview_id=33&amp;preview_nonce=ac886be15c" rel="nofollow">http://charlieflowers.wordpress.com/2009/04/01/elegant-appealing-parameter-validation-syntax-in-c-30/?preview=true&amp;preview_id=33&amp;preview_nonce=ac886be15c</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jacob Stanley</title>
		<link>http://jonfuller.codingtomusic.com/2008/12/11/static-reflection-method-guards/comment-page-1/#comment-189</link>
		<dc:creator>Jacob Stanley</dc:creator>
		<pubDate>Sun, 08 Mar 2009 08:16:16 +0000</pubDate>
		<guid isPermaLink="false">http://jonfuller.codingtomusic.com/2008/12/11/static-reflection-method-guards/#comment-189</guid>
		<description>You should check out the Lokad shared libraries. They use Func and some IL digging instead of Expression&lt;Func&gt;. So it doesn&#039;t require the extra compilation to evaluation the argument.

Here&#039;s the post explaining how it works: http://abdullin.com/journal/2008/12/19/how-to-get-parameter-name-and-argument-value-from-c-lambda-v.html</description>
		<content:encoded><![CDATA[<p>You should check out the Lokad shared libraries. They use Func and some IL digging instead of Expression&lt;Func&gt;. So it doesn&#8217;t require the extra compilation to evaluation the argument.</p>
<p>Here&#8217;s the post explaining how it works: <a href="http://abdullin.com/journal/2008/12/19/how-to-get-parameter-name-and-argument-value-from-c-lambda-v.html" rel="nofollow">http://abdullin.com/journal/2008/12/19/how-to-get-parameter-name-and-argument-value-from-c-lambda-v.html</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Justice</title>
		<link>http://jonfuller.codingtomusic.com/2008/12/11/static-reflection-method-guards/comment-page-1/#comment-169</link>
		<dc:creator>Justice</dc:creator>
		<pubDate>Tue, 24 Feb 2009 13:32:33 +0000</pubDate>
		<guid isPermaLink="false">http://jonfuller.codingtomusic.com/2008/12/11/static-reflection-method-guards/#comment-169</guid>
		<description>Well played with the Guard Method.  Do you take a performance hit each time the method is executed do to the expression needing to figure out the Name of the member?  Is there a significant change in performance between passing in the name and the value?  Very clever :)!</description>
		<content:encoded><![CDATA[<p>Well played with the Guard Method.  Do you take a performance hit each time the method is executed do to the expression needing to figure out the Name of the member?  Is there a significant change in performance between passing in the name and the value?  Very clever <img src='http://jonfuller.codingtomusic.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> !</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Static Reflection: Say What? - Brownie Points</title>
		<link>http://jonfuller.codingtomusic.com/2008/12/11/static-reflection-method-guards/comment-page-1/#comment-166</link>
		<dc:creator>Static Reflection: Say What? - Brownie Points</dc:creator>
		<pubDate>Mon, 23 Feb 2009 18:26:59 +0000</pubDate>
		<guid isPermaLink="false">http://jonfuller.codingtomusic.com/2008/12/11/static-reflection-method-guards/#comment-166</guid>
		<description>[...] for firing an INotifyPropertyChanged.PropertyChanged event. My colleague, Jon Fuller, showed me his code for Method Guards and my first comment was that this would be a great tool for implementing INotifyPropertyChanged. [...]</description>
		<content:encoded><![CDATA[<p>[...] for firing an INotifyPropertyChanged.PropertyChanged event. My colleague, Jon Fuller, showed me his code for Method Guards and my first comment was that this would be a great tool for implementing INotifyPropertyChanged. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: xan</title>
		<link>http://jonfuller.codingtomusic.com/2008/12/11/static-reflection-method-guards/comment-page-1/#comment-159</link>
		<dc:creator>xan</dc:creator>
		<pubDate>Tue, 27 Jan 2009 11:29:20 +0000</pubDate>
		<guid isPermaLink="false">http://jonfuller.codingtomusic.com/2008/12/11/static-reflection-method-guards/#comment-159</guid>
		<description>Good point well made! I apologise for the tone of my comment - rereading it, it is much more aggressive than I intended! Thanks for your interesting response.

Cheers,

xan</description>
		<content:encoded><![CDATA[<p>Good point well made! I apologise for the tone of my comment &#8211; rereading it, it is much more aggressive than I intended! Thanks for your interesting response.</p>
<p>Cheers,</p>
<p>xan</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jon</title>
		<link>http://jonfuller.codingtomusic.com/2008/12/11/static-reflection-method-guards/comment-page-1/#comment-158</link>
		<dc:creator>jon</dc:creator>
		<pubDate>Thu, 22 Jan 2009 19:12:54 +0000</pubDate>
		<guid isPermaLink="false">http://jonfuller.codingtomusic.com/2008/12/11/static-reflection-method-guards/#comment-158</guid>
		<description>While I agree that nasty compile statement is a bit smelly, its only in your guard class, and not sprinkled throughout your application code.

Also, while there is something to be said for the simplicity of your Validator class, it doesn&#039;t solve the issue I&#039;m after.  Your &quot;throw new ArgumentNullException(item);&quot; gives no context as to which argument was null.  In fact, the thing you&#039;re passing into that constructor, is null itself (which will be less than helpful when debugging/testing).  My solution provides you with the parameter name (which is what that constructor argument is supposed to be anyways, not the actual value, which in this case is always null, by definition).

Thanks for the feedback!</description>
		<content:encoded><![CDATA[<p>While I agree that nasty compile statement is a bit smelly, its only in your guard class, and not sprinkled throughout your application code.</p>
<p>Also, while there is something to be said for the simplicity of your Validator class, it doesn&#8217;t solve the issue I&#8217;m after.  Your &#8220;throw new ArgumentNullException(item);&#8221; gives no context as to which argument was null.  In fact, the thing you&#8217;re passing into that constructor, is null itself (which will be less than helpful when debugging/testing).  My solution provides you with the parameter name (which is what that constructor argument is supposed to be anyways, not the actual value, which in this case is always null, by definition).</p>
<p>Thanks for the feedback!</p>
]]></content:encoded>
	</item>
</channel>
</rss>
