How to get the param Collection of TypeInjectionElement

Sep 18, 2009 at 3:56 PM


I'm trying to read the the collection of parameter of constructor element from a specifi type in my configuration file.

I can get the collection of Types and the specific type I need but I'm not be able to get the collections of parameters to read them.

Anybody knows how I can retrieve this information using the classes of Unity? I know that I can read the Configuration File as a XML file, but I wanted use the Unity Classes.

Thankyou for help.

Dec 18, 2009 at 1:32 AM

(This has all changed radically in the recent Unity 2.0 drop, I'll limit myself to the 1.2 classes in this discussion).

One you have the UnityTypeElement, you'll need to walk the TypeConfig collection. This is polymorphic, so you'll need to find the ones that are actually InjectionConstructorElement.

Once you have the InjectionConstructorElement, walk the Params property to get the parameter elements. These are MethodParameterElements, and from there you can get the name and type of parameters being called. The values being passed, unfortunately, are private so you won't be able to get them without private reflection.