public void SetValue(object instance, PropertyInfo property, string value) { var targetType = property.PropertyType; var thing = assemblies.SelectMany(a => a.GetTypes()) .Select(t => new { Type = t, Attribute = GetTypeConverterAttributeOrNull(t) }) .Where(t => t.Attribute != null && IsTheRightConverter(t.Type, targetType)) .FirstOrDefault(); if (thing != null) { var typeConverterType = thing.Type; var typeConverter = objectActivator.GetInstance(typeConverterType); try { property.SetValue(instance, typeConverterType.GetMethod("Convert") .Invoke(typeConverter, new object[] { value }), null); } catch (Exception e) { throw new FeatureExecutionException(e, "Unhandled exception while attempting to convert {0} to {1} using {2}", value, targetType.FullName, typeConverterType.FullName); } } else { fallbackPropertySetter.SetValue(instance, property, value); } }
object CreateInstance() { return(objectActivator.GetInstance(Type)); }