简体   繁体   English

获取C#中方法的详细信息

[英]Get Details of a Method in C#

In C# we can get all the details of a method using the following code 在C#中,我们可以使用以下代码获取方法的所有详细信息

XmlDocument doc = new XmlDocument();

Type t = doc.GetType();

System.Reflection.MethodInfo[] methods = t.GetMethods();

Here I am not able to get the comments of a method and the exceptions available in the method. 在这里,我无法获取方法的注释以及该方法中可用的异常。

Comments are stripped at compile time and not part of the runtime metadata. 注释在编译时被剥离,而不是运行时元数据的一部分。

As for exceptions, any exception can be thrown from any method. 至于异常,可以从任何方法抛出任何异常。 Whereas exceptions in a sense are part of the interface of a method, they are not declared and are therefore not part of the runtime metadata either. 从某种意义上说,异常是方法接口的一部分,但它们没有声明,因此也不是运行时元数据的一部分。

Hope this helps. 希望这可以帮助。

What do you mean by the exceptions available? 您所说的例外是什么意思? Unlike Java, in .Net a method does not declare the exceptions that it can throw. 与Java不同,.Net中的方法不会声明它可以抛出的异常。

您无法获取该方法可以抛出的异常列表,并且注释会被编译器删除。

There is no way to get the comments that are declared on a method like this, because they are not part of the assembly. 无法获得在这样的方法上声明的注释,因为它们不是程序集的一部分。 You can't get the exceptions either, because in C# methods don't declare which exceptions the can throw. 您也无法获取异常,因为在C#方法中,不声明可以抛出的异常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM