Csharp/C Sharp/Reflection/ParameterInfo — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
(нет различий)
|
Текущая версия на 14:38, 26 мая 2010
Dumping the methods and their parameters for a class.
<source lang="csharp">
using System; using System.Reflection; using System.Reflection.Emit; using System.Collections; class MainClass {
public static void DumpParameters(ParameterInfo[] pars) { foreach (ParameterInfo pi in pars) { Console.WriteLine("\n Parameter Name: {0}",pi.Name); Console.WriteLine(" Parameter Type: {0}",pi.ParameterType); Console.WriteLine(" Is In? {0}",pi.IsIn); Console.WriteLine(" Is Out? {0}",pi.IsOut); } }
}
</source>
ParameterInfo: GetParameters
<source lang="csharp"> using System; using System.Reflection; public class Class1 {
public static int Main() { Type t = typeof(MyClass); Console.WriteLine("Type of class: " + t); Console.WriteLine("Namespace: " + t.Namespace); MethodInfo[] mi = t.GetMethods(); Console.WriteLine("Methods are:"); foreach (MethodInfo i in mi) { Console.WriteLine("Name: " + i.Name); ParameterInfo[] pif = i.GetParameters(); foreach (ParameterInfo p in pif) { Console.WriteLine("Type: " + p.ParameterType + " parameter name: " + p.Name); } } return 0; }
public class MyClass { public int pubInteger; private int _privValue; public MyClass() { } public MyClass(int IntegerValueIn) { pubInteger = IntegerValueIn; } public int Add10(int IntegerValueIn) { Console.WriteLine(IntegerValueIn); return IntegerValueIn + 10; } public int TestProperty { get { return _privValue; } set { _privValue = value; } } }
}
</source>