Getting at and modifying the value of an InjectionPropertyElement

Feb 17, 2010 at 11:49 AM

Hi.

I have an application for changing the configuration of multiple other applications. I've recently begun using Unity and I want to configure a UnityConfigurationSection as well. I got pretty far, this is were I landed:

 

UnityContainerElement container = ...;

foreach( UnityTypeElement type in container.Types )
{
    if( type.TypeName == "ILogger" )
    {
        foreach( TypeInjectionElement typeConfiguration in type.TypeConfig )
        {
            foreach( InjectionPropertyElement property in typeConfiguration.InjectionMembers )
            {
                if( property.Name == "LogDirectory" )
                {
                    ...
                }
            }
        }
    }
}

 

Setting a breakpoint in the innermost if, I see that I've gotten a hold of the LogDirectory InjectionPropertyElement. I can't get a hold of the value, however. The debugger shows there's a private InjectionParameterValueElement named valueElement, but it has no public accessor. That is the value I want to be able to modify and save back to disk. How do I do this?

Feb 17, 2010 at 6:29 PM

You'll have to use private reflection to change the field. Programatically creating configuration files is something that wasn't really part of the design in Unity 1.2. It is completely supported in 2.0 though, so if you can update to Unity 2.0 that's your best bet.