Information Technology Reference
In-Depth Information
For example, the following code uses the typeof operator to get information on a class
called SomeClass , and print the names of its public fields and methods.
using System.Reflection;
class SomeClass
{
public int Field1;
public int Field2;
public void Method1() { }
public int Method2() { return 1; }
}
class Program
{
static void Main()
{
Type t = typeof(SomeClass);
FieldInfo[] fi = t.GetFields();
MethodInfo[] mi = t.GetMethods();
foreach (FieldInfo f in fi)
Console.WriteLine("Field : {0}", f.Name);
foreach (MethodInfo m in mi)
Console.WriteLine("Method: {0}", m.Name);
}
}
Search WWH ::




Custom Search