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)); }
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(); }
void Initialize(PrefixLookup prefixLookup, XamlSchemaContext schemaContext, Func <IAmbientProvider> ambientProvider, IProvideValueTarget provideValue, IRootObjectProvider rootProvider, IDestinationTypeProvider destinationProvider, IXamlObjectWriterFactory objectWriterFactory) { prefix_lookup = prefixLookup ?? throw new ArgumentNullException("prefixLookup"); sctx = schemaContext ?? throw new ArgumentNullException("schemaContext"); _ambientProviderProvider = ambientProvider; this.provideValue = provideValue; this.rootProvider = rootProvider; this.destinationProvider = destinationProvider; this.objectWriterFactory = objectWriterFactory; }
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)); }
public ValueSerializerContext (PrefixLookup prefixLookup, XamlSchemaContext schemaContext, IAmbientProvider ambientProvider, IProvideValueTarget provideValue, IRootObjectProvider rootProvider, IDestinationTypeProvider destinationProvider) { if (prefixLookup == null) throw new ArgumentNullException ("prefixLookup"); if (schemaContext == null) throw new ArgumentNullException ("schemaContext"); prefix_lookup = prefixLookup; namespace_resolver = new NamespaceResolver (prefix_lookup.Namespaces); type_resolver = new XamlTypeResolver (namespace_resolver, schemaContext); sctx = schemaContext; ambient_provider = ambientProvider; this.provideValue = provideValue; this.rootProvider = rootProvider; this.destinationProvider = destinationProvider; }
public ValueSerializerContext(PrefixLookup prefixLookup, XamlSchemaContext schemaContext, IAmbientProvider ambientProvider, IProvideValueTarget provideValue, IRootObjectProvider rootProvider, IDestinationTypeProvider destinationProvider, IXamlObjectWriterFactory objectWriterFactory) { if (prefixLookup == null) { throw new ArgumentNullException("prefixLookup"); } if (schemaContext == null) { throw new ArgumentNullException("schemaContext"); } prefix_lookup = prefixLookup; sctx = schemaContext; ambient_provider = ambientProvider; this.provideValue = provideValue; this.rootProvider = rootProvider; this.destinationProvider = destinationProvider; this.objectWriterFactory = objectWriterFactory; }
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)); }
public ValueSerializerContext(PrefixLookup prefixLookup, XamlSchemaContext schemaContext, IAmbientProvider ambientProvider, IProvideValueTarget provideValue, IRootObjectProvider rootProvider, IDestinationTypeProvider destinationProvider) { if (prefixLookup == null) { throw new ArgumentNullException("prefixLookup"); } if (schemaContext == null) { throw new ArgumentNullException("schemaContext"); } prefix_lookup = prefixLookup; namespace_resolver = new NamespaceResolver(prefix_lookup.Namespaces); type_resolver = new XamlTypeResolver(namespace_resolver, schemaContext); sctx = schemaContext; ambient_provider = ambientProvider; this.provideValue = provideValue; this.rootProvider = rootProvider; this.destinationProvider = destinationProvider; }
public static ValueSerializerContext Create(PrefixLookup prefixLookup, XamlSchemaContext schemaContext, Func <IAmbientProvider> ambientProvider, IProvideValueTarget provideValue, IRootObjectProvider rootProvider, IDestinationTypeProvider destinationProvider, IXamlObjectWriterFactory objectWriterFactory) { var context = new ValueSerializerContext(); context.Initialize(prefixLookup, schemaContext, ambientProvider, provideValue, rootProvider, destinationProvider, objectWriterFactory); return(context); }
public static ValueSerializerContext Create(PrefixLookup prefixLookup, XamlSchemaContext schemaContext, IAmbientProvider ambientProvider, IProvideValueTarget provideValue, IRootObjectProvider rootProvider, IDestinationTypeProvider destinationProvider, IXamlObjectWriterFactory objectWriterFactory) { #if !HAS_TYPE_CONVERTER ValueSerializerContext context; var type = GetValueSerializerType(); if (type != null) { context = Activator.CreateInstance(type) as ValueSerializerContext; } else { context = new ValueSerializerContext(); } #else var context = new ValueSerializerContext(); #endif context.Initialize(prefixLookup, schemaContext, ambientProvider, provideValue, rootProvider, destinationProvider, objectWriterFactory); return(context); }