Skip to content
Discussion options

You must be logged in to vote

Unfortunately, there's no direct way to retrieve all callers of a method and their generic type arguments from within an aspect at compile time to use that information for code generation.

However, there are a few approaches depending on your goal:

1. Validation Only: Using Metalama.Extensions.Architecture

If you want to validate how your method is called (and report diagnostics), you can use inbound reference validation:

[AttributeUsage(AttributeTargets.Method)]
public class JsonMethodAttribute : Attribute, IAspect<IMethod>
{
    private static readonly DiagnosticDefinition<INamedType> _info = new(
        "JSON001",
        Severity.Info,
        "Method is called with type argument '{0}'"

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by gfraiteur
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants