C# 反射(怎么获得引用形参的类型实例)
C# 反射(如何获得引用形参的类型实例)
例如:
要获取Int32.TryParse(string str,out Int32 result) 的MethodInfo对象。
------解决方案--------------------
typeof(Int32).GetMethod("TryParse", new Type[] { typeof(string), typeof(Int32).MakeByRefType() });
例如:
要获取Int32.TryParse(string str,out Int32 result) 的MethodInfo对象。
//第一种方式 可以获取 但不是我想要的方式
tTarget.GetMethods().Where(x=>x.Name.Equals("TryParse")&&x.GetParameters().Length==2).FirstOrDefault();
//第二种方式 获取结果为Null
typeof(Int32).GetMethod("TryParse",new Type[]{typeof(string),typeof(Int32)});
//单步调试结果表示 out Int32的类型是"System.Int32&", 但是无法直接用于第二种方式。
//现求解如何获得out Int32 的 System.Type 对象
C#反射
形参类型
------解决方案--------------------
typeof(Int32).GetMethod("TryParse", new Type[] { typeof(string), typeof(Int32).MakeByRefType() });