internal static object GetRootTemplatedActivity(IServiceProvider serviceProvider)
        {
            IRootObjectProvider service = serviceProvider.GetService(typeof(IRootObjectProvider)) as IRootObjectProvider;

            if (service == null)
            {
                return(null);
            }
            IAmbientProvider provider2 = serviceProvider.GetService(typeof(IAmbientProvider)) as IAmbientProvider;

            if (provider2 == null)
            {
                return(null);
            }
            IXamlSchemaContextProvider provider3 = serviceProvider.GetService(typeof(IXamlSchemaContextProvider)) as IXamlSchemaContextProvider;

            if (provider3 == null)
            {
                return(null);
            }
            XamlMember member  = GetXamlMember(provider3.SchemaContext, typeof(Activity), "Implementation");
            XamlMember member2 = GetXamlMember(provider3.SchemaContext, typeof(DynamicActivity), "Implementation");

            if ((member == null) || (member2 == null))
            {
                return(null);
            }
            if (provider2.GetFirstAmbientValue(null, new XamlMember[] { member, member2 }) == null)
            {
                return(null);
            }
            return(service.RootObject as Activity);
        }
示例#2
0
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            IXamlSchemaContextProvider service  = serviceProvider.GetService(typeof(IXamlSchemaContextProvider)) as IXamlSchemaContextProvider;
            IAmbientProvider           provider = serviceProvider.GetService(typeof(IAmbientProvider)) as IAmbientProvider;

            Debug.Assert(provider != null, "The provider should not be null!");

            XamlSchemaContext schemaContext = service.SchemaContext;

            XamlType[] types = new XamlType [] { schemaContext.GetXamlType(typeof(ResourcesDict)) };

            // ResourceDict is marked as Ambient, so the instance current being deserialized should be in this list.
            List <AmbientPropertyValue> list = provider.GetAllAmbientValues(null, false, types) as List <AmbientPropertyValue>;

            if (list.Count != 1)
            {
                throw new Exception("expected ambient property count == 1 but " + list.Count);
            }

            AmbientPropertyValue value = list [0];
            ResourcesDict        dict  = value.Value as ResourcesDict;

            // For this example, we know that dict should not be null and that it is the only value in list.
            object result = dict [this.Key];

            return(result);
        }
示例#3
0
        public override object ConvertFrom(ITypeDescriptorContext typeDescriptorContext, CultureInfo cultureInfo, object value)
        {
            String s = value as string;

            if (null == s)
            {
                throw new ArgumentException("XAML can only convert from Strings");
            }

            ColorElement2 e = new ColorElement2();

            IXamlSchemaContextProvider schemaContextProvider = (IXamlSchemaContextProvider)typeDescriptorContext.GetService(typeof(IXamlSchemaContextProvider));
            IAmbientProvider           iAmbient = (IAmbientProvider)typeDescriptorContext.GetService(typeof(IAmbientProvider));

            XamlType             ambientLabel = schemaContextProvider.SchemaContext.GetXamlType(typeof(DerivedFromHasAmbientLabel));
            XamlMember           label        = ambientLabel.GetMember("Num");
            AmbientPropertyValue apVal        = iAmbient.GetFirstAmbientValue(null, label);

            if (apVal == null)
            {
                e.ColorName = s;
            }
            else
            {
                e.ColorName = s + "-" + apVal.Value.ToString();
            }
            return(e);
        }
        public override object ConvertFrom(ITypeDescriptorContext typeDescriptorContext, CultureInfo cultureInfo, object value)
        {
            string s = value as string;

            if (null == s)
            {
                throw new ArgumentException("XAML can only convert from Strings");
            }

            AmbientTC atc = new AmbientTC();
            IXamlSchemaContextProvider xscProvider = (IXamlSchemaContextProvider)typeDescriptorContext.GetService(typeof(IXamlSchemaContextProvider));
            IAmbientProvider           iAmbient    = (IAmbientProvider)typeDescriptorContext.GetService(typeof(IAmbientProvider));

            XamlType             ambientSP      = xscProvider.SchemaContext.GetXamlType(typeof(FooAmbient));
            XamlMember           textProp       = ambientSP.GetMember("AmbientTC");
            AmbientPropertyValue ambientPropVal = iAmbient.GetFirstAmbientValue(null, textProp);

            if (ambientPropVal == null)
            {
                atc.Text = s;
            }
            else
            {
                atc.Text = s + "-" + (ambientPropVal.Value as string);
            }

            return(atc);
        }
示例#5
0
        void ISupportInitialize.EndInit()
        {
            if (this.propertyName != null)
            {
                if (this.TargetName == null)
                {
                    this.Property = DependencyPropertyConverter.Resolve(this.serviceProvider, this.propertyName);
                }
                else
                {
                    // TargetName is specified so we need to look in the containing template for the named element
                    IAmbientProvider           ambient = (IAmbientProvider)this.serviceProvider.GetService(typeof(IAmbientProvider));
                    IXamlSchemaContextProvider schema  = (IXamlSchemaContextProvider)this.serviceProvider.GetService(typeof(IXamlSchemaContextProvider));

                    // Look up the FrameworkTemplate.Template property in the xaml schema.
                    XamlType   frameworkTemplateType = schema.SchemaContext.GetXamlType(typeof(FrameworkTemplate));
                    XamlMember templateProperty      = frameworkTemplateType.GetMember("Template");

                    // Get the value of the first ambient FrameworkTemplate.Template property.
                    TemplateContent templateContent = (TemplateContent)ambient.GetFirstAmbientValue(new[] { frameworkTemplateType }, templateProperty).Value;

                    // Look in the template for the type of TargetName.
                    Type targetType = templateContent.GetTypeForName(this.TargetName);

                    // Finally, find the dependency property on the type.
                    this.Property = DependencyObject.GetPropertyFromName(targetType, this.propertyName);
                }
            }
        }
示例#6
0
        public override object ConvertFrom(ITypeDescriptorContext typeDescriptorContext, CultureInfo cultureInfo, object value)
        {
            String s = value as string;

            if (String.IsNullOrEmpty(s))
            {
                throw new ArgumentException("XAML can only convert from Strings");
            }

            int    dashIdx   = s.IndexOf('-');
            string color     = s;
            string colorType = String.Empty;

            if (dashIdx > 1)
            {
                color     = s.Substring(0, dashIdx);
                colorType = s.Substring(dashIdx + 1);
            }

            ColorElement e = null;

            if (colorType == "Duel")
            {
                e           = new ColorElementDuel();
                e.ColorName = color;
                return(e);
            }
            else
            {
                e = new ColorElement();
            }

            IXamlSchemaContextProvider schemaContextProvider = (IXamlSchemaContextProvider)typeDescriptorContext.GetService(typeof(IXamlSchemaContextProvider));
            IAmbientProvider           iAmbient = (IAmbientProvider)typeDescriptorContext.GetService(typeof(IAmbientProvider));

            XamlType             ambientLabel = schemaContextProvider.SchemaContext.GetXamlType(typeof(HasAmbientLabel));
            XamlMember           label        = ambientLabel.GetMember("Label");
            AmbientPropertyValue apVal        = iAmbient.GetFirstAmbientValue(null, label);

            if (apVal == null)
            {
                e.ColorName = color;
            }
            else
            {
                e.ColorName = color + "-" + apVal.Value.ToString();
            }
            return(e);
        }
