internal static object DeserializeFrom(BinaryReader reader, ITypeDescriptorContext context) { SerializationBrushType brushType = (SerializationBrushType)reader.ReadByte(); if (brushType == SerializationBrushType.KnownSolidColor) { uint knownColorUint = reader.ReadUInt32(); SolidColorBrush scp = KnownColors.SolidColorBrushFromUint(knownColorUint); #if !PBTCOMPILER lock (s_knownSolidColorBrushStringCache) { if (!s_knownSolidColorBrushStringCache.ContainsKey(scp)) { string strColor = scp.Color.ConvertToString(null, System.Windows.Markup.TypeConverterHelper.InvariantEnglishUS); s_knownSolidColorBrushStringCache[scp] = strColor; } } #endif return(scp); } else if (brushType == SerializationBrushType.OtherColor) { string colorValue = reader.ReadString(); BrushConverter converter = new BrushConverter(); return(converter.ConvertFromInvariantString(context, colorValue)); } else { throw new Exception(SR.Get(SRID.BrushUnknownBamlType)); } }
private static Brush ToBrush(this string value, Brush defaultValue) { try { if (string.IsNullOrWhiteSpace(value)) return defaultValue; var converter = new BrushConverter(); return (Brush)converter.ConvertFromInvariantString(value); } catch (Exception e) { Logger.Error("Could not convert {0} to valid brush: {1}", value, e.Message); return defaultValue; } }
internal static object DeserializeFrom(BinaryReader reader, ITypeDescriptorContext context) { SerializationBrushType brushType = (SerializationBrushType)reader.ReadByte(); if (brushType == SerializationBrushType.KnownSolidColor) { uint knownColorUint = reader.ReadUInt32(); return(KnownColors.SolidColorBrushFromUint(knownColorUint)); } else if (brushType == SerializationBrushType.OtherColor) { string colorValue = reader.ReadString(); BrushConverter converter = new BrushConverter(); return(converter.ConvertFromInvariantString(context, colorValue)); } else { throw new Exception(SR.Get(SRID.BrushUnknownBamlType)); } }
internal static object DeserializeFrom(BinaryReader reader, ITypeDescriptorContext context) { SerializationBrushType brushType = (SerializationBrushType)reader.ReadByte(); if (brushType == SerializationBrushType.KnownSolidColor) { uint knownColorUint = reader.ReadUInt32(); return KnownColors.SolidColorBrushFromUint(knownColorUint); } else if (brushType == SerializationBrushType.OtherColor) { string colorValue = reader.ReadString(); BrushConverter converter = new BrushConverter(); return converter.ConvertFromInvariantString(context, colorValue); } else { throw new Exception(SR.Get(SRID.BrushUnknownBamlType)); } }