//------------------------------------------------------ 
        //
        //  Internal Methods 
        //
        //-----------------------------------------------------

        #region Internal Methods 

        // Returns non-null string if this value can be converted to a string, 
        // null otherwise. 
        internal static string GetStringValue(DependencyProperty property, object propertyValue)
        { 
            string stringValue = null;

            // Special cases working around incorrectly implemented type converters
            if (property == UIElement.BitmapEffectProperty) 
            {
                return null; // Always treat BitmapEffects as complex value 
            } 

            if (property == Inline.TextDecorationsProperty) 
            {
                stringValue = TextDecorationsFixup((TextDecorationCollection)propertyValue);
            }
            else if (typeof(CultureInfo).IsAssignableFrom(property.PropertyType)) //NumberSubstitution.CultureOverrideProperty 
            {
                stringValue = CultureInfoFixup(property, (CultureInfo)propertyValue); 
            } 

            if (stringValue == null) 
            {
                DPTypeDescriptorContext context = new DPTypeDescriptorContext(property, propertyValue);

                System.ComponentModel.TypeConverter typeConverter = System.ComponentModel.TypeDescriptor.GetConverter(property.PropertyType); 
                Invariant.Assert(typeConverter != null);
                if (typeConverter.CanConvertTo(context, typeof(string))) 
                { 
                    stringValue = (string)typeConverter.ConvertTo(
                        context, System.Globalization.CultureInfo.InvariantCulture, propertyValue, typeof(string)); 
                }
            }
            return stringValue;
        } 
        //------------------------------------------------------
        //
        //  Internal Methods
        //
        //------------------------------------------------------

        #region Internal Methods

        // Returns non-null string if this value can be converted to a string,
        // null otherwise.
        internal static string GetStringValue(DependencyProperty property, object propertyValue)
        {
            string stringValue = null;

            // Special cases working around incorrectly implemented type converters
            if (property == UIElement.BitmapEffectProperty)
            {
                return(null); // Always treat BitmapEffects as complex value
            }

            if (property == Inline.TextDecorationsProperty)
            {
                stringValue = TextDecorationsFixup((TextDecorationCollection)propertyValue);
            }
            else if (typeof(CultureInfo).IsAssignableFrom(property.PropertyType)) //NumberSubstitution.CultureOverrideProperty
            {
                stringValue = CultureInfoFixup(property, (CultureInfo)propertyValue);
            }

            if (stringValue == null)
            {
                DPTypeDescriptorContext context = new DPTypeDescriptorContext(property, propertyValue);

                System.ComponentModel.TypeConverter typeConverter = System.ComponentModel.TypeDescriptor.GetConverter(property.PropertyType);
                Invariant.Assert(typeConverter != null);
                if (typeConverter.CanConvertTo(context, typeof(string)))
                {
                    stringValue = (string)typeConverter.ConvertTo(
                        context, System.Globalization.CultureInfo.InvariantCulture, propertyValue, typeof(string));
                }
            }
            return(stringValue);
        }
Example #3
0
        // Token: 0x06002C36 RID: 11318 RVA: 0x000C8D04 File Offset: 0x000C6F04
        internal static string GetStringValue(DependencyProperty property, object propertyValue)
        {
            string text = null;

            if (property == UIElement.BitmapEffectProperty)
            {
                return(null);
            }
            if (property == Inline.TextDecorationsProperty)
            {
                text = DPTypeDescriptorContext.TextDecorationsFixup((TextDecorationCollection)propertyValue);
            }
            else if (typeof(CultureInfo).IsAssignableFrom(property.PropertyType))
            {
                text = DPTypeDescriptorContext.CultureInfoFixup(property, (CultureInfo)propertyValue);
            }
            if (text == null)
            {
                DPTypeDescriptorContext context   = new DPTypeDescriptorContext(property, propertyValue);
                TypeConverter           converter = TypeDescriptor.GetConverter(property.PropertyType);
                Invariant.Assert(converter != null);
                if (converter.CanConvertTo(context, typeof(string)))
                {
                    text = (string)converter.ConvertTo(context, CultureInfo.InvariantCulture, propertyValue, typeof(string));
                }
            }
            return(text);
        }
