<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: Linq Expressions &#8211; From and to delegates</title>
	<atom:link href="http://rogeralsing.com/2009/03/23/linq-expressions-from-and-to-delegates/feed/" rel="self" type="application/rss+xml" />
	<link>http://rogeralsing.com/2009/03/23/linq-expressions-from-and-to-delegates/</link>
	<description></description>
	<lastBuildDate>Sat, 28 Jan 2012 14:35:30 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: mbarbac</title>
		<link>http://rogeralsing.com/2009/03/23/linq-expressions-from-and-to-delegates/#comment-1613</link>
		<dc:creator><![CDATA[mbarbac]]></dc:creator>
		<pubDate>Tue, 20 Apr 2010 19:35:04 +0000</pubDate>
		<guid isPermaLink="false">http://rogeralsing.com/?p=579#comment-1613</guid>
		<description><![CDATA[@Keith:
Thanks.
And agree! The CLR/DLR should provide a full-powered conversion utility. But since it happens, at least we have the solution I present in the article that is usefull for LINQ-like scenarios, and maybe others.]]></description>
		<content:encoded><![CDATA[<p>@Keith:<br />
Thanks.<br />
And agree! The CLR/DLR should provide a full-powered conversion utility. But since it happens, at least we have the solution I present in the article that is usefull for LINQ-like scenarios, and maybe others.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Keith J. Farmer</title>
		<link>http://rogeralsing.com/2009/03/23/linq-expressions-from-and-to-delegates/#comment-1612</link>
		<dc:creator><![CDATA[Keith J. Farmer]]></dc:creator>
		<pubDate>Tue, 20 Apr 2010 07:04:39 +0000</pubDate>
		<guid isPermaLink="false">http://rogeralsing.com/?p=579#comment-1612</guid>
		<description><![CDATA[@mbarbac --

Indeed, note my comments from 3 Feb...

And boy is it a pain in the butt.  I&#039;d rather they just allow us to create Expression&lt;Func&gt; (which was my motivation).  I can come up with reasons why they can&#039;t, but I don&#039;t have to like the situation.

Congratulations on actually writing an article about it. :)]]></description>
		<content:encoded><![CDATA[<p>@mbarbac &#8211;</p>
<p>Indeed, note my comments from 3 Feb&#8230;</p>
<p>And boy is it a pain in the butt.  I&#8217;d rather they just allow us to create Expression&lt;Func&gt; (which was my motivation).  I can come up with reasons why they can&#8217;t, but I don&#8217;t have to like the situation.</p>
<p>Congratulations on actually writing an article about it. :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mbarbac</title>
		<link>http://rogeralsing.com/2009/03/23/linq-expressions-from-and-to-delegates/#comment-1610</link>
		<dc:creator><![CDATA[mbarbac]]></dc:creator>
		<pubDate>Mon, 19 Apr 2010 19:39:38 +0000</pubDate>
		<guid isPermaLink="false">http://rogeralsing.com/?p=579#comment-1610</guid>
		<description><![CDATA[Yes, it can be done. There is a way to convert a delegate into an expression tree, by means of using the power of C# 4.0 dynamic capabilities to intercept in real-time the dispatch of the calls, and tracking them.
I posted an article at this regards at: http://www.codeproject.com/KB/dotnet/delegates_into_expression.aspx
Cheers, M]]></description>
		<content:encoded><![CDATA[<p>Yes, it can be done. There is a way to convert a delegate into an expression tree, by means of using the power of C# 4.0 dynamic capabilities to intercept in real-time the dispatch of the calls, and tracking them.<br />
I posted an article at this regards at: <a href="http://www.codeproject.com/KB/dotnet/delegates_into_expression.aspx" rel="nofollow">http://www.codeproject.com/KB/dotnet/delegates_into_expression.aspx</a><br />
Cheers, M</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Keith J. Farmer</title>
		<link>http://rogeralsing.com/2009/03/23/linq-expressions-from-and-to-delegates/#comment-1584</link>
		<dc:creator><![CDATA[Keith J. Farmer]]></dc:creator>
		<pubDate>Thu, 01 Apr 2010 18:37:17 +0000</pubDate>
		<guid isPermaLink="false">http://rogeralsing.com/?p=579#comment-1584</guid>
		<description><![CDATA[@Roger:

&quot;Writing a decompiler is a bit too drastic to most of us.&quot;

Drastic, perhaps, but that&#039;s precisely what happenned immediately after PDC05, if you were hanging out on the LINQ Forums. (I forget whether you were or not.) :)

Personally, I would rather just have everything as an expression tree that were invocable.  Not difficult.  Can be done in a couple lines of code.  Would be nice if it (like many things) were OOB.]]></description>
		<content:encoded><![CDATA[<p>@Roger:</p>
<p>&#8220;Writing a decompiler is a bit too drastic to most of us.&#8221;</p>
<p>Drastic, perhaps, but that&#8217;s precisely what happenned immediately after PDC05, if you were hanging out on the LINQ Forums. (I forget whether you were or not.) :)</p>
<p>Personally, I would rather just have everything as an expression tree that were invocable.  Not difficult.  Can be done in a couple lines of code.  Would be nice if it (like many things) were OOB.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Roger Alsing</title>
		<link>http://rogeralsing.com/2009/03/23/linq-expressions-from-and-to-delegates/#comment-1581</link>
		<dc:creator><![CDATA[Roger Alsing]]></dc:creator>
		<pubDate>Thu, 01 Apr 2010 11:57:11 +0000</pubDate>
		<guid isPermaLink="false">http://rogeralsing.com/?p=579#comment-1581</guid>
		<description><![CDATA[@Onur Gamus

From the site you linked:
&quot;&quot;&quot; There’s no builtin feature to do that, it’s not a straightforward process. You basically have to decompile the compiled method.  &quot;&quot;&quot;&quot;

Writing a decompiler is a bit too drastic to most of us.
Just as splitting atoms is ;-)]]></description>
		<content:encoded><![CDATA[<p>@Onur Gamus</p>
<p>From the site you linked:<br />
&#8220;&#8221;" There’s no builtin feature to do that, it’s not a straightforward process. You basically have to decompile the compiled method.  &#8220;&#8221;"&#8221;</p>
<p>Writing a decompiler is a bit too drastic to most of us.<br />
Just as splitting atoms is ;-)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Onur Gumus</title>
		<link>http://rogeralsing.com/2009/03/23/linq-expressions-from-and-to-delegates/#comment-1579</link>
		<dc:creator><![CDATA[Onur Gumus]]></dc:creator>
		<pubDate>Thu, 01 Apr 2010 09:01:58 +0000</pubDate>
		<guid isPermaLink="false">http://rogeralsing.com/?p=579#comment-1579</guid>
		<description><![CDATA[&quot;This is not really possible, you can never cast or convert an existing delegate into an expression tree.&quot; Yeah and atoms weren&#039;t splittable ya remember ? Then check this :

http://evain.net/blog/articles/2009/04/22/converting-delegates-to-expression-trees]]></description>
		<content:encoded><![CDATA[<p>&#8220;This is not really possible, you can never cast or convert an existing delegate into an expression tree.&#8221; Yeah and atoms weren&#8217;t splittable ya remember ? Then check this :</p>
<p><a href="http://evain.net/blog/articles/2009/04/22/converting-delegates-to-expression-trees" rel="nofollow">http://evain.net/blog/articles/2009/04/22/converting-delegates-to-expression-trees</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Keith Farmer</title>
		<link>http://rogeralsing.com/2009/03/23/linq-expressions-from-and-to-delegates/#comment-1465</link>
		<dc:creator><![CDATA[Keith Farmer]]></dc:creator>
		<pubDate>Wed, 03 Feb 2010 21:17:34 +0000</pubDate>
		<guid isPermaLink="false">http://rogeralsing.com/?p=579#comment-1465</guid>
		<description><![CDATA[Of course, you could use pass dynamic objects through a delegate and record what calls are made, and try to make some sense out of that.  It works (I&#039;ve done so).  But it&#039;s ugly.]]></description>
		<content:encoded><![CDATA[<p>Of course, you could use pass dynamic objects through a delegate and record what calls are made, and try to make some sense out of that.  It works (I&#8217;ve done so).  But it&#8217;s ugly.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brad Stitt</title>
		<link>http://rogeralsing.com/2009/03/23/linq-expressions-from-and-to-delegates/#comment-1464</link>
		<dc:creator><![CDATA[Brad Stitt]]></dc:creator>
		<pubDate>Wed, 03 Feb 2010 20:00:33 +0000</pubDate>
		<guid isPermaLink="false">http://rogeralsing.com/?p=579#comment-1464</guid>
		<description><![CDATA[I use this for error logging which uses the logic previously posted. this creates a string representation of the method with parameter values.

example usage: ToString(() =&gt; somemethod(someparameter));

string ToString(Expression&lt;Action&gt; action)
        {
MethodCallExpression call = action.Body as MethodCallExpression;
            if (call == null) throw new ArgumentException();

            StringBuilder message = new StringBuilder(call.Method.Name + &quot;(&quot;);

            foreach (MemberExpression member in call.Arguments)
            {
                object paramvalue = (member.Expression as ConstantExpression).Value;
                FieldInfo field = paramvalue.GetType().GetField(member.Member.Name);

                object actualvalue = field.GetValue(paramvalue);
                if (actualvalue is string)
                {
                    actualvalue = &quot;\&quot;&quot; + actualvalue + &quot;\&quot;&quot;;
                }

                message.Append(&quot;(&quot; + field.FieldType.ToString() + &quot;) &quot; + field.Name + &quot; = &quot; + actualvalue.ToString() + &quot;, &quot;);
            }

            message.Remove(message.Length - 2, 2);
            message.Append(&quot;)&quot;);

            return message.ToString();
}]]></description>
		<content:encoded><![CDATA[<p>I use this for error logging which uses the logic previously posted. this creates a string representation of the method with parameter values.</p>
<p>example usage: ToString(() =&gt; somemethod(someparameter));</p>
<p>string ToString(Expression&lt;Action&gt; action)<br />
        {<br />
MethodCallExpression call = action.Body as MethodCallExpression;<br />
            if (call == null) throw new ArgumentException();</p>
<p>            StringBuilder message = new StringBuilder(call.Method.Name + &#8220;(&#8220;);</p>
<p>            foreach (MemberExpression member in call.Arguments)<br />
            {<br />
                object paramvalue = (member.Expression as ConstantExpression).Value;<br />
                FieldInfo field = paramvalue.GetType().GetField(member.Member.Name);</p>
<p>                object actualvalue = field.GetValue(paramvalue);<br />
                if (actualvalue is string)<br />
                {<br />
                    actualvalue = &#8220;\&#8221;" + actualvalue + &#8220;\&#8221;";<br />
                }</p>
<p>                message.Append(&#8220;(&#8221; + field.FieldType.ToString() + &#8220;) &#8221; + field.Name + &#8221; = &#8221; + actualvalue.ToString() + &#8220;, &#8220;);<br />
            }</p>
<p>            message.Remove(message.Length &#8211; 2, 2);<br />
            message.Append(&#8220;)&#8221;);</p>
<p>            return message.ToString();<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brad Stitt</title>
		<link>http://rogeralsing.com/2009/03/23/linq-expressions-from-and-to-delegates/#comment-1463</link>
		<dc:creator><![CDATA[Brad Stitt]]></dc:creator>
		<pubDate>Wed, 03 Feb 2010 19:54:40 +0000</pubDate>
		<guid isPermaLink="false">http://rogeralsing.com/?p=579#comment-1463</guid>
		<description><![CDATA[Func&lt;string, int, TestClass, int&gt; methoddelegate = this.testmethod;
            Expression&lt;Action&gt; action = () =&gt; methoddelegate(&quot;1&quot;, 2, new TestClass());
            MethodCallExpression method = action.Body as MethodCallExpression;

reposted to fix invalid characters]]></description>
		<content:encoded><![CDATA[<p>Func&lt;string, int, TestClass, int&gt; methoddelegate = this.testmethod;<br />
            Expression&lt;Action&gt; action = () =&gt; methoddelegate(&#8220;1&#8243;, 2, new TestClass());<br />
            MethodCallExpression method = action.Body as MethodCallExpression;</p>
<p>reposted to fix invalid characters</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brad Stitt</title>
		<link>http://rogeralsing.com/2009/03/23/linq-expressions-from-and-to-delegates/#comment-1462</link>
		<dc:creator><![CDATA[Brad Stitt]]></dc:creator>
		<pubDate>Wed, 03 Feb 2010 19:52:29 +0000</pubDate>
		<guid isPermaLink="false">http://rogeralsing.com/?p=579#comment-1462</guid>
		<description><![CDATA[Here is a quick thought:
Func methoddelegate = this.testmethod;
            Expression action = () =&gt; methoddelegate(&quot;1&quot;, 2, new TestClass());
            MethodCallExpression method = action.Body as MethodCallExpression;

based on what I know you can&#039;t get an expression tree from a delegate because it isn&#039;t an actual method call, it is just a definition. A similar situation would be to try and get the expression tree of an object, ex: Thread.]]></description>
		<content:encoded><![CDATA[<p>Here is a quick thought:<br />
Func methoddelegate = this.testmethod;<br />
            Expression action = () =&gt; methoddelegate(&#8220;1&#8243;, 2, new TestClass());<br />
            MethodCallExpression method = action.Body as MethodCallExpression;</p>
<p>based on what I know you can&#8217;t get an expression tree from a delegate because it isn&#8217;t an actual method call, it is just a definition. A similar situation would be to try and get the expression tree of an object, ex: Thread.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