示例#7
0
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            IValueSerializerContext    valueSerializerContext    = (IValueSerializerContext)context;
            IXamlSchemaContextProvider xamlSchemaContextProvider = valueSerializerContext.GetRequiredService <IXamlSchemaContextProvider>();

            if (xamlSchemaContextProvider.SchemaContext is ContentManager.InternalXamlSchemaContext xamlSchemaContext)
            {
                if (xamlSchemaContext.ContentManager.TryGetAssetPath(value, out string?path))
                {
                    return(path !);
                }
            }

            return(base.ConvertTo(context, culture, value, destinationType));
        }
        internal static DependencyProperty Resolve(IServiceProvider serviceProvider, string value)
        {
            IAmbientProvider           ambient = (IAmbientProvider)serviceProvider.GetService(typeof(IAmbientProvider));
            IXamlSchemaContextProvider schema  = (IXamlSchemaContextProvider)serviceProvider.GetService(typeof(IXamlSchemaContextProvider));

            // Get the XamlType which represents the <Style> element.
            XamlType styleType = schema.SchemaContext.GetXamlType(typeof(Style));

            // The first ambient value should be the enclosing <Style>.
            Style style = (Style)ambient.GetFirstAmbientValue(styleType);

            // Get the target type for the style from this.
            Type targetType = style.TargetType;

            // And get the dependency property.
            return(DependencyObject.GetPropertyFromName(targetType, value));
        }
        public override object Load(XamlReader xamlReader, IServiceProvider serviceProvider)
        {
            IXamlSchemaContextProvider schema     = (IXamlSchemaContextProvider)serviceProvider.GetService(typeof(IXamlSchemaContextProvider));
            XamlNodeList nodeList                 = new XamlNodeList(schema.SchemaContext);
            Dictionary <string, Type> typesByName = new Dictionary <string, Type>();
            bool nextValueIsName = false;
            Type currentType     = null;

            using (XamlWriter writer = nodeList.Writer)
            {
                while (xamlReader.Read())
                {
                    switch (xamlReader.NodeType)
                    {
                    case XamlNodeType.StartObject:
                        currentType = xamlReader.Type.UnderlyingType;
                        break;

                    case XamlNodeType.StartMember:
                        // HACK: This matches any Name property. Should probably just match
                        // FrameworkElement and x:Name but this'll do for now...
                        if (xamlReader.Member.Name == "Name")
                        {
                            nextValueIsName = true;
                        }

                        break;

                    case XamlNodeType.Value:
                        if (nextValueIsName)
                        {
                            typesByName.Add((string)xamlReader.Value, currentType);
                            nextValueIsName = false;
                        }

                        break;
                    }

                    writer.WriteNode(xamlReader);
                }
            }

            return(new TemplateContent(nodeList, typesByName));
        }
示例#10
0
        private bool SetOurEnv(IServiceProvider serviceProvider, out BindingTarget bindingTarget)
        {
            bindingTarget = null;

            if (serviceProvider == null)
            {
                return(false);
            }

            IProvideValueTarget provideValueTarget = serviceProvider.GetService(typeof(IProvideValueTarget)) as IProvideValueTarget;

            if (provideValueTarget == null)
            {
                return(false);
            }

            IXamlSchemaContextProvider schemaProvider = serviceProvider.GetService(typeof(IXamlSchemaContextProvider)) as IXamlSchemaContextProvider;

            // Currently working on getting the xmlns prefix used for this instance.
            //string ns = GetXmlnsPrefix(schemaProvider, this.GetType());


            DependencyObject targetObject = provideValueTarget.TargetObject as DependencyObject;

            if (targetObject == null)
            {
                return(false);
            }

            if (provideValueTarget.TargetProperty is DependencyProperty dp)
            {
                bindingTarget = new BindingTarget(targetObject, dp);
                return(true);
            }
            else if (provideValueTarget.TargetProperty is PropertyInfo pi)
            {
                bindingTarget = new BindingTarget(targetObject, pi);
                return(true);
            }
            else
            {
                throw new InvalidOperationException("The target of the binding must be a DependencyProperty or a PropertyInfo.");
            }
        }
示例#11
0
        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));
        }
        private static string ConvertTypeToString(ITypeDescriptorContext context, Type type)
        {
            IXamlSchemaContextProvider service = GetService <IXamlSchemaContextProvider>(context);

            if (service == null)
            {
                return(null);
            }
            if (service.SchemaContext == null)
            {
                return(null);
            }
            XamlType xamlType = service.SchemaContext.GetXamlType(type);

            if (xamlType == null)
            {
                return(null);
            }
            return(XamlTypeTypeConverter.ConvertXamlTypeToString(context, xamlType));
        }
        private static XamlType ConvertStringToXamlType(ITypeDescriptorContext context, string typeName)
        {
            IXamlNamespaceResolver service = GetService <IXamlNamespaceResolver>(context);

            if (service == null)
            {
                return(null);
            }
            XamlTypeName name = XamlTypeName.Parse(typeName, service);
            IXamlSchemaContextProvider provider = GetService <IXamlSchemaContextProvider>(context);

            if (provider == null)
            {
                return(null);
            }
            if (provider.SchemaContext == null)
            {
                return(null);
            }
            return(GetXamlTypeOrUnknown(provider.SchemaContext, name));
        }
