MethodBase 是否提供文件名和行号?
我正在尝试为 postsharp 编写一个 CompileTimeValidate(MethodBase method)
。 问题是当发生违规时,它仅在错误列表中显示描述。 “文件”和“行”列为空。
我可以使用的唯一信息是应用该属性的方法的 MethodBase
实例。
有没有办法从 MethodBase 对象中获取源文件和行号详细信息?
public override bool CompileTimeValidate(MethodBase method)
{
MessageSource.MessageSink.Write(new Message(SeverityType.Error, "CU0001",
"MyError", "MyAspectLibrary"));
return false;
}
I'm trying to write a CompileTimeValidate(MethodBase method)
for postsharp. the problem is when a violation occurs it only shows Description in the Error List. The 'File' and 'Line' columns are empty.
The only info that I get to work with is a MethodBase
instance of the method that the attribute was applied to.
is there a way to get the source file and line number detail out of a MethodBase
object?
public override bool CompileTimeValidate(MethodBase method)
{
MessageSource.MessageSink.Write(new Message(SeverityType.Error, "CU0001",
"MyError", "MyAspectLibrary"));
return false;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不,那里没有。 MethodBase 是 .Net 程序集底层元数据部分的表示。 包括文件和行信息在内的源信息不存储在 DLL 中,因此无法通过反射 API 获取。 文件和行信息实际上存储在 PDB 中,您需要通过那些匹配标记的 API 来查找文件/行信息。
No there is not. MethodBase is a representation for parts of the underlying metadata of .Net assembly. Source information including file and line information is not stored in the DLL and hence is not available via Reflection APIs. The file and line information is actually stored in the PDB and you would need to go through those APIs matching up tokens to find the file / line information.