internal T ConvertTo <T>(object value) { if (value == null) { return(default(T)); } Type type = typeof(T); TypeInfo typeInfo = type.GetTypeInfo(); // if no conversion is needed if (typeInfo.IsSubclassOf(type) || value.GetType() == type) { return((T)value); } if (type == typeof(Dictionary)) { ObservableObject observableObject = value as ObservableObject; if (observableObject != null) { return(new Dictionary( (DictionaryAdapter)ObjectStaticsUtil.CreateInspectable( observableObject.Adapter.Detach(), DictionaryAdapter.Type), this.ClassFactory).AssertCast <T>()); } } // support for arrays if (type.IsArray && !(type.GetElementType().GetTypeInfo().IsPrimitive || type.GetElementType() == typeof(string))) { Array rawItems = (Array)value; int size = rawItems.GetLength(0); Array adapterItems = Array.CreateInstance(type.GetElementType(), size); for (int index = 0; index < size; ++index) { adapterItems.SetValue(ToFactoryObject(rawItems.GetValue(index).AssertCast <InspectableAdapter>()), index); } return(adapterItems.AssertCast <T>()); } return(value.AssertCast <T>()); }
public T ActivateObject <T>(Guid iidType, object context) { ObjectAdapter objectAdapter = ObjectStaticsUtil.ActivateObject(iidType, ToAdapter(context)); return(GetOrCreateObject(objectAdapter).AssertCast <T>()); }