示例#14
0
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            IXamlSchemaContextProvider schemaContextProvider =
                (IXamlSchemaContextProvider)context.GetService(typeof(IXamlSchemaContextProvider));
            IAmbientProvider ambientValueProvider =
                (IAmbientProvider)context.GetService(typeof(IAmbientProvider));
            IXamlNamespaceResolver namespaceResolver =
                (IXamlNamespaceResolver)context.GetService(typeof(IXamlNamespaceResolver));

            XamlTypeName typeName        = XamlTypeName.Parse("TemplateClass2", namespaceResolver);
            XamlType     xamlType        = schemaContextProvider.SchemaContext.GetXamlType(typeName);
            XamlMember   ambientProperty = xamlType.GetMember("Suffix");
            IEnumerable <AmbientPropertyValue> propVals = ambientValueProvider.GetAllAmbientValues(null, ambientProperty);
            string s = (string)value;

            foreach (AmbientPropertyValue val in propVals)
            {
                s += (string)val.Value;
            }
            return(s);
        }
        internal static object GetRootTemplatedActivity(IServiceProvider serviceProvider)
        {
            // For now, we only support references to the root Activity when we're inside an Activity.Body
            // Note that in the case of nested activity bodies, this gives us the outer activity
            IRootObjectProvider rootProvider =
                serviceProvider.GetService(typeof(IRootObjectProvider)) as IRootObjectProvider;

            if (rootProvider == null)
            {
                return(null);
            }
            IAmbientProvider ambientProvider =
                serviceProvider.GetService(typeof(IAmbientProvider)) as IAmbientProvider;

            if (ambientProvider == null)
            {
                return(null);
            }
            IXamlSchemaContextProvider schemaContextProvider =
                serviceProvider.GetService(typeof(IXamlSchemaContextProvider)) as IXamlSchemaContextProvider;

            if (schemaContextProvider == null)
            {
                return(null);
            }
            XamlMember activityBody        = GetXamlMember(schemaContextProvider.SchemaContext, typeof(Activity), "Implementation");
            XamlMember dynamicActivityBody = GetXamlMember(schemaContextProvider.SchemaContext, typeof(DynamicActivity), "Implementation");

            if (activityBody == null || dynamicActivityBody == null)
            {
                return(null);
            }
            if (ambientProvider.GetFirstAmbientValue(null, activityBody, dynamicActivityBody) == null)
            {
                return(null);
            }
            object rootActivity = rootProvider.RootObject as Activity;

            return(rootActivity);
        }
        private static XamlSchemaContext GetSchemaContext(ITypeDescriptorContext context)
        {
            IXamlSchemaContextProvider provider = context.GetService(typeof(IXamlSchemaContextProvider)) as IXamlSchemaContextProvider;

            return(provider != null ? provider.SchemaContext : null);
        }
        // Token: 0x0600224E RID: 8782 RVA: 0x000AA9F8 File Offset: 0x000A8BF8
        internal static object ResolveValue(ITypeDescriptorContext serviceProvider, DependencyProperty property, CultureInfo culture, object source)
        {
            if (serviceProvider == null)
            {
                throw new ArgumentNullException("serviceProvider");
            }
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            if (!(source is byte[]) && !(source is string) && !(source is Stream))
            {
                return(source);
            }
            IXamlSchemaContextProvider xamlSchemaContextProvider = serviceProvider.GetService(typeof(IXamlSchemaContextProvider)) as IXamlSchemaContextProvider;

            if (xamlSchemaContextProvider == null)
            {
                throw new NotSupportedException(SR.Get("ParserCannotConvertPropertyValue", new object[]
                {
                    "Value",
                    typeof(object).FullName
                }));
            }
            XamlSchemaContext schemaContext = xamlSchemaContextProvider.SchemaContext;

            if (property == null)
            {
                return(source);
            }
            XamlMember xamlMember = schemaContext.GetXamlType(property.OwnerType).GetMember(property.Name);

            if (xamlMember == null)
            {
                xamlMember = schemaContext.GetXamlType(property.OwnerType).GetAttachableMember(property.Name);
            }
            XamlValueConverter <TypeConverter> typeConverter;

            if (xamlMember != null)
            {
                if (xamlMember.Type.UnderlyingType.IsEnum && schemaContext is Baml2006SchemaContext)
                {
                    typeConverter = XamlReader.BamlSharedSchemaContext.GetTypeConverter(xamlMember.Type.UnderlyingType);
                }
                else
                {
                    typeConverter = xamlMember.TypeConverter;
                    if (typeConverter == null)
                    {
                        typeConverter = xamlMember.Type.TypeConverter;
                    }
                }
            }
            else
            {
                typeConverter = schemaContext.GetXamlType(property.PropertyType).TypeConverter;
            }
            if (typeConverter.ConverterType == null)
            {
                return(source);
            }
            TypeConverter typeConverter2;

            if (xamlMember != null && xamlMember.Type.UnderlyingType == typeof(bool))
            {
                if (source is string)
                {
                    typeConverter2 = new BooleanConverter();
                }
                else
                {
                    if (!(source is byte[]))
                    {
                        throw new NotSupportedException(SR.Get("ParserCannotConvertPropertyValue", new object[]
                        {
                            "Value",
                            typeof(object).FullName
                        }));
                    }
                    byte[] array = source as byte[];
                    if (array != null && array.Length == 1)
                    {
                        return(array[0] > 0);
                    }
                    throw new NotSupportedException(SR.Get("ParserCannotConvertPropertyValue", new object[]
                    {
                        "Value",
                        typeof(object).FullName
                    }));
                }
            }
            else
            {
                typeConverter2 = typeConverter.ConverterInstance;
            }
            return(typeConverter2.ConvertFrom(serviceProvider, culture, source));
        }
        // Token: 0x0600210C RID: 8460 RVA: 0x00097FBC File Offset: 0x000961BC
        internal static DependencyProperty ResolveProperty(IServiceProvider serviceProvider, string targetName, object source)
        {
            Type               type = null;
            string             text = null;
            DependencyProperty dependencyProperty = source as DependencyProperty;

            if (dependencyProperty != null)
            {
                return(dependencyProperty);
            }
            byte[] array;
            if ((array = (source as byte[])) != null)
            {
                Baml2006SchemaContext baml2006SchemaContext = (serviceProvider.GetService(typeof(IXamlSchemaContextProvider)) as IXamlSchemaContextProvider).SchemaContext as Baml2006SchemaContext;
                if (array.Length == 2)
                {
                    short propertyId = (short)((int)array[0] | (int)array[1] << 8);
                    return(baml2006SchemaContext.GetDependencyProperty(propertyId));
                }
                using (BinaryReader binaryReader = new BinaryReader(new MemoryStream(array)))
                {
                    type = baml2006SchemaContext.GetXamlType(binaryReader.ReadInt16()).UnderlyingType;
                    text = binaryReader.ReadString();
                    goto IL_142;
                }
            }
            string text2;

            if ((text2 = (source as string)) == null)
            {
                throw new NotSupportedException(SR.Get("ParserCannotConvertPropertyValue", new object[]
                {
                    "Property",
                    typeof(DependencyProperty).FullName
                }));
            }
            text2 = text2.Trim();
            if (text2.Contains("."))
            {
                int    num = text2.LastIndexOf('.');
                string qualifiedTypeName = text2.Substring(0, num);
                text = text2.Substring(num + 1);
                IXamlTypeResolver xamlTypeResolver = serviceProvider.GetService(typeof(IXamlTypeResolver)) as IXamlTypeResolver;
                type = xamlTypeResolver.Resolve(qualifiedTypeName);
            }
            else
            {
                int num2 = text2.LastIndexOf(':');
                text = text2.Substring(num2 + 1);
            }
IL_142:
            if (type == null && targetName != null)
            {
                IAmbientProvider  ambientProvider = serviceProvider.GetService(typeof(IAmbientProvider)) as IAmbientProvider;
                XamlSchemaContext schemaContext   = (serviceProvider.GetService(typeof(IXamlSchemaContextProvider)) as IXamlSchemaContextProvider).SchemaContext;
                type = DependencyPropertyConverter.GetTypeFromName(schemaContext, ambientProvider, targetName);
            }
            if (type == null)
            {
                IXamlSchemaContextProvider xamlSchemaContextProvider = serviceProvider.GetService(typeof(IXamlSchemaContextProvider)) as IXamlSchemaContextProvider;
                if (xamlSchemaContextProvider == null)
                {
                    throw new NotSupportedException(SR.Get("ParserCannotConvertPropertyValue", new object[]
                    {
                        "Property",
                        typeof(DependencyProperty).FullName
                    }));
                }
                XamlSchemaContext schemaContext2 = xamlSchemaContextProvider.SchemaContext;
                XamlType          xamlType       = schemaContext2.GetXamlType(typeof(Style));
                XamlType          xamlType2      = schemaContext2.GetXamlType(typeof(FrameworkTemplate));
                XamlType          xamlType3      = schemaContext2.GetXamlType(typeof(DataTemplate));
                XamlType          xamlType4      = schemaContext2.GetXamlType(typeof(ControlTemplate));
                List <XamlType>   list           = new List <XamlType>();
                list.Add(xamlType);
                list.Add(xamlType2);
                list.Add(xamlType3);
                list.Add(xamlType4);
                XamlMember       member           = xamlType.GetMember("TargetType");
                XamlMember       member2          = xamlType2.GetMember("Template");
                XamlMember       member3          = xamlType4.GetMember("TargetType");
                IAmbientProvider ambientProvider2 = serviceProvider.GetService(typeof(IAmbientProvider)) as IAmbientProvider;
                if (ambientProvider2 == null)
                {
                    throw new NotSupportedException(SR.Get("ParserCannotConvertPropertyValue", new object[]
                    {
                        "Property",
                        typeof(DependencyProperty).FullName
                    }));
                }
                AmbientPropertyValue firstAmbientValue = ambientProvider2.GetFirstAmbientValue(list, new XamlMember[]
                {
                    member,
                    member2,
                    member3
                });
                if (firstAmbientValue != null)
                {
                    if (firstAmbientValue.Value is Type)
                    {
                        type = (Type)firstAmbientValue.Value;
                    }
                    else
                    {
                        if (!(firstAmbientValue.Value is TemplateContent))
                        {
                            throw new NotSupportedException(SR.Get("ParserCannotConvertPropertyValue", new object[]
                            {
                                "Property",
                                typeof(DependencyProperty).FullName
                            }));
                        }
                        TemplateContent templateContent = firstAmbientValue.Value as TemplateContent;
                        type = templateContent.OwnerTemplate.TargetTypeInternal;
                    }
                }
            }
            if (type != null && text != null)
            {
                return(DependencyProperty.FromName(text, type));
            }
            throw new NotSupportedException(SR.Get("ParserCannotConvertPropertyValue", new object[]
            {
                "Property",
                typeof(DependencyProperty).FullName
            }));
        }
