// 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
            }));
        }
        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));
        }