metalama

Using Metalama how do you get the method's line number and include it in `StringBuilder`


The title says it all. Using OverrideMethodAspect.

I've been using PostSharp for many years and am trying to convert to Metalama.


Solution

  • In Metalama 2023.3 or later, you can do:

    meta.Target.Declaration.Sources.SingleOrDefault( x => x.IsImplementationPart ).Span
    

    The returned object gives you the file and line number.