示例#19
0
        public static VisualBasicSettings CollectXmlNamespacesAndAssemblies(ITypeDescriptorContext context)
        {
            // access XamlSchemaContext.ReferenceAssemblies
            // for the Compiled Xaml scenario
            IList <Assembly>           xsCtxReferenceAssemblies  = null;
            IXamlSchemaContextProvider xamlSchemaContextProvider = context.GetService(typeof(IXamlSchemaContextProvider)) as IXamlSchemaContextProvider;

            if (xamlSchemaContextProvider != null && xamlSchemaContextProvider.SchemaContext != null)
            {
                xsCtxReferenceAssemblies = xamlSchemaContextProvider.SchemaContext.ReferenceAssemblies;
                if (xsCtxReferenceAssemblies != null && xsCtxReferenceAssemblies.Count == 0)
                {
                    xsCtxReferenceAssemblies = null;
                }
            }

            VisualBasicSettings    settings          = null;
            IXamlNamespaceResolver namespaceResolver = (IXamlNamespaceResolver)context.GetService(typeof(IXamlNamespaceResolver));

            if (namespaceResolver == null)
            {
                return(null);
            }

            lock (AssemblyCache.XmlnsMappingsLockObject)
            {
                // Fetch xmlnsMappings for the prefixes returned by the namespaceResolver service

                foreach (NamespaceDeclaration prefix in namespaceResolver.GetNamespacePrefixes())
                {
                    ReadOnlyXmlnsMapping mapping;
                    WrapCachedMapping(prefix, out mapping);
                    if (!mapping.IsEmpty)
                    {
                        if (settings == null)
                        {
                            settings = new VisualBasicSettings();
                        }

                        if (!mapping.IsEmpty)
                        {
                            foreach (ReadOnlyVisualBasicImportReference importReference in mapping.ImportReferences)
                            {
                                if (xsCtxReferenceAssemblies != null)
                                {
                                    // this is "compiled Xaml"
                                    VisualBasicImportReference newImportReference;

                                    if (importReference.EarlyBoundAssembly != null)
                                    {
                                        if (xsCtxReferenceAssemblies.Contains(importReference.EarlyBoundAssembly))
                                        {
                                            newImportReference = importReference.Clone();
                                            newImportReference.EarlyBoundAssembly = importReference.EarlyBoundAssembly;
                                            settings.ImportReferences.Add(newImportReference);
                                        }
                                        continue;
                                    }

                                    for (int i = 0; i < xsCtxReferenceAssemblies.Count; i++)
                                    {
                                        AssemblyName xsCtxAssemblyName = VisualBasicHelper.GetFastAssemblyName(xsCtxReferenceAssemblies[i]);
                                        if (importReference.AssemblySatisfiesReference(xsCtxAssemblyName))
                                        {
                                            // bind this assembly early to the importReference
                                            // so later AssemblyName resolution can be skipped
                                            newImportReference = importReference.Clone();
                                            newImportReference.EarlyBoundAssembly = xsCtxReferenceAssemblies[i];
                                            settings.ImportReferences.Add(newImportReference);
                                            break;
                                        }
                                    }
                                }
                                else
                                {
                                    // this is "loose Xaml"
                                    VisualBasicImportReference newImportReference = importReference.Clone();
                                    if (importReference.EarlyBoundAssembly != null)
                                    {
                                        // VBImportReference.Clone() method deliberately doesn't copy
                                        // its EarlyBoundAssembly to the cloned instance.
                                        // we need to explicitly copy the original's EarlyBoundAssembly
                                        newImportReference.EarlyBoundAssembly = importReference.EarlyBoundAssembly;
                                    }
                                    settings.ImportReferences.Add(newImportReference);
                                }
                            }
                        }
                    }
                }
            }
            return(settings);
        }
        internal static object ResolveValue(ITypeDescriptorContext serviceProvider,
                                            DependencyProperty property, CultureInfo culture, object source)
        {
            if (serviceProvider == null)
            {
                throw new ArgumentNullException("serviceProvider");
            }
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            // Only need to type convert strings and byte[]
            if (!(source is byte[] || source is String || source is Stream))
            {
                return(source);
            }

            IXamlSchemaContextProvider ixsc = (serviceProvider.GetService(typeof(IXamlSchemaContextProvider))
                                               as IXamlSchemaContextProvider);

            if (ixsc == null)
            {
                throw new NotSupportedException(SR.Get(SRID.ParserCannotConvertPropertyValue, "Value", typeof(Object).FullName));
            }
            XamlSchemaContext schemaContext = ixsc.SchemaContext;

            if (property != null)
            {
                //Get XamlMember from dp
                System.Xaml.XamlMember xamlProperty =
                    schemaContext.GetXamlType(property.OwnerType).GetMember(property.Name);
                if (xamlProperty == null)
                {
                    xamlProperty =
                        schemaContext.GetXamlType(property.OwnerType).GetAttachableMember(property.Name);
                }

                System.Xaml.Schema.XamlValueConverter <TypeConverter> typeConverter = null;

                if (xamlProperty != null)
                {
                    // If we have a Baml2006SchemaContext and the property is of type Enum, we already know that the
                    // type converter must be the EnumConverter.
                    if (xamlProperty.Type.UnderlyingType.IsEnum && schemaContext is Baml2006.Baml2006SchemaContext)
                    {
                        typeConverter = XamlReader.BamlSharedSchemaContext.GetTypeConverter(xamlProperty.Type.UnderlyingType);
                    }
                    else
                    {
                        typeConverter = xamlProperty.TypeConverter;

                        if (typeConverter == null)
                        {
                            typeConverter = xamlProperty.Type.TypeConverter;
                        }
                    }
                }
                else
                {
                    typeConverter = schemaContext.GetXamlType(property.PropertyType).TypeConverter;
                }


                // No Type converter case...
                if (typeConverter.ConverterType == null)
                {
                    return(source);
                }

                TypeConverter converter = null;

                if (xamlProperty != null && xamlProperty.Type.UnderlyingType == typeof(Boolean))
                {
                    if (source is String)
                    {
                        converter = new BooleanConverter();
                    }
                    else if (source is byte[])
                    {
                        byte[] bytes = source as byte[];
                        if (bytes != null && bytes.Length == 1)
                        {
                            return(bytes[0] != 0);
                        }
                        else
                        {
                            throw new NotSupportedException(SR.Get(SRID.ParserCannotConvertPropertyValue, "Value", typeof(Object).FullName));
                        }
                    }
                    else
                    {
                        throw new NotSupportedException(SR.Get(SRID.ParserCannotConvertPropertyValue, "Value", typeof(Object).FullName));
                    }
                }
                else
                {
                    converter = (TypeConverter)typeConverter.ConverterInstance;
                }

                return(converter.ConvertFrom(serviceProvider, culture, source));
            }
            else
            {
                return(source);
            }
        }
