/// <summary>Attempts to convert the specified object to a <see cref="T:System.Windows.DependencyProperty" />, using the specified context.</summary>
        /// <param name="context">A format context that provides information about the environment from which this converter is being invoked.</param>
        /// <param name="culture">Culture specific information.</param>
        /// <param name="source">The object to convert.</param>
        /// <returns>The converted object. If the conversion is successful, this is a <see cref="T:System.Windows.DependencyProperty" />.</returns>
        /// <exception cref="T:System.NotSupportedException">
        ///         <paramref name="source" /> cannot be converted.</exception>
        /// <exception cref="T:System.ArgumentNullException">
        ///         <paramref name="context" /> or <paramref name="source" /> are <see langword="null" />.</exception>
        // Token: 0x0600210A RID: 8458 RVA: 0x00097F7C File Offset: 0x0009617C
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object source)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            DependencyProperty dependencyProperty = DependencyPropertyConverter.ResolveProperty(context, null, source);

            if (dependencyProperty != null)
            {
                return(dependencyProperty);
            }
            throw base.GetConvertFromException(source);
        }
Esempio n. 2
0
 // Initialize known object types
 internal static TypeConverter CreateKnownTypeConverter(Int16 converterId)
 { 
     TypeConverter o = null;
     switch (converterId) 
     { 
         case -42: o = new System.Windows.Media.Converters.BoolIListConverter(); break;
         case -46: o = new System.ComponentModel.BooleanConverter(); break; 
         case -53: o = new System.Windows.Media.BrushConverter(); break;
         case -61: o = new System.ComponentModel.ByteConverter(); break;
         case -70: o = new System.ComponentModel.CharConverter(); break;
         case -71: o = new System.Windows.Media.Converters.CharIListConverter(); break; 
         case -87: o = new System.Windows.Media.ColorConverter(); break;
         case -94: o = new System.Windows.Input.CommandConverter(); break; 
         case -96: o = new System.Windows.Markup.ComponentResourceKeyConverter(); break; 
         case -111: o = new System.Windows.CornerRadiusConverter(); break;
         case -114: o = new System.ComponentModel.CultureInfoConverter(); break; 
         case -115: o = new System.Windows.CultureInfoIetfLanguageTagConverter(); break;
         case -117: o = new System.Windows.Input.CursorConverter(); break;
         case -124: o = new System.ComponentModel.DateTimeConverter(); break;
         case -125: o = new System.Windows.Markup.DateTimeConverter2(); break; 
         case -130: o = new System.ComponentModel.DecimalConverter(); break;
         case -137: o = new System.Windows.Markup.DependencyPropertyConverter(); break; 
         case -138: o = new System.Windows.DialogResultConverter(); break; 
         case -174: o = new System.Windows.Media.DoubleCollectionConverter(); break;
         case -175: o = new System.ComponentModel.DoubleConverter(); break; 
         case -176: o = new System.Windows.Media.Converters.DoubleIListConverter(); break;
         case -188: o = new System.Windows.DurationConverter(); break;
         case -190: o = new System.Windows.DynamicResourceExtensionConverter(); break;
         case -201: o = new System.Windows.ExpressionConverter(); break; 
         case -204: o = new System.Windows.FigureLengthConverter(); break;
         case -215: o = new System.Windows.Media.FontFamilyConverter(); break; 
         case -216: o = new System.Windows.FontSizeConverter(); break; 
         case -218: o = new System.Windows.FontStretchConverter(); break;
         case -220: o = new System.Windows.FontStyleConverter(); break; 
         case -222: o = new System.Windows.FontWeightConverter(); break;
         case -240: o = new System.Windows.Media.GeometryConverter(); break;
         case -256: o = new System.Windows.GridLengthConverter(); break;
         case -267: o = new System.ComponentModel.GuidConverter(); break; 
         case -286: o = new System.Windows.Media.ImageSourceConverter(); break;
         case -299: o = new System.Windows.Input.InputScopeConverter(); break; 
         case -301: o = new System.Windows.Input.InputScopeNameConverter(); break; 
         case -306: o = new System.ComponentModel.Int16Converter(); break;
         case -314: o = new System.Windows.Media.Int32CollectionConverter(); break; 
         case -315: o = new System.ComponentModel.Int32Converter(); break;
         case -319: o = new System.Windows.Int32RectConverter(); break;
         case -324: o = new System.ComponentModel.Int64Converter(); break;
         case -338: o = new System.Windows.Input.KeyConverter(); break; 
         case -340: o = new System.Windows.Input.KeyGestureConverter(); break;
         case -342: o = new System.Windows.KeySplineConverter(); break; 
         case -344: o = new System.Windows.KeyTimeConverter(); break; 
         case -348: o = new System.Windows.LengthConverter(); break;
         case -387: o = new System.Windows.Media.Media3D.Matrix3DConverter(); break; 
         case -392: o = new System.Windows.Media.MatrixConverter(); break;
         case -410: o = new System.Windows.Input.ModifierKeysConverter(); break;
         case -411: o = new System.Windows.Input.MouseActionConverter(); break;
         case -415: o = new System.Windows.Input.MouseGestureConverter(); break; 
         case -423: o = new System.Windows.NullableBoolConverter(); break;
         case -445: o = new System.Windows.Media.PathFigureCollectionConverter(); break; 
         case -453: o = new System.Windows.Media.PixelFormatConverter(); break; 
         case -462: o = new System.Windows.Media.Media3D.Point3DCollectionConverter(); break;
         case -463: o = new System.Windows.Media.Media3D.Point3DConverter(); break; 
         case -467: o = new System.Windows.Media.Media3D.Point4DConverter(); break;
         case -473: o = new System.Windows.Media.PointCollectionConverter(); break;
         case -474: o = new System.Windows.PointConverter(); break;
         case -475: o = new System.Windows.Media.Converters.PointIListConverter(); break; 
         case -492: o = new System.Windows.PropertyPathConverter(); break;
         case -498: o = new System.Windows.Media.Media3D.QuaternionConverter(); break; 
         case -507: o = new System.Windows.Media.Media3D.Rect3DConverter(); break; 
         case -511: o = new System.Windows.RectConverter(); break;
         case -521: o = new System.Windows.Media.Animation.RepeatBehaviorConverter(); break; 
         case -538: o = new System.Windows.Markup.RoutedEventConverter(); break;
         case -545: o = new System.ComponentModel.SByteConverter(); break;
         case -563: o = new System.ComponentModel.SingleConverter(); break;
         case -568: o = new System.Windows.Media.Media3D.Size3DConverter(); break; 
         case -572: o = new System.Windows.SizeConverter(); break;
         case -615: o = new System.ComponentModel.StringConverter(); break; 
         case -619: o = new System.Windows.StrokeCollectionConverter(); break; 
         case -633: o = new System.Windows.TemplateBindingExpressionConverter(); break;
         case -635: o = new System.Windows.TemplateBindingExtensionConverter(); break; 
         case -637: o = new System.Windows.Markup.TemplateKeyConverter(); break;
         case -645: o = new System.Windows.TextDecorationCollectionConverter(); break;
         case -655: o = new System.Windows.ThicknessConverter(); break;
         case -664: o = new System.ComponentModel.TimeSpanConverter(); break; 
         case -681: o = new System.Windows.Media.TransformConverter(); break;
         case -692: o = new System.Windows.Markup.TypeTypeConverter(); break; 
         case -696: o = new System.ComponentModel.UInt16Converter(); break; 
         case -698: o = new System.ComponentModel.UInt32Converter(); break;
         case -700: o = new System.ComponentModel.UInt64Converter(); break; 
         case -701: o = new System.Windows.Media.Converters.UShortIListConverter(); break;
         case -705: o = new System.UriTypeConverter(); break;
         case -714: o = new System.Windows.Media.Media3D.Vector3DCollectionConverter(); break;
         case -715: o = new System.Windows.Media.Media3D.Vector3DConverter(); break; 
         case -722: o = new System.Windows.Media.VectorCollectionConverter(); break;
         case -723: o = new System.Windows.VectorConverter(); break; 
         case -757: o = new System.Windows.Markup.XmlLanguageConverter(); break; 
     }
     return o; 
 }
        // 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
            }));
        }