using System;
using System.ComponentModel;
using System.Globalization;
namespace System
{
/// Converts a type to a type, and vice versa.
// Token: 0x02000306 RID: 774
public class UriTypeConverter : global::System.ComponentModel.TypeConverter
{
// Token: 0x06001BEF RID: 7151 RVA: 0x00068A78 File Offset: 0x00066C78
private bool CanConvert(Type type)
{
return type == typeof(string) || type == typeof(global::System.Uri);
}
/// Returns whether this converter can convert an object of the given type to the type of this converter.
/// true if is a type or a type can be assigned from ; otherwise, false.
/// An that provides a format context.
/// A that represents the type that you want to convert from.
/// The parameter is null.
// Token: 0x06001BF0 RID: 7152 RVA: 0x00068AA0 File Offset: 0x00066CA0
public override bool CanConvertFrom(global::System.ComponentModel.ITypeDescriptorContext context, Type sourceType)
{
if (sourceType == null)
{
throw new ArgumentNullException("sourceType");
}
return this.CanConvert(sourceType);
}
/// Returns whether this converter can convert the object to the specified type, using the specified context.
/// true if is of type , , or ; otherwise, false.
/// An that provides a format context.
/// A that represents the type that you want to convert to.
// Token: 0x06001BF1 RID: 7153 RVA: 0x00068ABC File Offset: 0x00066CBC
public override bool CanConvertTo(global::System.ComponentModel.ITypeDescriptorContext context, Type destinationType)
{
return destinationType != null && this.CanConvert(destinationType);
}
/// Converts the given object to the type of this converter, using the specified context and culture information.
/// An that represents the converted value.
/// An that provides a format context.
/// The to use as the current culture.
/// The to convert.
/// The conversion cannot be performed.
// Token: 0x06001BF2 RID: 7154 RVA: 0x00068AD0 File Offset: 0x00066CD0
public override object ConvertFrom(global::System.ComponentModel.ITypeDescriptorContext context, CultureInfo culture, object value)
{
if (value == null)
{
throw new ArgumentNullException("value");
}
if (!this.CanConvertFrom(context, value.GetType()))
{
throw new NotSupportedException(global::Locale.GetText("Cannot convert from value."));
}
if (value is global::System.Uri)
{
return value;
}
string text = value as string;
if (text != null)
{
return new global::System.Uri(text, global::System.UriKind.RelativeOrAbsolute);
}
return base.ConvertFrom(context, culture, value);
}
/// Converts a given value object to the specified type, using the specified context and culture information.
/// An that represents the converted value.
/// An that provides a format context.
/// A . If null is passed, the current culture is assumed.
/// The to convert.
/// The to convert the parameter to.
/// The parameter is null.
/// The conversion cannot be performed.
// Token: 0x06001BF3 RID: 7155 RVA: 0x00068B3C File Offset: 0x00066D3C
public override object ConvertTo(global::System.ComponentModel.ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if (!this.CanConvertTo(context, destinationType))
{
throw new NotSupportedException(global::Locale.GetText("Cannot convert to destination type."));
}
global::System.Uri uri = value as global::System.Uri;
if (uri != null)
{
if (destinationType == typeof(string))
{
return uri.ToString();
}
if (destinationType == typeof(global::System.Uri))
{
return uri;
}
}
return base.ConvertTo(context, culture, value, destinationType);
}
}
}