开发者

Is there a way to programmatically get the source file and line number of an arbitrary MemberInfo?

开发者 https://www.devze.com 2022-12-18 16:48 出处:网络
I am writing a code analysis tool that uses reflection to validate a particular code base. When I encounter a type or member of interest I would like to load the symbols and extract the source file an

I am writing a code analysis tool that uses reflection to validate a particular code base. When I encounter a type or member of interest I would like to load the symbols and extract the source file and line number where the member or type is defined. Is this possible? If so, how?

class SourceInfo
{
    public static SourceInfo GetFrom(MemberInfo member)
    {
        // What do I do here??
        throw new NotImplementedException();
    }

    public static SourceInfo GetF开发者_StackOverflow中文版rom(Type member)
    {
        // What do I do here??
        throw new NotImplementedException();
    }

    public string SourceFilePath { get; private set; }
    public int LineNumber { get; private set; }
}


The available symbol APIs are listed in this blog article. I think the MDbg wrappers are your best bet for managed code. I only tried the DIA sdk and wasn't thrilled.


This codeproject article has some information about retrieving information from PDB file.


No, you can not do this using reflection. To do this, you need the associated program database file using the Symbol API.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号