示例#21
0
        /// <summary>
        ///     Convert a string like "Button.Click" into the corresponding RoutedEvent
        /// </summary>
        public override object ConvertFrom(ITypeDescriptorContext typeDescriptorContext,
                                           CultureInfo cultureInfo,
                                           object source)
        {
            string      routedEventName = source as string;
            RoutedEvent routedEvent     = null;

            if (routedEventName != null)
            {
                routedEventName = routedEventName.Trim();
                IServiceProvider serviceProvider = typeDescriptorContext as IServiceProvider;

                if (serviceProvider != null)
                {
                    IXamlTypeResolver resolver = serviceProvider.GetService(typeof(IXamlTypeResolver)) as IXamlTypeResolver;
                    Type type = null;

                    if (resolver != null)
                    {
                        // Verify that there's at least one period.  (A simple
                        //  but not foolproof check for "[class].[event]")
                        int lastIndex = routedEventName.IndexOf('.');
                        if (lastIndex != -1)
                        {
                            string typeName = routedEventName.Substring(0, lastIndex);
                            routedEventName = routedEventName.Substring(lastIndex + 1);

                            type = resolver.Resolve(typeName);
                        }
                    }

                    if (type == null)
                    {
                        IXamlSchemaContextProvider schemaContextProvider = (typeDescriptorContext.
                                                                            GetService(typeof(IXamlSchemaContextProvider))
                                                                            as IXamlSchemaContextProvider);

                        IAmbientProvider iapp = serviceProvider.GetService(typeof(IAmbientProvider)) as IAmbientProvider;

                        if (schemaContextProvider != null && iapp != null)
                        {
                            XamlSchemaContext schemaContext = schemaContextProvider.SchemaContext;

                            XamlType styleXType = schemaContext.GetXamlType(typeof(Style));

                            List <XamlType> ceilingTypes = new List <XamlType>();
                            ceilingTypes.Add(styleXType);

                            XamlMember styleTargetType = styleXType.GetMember("TargetType");

                            AmbientPropertyValue firstAmbientValue = iapp.GetFirstAmbientValue(ceilingTypes, styleTargetType);

                            if (firstAmbientValue != null)
                            {
                                type = firstAmbientValue.Value as Type;
                            }
                            if (type == null)
                            {
                                type = typeof(FrameworkElement);
                            }
                        }
                    }

                    if (type != null)
                    {
                        Type currentType = type;

                        // Force load the Statics by walking up the hierarchy and running class constructors
                        while (null != currentType)
                        {
                            MS.Internal.WindowsBase.SecurityHelper.RunClassConstructor(currentType);
                            currentType = currentType.BaseType;
                        }

                        routedEvent = EventManager.GetRoutedEventFromName(routedEventName, type);
                    }
                }
            }

            if (routedEvent == null)
            {
                // Falling through here means we are unable to perform the conversion.
                throw GetConvertFromException(source);
            }

            return(routedEvent);
        }
