I am possibly asking the impossible but I shall ask anyway. From the following:
public SomeClassConstructor(SomeOtherClass someOtherClass, string someString){
...
}
Is it possible to access the arguments so that they can be iterated (for example some sort of reflection to access an IEnumerable<object>
that contains the arguments)?
Note: The params[] collection is not an answer in this situation. Other restrictions are that this is to be used in a WinForms environment; .Net 4.5 is acceptable.
EDIT: In response to DavidG's comment I am after the objects themselves (aka values and names). The reason being that I have a requirement to log (serialized) the arguments when a form is opened (when a UAT flag is set in app.config!). Large objects have their serialization over ridden to return simple strings so as not to bloat in memory.).
No, you can't access parameter values via reflection. You can get the names, types, attributes etc - but not the values. That's true of methods, constructors, property setters, indexers etc.
You could potentially do it in a debugger API, but that's almost never the right approach.
For logging, you should either just do this manually:
Log("someOtherClass={0}, someString={1}", someOtherClass, someString);
or look into AOP to inject calls automatically - look at PostSharp for example.
See more on this question at Stackoverflow