Example #4
0
        // Token: 0x06002C38 RID: 11320 RVA: 0x000C8E1C File Offset: 0x000C701C
        private static string CultureInfoFixup(DependencyProperty property, CultureInfo cultureInfo)
        {
            string result = null;
            DPTypeDescriptorContext context       = new DPTypeDescriptorContext(property, cultureInfo);
            TypeConverter           typeConverter = new CultureInfoIetfLanguageTagConverter();

            if (typeConverter.CanConvertTo(context, typeof(string)))
            {
                result = (string)typeConverter.ConvertTo(context, CultureInfo.InvariantCulture, cultureInfo, typeof(string));
            }
            return(result);
        }
        // Token: 0x06003C05 RID: 15365 RVA: 0x00114FA8 File Offset: 0x001131A8
        private static bool AreBrushesEqual(Brush brush1, Brush brush2)
        {
            SolidColorBrush solidColorBrush = brush1 as SolidColorBrush;

            if (solidColorBrush != null)
            {
                return(solidColorBrush.Color.Equals(((SolidColorBrush)brush2).Color));
            }
            string stringValue  = DPTypeDescriptorContext.GetStringValue(TextElement.BackgroundProperty, brush1);
            string stringValue2 = DPTypeDescriptorContext.GetStringValue(TextElement.BackgroundProperty, brush2);

            return(stringValue != null && stringValue2 != null && stringValue == stringValue2);
        }
Example #6
0
        private static bool AreBrushesEqual(Brush brush1, Brush brush2)
        {
            SolidColorBrush solidBrush1 = brush1 as SolidColorBrush;

            if (solidBrush1 != null)
            {
                return(solidBrush1.Color.Equals(((SolidColorBrush)brush2).Color));
            }
            else
            {
                // When the brush is not serializable to string, we consider values equal only is they are equal as objects
                string string1 = DPTypeDescriptorContext.GetStringValue(TextElement.BackgroundProperty, brush1);
                string string2 = DPTypeDescriptorContext.GetStringValue(TextElement.BackgroundProperty, brush2);
                return(string1 != null && string2 != null ? string1 == string2 : false);
            }
        }
        private static string CultureInfoFixup(DependencyProperty property, CultureInfo cultureInfo)
        {
            string stringValue = null;

            // Parser uses a specific type coverter for converting instances of other types to and from CultureInfo.
            // This class differs from System.ComponentModel.CultureInfoConverter, the default type converter
            // for the CultureInfo class.
            // It uses a string representation based on the IetfLanguageTag property rather than the Name property
            // (i.e., RFC 3066 rather than RFC 1766).
            // In order to guarantee roundtripability of serialized xaml, textrange serialization needs to use
            // this type coverter for CultureInfo types.

            DPTypeDescriptorContext context = new DPTypeDescriptorContext(property, cultureInfo);

            System.ComponentModel.TypeConverter typeConverter = new CultureInfoIetfLanguageTagConverter();

            if (typeConverter.CanConvertTo(context, typeof(string)))
            {
                stringValue = (string)typeConverter.ConvertTo(
                    context, System.Globalization.CultureInfo.InvariantCulture, cultureInfo, typeof(string));
            }
            return(stringValue);
        }
        private static string CultureInfoFixup(DependencyProperty property, CultureInfo cultureInfo) 
        {
            string stringValue = null; 
 
            // Parser uses a specific type coverter for converting instances of other types to and from CultureInfo.
            // This class differs from System.ComponentModel.CultureInfoConverter, the default type converter 
            // for the CultureInfo class.
            // It uses a string representation based on the IetfLanguageTag property rather than the Name property
            // (i.e., RFC 3066 rather than RFC 1766).
            // In order to guarantee roundtripability of serialized xaml, textrange serialization needs to use 
            // this type coverter for CultureInfo types.
 
            DPTypeDescriptorContext context = new DPTypeDescriptorContext(property, cultureInfo); 
            System.ComponentModel.TypeConverter typeConverter = new CultureInfoIetfLanguageTagConverter();
 
            if (typeConverter.CanConvertTo(context, typeof(string)))
            {
                stringValue = (string)typeConverter.ConvertTo(
                    context, System.Globalization.CultureInfo.InvariantCulture, cultureInfo, typeof(string)); 
            }
            return stringValue;