/// <summary> /// TypeConverter method implementation. /// </summary> /// <param name="context"> /// ITypeDescriptorContext /// </param> /// <param name="culture"> /// current culture (see CLR specs) /// </param> /// <param name="value"> /// value to convert from /// </param> /// <param name="destinationType"> /// Type to convert to /// </param> /// <returns> /// converted value /// </returns> public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { // Input validation if (destinationType == null) { throw new ArgumentNullException("destinationType"); } if (destinationType == typeof(MarkupExtension) && CanConvertTo(context, destinationType)) { SystemResourceKeyID keyId; // Get the SystemResourceKeyID if (value is SystemResourceKey) { keyId = (value as SystemResourceKey).InternalKey; } else if (value is SystemThemeKey) { keyId = (value as SystemThemeKey).InternalKey; } else { throw new ArgumentException(SR.Get(SRID.MustBeOfType, "value", "SystemResourceKey or SystemThemeKey")); } // System resource keys can be converted into a MarkupExtension (StaticExtension) Type keyType = SystemKeyConverter.GetSystemClassType(keyId); // Get the value serialization context IValueSerializerContext valueSerializerContext = context as IValueSerializerContext; if (valueSerializerContext != null) { // And from that get a System.Type serializer ValueSerializer typeSerializer = valueSerializerContext.GetValueSerializerFor(typeof(Type)); if (typeSerializer != null) { // And use that to create the string-ized class name string systemClassName = typeSerializer.ConvertToString(keyType, valueSerializerContext); // And finally create the StaticExtension. return(new StaticExtension(systemClassName + "." + GetSystemKeyName(keyId))); } } } return(base.CanConvertTo(context, destinationType)); }
// Token: 0x06002403 RID: 9219 RVA: 0x000AF8C4 File Offset: 0x000ADAC4 public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if (destinationType == null) { throw new ArgumentNullException("destinationType"); } if (destinationType == typeof(MarkupExtension) && this.CanConvertTo(context, destinationType)) { SystemResourceKeyID internalKey; if (value is SystemResourceKey) { internalKey = (value as SystemResourceKey).InternalKey; } else { if (!(value is SystemThemeKey)) { throw new ArgumentException(SR.Get("MustBeOfType", new object[] { "value", "SystemResourceKey or SystemThemeKey" })); } internalKey = (value as SystemThemeKey).InternalKey; } Type systemClassType = SystemKeyConverter.GetSystemClassType(internalKey); IValueSerializerContext valueSerializerContext = context as IValueSerializerContext; if (valueSerializerContext != null) { ValueSerializer valueSerializerFor = valueSerializerContext.GetValueSerializerFor(typeof(Type)); if (valueSerializerFor != null) { string str = valueSerializerFor.ConvertToString(systemClassType, valueSerializerContext); return(new StaticExtension(str + "." + SystemKeyConverter.GetSystemKeyName(internalKey))); } } } return(base.CanConvertTo(context, destinationType)); }