Exemplo n.º 1
0
        /// <summary>
        /// Creates a string representation of this object based on the format string
        /// and IFormatProvider passed in.
        /// If the provider is null, the CurrentCulture is used.
        /// See the documentation for IFormattable for more information.
        /// </summary>
        /// <returns>
        /// A string representation of this object.
        /// </returns>
        internal override string ConvertToString(string format, IFormatProvider provider)
        {
            string strBrush = Color.ConvertToString(format, provider);

#if !PBTCOMPILER
            // We maintain a cache of strings representing well-known SolidColorBrush objects corresponding to
            // each of the KnownColors. This cache is primarily intended to be passed to the localizer which
            // maintains SolidColorBrush values as a string. When the localizer passes
            // this string back to SolidColorBrush.SerializeOn(), we'd know which ones to
            // serialize as SerializationBrushType.KnownSolidColor vs. which ones to write as
            // SerializationBrushType.OtherColor.
            //
            // The BamlReader.GetPropertyCustomRecordId() calls ConvertToString() with format=null &&
            // provider = System.Windows.Markup.TypeConverterHelper.InvariantEnglishUS, so we use that
            // to decide which string objects to cache.
            if ((format == null) && (provider == System.Windows.Markup.TypeConverterHelper.InvariantEnglishUS) && KnownColors.IsKnownSolidColorBrush(this))
            {
                lock (s_knownSolidColorBrushStringCache)
                {
                    string strCachedBrush = null;
                    if (s_knownSolidColorBrushStringCache.TryGetValue(this, out strCachedBrush))
                    {
                        strBrush = strCachedBrush;
                    }
                    else
                    {
                        s_knownSolidColorBrushStringCache[this] = strBrush;
                    }
                }
            }
#endif
            return(strBrush);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Creates a string representation of this object based on the format string
 /// and IFormatProvider passed in.
 /// If the provider is null, the CurrentCulture is used.
 /// See the documentation for IFormattable for more information.
 /// </summary>
 /// <returns>
 /// A string representation of this object.
 /// </returns>
 internal override string ConvertToString(string format, IFormatProvider provider)
 {
     return(Color.ConvertToString(format, provider));
 }