示例#22
0
        // Token: 0x060064CC RID: 25804 RVA: 0x001C4434 File Offset: 0x001C2634
        internal static void CheckCanReceiveMarkupExtension(MarkupExtension markupExtension, IServiceProvider serviceProvider, out DependencyObject targetDependencyObject, out DependencyProperty targetDependencyProperty)
        {
            targetDependencyObject   = null;
            targetDependencyProperty = null;
            IProvideValueTarget provideValueTarget = serviceProvider.GetService(typeof(IProvideValueTarget)) as IProvideValueTarget;

            if (provideValueTarget == null)
            {
                return;
            }
            object targetObject = provideValueTarget.TargetObject;

            if (targetObject == null)
            {
                return;
            }
            Type   type           = targetObject.GetType();
            object targetProperty = provideValueTarget.TargetProperty;

            if (targetProperty != null)
            {
                targetDependencyProperty = (targetProperty as DependencyProperty);
                if (targetDependencyProperty != null)
                {
                    targetDependencyObject = (targetObject as DependencyObject);
                    return;
                }
                MemberInfo memberInfo = targetProperty as MemberInfo;
                if (memberInfo != null)
                {
                    PropertyInfo propertyInfo = memberInfo as PropertyInfo;
                    EventHandler <XamlSetMarkupExtensionEventArgs> eventHandler = Helper.LookupSetMarkupExtensionHandler(type);
                    if (eventHandler != null && propertyInfo != null)
                    {
                        IXamlSchemaContextProvider xamlSchemaContextProvider = serviceProvider.GetService(typeof(IXamlSchemaContextProvider)) as IXamlSchemaContextProvider;
                        if (xamlSchemaContextProvider != null)
                        {
                            XamlSchemaContext schemaContext = xamlSchemaContextProvider.SchemaContext;
                            XamlType          xamlType      = schemaContext.GetXamlType(type);
                            if (xamlType != null)
                            {
                                XamlMember member = xamlType.GetMember(propertyInfo.Name);
                                if (member != null)
                                {
                                    XamlSetMarkupExtensionEventArgs xamlSetMarkupExtensionEventArgs = new XamlSetMarkupExtensionEventArgs(member, markupExtension, serviceProvider);
                                    eventHandler(targetObject, xamlSetMarkupExtensionEventArgs);
                                    if (xamlSetMarkupExtensionEventArgs.Handled)
                                    {
                                        return;
                                    }
                                }
                            }
                        }
                    }
                    Type type2;
                    if (propertyInfo != null)
                    {
                        type2 = propertyInfo.PropertyType;
                    }
                    else
                    {
                        MethodInfo      methodInfo = (MethodInfo)memberInfo;
                        ParameterInfo[] parameters = methodInfo.GetParameters();
                        type2 = parameters[1].ParameterType;
                    }
                    if (!typeof(MarkupExtension).IsAssignableFrom(type2) || !type2.IsAssignableFrom(markupExtension.GetType()))
                    {
                        throw new System.Windows.Markup.XamlParseException(SR.Get("MarkupExtensionDynamicOrBindingOnClrProp", new object[]
                        {
                            markupExtension.GetType().Name,
                            memberInfo.Name,
                            type.Name
                        }));
                    }
                }
                else if (!typeof(BindingBase).IsAssignableFrom(markupExtension.GetType()) || !typeof(Collection <BindingBase>).IsAssignableFrom(targetProperty.GetType()))
                {
                    throw new System.Windows.Markup.XamlParseException(SR.Get("MarkupExtensionDynamicOrBindingInCollection", new object[]
                    {
                        markupExtension.GetType().Name,
                        targetProperty.GetType().Name
                    }));
                }
            }
            else if (!typeof(BindingBase).IsAssignableFrom(markupExtension.GetType()) || !typeof(Collection <BindingBase>).IsAssignableFrom(type))
            {
                throw new System.Windows.Markup.XamlParseException(SR.Get("MarkupExtensionDynamicOrBindingInCollection", new object[]
                {
                    markupExtension.GetType().Name,
                    type.Name
                }));
            }
        }
        public static VisualBasicSettings CollectXmlNamespacesAndAssemblies(ITypeDescriptorContext context)
        {
            IList <Assembly>           referenceAssemblies = null;
            IXamlSchemaContextProvider service             = context.GetService(typeof(IXamlSchemaContextProvider)) as IXamlSchemaContextProvider;

            if ((service != null) && (service.SchemaContext != null))
            {
                referenceAssemblies = service.SchemaContext.ReferenceAssemblies;
                if ((referenceAssemblies != null) && (referenceAssemblies.Count == 0))
                {
                    referenceAssemblies = null;
                }
            }
            VisualBasicSettings    settings = null;
            IXamlNamespaceResolver resolver = (IXamlNamespaceResolver)context.GetService(typeof(IXamlNamespaceResolver));

            if (resolver == null)
            {
                return(null);
            }
            lock (AssemblyCache.XmlnsMappings)
            {
                foreach (System.Xaml.NamespaceDeclaration declaration in resolver.GetNamespacePrefixes())
                {
                    XmlnsMapping mapping;
                    XNamespace   key = XNamespace.Get(declaration.Namespace);
                    if (!AssemblyCache.XmlnsMappings.TryGetValue(key, out mapping))
                    {
                        Match match = assemblyQualifiedNamespaceRegex.Match(declaration.Namespace);
                        if (match.Success)
                        {
                            mapping.ImportReferences = new System.Collections.Generic.HashSet <VisualBasicImportReference>();
                            VisualBasicImportReference item = new VisualBasicImportReference {
                                Assembly = match.Groups["assembly"].Value,
                                Import   = match.Groups["namespace"].Value,
                                Xmlns    = key
                            };
                            mapping.ImportReferences.Add(item);
                        }
                        else
                        {
                            mapping.ImportReferences = new System.Collections.Generic.HashSet <VisualBasicImportReference>();
                        }
                        AssemblyCache.XmlnsMappings[key] = mapping;
                    }
                    if (!mapping.IsEmpty)
                    {
                        if (settings == null)
                        {
                            settings = new VisualBasicSettings();
                        }
                        foreach (VisualBasicImportReference reference2 in mapping.ImportReferences)
                        {
                            if (referenceAssemblies != null)
                            {
                                VisualBasicImportReference reference3;
                                AssemblyName assemblyName = reference2.AssemblyName;
                                if (reference2.EarlyBoundAssembly != null)
                                {
                                    if (referenceAssemblies.Contains(reference2.EarlyBoundAssembly))
                                    {
                                        reference3 = reference2.Clone();
                                        reference3.EarlyBoundAssembly = reference2.EarlyBoundAssembly;
                                        settings.ImportReferences.Add(reference3);
                                    }
                                }
                                else
                                {
                                    for (int i = 0; i < referenceAssemblies.Count; i++)
                                    {
                                        if (AssemblySatisfiesReference(VisualBasicHelper.GetFastAssemblyName(referenceAssemblies[i]), assemblyName))
                                        {
                                            reference3 = reference2.Clone();
                                            reference3.EarlyBoundAssembly = referenceAssemblies[i];
                                            settings.ImportReferences.Add(reference3);
                                            break;
                                        }
                                    }
                                }
                            }
                            else
                            {
                                VisualBasicImportReference reference4 = reference2.Clone();
                                if (reference2.EarlyBoundAssembly != null)
                                {
                                    reference4.EarlyBoundAssembly = reference2.EarlyBoundAssembly;
                                }
                                settings.ImportReferences.Add(reference4);
                            }
                        }
                    }
                }
            }
            return(settings);
        }
        // Token: 0x06000865 RID: 2149 RVA: 0x0001B4E8 File Offset: 0x000196E8
        private ResourceDictionary FindTheResourceDictionary(IServiceProvider serviceProvider, bool isDeferredContentSearch)
        {
            IXamlSchemaContextProvider xamlSchemaContextProvider = serviceProvider.GetService(typeof(IXamlSchemaContextProvider)) as IXamlSchemaContextProvider;

            if (xamlSchemaContextProvider == null)
            {
                throw new InvalidOperationException(SR.Get("MarkupExtensionNoContext", new object[]
                {
                    base.GetType().Name,
                    "IXamlSchemaContextProvider"
                }));
            }
            IAmbientProvider ambientProvider = serviceProvider.GetService(typeof(IAmbientProvider)) as IAmbientProvider;

            if (ambientProvider == null)
            {
                throw new InvalidOperationException(SR.Get("MarkupExtensionNoContext", new object[]
                {
                    base.GetType().Name,
                    "IAmbientProvider"
                }));
            }
            XamlSchemaContext schemaContext = xamlSchemaContextProvider.SchemaContext;
            XamlType          xamlType      = schemaContext.GetXamlType(typeof(FrameworkElement));
            XamlType          xamlType2     = schemaContext.GetXamlType(typeof(Style));
            XamlType          xamlType3     = schemaContext.GetXamlType(typeof(FrameworkTemplate));
            XamlType          xamlType4     = schemaContext.GetXamlType(typeof(Application));
            XamlType          xamlType5     = schemaContext.GetXamlType(typeof(FrameworkContentElement));
            XamlMember        member        = xamlType5.GetMember("Resources");
            XamlMember        member2       = xamlType.GetMember("Resources");
            XamlMember        member3       = xamlType2.GetMember("Resources");
            XamlMember        member4       = xamlType2.GetMember("BasedOn");
            XamlMember        member5       = xamlType3.GetMember("Resources");
            XamlMember        member6       = xamlType4.GetMember("Resources");

            XamlType[] types = new XamlType[]
            {
                schemaContext.GetXamlType(typeof(ResourceDictionary))
            };
            IEnumerable <AmbientPropertyValue> allAmbientValues = ambientProvider.GetAllAmbientValues(null, isDeferredContentSearch, types, new XamlMember[]
            {
                member,
                member2,
                member3,
                member4,
                member5,
                member6
            });
            List <AmbientPropertyValue> list = allAmbientValues as List <AmbientPropertyValue>;

            for (int i = 0; i < list.Count; i++)
            {
                AmbientPropertyValue ambientPropertyValue = list[i];
                if (ambientPropertyValue.Value is ResourceDictionary)
                {
                    ResourceDictionary resourceDictionary = (ResourceDictionary)ambientPropertyValue.Value;
                    if (resourceDictionary.Contains(this.ResourceKey))
                    {
                        return(resourceDictionary);
                    }
                }
                if (ambientPropertyValue.Value is Style)
                {
                    Style style = (Style)ambientPropertyValue.Value;
                    ResourceDictionary resourceDictionary2 = style.FindResourceDictionary(this.ResourceKey);
                    if (resourceDictionary2 != null)
                    {
                        return(resourceDictionary2);
                    }
                }
            }
            return(null);
        }
        internal static DependencyProperty ResolveProperty(IServiceProvider serviceProvider,
                                                           string targetName, object source)
        {
            Type   type     = null;
            string property = null;

            DependencyProperty dProperty = source as DependencyProperty;

            byte[] bytes;
            String value;

            if (dProperty != null)
            {
                return(dProperty);
            }
            // If it's a byte[] we got it from BAML.  Let's resolve it using the schema context
            else if ((bytes = source as byte[]) != null)
            {
                Baml2006SchemaContext schemaContext = (serviceProvider.GetService(typeof(IXamlSchemaContextProvider))
                                                       as IXamlSchemaContextProvider).SchemaContext as Baml2006SchemaContext;

                // Array with length of 2 means its an ID for a
                // DependencyProperty in the Baml2006SchemaContext
                if (bytes.Length == 2)
                {
                    short propId = (short)(bytes[0] | (bytes[1] << 8));

                    return(schemaContext.GetDependencyProperty(propId));
                }
                else
                {
                    // Otherwise it's a string with a TypeId encoded in front
                    using (BinaryReader reader = new BinaryReader(new MemoryStream(bytes)))
                    {
                        type     = schemaContext.GetXamlType(reader.ReadInt16()).UnderlyingType;
                        property = reader.ReadString();
                    }
                }
            }
            else if ((value = source as string) != null)
            {
                value = value.Trim();
                // If it contains a . it means that it is a full name with type and property.
                if (value.Contains("."))
                {
                    // Prefixes could have .'s so we take the last one and do a type resolve against that
                    int    lastIndex = value.LastIndexOf('.');
                    string typeName  = value.Substring(0, lastIndex);
                    property = value.Substring(lastIndex + 1);

                    IXamlTypeResolver resolver = serviceProvider.GetService(typeof(IXamlTypeResolver))
                                                 as IXamlTypeResolver;
                    type = resolver.Resolve(typeName);
                }
                else
                {
                    // Only have the property name
                    // Strip prefixes if there are any, v3 essentially discards the prefix in this case
                    int lastIndex = value.LastIndexOf(':');
                    property = value.Substring(lastIndex + 1);
                }
            }
            else
            {
                throw new NotSupportedException(SR.Get(SRID.ParserCannotConvertPropertyValue, "Property", typeof(DependencyProperty).FullName));
            }

            // We got additional info from either Trigger.SourceName or Setter.TargetName
            if (type == null && targetName != null)
            {
                IAmbientProvider ambientProvider = serviceProvider.GetService(typeof(IAmbientProvider))
                                                   as System.Xaml.IAmbientProvider;
                XamlSchemaContext schemaContext = (serviceProvider.GetService(typeof(IXamlSchemaContextProvider))
                                                   as IXamlSchemaContextProvider).SchemaContext;

                type = GetTypeFromName(schemaContext,
                                       ambientProvider, targetName);
            }

            // Still don't have a Type so we need to loop up the chain and grab either Style.TargetType,
            // DataTemplate.DataType, or ControlTemplate.TargetType
            if (type == null)
            {
                IXamlSchemaContextProvider ixscp = (serviceProvider.GetService(typeof(IXamlSchemaContextProvider))
                                                    as IXamlSchemaContextProvider);
                if (ixscp == null)
                {
                    throw new NotSupportedException(SR.Get(SRID.ParserCannotConvertPropertyValue, "Property", typeof(DependencyProperty).FullName));
                }
                XamlSchemaContext schemaContext = ixscp.SchemaContext;

                XamlType styleXType             = schemaContext.GetXamlType(typeof(Style));
                XamlType frameworkTemplateXType = schemaContext.GetXamlType(typeof(FrameworkTemplate));
                XamlType dataTemplateXType      = schemaContext.GetXamlType(typeof(DataTemplate));
                XamlType controlTemplateXType   = schemaContext.GetXamlType(typeof(ControlTemplate));

                List <XamlType> ceilingTypes = new List <XamlType>();
                ceilingTypes.Add(styleXType);
                ceilingTypes.Add(frameworkTemplateXType);
                ceilingTypes.Add(dataTemplateXType);
                ceilingTypes.Add(controlTemplateXType);

                // We don't look for DataTemplate's DataType since we want to use the TargetTypeInternal instead
                XamlMember styleTargetType           = styleXType.GetMember("TargetType");
                XamlMember templateProperty          = frameworkTemplateXType.GetMember("Template");
                XamlMember controlTemplateTargetType = controlTemplateXType.GetMember("TargetType");

                IAmbientProvider ambientProvider = serviceProvider.GetService(typeof(IAmbientProvider))
                                                   as System.Xaml.IAmbientProvider;
                if (ambientProvider == null)
                {
                    throw new NotSupportedException(SR.Get(SRID.ParserCannotConvertPropertyValue, "Property", typeof(DependencyProperty).FullName));
                }
                AmbientPropertyValue firstAmbientValue = ambientProvider.GetFirstAmbientValue(ceilingTypes, styleTargetType,
                                                                                              templateProperty, controlTemplateTargetType);

                if (firstAmbientValue != null)
                {
                    if (firstAmbientValue.Value is Type)
                    {
                        type = (Type)firstAmbientValue.Value;
                    }
                    else if (firstAmbientValue.Value is TemplateContent)
                    {
                        TemplateContent tempContent = firstAmbientValue.Value
                                                      as TemplateContent;

                        type = tempContent.OwnerTemplate.TargetTypeInternal;
                    }
                    else
                    {
                        throw new NotSupportedException(SR.Get(SRID.ParserCannotConvertPropertyValue, "Property", typeof(DependencyProperty).FullName));
                    }
                }
            }

            if (type != null && property != null)
            {
                return(DependencyProperty.FromName(property, type));
            }

            throw new NotSupportedException(SR.Get(SRID.ParserCannotConvertPropertyValue, "Property", typeof(DependencyProperty).FullName));
        }
