您的位置:首页 > 编程语言 > C#

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

2018-03-23 11:46 351 查看
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#
相关文章推荐