Csharp/C Sharp by API/System.Reflection/MethodInfo — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Версия 15:31, 26 мая 2010
MethodInfo.GetParameters()
using System;
using System.Reflection;
public class Test
{
public static void Main(string[] args)
{
Assembly a = null;
AssemblyName asmName;
asmName = new AssemblyName();
asmName.Name = "Test";
Version v = new Version("1.0.454.30104");
asmName.Version = v;
a = Assembly.Load(asmName);
Type testClassName = a.GetType("Test");
MethodInfo mi = testClassName.GetMethod("Main");
Console.WriteLine("Here are the params for {0}", mi.Name);
// Show number of params.
ParameterInfo[] myParams = mi.GetParameters();
Console.WriteLine("Method has {0} params", myParams.Length);
// Show info about param.
foreach(ParameterInfo pi in myParams)
{
Console.WriteLine("Param name: {0}", pi.Name);
Console.WriteLine("Position in method: {0}", pi.Position);
Console.WriteLine("Param type: {0}", pi.ParameterType);
}
}
}
MethodInfo.TypeHandle
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Reflection;
using System.Reflection.Emit;
public class MainClass
{
public static void Main()
{
Type typeInfo = typeof(object);
MethodInfo methInfo = typeInfo.GetMethod("ToString");
RuntimeTypeHandle typeHandle = typeInfo.TypeHandle;
RuntimeMethodHandle methHandle = methInfo.MethodHandle;
Console.WriteLine("Handle: {0}", methHandle);
}
}