mardi 25 juillet 2023

Get Parameters Pass into an method from an attribute

I have an attribute that I'm placing on a method:

[MyAttribute]
public void MyMethod(SomeClass prop) {
    //...
}

Lets say I'm invoking the method like so:

MyMethod(new SomeClass() { MyProp = 354});

I would like My attribute to be able to read in the properties which are passed into the method.

How can I Obtain access to the parameters of the method which the attribute is on. I would Imagine the call would look something like so:

var callStack = GetCallStack().
callStack.Pop();
var methodFrame = callStack.Current;
methodFrame.GetParameterAtIndex<SomeClass>(0);

Is there a way I can do this from the internals of the attribute?





Aucun commentaire:

Enregistrer un commentaire