<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Getting Information About Objects, Types, and Members with Expression Trees</title><link>http://blogs.msdn.com/b/csharpfaq/archive/2010/01/06/getting-information-about-objects-types-and-members-with-expression-trees.aspx</link><description>Starting with C# 3.0 and Visual Studio 2008, you can use expression trees to get information about objects, types, and members. In this post I’m going to show some examples and explain what benefits you can get by using this technique. If you are not</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>re: Getting Information About Objects, Types, and Members with Expression Trees</title><link>http://blogs.msdn.com/b/csharpfaq/archive/2010/01/06/getting-information-about-objects-types-and-members-with-expression-trees.aspx#10306914</link><pubDate>Fri, 18 May 2012 19:26:41 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10306914</guid><dc:creator>Dave Black</dc:creator><description>&lt;p&gt;Thanks for this informative post.&lt;/p&gt;
&lt;p&gt;Do you have any idea what the performance difference is between using ExpressionTrees as mentioned above vs. Reflection?&lt;/p&gt;
&lt;p&gt;Thank you for your time.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10306914" width="1" height="1"&gt;</description></item><item><title>re: Getting Information About Objects, Types, and Members with Expression Trees</title><link>http://blogs.msdn.com/b/csharpfaq/archive/2010/01/06/getting-information-about-objects-types-and-members-with-expression-trees.aspx#10055899</link><pubDate>Mon, 30 Aug 2010 17:34:51 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10055899</guid><dc:creator>Fabrice Marguerie</dc:creator><description>&lt;p&gt;I show on my blog how I use this with INotifyPropertyChanged: &lt;a rel="nofollow" target="_new" href="http://weblogs.asp.net/fmarguerie/archive/2010/08/30/PropertyOf-INotifyPropertyChanged-PropertyChanged-strings-infoof.aspx"&gt;weblogs.asp.net/.../PropertyOf-INotifyPropertyChanged-PropertyChanged-strings-infoof.aspx&lt;/a&gt;&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10055899" width="1" height="1"&gt;</description></item><item><title>re: Getting Information About Objects, Types, and Members with Expression Trees</title><link>http://blogs.msdn.com/b/csharpfaq/archive/2010/01/06/getting-information-about-objects-types-and-members-with-expression-trees.aspx#10020396</link><pubDate>Sat, 05 Jun 2010 12:11:02 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10020396</guid><dc:creator>Oliver Hanappi</dc:creator><description>&lt;p&gt;Hi Brandon!&lt;/p&gt;
&lt;p&gt;My code is a bit more complex in order to handle more scenarios. For example I am allowing to get the name of a &amp;quot;sub-member&amp;quot; in dot notation and so on. But basically it is the same :)&lt;/p&gt;
&lt;p&gt;Oliver Hanappi&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10020396" width="1" height="1"&gt;</description></item><item><title>re: Getting Information About Objects, Types, and Members with Expression Trees</title><link>http://blogs.msdn.com/b/csharpfaq/archive/2010/01/06/getting-information-about-objects-types-and-members-with-expression-trees.aspx#9974344</link><pubDate>Sun, 07 Mar 2010 13:22:08 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9974344</guid><dc:creator>甜番薯</dc:creator><description>&lt;p&gt;I had translate this article to chinese.&lt;/p&gt;
&lt;p&gt;我已将此文章翻译成中文：&lt;/p&gt;
&lt;p&gt;&lt;a rel="nofollow" target="_new" href="http://www.cnblogs.com/tianfan/archive/2010/03/07/getting-information-about-objects-types-and-members-with-expression-trees.html"&gt;http://www.cnblogs.com/tianfan/archive/2010/03/07/getting-information-about-objects-types-and-members-with-expression-trees.html&lt;/a&gt;&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9974344" width="1" height="1"&gt;</description></item><item><title>re: Getting Information About Objects, Types, and Members with Expression Trees</title><link>http://blogs.msdn.com/b/csharpfaq/archive/2010/01/06/getting-information-about-objects-types-and-members-with-expression-trees.aspx#9963677</link><pubDate>Mon, 15 Feb 2010 16:41:30 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9963677</guid><dc:creator>Alexandra Rusina</dc:creator><description>&lt;p&gt;@Edgar&lt;/p&gt;
&lt;p&gt;I'd say this post falls more into &amp;quot;tips and tricks&amp;quot; category. It's not a guideline. And of course, expression trees (as well as reflection) is an advanced technique in general, so I personally would not recommend any novice developer to mess with it.&lt;/p&gt;
&lt;p&gt;Yes, it's not an ideal solution. But in some cases it might be more convinient than reflection. &lt;/p&gt;
&lt;p&gt;As for strongly typed reflection, I am not aware of such plans. But you are always welcome to post your suggestions at Microsfot Connect: &lt;a rel="nofollow" target="_new" href="http://connect.microsoft.com/VisualStudio"&gt;http://connect.microsoft.com/VisualStudio&lt;/a&gt;&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9963677" width="1" height="1"&gt;</description></item><item><title>re: Getting Information About Objects, Types, and Members with Expression Trees</title><link>http://blogs.msdn.com/b/csharpfaq/archive/2010/01/06/getting-information-about-objects-types-and-members-with-expression-trees.aspx#9962885</link><pubDate>Fri, 12 Feb 2010 22:08:12 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9962885</guid><dc:creator>Edgar</dc:creator><description>&lt;p&gt;On a side note I think MS should consider providing strongly typed reflection to help us solve this problem. &amp;nbsp;Let's face with the advent of WPF, and the INotifyPropertyChanged event we need to know the names of properties in our code. &amp;nbsp;Right now we either need to employ this proposed solution, which I think could confuse a lot of developers, or we need to use string constants, which need to be updated as the code changes. &amp;nbsp;Neither solution is ideal. &amp;nbsp;I think that MS should provide strongly typed reflection by overloading the class keyword. &amp;nbsp;It would look something like this:&lt;/p&gt;
&lt;p&gt;class&amp;lt;Foo&amp;gt; fooReflector = new class&amp;lt;Foo&amp;gt;();&lt;/p&gt;
&lt;p&gt;if (e.PropertyName == fooReflector.Properties.Bar.Name)&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp;//Code goes here.&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9962885" width="1" height="1"&gt;</description></item><item><title>re: Getting Information About Objects, Types, and Members with Expression Trees</title><link>http://blogs.msdn.com/b/csharpfaq/archive/2010/01/06/getting-information-about-objects-types-and-members-with-expression-trees.aspx#9962881</link><pubDate>Fri, 12 Feb 2010 22:01:45 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9962881</guid><dc:creator>Edgar</dc:creator><description>&lt;p&gt;We've been debating using this technique at my work for a while now. &amp;nbsp;Honestly I don't like it. &amp;nbsp;By using an expression tree you're changing the meaning of things. &amp;nbsp;At first glance it looks like you're passing in a lambda function that will be executed, but what you're really doing is passing in a lambda function that gets evaluated. &amp;nbsp;This is very confusing; especially for less seasoned C# developers that may not have a good grasp on lambda functions. &amp;nbsp;Additionally this technique isn't that type safe. &amp;nbsp;For example I could make the call this way: &amp;nbsp;GetName(()=&amp;gt; 1 + 2);, and that will compile. &amp;nbsp;At the end of the day I prefer a more straight forward approach; such as using constants. &amp;nbsp;Sure you need to update your constants whenever you change a property name, but once you've done that you will still enlist the compiler without creating a solution that will confuse many developers.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9962881" width="1" height="1"&gt;</description></item><item><title>re: Getting Information About Objects, Types, and Members with Expression Trees</title><link>http://blogs.msdn.com/b/csharpfaq/archive/2010/01/06/getting-information-about-objects-types-and-members-with-expression-trees.aspx#9961628</link><pubDate>Thu, 11 Feb 2010 00:38:38 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9961628</guid><dc:creator>Alexandra Rusina</dc:creator><description>&lt;p&gt;@ Corey&lt;/p&gt;
&lt;p&gt;Yes, it is not a perfect solution. And I am not aware of any plans for &amp;quot;memberof&amp;quot;. &lt;/p&gt;
&lt;p&gt;You can read Eric Lippert's post about some design complications with this feature:&lt;/p&gt;
&lt;p&gt;&lt;a rel="nofollow" target="_new" href="http://blogs.msdn.com/ericlippert/archive/2009/05/21/in-foof-we-trust-a-dialogue.aspx"&gt;http://blogs.msdn.com/ericlippert/archive/2009/05/21/in-foof-we-trust-a-dialogue.aspx&lt;/a&gt;&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9961628" width="1" height="1"&gt;</description></item><item><title>re: Getting Information About Objects, Types, and Members with Expression Trees</title><link>http://blogs.msdn.com/b/csharpfaq/archive/2010/01/06/getting-information-about-objects-types-and-members-with-expression-trees.aspx#9961450</link><pubDate>Wed, 10 Feb 2010 20:08:34 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9961450</guid><dc:creator>Corey Kosak</dc:creator><description>&lt;p&gt;This is a obviously a powerful and extremely useful technique. &amp;nbsp;However (as one can see with a tool like ildasm) it still results in a lot of (in this case needless) code being generated and expression tree node objects being allocated, and therefore is not nearly as efficient as a hypothetical operator like &amp;quot;memberof&amp;quot; could be. &amp;nbsp;Given that, do you think there is any interest from Microsoft to support memberof/infoof?&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9961450" width="1" height="1"&gt;</description></item><item><title>re: Getting Information About Objects, Types, and Members with Expression Trees</title><link>http://blogs.msdn.com/b/csharpfaq/archive/2010/01/06/getting-information-about-objects-types-and-members-with-expression-trees.aspx#9958919</link><pubDate>Fri, 05 Feb 2010 18:22:09 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9958919</guid><dc:creator>Alexandra Rusina</dc:creator><description>&lt;p&gt;@ RN&lt;/p&gt;
&lt;p&gt;Glad that you saw it yourself :-) Of course I've been talking about string literals, not about the property name in a variable.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9958919" width="1" height="1"&gt;</description></item></channel></rss>