<?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: Introduction to static reflection</title>
	<atom:link href="http://jagregory.com/writings/introduction-to-static-reflection/feed/" rel="self" type="application/rss+xml" />
	<link>http://jagregory.com/writings/introduction-to-static-reflection/</link>
	<description>Monkeying with the code</description>
	<lastBuildDate>Thu, 04 Aug 2011 15:17:48 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
	<item>
		<title>By: MVP, ohhh boy! Again? &#171; Technical &#34;craftsmanship&#34;</title>
		<link>http://jagregory.com/writings/introduction-to-static-reflection/comment-page-1/#comment-51337</link>
		<dc:creator>MVP, ohhh boy! Again? &#171; Technical &#34;craftsmanship&#34;</dc:creator>
		<pubDate>Fri, 19 Mar 2010 18:49:31 +0000</pubDate>
		<guid isPermaLink="false">http://blog.jagregory.com/?p=232#comment-51337</guid>
		<description>[...] Model and View. But we are doing winforms on .net 2.0. You don’t have lambda expressions to do static reflection (for INotifyPropertyChanged implementation). Instead of mapping specific fields from Model to View [...]</description>
		<content:encoded><![CDATA[<p>[...] Model and View. But we are doing winforms on .net 2.0. You don’t have lambda expressions to do static reflection (for INotifyPropertyChanged implementation). Instead of mapping specific fields from Model to View [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mark&#8217;s Testblog &#187; Blog Archive &#187; Strongly typed commandline arguments - &#8230;for these are testing times, indeed.</title>
		<link>http://jagregory.com/writings/introduction-to-static-reflection/comment-page-1/#comment-38138</link>
		<dc:creator>Mark&#8217;s Testblog &#187; Blog Archive &#187; Strongly typed commandline arguments - &#8230;for these are testing times, indeed.</dc:creator>
		<pubDate>Mon, 28 Sep 2009 01:19:31 +0000</pubDate>
		<guid isPermaLink="false">http://blog.jagregory.com/?p=232#comment-38138</guid>
		<description>[...] read quite a bit about Static Reflection and found it to be very appealing, but I hadn&#8217;t used it&#8230; until now!  Please have a [...]</description>
		<content:encoded><![CDATA[<p>[...] read quite a bit about Static Reflection and found it to be very appealing, but I hadn&#8217;t used it&#8230; until now!  Please have a [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: DotNetIsFun</title>
		<link>http://jagregory.com/writings/introduction-to-static-reflection/comment-page-1/#comment-29630</link>
		<dc:creator>DotNetIsFun</dc:creator>
		<pubDate>Wed, 29 Jul 2009 12:32:43 +0000</pubDate>
		<guid isPermaLink="false">http://blog.jagregory.com/?p=232#comment-29630</guid>
		<description>Looks like it can&#039;t be done without reflection, which is what I wanted to avoid. I&#039;ve tried to use Expression.Field(...) to get the MemberExpression. It has 2 overloads:

1) Expression.Field(Expression ex, string name); &quot;ex&quot; is the expression which should be null (see my previous post); so I should pass null and the name of the field; well it doesn&#039;t work - throws exception: &quot;ex&quot; can&#039;t be null.

2) Expression.Field(Expression ex, FieldInfo field). Using this I pass null for ex and the FieldInfo for my field, which I get using reflection;

So I figured: when the member expression refers to a static member, its Expression property is always null. This means the only info regarding the target&#039;s declaring type is kept in the Member property. 

In a more general context, there is no way to create an expression to access a static member. Please tell me that I&#039;m wrong...</description>
		<content:encoded><![CDATA[<p>Looks like it can&#8217;t be done without reflection, which is what I wanted to avoid. I&#8217;ve tried to use Expression.Field(&#8230;) to get the MemberExpression. It has 2 overloads:</p>
<p>1) Expression.Field(Expression ex, string name); &#8220;ex&#8221; is the expression which should be null (see my previous post); so I should pass null and the name of the field; well it doesn&#8217;t work &#8211; throws exception: &#8220;ex&#8221; can&#8217;t be null.</p>
<p>2) Expression.Field(Expression ex, FieldInfo field). Using this I pass null for ex and the FieldInfo for my field, which I get using reflection;</p>
<p>So I figured: when the member expression refers to a static member, its Expression property is always null. This means the only info regarding the target&#8217;s declaring type is kept in the Member property. </p>
<p>In a more general context, there is no way to create an expression to access a static member. Please tell me that I&#8217;m wrong&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: James Gregory</title>
		<link>http://jagregory.com/writings/introduction-to-static-reflection/comment-page-1/#comment-29606</link>
		<dc:creator>James Gregory</dc:creator>
		<pubDate>Wed, 29 Jul 2009 07:40:05 +0000</pubDate>
		<guid isPermaLink="false">http://blog.jagregory.com/?p=232#comment-29606</guid>
		<description>You should just need to build up the Expression objects to match the structure you analysed; if it&#039;s possible to be given that structure, then it&#039;s possible to create it.</description>
		<content:encoded><![CDATA[<p>You should just need to build up the Expression objects to match the structure you analysed; if it&#8217;s possible to be given that structure, then it&#8217;s possible to create it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: DotNetIsFun</title>
		<link>http://jagregory.com/writings/introduction-to-static-reflection/comment-page-1/#comment-29603</link>
		<dc:creator>DotNetIsFun</dc:creator>
		<pubDate>Wed, 29 Jul 2009 06:33:15 +0000</pubDate>
		<guid isPermaLink="false">http://blog.jagregory.com/?p=232#comment-29603</guid>
		<description>Is there any way to access a static member using Expressions? E.g.

class SomeClass {
    public static readonly int Field = 6;
}

Say there&#039;s some method GetStaticField(Expression&lt;Func&gt; fieldExpression);
then I would call
GetStaticField(() =&gt; SomeClass.Field); analyzing this expression yields eventually a MemberExpression whose Expression is NULL and whose member is the FieldInfo corresponding to SomeClass.Field. 

What I need to do (and can&#039;t figure out how) is to build that member expression from scratch, knowing only the field&#039;s declaring type (== typeof(SomeClass)) and its name (== &quot;Field&quot;)</description>
		<content:encoded><![CDATA[<p>Is there any way to access a static member using Expressions? E.g.</p>
<p>class SomeClass {<br />
    public static readonly int Field = 6;<br />
}</p>
<p>Say there&#8217;s some method GetStaticField(Expression&lt;Func&gt; fieldExpression);<br />
then I would call<br />
GetStaticField(() =&gt; SomeClass.Field); analyzing this expression yields eventually a MemberExpression whose Expression is NULL and whose member is the FieldInfo corresponding to SomeClass.Field. </p>
<p>What I need to do (and can&#8217;t figure out how) is to build that member expression from scratch, knowing only the field&#8217;s declaring type (== typeof(SomeClass)) and its name (== &#8220;Field&#8221;)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: James Gregory</title>
		<link>http://jagregory.com/writings/introduction-to-static-reflection/comment-page-1/#comment-15436</link>
		<dc:creator>James Gregory</dc:creator>
		<pubDate>Tue, 27 Jan 2009 13:42:00 +0000</pubDate>
		<guid isPermaLink="false">http://blog.jagregory.com/?p=232#comment-15436</guid>
		<description>You can do both, you can use the expression API to interrogate the structure of the lambda, and then evaluate it for it&#039;s value.

&lt;pre name=&quot;code&quot; class=&quot;c-sharp&quot;&gt;
Expression&lt;Func&lt;Customer, object&gt;&gt; exp = c =&gt; c.Name;

// get PropertyInfo (for .Name)
var property = exp.Body as PropertyInfo;

// evaluate expression for value of Name, passing in the model object
var value = exp(ViewData.Model);
&lt;/pre&gt;

Something along those lines...</description>
		<content:encoded><![CDATA[<p>You can do both, you can use the expression API to interrogate the structure of the lambda, and then evaluate it for it&#8217;s value.</p>
<pre name="code" class="c-sharp">
Expression&lt;Func&lt;Customer, object&gt;&gt; exp = c =&gt; c.Name;

// get PropertyInfo (for .Name)
var property = exp.Body as PropertyInfo;

// evaluate expression for value of Name, passing in the model object
var value = exp(ViewData.Model);
</pre>
<p>Something along those lines&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steve</title>
		<link>http://jagregory.com/writings/introduction-to-static-reflection/comment-page-1/#comment-15435</link>
		<dc:creator>Steve</dc:creator>
		<pubDate>Tue, 27 Jan 2009 13:35:53 +0000</pubDate>
		<guid isPermaLink="false">http://blog.jagregory.com/?p=232#comment-15435</guid>
		<description>Ok, that makes sense.

Here is my stupid question then:

What if I wanted to get the value?

ie. suspose I wanted to create a new asp.net mvc textbox control that didn&#039;t use &#039;magic strings&#039; anymore.

ie. instead of:
Html.TextBox(&quot;Name&quot;, ViewData.Model.Name) where ViewData.Model is the &#039;Customer&#039;

Instead I&#039;d rather have a 
Html.TextBox(c =&gt; c.Name) (or something like this)- that 

1. uses reflection to set the textbox id to &#039;name&#039; and 
2. also sets the value

I bring this up, after seeing the code in MvcContrib, much of it is using lamba expressions.

Thanks again for the post, very informative - I&#039;ll go check out the source of the links you provided to help understand this more.</description>
		<content:encoded><![CDATA[<p>Ok, that makes sense.</p>
<p>Here is my stupid question then:</p>
<p>What if I wanted to get the value?</p>
<p>ie. suspose I wanted to create a new asp.net mvc textbox control that didn&#8217;t use &#8216;magic strings&#8217; anymore.</p>
<p>ie. instead of:<br />
Html.TextBox(&#8220;Name&#8221;, ViewData.Model.Name) where ViewData.Model is the &#8216;Customer&#8217;</p>
<p>Instead I&#8217;d rather have a<br />
Html.TextBox(c =&gt; c.Name) (or something like this)- that </p>
<p>1. uses reflection to set the textbox id to &#8216;name&#8217; and<br />
2. also sets the value</p>
<p>I bring this up, after seeing the code in MvcContrib, much of it is using lamba expressions.</p>
<p>Thanks again for the post, very informative &#8211; I&#8217;ll go check out the source of the links you provided to help understand this more.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: James Gregory</title>
		<link>http://jagregory.com/writings/introduction-to-static-reflection/comment-page-1/#comment-15432</link>
		<dc:creator>James Gregory</dc:creator>
		<pubDate>Tue, 27 Jan 2009 10:10:17 +0000</pubDate>
		<guid isPermaLink="false">http://blog.jagregory.com/?p=232#comment-15432</guid>
		<description>Traditionally, when you receive a delegate you&#039;d plan to execute it at some point, and use it&#039;s value in your application; you&#039;re interested in the return value of that delegate, not where that value comes from. However, with static reflection you don&#039;t actually care what value is returned, just where it comes from!

Expression is a collection of classes that describe how methods are written, you can use it to interrogate a method to find any declarations, assignments, and method accesses (and more). In the same way that the reflection API is a programatic way of accessing class definitions, rather than objects; Expression is a way of accessing the contents of a method declaration, rather than the result of the evaluation of that method.

Clear as mud? :)</description>
		<content:encoded><![CDATA[<p>Traditionally, when you receive a delegate you&#8217;d plan to execute it at some point, and use it&#8217;s value in your application; you&#8217;re interested in the return value of that delegate, not where that value comes from. However, with static reflection you don&#8217;t actually care what value is returned, just where it comes from!</p>
<p>Expression is a collection of classes that describe how methods are written, you can use it to interrogate a method to find any declarations, assignments, and method accesses (and more). In the same way that the reflection API is a programatic way of accessing class definitions, rather than objects; Expression is a way of accessing the contents of a method declaration, rather than the result of the evaluation of that method.</p>
<p>Clear as mud? <img src='http://jagregory.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steve</title>
		<link>http://jagregory.com/writings/introduction-to-static-reflection/comment-page-1/#comment-15421</link>
		<dc:creator>Steve</dc:creator>
		<pubDate>Tue, 27 Jan 2009 01:28:29 +0000</pubDate>
		<guid isPermaLink="false">http://blog.jagregory.com/?p=232#comment-15421</guid>
		<description>Thank you for explaining this.

&quot;we don’t actually care about the value that’s returned! In-fact, we don’t even evaluate this expression at all.&quot;

Please explain more  :)  Makes the head swim a bit.</description>
		<content:encoded><![CDATA[<p>Thank you for explaining this.</p>
<p>&#8220;we don’t actually care about the value that’s returned! In-fact, we don’t even evaluate this expression at all.&#8221;</p>
<p>Please explain more  <img src='http://jagregory.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />   Makes the head swim a bit.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
