C#取得一个函数或方法的参数类型参数名称返回值类型


2018年3月23日11:43:06


using System.Reflection

//取得YourClassName中的名称为foo的方法
Type className = Type(YourClassName)
MethodInfo method = className.GetMethod("foo");     

/*取得方法的参数个数、参数类型和名称、返回值类型*/
Console.Out.WriteLine(method.ReturnType.ToString());
Console.Out.WriteLine(method.GetGenericArguments());
Console.Out.WriteLine(method.GetParameters().Length);
Console.Out.WriteLine(method.GetParameters()[0].ToString())

总结

使用System.Reflection提供的方法即可实现。

你可能感兴趣的:(C#)