using System; using System.ComponentModel.Design.Serialization; using System.Globalization; using System.Reflection; namespace System.ComponentModel { /// Provides a type converter to convert objects to and from various other representations. // Token: 0x02000083 RID: 131 public class GuidConverter : TypeConverter { /// Gets a value indicating whether this converter can convert an object in the given source type to a GUID object using the context. /// true if this converter can perform the conversion; otherwise, false. /// An that provides a format context. /// A that represents the type you wish to convert from. // Token: 0x060004AB RID: 1195 RVA: 0x0000D7F4 File Offset: 0x0000B9F4 public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) { return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); } /// Gets a value indicating whether this converter can convert an object to the given destination type using the context. /// true if this converter can perform the conversion; otherwise, false. /// An that provides a format context. /// A that represents the type you wish to convert to. // Token: 0x060004AC RID: 1196 RVA: 0x0000D810 File Offset: 0x0000BA10 public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) { return destinationType == typeof(string) || destinationType == typeof(global::System.ComponentModel.Design.Serialization.InstanceDescriptor) || base.CanConvertTo(context, destinationType); } /// Converts the given object to a GUID object. /// An that represents the converted . /// An that provides a format context. /// An optional . If not supplied, the current culture is assumed. /// The to convert. /// The conversion cannot be performed. // Token: 0x060004AD RID: 1197 RVA: 0x0000D84C File Offset: 0x0000BA4C public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { if (value.GetType() == typeof(string)) { string text = (string)value; try { return new Guid(text); } catch { throw new FormatException(text + "is not a valid GUID."); } } return base.ConvertFrom(context, culture, value); } /// Converts the given object to another type. /// The converted object. /// A formatter context. /// The culture into which will be converted. /// The object to convert. /// The type to convert the object to. /// /// is null. /// The conversion cannot be performed. // Token: 0x060004AE RID: 1198 RVA: 0x0000D8CC File Offset: 0x0000BACC public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if (value is Guid) { Guid guid = (Guid)value; if (destinationType == typeof(string) && value != null) { return guid.ToString("D"); } if (destinationType == typeof(global::System.ComponentModel.Design.Serialization.InstanceDescriptor)) { ConstructorInfo constructor = typeof(Guid).GetConstructor(new Type[] { typeof(string) }); return new global::System.ComponentModel.Design.Serialization.InstanceDescriptor(constructor, new object[] { guid.ToString("D") }); } } return base.ConvertTo(context, culture, value, destinationType); } } }