0

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?

johnny 5
  • 19,893
  • 50
  • 121
  • 195
  • 1
    Any indications that you can actually do that? (surprising that you suggest using stack frames that you obviously already checked out - https://stackoverflow.com/questions/75076/obtain-parameter-values-from-a-stack-frame-in-net) – Alexei Levenkov Jul 25 '23 at 21:21
  • 1
    Side note: I'd recommend removing all that "attribute" part from the question as attributes don't have a way to run any code on their own. – Alexei Levenkov Jul 25 '23 at 21:22
  • @AlexeiLevenkov I've been able to dynamically switch methods internally to the code at runtime. I figured there's a way to hook into the process space and then find the function call to the attribute and override it to read the params on the heap, but the more I think about it, this would not be good for production code, but its more of a question on whether its possible now – johnny 5 Jul 31 '23 at 21:06

0 Answers0