Question

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;
    }
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top