<?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: Dealing with parameters in expressions and strongly-typed reflection</title>
	<atom:link href="http://lostechies.com/jimmybogard/2008/11/25/dealing-with-parameters-in-expressions-and-strongly-typed-reflection/feed/" rel="self" type="application/rss+xml" />
	<link>http://lostechies.com/jimmybogard/2008/11/25/dealing-with-parameters-in-expressions-and-strongly-typed-reflection/</link>
	<description>Strong opinions, weakly held</description>
	<lastBuildDate>Sun, 19 May 2013 03:22:18 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4.2</generator>
	<item>
		<title>By: bogardj</title>
		<link>http://lostechies.com/jimmybogard/2008/11/25/dealing-with-parameters-in-expressions-and-strongly-typed-reflection/#comment-1067</link>
		<dc:creator>bogardj</dc:creator>
		<pubDate>Wed, 17 Dec 2008 18:12:01 +0000</pubDate>
		<guid isPermaLink="false">/blogs/jimmy_bogard/archive/2008/11/24/dealing-with-parameters-in-expressions-and-strongly-typed-reflection.aspx#comment-1067</guid>
		<description>@Andy

I like the right part, but I wish the compiler would just...figure out the left part.  We&#039;ve just ignored it for now, accepting that no matter what we do, it&#039;ll be ugly.  Just trying to find the least ugly way...</description>
		<content:encoded><![CDATA[<p>@Andy</p>
<p>I like the right part, but I wish the compiler would just&#8230;figure out the left part.  We&#8217;ve just ignored it for now, accepting that no matter what we do, it&#8217;ll be ugly.  Just trying to find the least ugly way&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andy Alm</title>
		<link>http://lostechies.com/jimmybogard/2008/11/25/dealing-with-parameters-in-expressions-and-strongly-typed-reflection/#comment-1066</link>
		<dc:creator>Andy Alm</dc:creator>
		<pubDate>Wed, 17 Dec 2008 16:50:01 +0000</pubDate>
		<guid isPermaLink="false">/blogs/jimmy_bogard/archive/2008/11/24/dealing-with-parameters-in-expressions-and-strongly-typed-reflection.aspx#comment-1066</guid>
		<description>In order to not specify the parameters of the method, could you do something like this:

Expr.Method&lt;SomeClass,Func&lt;string,string,int&gt;&gt;(o =&gt; o.SomeMethod);

Given all the generic parameters you have to specify, that may not be any better.  Just thought I would throw that out there.  I did a little test and it seemed to work.  Here is the code:

public static class Expr
	{
		public static string Method&lt;TDelegate&gt;(Expression&lt;Func&lt;TDelegate&gt;&gt; methodExpression)
			where TDelegate : ICloneable,ISerializable //you cannot limit a generic parameter to be a Delegate, but this gets us closer.
		{
			return GetMethodName((UnaryExpression)methodExpression.Body);
		}

		public static string Method&lt;TObject,TDelegate&gt;(Expression&lt;Func&lt;TObject,TDelegate&gt;&gt; methodExpression)
		{
			return GetMethodName((UnaryExpression) methodExpression.Body);
		}

		private static string GetMethodName(UnaryExpression unaryExpression)
		{
			var methodCallExpression = (MethodCallExpression)unaryExpression.Operand;
			var constantExpression = (ConstantExpression)methodCallExpression.Arguments[2];
			var method = (MethodInfo)constantExpression.Value;

			return method.Name;
		}
	}

</description>
		<content:encoded><![CDATA[<p>In order to not specify the parameters of the method, could you do something like this:</p>
<p>Expr.Method<someclass ,Func<string,string,int>>(o => o.SomeMethod);</p>
<p>Given all the generic parameters you have to specify, that may not be any better.  Just thought I would throw that out there.  I did a little test and it seemed to work.  Here is the code:</p>
<p>public static class Expr<br />
	{<br />
		public static string Method
<tdelegate>(Expression<func <TDelegate>> methodExpression)<br />
			where TDelegate : ICloneable,ISerializable //you cannot limit a generic parameter to be a Delegate, but this gets us closer.<br />
		{<br />
			return GetMethodName((UnaryExpression)methodExpression.Body);<br />
		}</p>
<p>		public static string Method<tobject ,TDelegate>(Expression<func <TObject,TDelegate>> methodExpression)<br />
		{<br />
			return GetMethodName((UnaryExpression) methodExpression.Body);<br />
		}</p>
<p>		private static string GetMethodName(UnaryExpression unaryExpression)<br />
		{<br />
			var methodCallExpression = (MethodCallExpression)unaryExpression.Operand;<br />
			var constantExpression = (ConstantExpression)methodCallExpression.Arguments[2];<br />
			var method = (MethodInfo)constantExpression.Value;</p>
<p>			return method.Name;<br />
		}<br />
	}</p>
<p></func></tobject></func></tdelegate></someclass></p>
]]></content:encoded>
	</item>
</channel>
</rss>
