internal static void GetRootObjectAndDelegateType(ITypeDescriptorContext context, out object rootObject, out Type delegateType) { rootObject = null; delegateType = null; if (context == null) { return; } IRootObjectProvider rootObjectService = context.GetService(typeof(IRootObjectProvider)) as IRootObjectProvider; if (rootObjectService == null) { return; } rootObject = rootObjectService.RootObject; IDestinationTypeProvider targetService = context.GetService(typeof(IDestinationTypeProvider)) as IDestinationTypeProvider; if (targetService == null) { return; } delegateType = targetService.GetDestinationType(); }
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { if (value is string stringValue) { TypeConverterHelper currentHelper = helper; if (currentHelper == null) { IDestinationTypeProvider targetService = context.GetService(typeof(IDestinationTypeProvider)) as IDestinationTypeProvider; Type targetType = targetService.GetDestinationType(); if (!this.helpers.Value.TryGetValue(targetType, out currentHelper)) { currentHelper = GetTypeConverterHelper(targetType, this.baseType, this.helperType); if (!this.helpers.Value.TryAdd(targetType, currentHelper)) { if (!this.helpers.Value.TryGetValue(targetType, out currentHelper)) { throw FxTrace.Exception.AsError(new InvalidOperationException(SR.TypeConverterHelperCacheAddFailed(targetType))); } } } } object result = currentHelper.UntypedConvertFromString(stringValue, context); return(result); } return(base.ConvertFrom(context, culture, value)); }
public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { if (value.GetType() == typeof(string)) { IDestinationTypeProvider targetService = context.GetService(typeof(IDestinationTypeProvider)) as IDestinationTypeProvider; Type targetType = targetService.GetDestinationType(); return(Activator.CreateInstance(targetType)); } return(base.ConvertFrom(context, culture, value)); }
internal static void GetRootObjectAndDelegateType(ITypeDescriptorContext context, out object rootObject, out Type delegateType) { rootObject = null; delegateType = null; if (context != null) { IRootObjectProvider service = context.GetService(typeof(IRootObjectProvider)) as IRootObjectProvider; if (service != null) { rootObject = service.RootObject; IDestinationTypeProvider provider2 = context.GetService(typeof(IDestinationTypeProvider)) as IDestinationTypeProvider; if (provider2 != null) { delegateType = provider2.GetDestinationType(); } } } }
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { if (value is string path) { IValueSerializerContext valueSerializerContext = (IValueSerializerContext)context; IXamlSchemaContextProvider xamlSchemaContextProvider = valueSerializerContext.GetRequiredService <IXamlSchemaContextProvider>(); if (xamlSchemaContextProvider.SchemaContext is ContentManager.InternalXamlSchemaContext xamlSchemaContext) { IDestinationTypeProvider destinationTypeProvider = valueSerializerContext.GetRequiredService <IDestinationTypeProvider>(); Type type = destinationTypeProvider.GetDestinationType(); return(xamlSchemaContext.ContentManager.DeserializeAsync(path, type, xamlSchemaContext.ParentReference, null).Result); } } return(base.ConvertFrom(context, culture, value)); }