<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Stephen Lacy &#187; System.Reflection</title>
	<atom:link href="http://www.lacy.ie/tag/system-reflection/feed" rel="self" type="application/rss+xml" />
	<link>http://www.lacy.ie</link>
	<description>Impressions as an ASP.Net Developer</description>
	<lastBuildDate>Mon, 05 Jul 2010 09:26:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Call MethodInfo.Invoke with an out parameter</title>
		<link>http://www.lacy.ie/call-methodinfo-invoke-with-an-out-parameter</link>
		<comments>http://www.lacy.ie/call-methodinfo-invoke-with-an-out-parameter#comments</comments>
		<pubDate>Fri, 21 Aug 2009 19:19:21 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[ASP.net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[System.Reflection]]></category>

		<guid isPermaLink="false">http://lacy.ie/?p=168</guid>
		<description><![CDATA[Taken from http://www.galcho.com/Blog/P&#8230; Here is how to call a method with an out parameter using MethodInfo.Invoke, in this case the out parameter is the last one (int). int parNum = 0; string parText = &#8220;99&#8243;; object[] methodParms = new object[] { parText, parNum }; MethodInfo methInfo = parNum.GetType().GetMethod(&#8220;TryParse&#8221;, new Type[] { typeof(string), typeof(int).MakeByRefType() }); methInfo.Invoke(null, [...]


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>Taken from <a href="http://www.galcho.com/Blog/PermaLink.aspx?guid=2447b6ad-83e2-45ec-8257-672c42bba78b">http://www.galcho.com/Blog/P&#8230;</a></p>
<p>Here is how to call a method with an out parameter using MethodInfo.Invoke, in this case the out parameter is the last one (int).</p>
<p>int parNum = 0;<br />
string parText = &#8220;99&#8243;;<br />
object[] methodParms = new object[] { parText, parNum };</p>
<p>MethodInfo methInfo = parNum.GetType().GetMethod(&#8220;TryParse&#8221;, new Type[] { typeof(string),<strong> </strong><strong>typeof(int).MakeByRefType()</strong> });<br />
methInfo.Invoke(null, methodParms);<br />
<strong> parNum = (int)methodParms[1];</strong><br />
Console.WriteLine(&#8220;Parsed number:{0}&#8221;, parNum);</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.lacy.ie%2Fcall-methodinfo-invoke-with-an-out-parameter&amp;linkname=Call%20MethodInfo.Invoke%20with%20an%20out%20parameter"><img src="http://www.lacy.ie/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>

<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.lacy.ie/call-methodinfo-invoke-with-an-out-parameter/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Generic Method Overloading in C#</title>
		<link>http://www.lacy.ie/generic-method-overloading-in-c</link>
		<comments>http://www.lacy.ie/generic-method-overloading-in-c#comments</comments>
		<pubDate>Tue, 17 Feb 2009 12:54:46 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[ASP.net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Overloading]]></category>
		<category><![CDATA[System.Reflection]]></category>

		<guid isPermaLink="false">http://lacy.ie/?p=94</guid>
		<description><![CDATA[Say you have an outer method: public OuterMethod(object x) { InnerMethod(x); } and an inner method with these overloads public InnerMethod(object x) { //Generic Actions } public InnerMethod(Person x) { //Person Specific Actions } public InnerMethod(Dog x) { // Dog Specific Actions } How do you make it so that when the outer method calls [...]


Related posts:<ol><li><a href='http://www.lacy.ie/call-methodinfo-invoke-with-an-out-parameter' rel='bookmark' title='Permanent Link: Call MethodInfo.Invoke with an out parameter'>Call MethodInfo.Invoke with an out parameter</a> <small>Taken from http://www.galcho.com/Blog/P&#8230; Here is how to call a method...</small></li>
<li><a href='http://www.lacy.ie/how-to-mock-the-httpcontext-in-asp-net' rel='bookmark' title='Permanent Link: How to Mock the HttpContext in asp.net'>How to Mock the HttpContext in asp.net</a> <small>I find mocking the http context rather difficult, you can&#8217;t...</small></li>
<li><a href='http://www.lacy.ie/redirecting-using-strong-types-in-an-asp-net-web-application-project' rel='bookmark' title='Permanent Link: Redirecting using strong types in an asp.net web application project'>Redirecting using strong types in an asp.net web application project</a> <small>Update, I recommend also reading the following post after you...</small></li>
</ol>

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>Say you have an outer method:<br />
<code>public OuterMethod(object x)<br />
{<br />
InnerMethod(x);<br />
}</code><br />
and an inner method with these overloads<br />
<code><br />
public InnerMethod(object x)<br />
{<br />
//Generic Actions<br />
}<br />
public InnerMethod(Person x)<br />
{<br />
//Person Specific Actions<br />
}<br />
public InnerMethod(Dog x)<br />
{<br />
// Dog Specific Actions<br />
}<br />
</code><br />
How do you make it so that when the outer method calls the inner method it completes the specific actions as well as the generic ones that allows you to add an overload without editing any other function (useful when working on a team). Well here is the answer&#8230;<span id="more-94"></span></p>
<p>System.Reflections allows you to search for the relevant method by descibing what it looks like<br />
<code><br />
using System.Reflection;<br />
...<br />
public InnerMethod(Object x)<br />
{<br />
MethodInfo methodInfo = entity.GetType().GetMethod( "InnerMethod", new Type[] { x.GetType() });<br />
if(methodInfo != null)<br />
{<br />
methodInfo.invoke(this,Invoke(null, new object[] { x }) ;<br />
}<br />
// Generic Actions<br />
}<br />
</code></p>
<p>Now every time you add or remove a method, you only have to add or remove it in one place.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.lacy.ie%2Fgeneric-method-overloading-in-c&amp;linkname=Generic%20Method%20Overloading%20in%20C%23"><img src="http://www.lacy.ie/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>

<p>Related posts:<ol><li><a href='http://www.lacy.ie/call-methodinfo-invoke-with-an-out-parameter' rel='bookmark' title='Permanent Link: Call MethodInfo.Invoke with an out parameter'>Call MethodInfo.Invoke with an out parameter</a> <small>Taken from http://www.galcho.com/Blog/P&#8230; Here is how to call a method...</small></li>
<li><a href='http://www.lacy.ie/how-to-mock-the-httpcontext-in-asp-net' rel='bookmark' title='Permanent Link: How to Mock the HttpContext in asp.net'>How to Mock the HttpContext in asp.net</a> <small>I find mocking the http context rather difficult, you can&#8217;t...</small></li>
<li><a href='http://www.lacy.ie/redirecting-using-strong-types-in-an-asp-net-web-application-project' rel='bookmark' title='Permanent Link: Redirecting using strong types in an asp.net web application project'>Redirecting using strong types in an asp.net web application project</a> <small>Update, I recommend also reading the following post after you...</small></li>
</ol></p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.lacy.ie/generic-method-overloading-in-c/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</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! -->