标签:this flags tty return 基础 arp lag odi 测试
/// <summary>
/// 测试反射模型
/// </summary>
public class TestFunction
{
public TestFunction() { }
public TestFunction(string param)
{
this.Param = param;
}
public string Param { get; set; }
public string Function(string fParam)
{
return this.Param + "-" + fParam;
}
}
class Program
{
static void Main(string[] args)
{
TestReflection(new TestFunction());
Console.Read();
}
public static void TestReflection(object obj)
{
//obj类的类型
var t = obj.GetType();
//字段集GetProperties参数可指定字段修饰符
var field = t.GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);
//构造函数的参数
object[] constuctParms = new object[] { "构造函数的值" };
//根据类型创建对象
object dObj = Activator.CreateInstance(t, constuctParms);
//获取方法的信息
MethodInfo method = t.GetMethod("Function");
//GetValue方法的参数
object[] parameters = new object[] { "Function函数中的值" };
//调用方法,用一个object接收返回值
object returnValue = method.Invoke(dObj, BindingFlags.Public, Type.DefaultBinder, parameters, null);
Console.Write(returnValue);
}
}
标签:this flags tty return 基础 arp lag odi 测试
原文地址:https://www.cnblogs.com/liyiboke/p/10008900.html