views:

133

answers:

1

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;
    }
+3  A: 

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.

JaredPar
See here for more info on parsing managed PDBs, with premade code that you might be able to use as is: http://blogs.msdn.com/jmstall/archive/2005/08/25/pdb2xml.aspx
Pavel Minaev
PostSharp does read (and rewrite) PDB files, but they are not expose to Laos. The problem is that the PDB file does not contain the location of fields, methods, types, ... but only the location of instructions inside methods. This is of little help for abstract methods, types, fields, and so on,
Gael Fraiteur