<?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>C# Help &#187; Reflection</title>
	<atom:link href="http://www.csharphelp.com/tag/reflection/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.csharphelp.com</link>
	<description>C# Tutorial and Guides</description>
	<lastBuildDate>Tue, 07 Feb 2012 01:03:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>C# Reflection</title>
		<link>http://www.csharphelp.com/2007/02/c-reflection/</link>
		<comments>http://www.csharphelp.com/2007/02/c-reflection/#comments</comments>
		<pubDate>Mon, 26 Feb 2007 04:01:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[C# Language]]></category>
		<category><![CDATA[Reflection]]></category>

		<guid isPermaLink="false">http://www.csharphelp.com.php5-3.dfw1-2.websitetestlink.com/?p=466</guid>
		<description><![CDATA[It&#39;s about two and a half years since I&#39;vestarted using .NET. Maybe I can say that I know it very well. I am nowconvinced that the only real advantage of .NET, if we compare it toJava, is in the existence of metadata, IL and Reflection.Emit, but veryfew programmers are willing or capable to go there. [...]]]></description>
			<content:encoded><![CDATA[<p><span class="smallblack">It&#39;s about two and a half years since I&#39;vestarted using .NET. Maybe I can say that I know it very well. I am nowconvinced that the only real advantage of .NET, if we compare it toJava, is in the existence of metadata, IL and Reflection.Emit, but veryfew programmers are willing or capable to go there. So let me presentthe example where we can use Reflection and Reflection.Emit to dosomething interesting. </span></p>
<p><span class="smallblack">Light non-trivial introductory example of reusability</span></p>
<p><span class="smallblack">There&#39;s a possibility that we need to add somefunctionality to the existing library but we are not in a position tochange that library. One possible reason why we can&#39;t change thatlibrary could be that such a library is copyright protected. So wecan&#39;t rely on our knowledge of IL and reengineer it. Luckily there is away to achieve our goals and leave that library in its current shape.Our example is an arithmetic tree. The purpose of arithmetic tree is tobuild OO representation of arithmetic expression. Its structure is abinary tree where leaf nodes represent numeric values and other nodesrepresent operators. We have two types of nodes &#8211; operators and numbersand they are instances of different classes. So we are dealing with anon-trivial example. Very nice example of arithmetic tree is presentedin article Polymorphism in C++ by Bartosz Milewski, naturally it waswritten in C++ and we will have to translate it to C#.</span></p>
<p><span class="smallestblack"><span class="smallblack">public abstract class ArithmeticNode<br />{<br /> public abstract double Calculate(); <br />} <br />public class NumericNode:ArithmeticNode<br />{<br /> double _num;<br /> public NumericNode(double num){_num = num;}<br /> public override double Calculate() <br /> {<br /> return _num;<br /> }<br />}<br />public abstract class BinaryNode:ArithmeticNode<br />{<br /> protected ArithmeticNode _Left;<br /> protected ArithmeticNode _Right;<br /> public BinaryNode(ArithmeticNode mLeft, ArithmeticNode mRight)<br /> {<br /> _Left = mLeft;<br /> _Right = mRight;<br /> }<br />}<br />public class AddNode:BinaryNode<br />{<br /> public AddNode(ArithmeticNode mLeft, <br />ArithmeticNode mRight):base(mLeft, mRight){}<br /> public override double Calculate() <br /> {<br /> return _Left.Calculate() + _Right.Calculate();<br /> }<br />}<br />public class MultiplyNode:BinaryNode<br />{<br /> public MultiplyNode(ArithmeticNode mLeft, <br />ArithmeticNode mRight):base(mLeft, mRight) {}<br /> public override double Calculate() <br /> {<br /> return _Left.Calculate() * _Right.Calculate();<br /> }<br />}<br />public class DeductNode:BinaryNode<br />{<br /> public DeductNode(ArithmeticNode mLeft, <br />ArithmeticNode mRight):base(mLeft, mRight){}<br /> public override double Calculate() <br /> {<br /> return _Left.Calculate() &#8211; _Right.Calculate();<br /> }<br />}<br />public class DivideNode:BinaryNode<br />{<br /> public DivideNode(ArithmeticNode mLeft, <br />ArithmeticNode mRight):base(mLeft, mRight){}<br /> public override double Calculate() <br /> {<br /> return _Left.Calculate() / _Right.Calculate();<br /> }<br />}<br /></span>
<p><span class="smallblack">As we can see we have hierarchy of classes andone very elegant idea which is unfortunately not mine, I justtranslated it to C#. To build such a tree we usually produce some kindof parser, but to make things simple we will skip parser and build itmanually, like this :</span></p>
<p><span class="smallestblack"><span class="smallblack">ArithmeticNode n1 = new AddNode(new NumericNode(1.0), new NumericNode(2.0));<br />ArithmeticNode n2 = new MultiplyNode(n1, new NumericNode(3.0));<br />double x = n2.Calculate ();<br /></span>
<p><span class="smallblack">That would be (1 + 2) * 3. With tree comesfree recursion and to find out what is the result we just need to callCalculate method of the root node. </span></p>
<p><span class="smallblack">Now imagine that we are assigned to a projectwhere we should make simple arithmetic calculator. So we need parserand GUI and we may use that library, lets imagine that library is freeor that we will acquire license to use it. Unfortunately, specificationsays that arithmetic tree must print arithmetic expression. Sinceclasses are not sealed we can make them visitable and use Visitorpattern. So we will inherit from each class and add accept method. </span></p>
<p><span class="smallblack">Just in time inheritance</span></p>
<p><span class="smallblack">Repetitive task of extending all classes andadding accept method is boring so we will automate it. Even better, wewill use Reflection.Emit and extend dynamically only when and what isneeded. To make invocation easier we will use interface. That was theproject plan and now we can write the code. After few minutes thecoding is done (OK I had something similar already written) and this isthe code :</span></p>
<p><span class="smallestblack"><span class="smallblack">using System;<br />using System.Reflection;<br />using System.Reflection.Emit;<br />using System.Threading;<br />public interface IVisitable<br />{<br /> void Accept(IVisitor v);<br />}<br />public interface IVisitor<br />{<br /> void Visit(IVisitable v);<br />}<br />public class VisitableWrapper<br />{<br /> static System.Collections.Hashtable _assembliesHolder = <br /> System.Collections.Hashtable.Synchronized(new System.Collections.Hashtable());<br /> IVisitable _instance;</p>
<p> public object Current<br /> {<br /> get{<br /> return _instance;<br /> }<br /> set{<br /> _instance = build(value);<br /> }<br /> }<br /> IVisitable build(object current)<br /> {<br /> Type restype;<br /> IVisitable result;<br /> Type currentType = current.GetType();<br /> string theName = &quot;Visitable&quot; + currentType.Name;<br /> if(!_assembliesHolder.ContainsKey(theName)){<br /> AssemblyName assemblyName = new AssemblyName();<br /> assemblyName.Name = theName;<br /> ILGenerator methodIL;<br /> MethodBuilder mb;<br /> 	 AssemblyBuilder assembly = <br /> Thread.GetDomain().DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Run);<br /> ModuleBuilder module = assembly.DefineDynamicModule(theName+&quot;.dll&quot;);<br /> TypeBuilder visitableClass = module.DefineType(theName, TypeAttributes.Public);<br /> visitableClass.SetParent(currentType);<br /> visitableClass.AddInterfaceImplementation(typeof(IVisitable));<br /> Type[] arg = new Type[0];<br /> ConstructorBuilder cb = visitableClass.DefineConstructor(MethodAttributes.Public,<br /> CallingConventions.Standard,null);<br /> ILGenerator ctorIL = cb.GetILGenerator();<br /> ConstructorInfo bc = <br /> currentType.GetConstructor(new Type[]{typeof(ArithmeticNode),typeof(ArithmeticNode)});<br /> if(bc != null){<br /> ctorIL.Emit(OpCodes.Ldarg_0);<br /> ctorIL.Emit(OpCodes.Ldnull);<br /> ctorIL.Emit(OpCodes.Ldnull);<br /> ctorIL.Emit(OpCodes.Call, bc);<br /> ctorIL.Emit(OpCodes.Ret);<br /> }<br /> else{<br /> bc = currentType.GetConstructor(new Type[]{typeof(double)});<br /> ctorIL.Emit(OpCodes.Ldarg_0);<br /> ctorIL.Emit(OpCodes.Ldc_R8,0.0);<br /> ctorIL.Emit(OpCodes.Call, bc);<br /> ctorIL.Emit(OpCodes.Ret);<br /> arg = new Type[1]{typeof(IVisitor)};<br /> }<br /> arg = new Type[1]{typeof(IVisitor)};<br /> mb = visitableClass.DefineMethod(&quot;Accept&quot;,<br /> MethodAttributes.Public|MethodAttributes.NewSlot|MethodAttributes.HideBySig|<br /> MethodAttributes.Final|MethodAttributes.Virtual,<br /> typeof(void),arg);<br /> methodIL = mb.GetILGenerator();<br /> ParameterBuilder paramBuilder = <br /> mb.DefineParameter(1,ParameterAttributes.None,&quot;v&quot;);<br /> methodIL.DeclareLocal(typeof(object[]));<br /> methodIL.Emit(OpCodes.Ldarg_1);<br /> methodIL.Emit(OpCodes.Callvirt,(new object().GetType()).GetMethod(&quot;GetType&quot;));<br /> methodIL.Emit(OpCodes.Ldstr,&quot;Visit&quot;);<br /> methodIL.Emit(OpCodes.Ldc_I4,0&#215;100);<br /> methodIL.Emit(OpCodes.Ldnull);<br /> methodIL.Emit(OpCodes.Ldarg_1);<br /> methodIL.Emit(OpCodes.Ldc_I4_1);<br /> methodIL.Emit(OpCodes.Newarr,(new object()).GetType());<br /> methodIL.Emit(OpCodes.Stloc_0);<br /> methodIL.Emit(OpCodes.Ldloc_0);<</p>
<p>br /> me<br />
thodIL.Emit(OpCodes.Ldc_I4_0);<br /> methodIL.Emit(OpCodes.Ldarg_0);<br /> methodIL.Emit(OpCodes.Stelem_Ref);<br /> methodIL.Emit(OpCodes.Ldloc_0);<br /> methodIL.Emit(OpCodes.Callvirt,<br /> typeof(System.Type).GetMethod(&quot;InvokeMember&quot;, <br /> new Type[]{typeof(string),typeof(BindingFlags),typeof(Binder),<br /> typeof(object),typeof(object[])}));<br /> methodIL.Emit(OpCodes.Pop);<br /> methodIL.Emit(OpCodes.Ret);<br /> restype=visitableClass.CreateType();<br /> result = (IVisitable)Activator.CreateInstance(restype);<br /> _assembliesHolder.Add(theName,result);<br /> }<br /> else{<br /> result = (IVisitable)_assembliesHolder[theName];<br /> restype = result.GetType();<br /> }<br /> FieldInfo[] fields = currentType.GetFields(BindingFlags.NonPublic | <br /> BindingFlags.Instance | BindingFlags.Public | BindingFlags.Static );<br /> for(int i = 0;i &lt; fields.Length;i++){<br /> fields[i].SetValue(result,fields[i].GetValue(current));<br /> } <br /> return result;<br /> }<br /> public void Accept(IVisitor v)<br /> {<br /> _instance.Accept(v);<br /> }<br />}<br /></span>
<p><span class="smallblack">As simple as that. Whatever other kind of nodeis added in the future to hierarchy, under the condition that it usesthe prescribed constructor signature, it will work on it too. Interfaceis the same as I used in the article about Visitor (please use Google Idon&#39;t have a link). If you&#39;re now wondering how I&#39;m going to useVisitor on protected field, don&#39;t worry, Reflection will give us accessto non-public fields. Here is the code for the Visitor and test :</span></p>
<p><span class="smallestblack"><span class="smallblack">using System;<br />using System.Reflection;<br />class driver{<br /> static void Main ()<br /> {<br /> ArithmeticNode n1 = new DeductNode(new NumericNode(18.0), new NumericNode(11.0));<br /> ArithmeticNode n2 = new MultiplyNode(n1, new NumericNode(2.0));<br /> ArithmeticNode n3 = new DivideNode(new NumericNode(36.0),new NumericNode(6.0));<br /> ArithmeticNode n4 = new AddNode(n2, n3);<br /> double x = n4.Calculate ();<br /> VisitableWrapper vis = new VisitableWrapper();<br /> vis.Current = n4;<br /> Visitor v =new Visitor();<br /> vis.Accept(v);<br /> System.Console.WriteLine(&quot; = {0}&quot;,x);<br /> }<br />}<br />class Visitor:IVisitor<br />{<br /> public void Visit(IVisitable ve)<br /> {<br /> if(ve is BinaryNode){<br /> System.Console.Write(&quot;(&quot;);<br /> VisitableWrapper temp = new VisitableWrapper();<br /> temp.Current = ve.GetType().GetField(&quot;_Left&quot;, <br /> BindingFlags.NonPublic |<br /> BindingFlags.Instance).GetValue( ve );<br /> temp.Accept(this);<br /> switch(ve.GetType().ToString())<br /> {<br /> case &quot;VisitableAddNode&quot; : System.Console.Write(&quot; + &quot;);break;<br /> case &quot;VisitableMultiplyNode&quot; : System.Console.Write(&quot; * &quot;);break;<br /> case &quot;VisitableDeductNode&quot; : System.Console.Write(&quot; &#8211; &quot;);break;<br /> case &quot;VisitableDivideNode&quot; : System.Console.Write(&quot; / &quot;);break;<br /> }<br /> temp.Current = ve.GetType().GetField(&quot;_Right&quot;, <br /> BindingFlags.NonPublic |<br /> BindingFlags.Instance).GetValue( ve );<br /> temp.Accept(this);<br /> System.Console.Write(&quot;)&quot;);<br /> }<br /> else<br /> System.Console.Write(((NumericNode)ve).Calculate());<br /> }<br />}<br /></span>
<p><span class="smallblack">Maybe not very elegant, but it works and itsvery RAD. Yes, try this at home and all code in this article comeswithout any kind of warranty.Now probably comes the question why we must use Visitor. For printingonly we can leave it out, but tomorrow we may expect a request for XMLserializable arithmetic tree or who knows what and then we will behappy to have Visitor. See it as quick-fix framework.What if classes in hierarchy were sealed? Then we must do differently.The source of the problem is that we have no access to protected fieldsof BinaryNode. To gain access we may do something like this :</span></p>
<p><span class="smallestblack"><span class="smallblack">using System;<br />using System.Reflection;</p>
<p>class GoodBinaryNode<br />{<br /> BinaryNode _target;<br /> Type targetType; <br /> public GoodBinaryNode(BinaryNode target)<br /> {<br /> _target=target;<br /> targetType = target.GetType();<br /> }<br /> public ArithmeticNode Left<br /> {<br /> get<br /> {<br /> FieldInfo _LeftInfo = targetType.GetField(&quot;_Left&quot;, <br /> BindingFlags.NonPublic |<br /> BindingFlags.Instance);<br /> return (ArithmeticNode)_LeftInfo.GetValue( _target );<br /> }<br /> }<br /> public ArithmeticNode Right<br /> {<br /> get<br /> {<br /> FieldInfo _RightInfo = targetType.GetField(&quot;_Right&quot;, <br /> BindingFlags.NonPublic |<br /> BindingFlags.Instance);<br /> return (ArithmeticNode)_RightInfo.GetValue( _target );<br /> }<br /> }<br /> public double Calculate() <br /> {<br /> return _target.Calculate();<br /> }<br /> public void Print()<br /> {<br /> System.Console.Write(&quot;(&quot;);<br /> if(Left is BinaryNode)<br /> {<br /> GoodBinaryNode temp = new GoodBinaryNode((BinaryNode)Left);<br /> temp.Print();<br /> }<br /> else<br /> {<br /> System.Console.Write(Left.Calculate());<br /> }</p>
<p> switch(targetType.ToString())<br /> {<br /> case &quot;AddNode&quot; : System.Console.Write(&quot; + &quot;);break;<br /> case &quot;MultiplyNode&quot; : System.Console.Write(&quot; * &quot;);break;<br /> case &quot;DeductNode&quot; : System.Console.Write(&quot; &#8211; &quot;);break;<br /> case &quot;DivideNode&quot; : System.Console.Write(&quot; / &quot;);break;<br /> }</p>
<p> if(Right is BinaryNode)<br /> {<br /> GoodBinaryNode temp = new GoodBinaryNode((BinaryNode)Right);<br /> temp.Print();<br /> }<br /> else<br /> {<br /> System.Console.Write(Right.Calculate());<br /> }<br /> System.Console.Write(&quot;)&quot;);<br /> }<br />}<br />class driver<br />{<br /> static void Main ()<br /> {<br /> ArithmeticNode n1 = new DeductNode(new NumericNode(18.0), new NumericNode(11.0));<br /> ArithmeticNode n2 = new MultiplyNode(n1, new NumericNode(2.0));<br /> ArithmeticNode n3 = new DivideNode(new NumericNode(36.0),new NumericNode(6.0));<br /> ArithmeticNode n4 = new AddNode(n2, n3);<br /> double x = n4.Calculate ();<br /> GoodBinaryNode printRoot = new GoodBinaryNode((BinaryNode)n4);<br /> printRoot.Print();<br /> System.Console.WriteLine(&quot; = {0}&quot;,x);<br /> }<br />}<br /></span>
<p><span class="smallblack">It resembles Decorator pattern a little and ismuch easier to code than that Visitor example, only if we have to passinstance of it to some method which expects one of original hierarchytypes then we are in trouble. But then we are in trouble anyway.Naturally, we will skip Reflection.Emit exercise-we need to code onlyone class. It is much easier to write code in IL than to useReflection.Emit.</span></p>
<p><span class="smallblack">Isn&#39;t that against OO principles to try togain access to fields or methods which are not meant to be accessedfrom outside? Yes it is, if somebody makes fields inaccessible therecould be reason for that, but if it helps me to write less code then Iwill defend myself with reusability argument. A bit of creative hacking(that kind of hacking which won&#39;t make public prosecutor interested inyour activities) is always helpful.I can&#39;t remember any more good questions, if you have any, my e-mail isbelow.</span></p>
<p><span class="smallblack">Conclusion</span></p>
<p><span class="smallblack">As I demonstrated, Reflection andReflection.Emit may be used to achieve interesting things. Naturally,we need to know IL to use Reflection.Emit. Possible areas where itcould be used are AOP or Coordination Contracts. So highly configurableapplications where about everything could be changed at run time arepossible if appropriate OO patterns like Chain of Responsibility areused.About two and a half years ago I went to Microsoft of South Africa(that is where I am staying, but I am not South African) to get my copyof .NET beta 1. They charged me about US$ 5 for three CDs. Today thereis .NET 1.1, which I haven&#39;t got yet. Maybe I will go again toMicrosoft of South Africa to get CDs, but this t</p>
<p>ime I am not in ahurry. It looks to me that .NET started to lose its breath andadvantages which it used to have over its competitors. For example,UDDI V2 API client side implementation for .NET is still in beta 1stage! Lot of things have changed in the last two and a half years andin the world of programming changes are very fast. </span></p>
<p><span class="smallblack">About Myself</span></p>
<p><span class="smallblack">Currently I&#39;m writing for CodeNotes.http://www.codenotes.com and preparing presentation for InternationalWeb Services Conference &amp; Exposition in Toronto, Canada on October14-16, 2003. For more info visit http://www.WowGao.com. If you have anysuggestions, questions my address is filipbulovic@mail.com, I will tryto answer. </span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.csharphelp.com/2007/02/c-reflection/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dynamic Method Invocation in C# using Reflection</title>
		<link>http://www.csharphelp.com/2006/05/dynamic-method-invocation-in-c-using-reflection/</link>
		<comments>http://www.csharphelp.com/2006/05/dynamic-method-invocation-in-c-using-reflection/#comments</comments>
		<pubDate>Mon, 29 May 2006 04:01:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[C# Language]]></category>
		<category><![CDATA[Reflection]]></category>

		<guid isPermaLink="false">http://www.csharphelp.com.php5-3.dfw1-2.websitetestlink.com/?p=193</guid>
		<description><![CDATA[Abstract Reflection allows the developer todynamically manipulate and inspect the members of objects, whichincludes their fields, methods and types. This is a consequence of C#being a managed language. This Article demonstrates how the developercan use Reflection to dynamically locate and call methods within aclass, including passing the respective parameters to the method andalso manage any [...]]]></description>
			<content:encoded><![CDATA[<p><span style="font-size: xx-small;"><strong><br />
</strong></span><span class="smallblack"><a href="http://www.csharphelp.com/bio/luke.html"></a></span></p>
<p><span class="smallblack"> <strong>Abstract</strong></span></p>
<p><span class="smallblack"> Reflection allows the developer todynamically manipulate and inspect the members of objects, whichincludes their fields, methods and types. This is a consequence of C#being a managed language.</span></p>
<p><span class="smallblack"> This Article demonstrates how the developercan use Reflection to dynamically locate and call methods within aclass, including passing the respective parameters to the method andalso manage any error conditions that could arise during this process.</span></p>
<p><span class="smallblack"> This article requires that you have hadexposure to C# and are comfortable with the language. The tutoriallargely resides in the example provided, where you are shown how amethod can be dynamically invoked using console input.</span></p>
<p><span class="smallblack"> <strong>The Example: Bob?s Burger Barn</strong></span></p>
<p><span class="smallblack"> Bob?s Burger Barn is quite amodern restaurant that allows it?s customers to order their meals usinga computer terminal. The user logs into the ordering application andsends commands to order what he wants. For example, if a customer wantsto order a burger, he must use the ?burger? command with the followingsyntax:</span></p>
<p><span class="smallblack"> burger &lt;bun type&gt; &lt;sauce name&gt; &lt;meat type&gt;</span></p>
<p><span class="smallblack"> Examples: </span></p>
<p><span class="smallblack">burger sesame chilli chicken</span></p>
<p><span class="smallblack">burger plain ketchup beef</span></p>
<p><span class="smallblack"> Bob decided that since his Burger Barn?s menuchanges so much, it is wiser for him to allow his ordering applicationas much flexibility as possible. His C# developer recognised his needand made all ordering method invocations and listing completelydynamic.</span></p>
<p><span class="smallblack"> If a customer wants to order a burger, he types burger&lt;param1&gt;&lt;param2&gt;&lt;param3&gt;and the ordering application checks to see if it has a method called?burger?. If it does, then the three parameters are passed to themethod using Reflection method invocation. If the number of parametersis not correct an exception is thrown and the user is prompted with anappropriate error message.&lt;/param3&gt;&lt;/param2&gt;&lt;/param1&gt;</span></p>
<p><span class="smallblack"> Inthis way, Bob can add new menu items to his ordering application andthe application will automatically be able to list and invoke them.</span></p>
<p><span class="smallblack"> <strong>Dynamically Invoking a Method</strong> </span></p>
<p><span class="smallblack">Bob?s clever C# Developer uses a series ofeasy steps to look a method up and then invoke it. All this is doneinside the GetCommand() method. The first step he takes is to get thefirst space-seperated word from the console input string. He then getsa reflection or type representation of the object that he wants to calla method on, namely the DynamicMethods object.</span></p>
<p><span class="smallblack"> Type thisType = this.GetType();</span></p>
<p><span class="smallblack"> He then asks the Type object ifthe class it is reflecting holds a method with a name that matches theword he read in from the console. If there is such a method, a methoddescriptor object is returned in the form of MethodInfo:</span><br /><i>Continues&#8230;</i></p>
]]></content:encoded>
			<wfw:commentRss>http://www.csharphelp.com/2006/05/dynamic-method-invocation-in-c-using-reflection/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Reflection in C#</title>
		<link>http://www.csharphelp.com/2006/03/reflection-in-c/</link>
		<comments>http://www.csharphelp.com/2006/03/reflection-in-c/#comments</comments>
		<pubDate>Mon, 20 Mar 2006 04:01:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[C# Language]]></category>
		<category><![CDATA[Reflection]]></category>

		<guid isPermaLink="false">http://www.csharphelp.com.php5-3.dfw1-2.websitetestlink.com/?p=123</guid>
		<description><![CDATA[This article explains how to make use ofSystem.Reflection class to extract each and every detail of any classin .Net Framework.The MemberInfo class available in System.Reflection namespace is anabstract class.It discovers the attributes of a member and provides access to themember metadata.We need to assign the details we need to query about a type viz.Constructors/Methods/Interfaces/Fields/Property etc. [...]]]></description>
			<content:encoded><![CDATA[<p><span style="font-size:xx-small;"><b><br /></b></span><span class="smallblack"><a href="mailto:rajadurai_p@hotmail.com"></a></span></p>
<p><span class="smallblack">This article explains how to make use ofSystem.Reflection class to extract each and every detail of any classin .Net Framework.The MemberInfo class available in System.Reflection namespace is anabstract class.It discovers the attributes of a member and provides access to themember metadata.We need to assign the details we need to query about a type viz.Constructors/Methods/Interfaces/Fields/Property etc. to the MemberInfoclass local variable.For this, We can make use of the methodsGetFields/GetMethods/GetInterfaces etc. In this code example, the userwill be prompted to select the class about which he would like to viewdetails.The details of the class selected (available Methods/Interfaces/Fields)will be listed out in the corresponding listboxes.</span></p>
<p><span class="smallblack">To compile, type: csc reflection.csDownload <a href="http://www.csharphelp.com/archives/files/archive124/reflection.cs">reflection.cs</a></span></p>
<p><span class="smallblack">Here&#39;s what it looks like</span></p>
<p><span class="smallblack"><img src="http://www.csharphelp.com/archives/files/archive124/reflection.jpg" alt="" /></span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.csharphelp.com/2006/03/reflection-in-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