示例#26
0
        /// <summary>Attempts to convert the specified object to a <see cref="T:System.Windows.RoutedEvent" /> object, using the specified context.</summary>
        /// <param name="typeDescriptorContext">A format context that provides information about the environment from which this converter is being invoked.</param>
        /// <param name="cultureInfo">Culture specific information.</param>
        /// <param name="source">The object to convert.</param>
        /// <returns>The conversion result.</returns>
        /// <exception cref="T:System.NotSupportedException">
        ///         <paramref name="source" /> is not a string or cannot be converted.</exception>
        // Token: 0x0600223F RID: 8767 RVA: 0x000AA6D4 File Offset: 0x000A88D4
        public override object ConvertFrom(ITypeDescriptorContext typeDescriptorContext, CultureInfo cultureInfo, object source)
        {
            string      text        = source as string;
            RoutedEvent routedEvent = null;

            if (text != null)
            {
                text = text.Trim();
                if (typeDescriptorContext != null)
                {
                    IXamlTypeResolver xamlTypeResolver = typeDescriptorContext.GetService(typeof(IXamlTypeResolver)) as IXamlTypeResolver;
                    Type type = null;
                    if (xamlTypeResolver != null)
                    {
                        int num = text.IndexOf('.');
                        if (num != -1)
                        {
                            string qualifiedTypeName = text.Substring(0, num);
                            text = text.Substring(num + 1);
                            type = xamlTypeResolver.Resolve(qualifiedTypeName);
                        }
                    }
                    if (type == null)
                    {
                        IXamlSchemaContextProvider xamlSchemaContextProvider = typeDescriptorContext.GetService(typeof(IXamlSchemaContextProvider)) as IXamlSchemaContextProvider;
                        IAmbientProvider           ambientProvider           = typeDescriptorContext.GetService(typeof(IAmbientProvider)) as IAmbientProvider;
                        if (xamlSchemaContextProvider != null && ambientProvider != null)
                        {
                            XamlSchemaContext schemaContext = xamlSchemaContextProvider.SchemaContext;
                            XamlType          xamlType      = schemaContext.GetXamlType(typeof(Style));
                            List <XamlType>   list          = new List <XamlType>();
                            list.Add(xamlType);
                            XamlMember           member            = xamlType.GetMember("TargetType");
                            AmbientPropertyValue firstAmbientValue = ambientProvider.GetFirstAmbientValue(list, new XamlMember[]
                            {
                                member
                            });
                            if (firstAmbientValue != null)
                            {
                                type = (firstAmbientValue.Value as Type);
                            }
                            if (type == null)
                            {
                                type = typeof(FrameworkElement);
                            }
                        }
                    }
                    if (type != null)
                    {
                        Type type2 = type;
                        while (null != type2)
                        {
                            SecurityHelper.RunClassConstructor(type2);
                            type2 = type2.BaseType;
                        }
                        routedEvent = EventManager.GetRoutedEventFromName(text, type);
                    }
                }
            }
            if (routedEvent == null)
            {
                throw base.GetConvertFromException(source);
            }
            return(routedEvent);
        }