简体   繁体   中英

Get SequencePoint for CustomAttribute in Fody/Mono.Cecil

I am writing a Fody Addin and I am able to inject my code and to provide error messages to the user. I am able to determine the sequence points of instructions, but I cannot find a way to find the sequence points of CustomAttributes.

I need to get this information to provide the debugger a hint where to find the location of an error, in case that an attribute has been applied wrongly.

So basically I have something like this:

[MyAttribute]
public void Test()
{

}

Now I want to get the SequencePoint of the MyAttribute attribute.

**Edit: ** As I got down voted (without any information why) here some additional information. I can access the sequence point of instructions like this:

public static SequencePoint GetSP(MethodDefinition method)
{
    return method.Body.Instructions
        .Where(instruction => instruction.SequencePoint != null)
        .Select(instruction => instruction.SequencePoint)
        .FirstOrDefault();
}

That works fine for instructions but when I access an attribute I am not sure how to get the sequence point:

public static SequencePoint GetSP(MethodDefinition method)
{
    var attribute = method.CustomAttributes.First();
    // what to enter here to get SequencePoint of attribute?
}

this is not possible. attributes dont have sequence points. i suggest you just use the first sequencepoint for the method instead

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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