是否可以通过反射获取程序集的注释?
我想知道是否有一种方法可以通过反射访问类上的注释,或者它们是否完全从二进制文件中删除。
I would like to know if there is a way to access comments on a class through Reflection or if they are completely stripped from the binaries.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
不。注释被编译器删除 - 它们不存在于二进制文件中,因此无法将它们恢复。
No. Comments are stripped by the compiler - they're not present in the binaries, so there's no way to get them back.
编译代码时,注释将被忽略。
这意味着您无法让它们“回来”,因为它们从一开始就不存在。
Comments are ignored when code is compiled.
This means you can't get them "back" as they were never there in the first place.
当代码被编译器编译时,注释将被忽略。
但是您可以通过创建自己的用户定义的属性类来传递属性中的信息。
Comments are ignored when code get complied by compiler.
But you can pass information in the Attributes by creating your own user defined attribute class.
注释无法从二进制文件中获得,但可以通过 XML 获得。请参阅这个答案。
Comments are not available from the binaries, but they are via XML. See this SO answer.