Complex type converter that need to resolve objects

Aug 8, 2013 at 10:01 AM

I've written a type converter for Unity 2.1 to be able to instantiate objects whose constructor expects, for example, an IDictionary<int, T> where T is a type or interface.

The syntax for the value is something like this:

"1 => Type1; 2 => Type2; ...; key => Type"

Inside the type converter, I split the string, extract the keys and resolve the values (creating an instance of the requested type).

Currently, I only support standard .NET type descriptions compatible with the Type.GetType method (e.g., Type1 could be "Namespace.TypeName, Assembly"). Once I have the System.Type instance, I use Unity to resolve it with the default registration.

I would like to extend the mechanism to accept Unity searched types (aliases and assembly and namespace hints declared in the configuration file). For that, I would need to call Unity's internal methods to derive a System.Type instance from a textual representation of it (including aliases, shortcuts, assembly and namespace declarations, and standard type descriptions). Calls to those methods would substitute for the current call to Type.GetType prior to resolving.

Are these methods public?
Does anyone know their names?

Thank you very much.
Aug 8, 2013 at 6:00 PM
You can access the Unity configuration using the UnityConfigurationSection class.

For example, you can retrieve the aliases defined in the config file:
    var config = ConfigurationManager.GetSection("unity") as UnityConfigurationSection;

    foreach (var alias in config.TypeAliases)
        Console.WriteLine(alias.Alias + " = " + alias.TypeName); 
Randy Levy
Enterprise Library support engineer
Support How-to