263 lines
13 KiB
C#
263 lines
13 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Globalization;
|
|
|
|
namespace System.ComponentModel
|
|
{
|
|
/// <summary>Provides automatic conversion between a nullable type and its underlying primitive type.</summary>
|
|
// Token: 0x020000B1 RID: 177
|
|
public class NullableConverter : TypeConverter
|
|
{
|
|
/// <summary>Initializes a new instance of the <see cref="T:System.ComponentModel.NullableConverter" /> class.</summary>
|
|
/// <param name="type">The specified nullable type.</param>
|
|
/// <exception cref="T:System.ArgumentException">
|
|
/// <paramref name="type" /> is not a nullable type.</exception>
|
|
// Token: 0x060005B6 RID: 1462 RVA: 0x0000EC38 File Offset: 0x0000CE38
|
|
public NullableConverter(Type nullableType)
|
|
{
|
|
if (nullableType == null)
|
|
{
|
|
throw new ArgumentNullException("nullableType");
|
|
}
|
|
this.nullableType = nullableType;
|
|
this.underlyingType = Nullable.GetUnderlyingType(nullableType);
|
|
this.underlyingTypeConverter = TypeDescriptor.GetConverter(this.underlyingType);
|
|
}
|
|
|
|
/// <summary>Returns whether this converter can convert an object of the given type to the type of this converter, using the specified context.</summary>
|
|
/// <returns>true if this converter can perform the conversion; otherwise, false.</returns>
|
|
/// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext" /> that provides a format context.</param>
|
|
/// <param name="sourceType">A <see cref="T:System.Type" /> that represents the type you want to convert from.</param>
|
|
// Token: 0x060005B7 RID: 1463 RVA: 0x0000EC78 File Offset: 0x0000CE78
|
|
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
|
|
{
|
|
if (sourceType == this.underlyingType)
|
|
{
|
|
return true;
|
|
}
|
|
if (this.underlyingTypeConverter != null)
|
|
{
|
|
return this.underlyingTypeConverter.CanConvertFrom(context, sourceType);
|
|
}
|
|
return base.CanConvertFrom(context, sourceType);
|
|
}
|
|
|
|
/// <summary>Returns whether this converter can convert the object to the specified type, using the specified context.</summary>
|
|
/// <returns>true if this converter can perform the conversion; otherwise, false.</returns>
|
|
/// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext" /> that provides a format context.</param>
|
|
/// <param name="destinationType">A <see cref="T:System.Type" /> that represents the type you want to convert to.</param>
|
|
// Token: 0x060005B8 RID: 1464 RVA: 0x0000ECAC File Offset: 0x0000CEAC
|
|
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
|
|
{
|
|
if (destinationType == this.underlyingType)
|
|
{
|
|
return true;
|
|
}
|
|
if (this.underlyingTypeConverter != null)
|
|
{
|
|
return this.underlyingTypeConverter.CanConvertTo(context, destinationType);
|
|
}
|
|
return base.CanConvertFrom(context, destinationType);
|
|
}
|
|
|
|
/// <summary>Converts the given object to the type of this converter, using the specified context and culture information.</summary>
|
|
/// <returns>An <see cref="T:System.Object" /> that represents the converted value.</returns>
|
|
/// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext" /> that provides a format context.</param>
|
|
/// <param name="culture">The <see cref="T:System.Globalization.CultureInfo" /> to use as the current culture.</param>
|
|
/// <param name="value">The <see cref="T:System.Object" /> to convert.</param>
|
|
/// <exception cref="T:System.NotSupportedException">The conversion cannot be performed. </exception>
|
|
// Token: 0x060005B9 RID: 1465 RVA: 0x0000ECE0 File Offset: 0x0000CEE0
|
|
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
|
|
{
|
|
if (value == null || value.GetType() == this.underlyingType)
|
|
{
|
|
return value;
|
|
}
|
|
if (value is string && string.IsNullOrEmpty((string)value))
|
|
{
|
|
return null;
|
|
}
|
|
if (this.underlyingTypeConverter != null)
|
|
{
|
|
return this.underlyingTypeConverter.ConvertFrom(context, culture, value);
|
|
}
|
|
return base.ConvertFrom(context, culture, value);
|
|
}
|
|
|
|
/// <summary>Converts the given value object to the specified type, using the specified context and culture information.</summary>
|
|
/// <returns>An <see cref="T:System.Object" /> that represents the converted value.</returns>
|
|
/// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext" /> that provides a format context.</param>
|
|
/// <param name="culture">The <see cref="T:System.Globalization.CultureInfo" /> to use as the current culture.</param>
|
|
/// <param name="value">The <see cref="T:System.Object" /> to convert.</param>
|
|
/// <param name="destinationType">The <see cref="T:System.Type" /> to convert the value parameter to.</param>
|
|
/// <exception cref="T:System.ArgumentNullException">
|
|
/// <paramref name="destinationType" /> is null.</exception>
|
|
/// <exception cref="T:System.NotSupportedException">The conversion cannot be performed. </exception>
|
|
// Token: 0x060005BA RID: 1466 RVA: 0x0000ED48 File Offset: 0x0000CF48
|
|
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
|
|
{
|
|
if (destinationType == null)
|
|
{
|
|
throw new ArgumentNullException("destinationType");
|
|
}
|
|
if (destinationType == this.underlyingType && value.GetType() == this.nullableType)
|
|
{
|
|
return value;
|
|
}
|
|
if (this.underlyingTypeConverter != null && value != null)
|
|
{
|
|
return this.underlyingTypeConverter.ConvertTo(context, culture, value, destinationType);
|
|
}
|
|
return base.ConvertTo(context, culture, value, destinationType);
|
|
}
|
|
|
|
/// <returns>An <see cref="T:System.Object" /> representing the given <see cref="T:System.Collections.IDictionary" />, or null if the object cannot be created. This method always returns null.</returns>
|
|
/// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext" /> that provides a format context. </param>
|
|
/// <param name="propertyValues">An <see cref="T:System.Collections.IDictionary" /> of new property values. </param>
|
|
// Token: 0x060005BB RID: 1467 RVA: 0x0000EDB4 File Offset: 0x0000CFB4
|
|
public override object CreateInstance(ITypeDescriptorContext context, IDictionary propertyValues)
|
|
{
|
|
if (this.underlyingTypeConverter != null)
|
|
{
|
|
return this.underlyingTypeConverter.CreateInstance(context, propertyValues);
|
|
}
|
|
return base.CreateInstance(context, propertyValues);
|
|
}
|
|
|
|
/// <returns>true if changing a property on this object requires a call to <see cref="M:System.ComponentModel.TypeConverter.CreateInstance(System.Collections.IDictionary)" /> to create a new value; otherwise, false.</returns>
|
|
/// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext" /> that provides a format context.</param>
|
|
// Token: 0x060005BC RID: 1468 RVA: 0x0000EDD8 File Offset: 0x0000CFD8
|
|
public override bool GetCreateInstanceSupported(ITypeDescriptorContext context)
|
|
{
|
|
if (this.underlyingTypeConverter != null)
|
|
{
|
|
return this.underlyingTypeConverter.GetCreateInstanceSupported(context);
|
|
}
|
|
return base.GetCreateInstanceSupported(context);
|
|
}
|
|
|
|
/// <returns>A <see cref="T:System.ComponentModel.PropertyDescriptorCollection" /> with the properties that are exposed for this data type, or null if there are no properties.</returns>
|
|
/// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext" /> that provides a format context. </param>
|
|
/// <param name="value">An <see cref="T:System.Object" /> that specifies the type of array for which to get properties. </param>
|
|
/// <param name="attributes">An array of type <see cref="T:System.Attribute" /> that is used as a filter. </param>
|
|
// Token: 0x060005BD RID: 1469 RVA: 0x0000EDFC File Offset: 0x0000CFFC
|
|
public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes)
|
|
{
|
|
if (this.underlyingTypeConverter != null)
|
|
{
|
|
return this.underlyingTypeConverter.GetProperties(context, value, attributes);
|
|
}
|
|
return base.GetProperties(context, value, attributes);
|
|
}
|
|
|
|
/// <returns>true if <see cref="M:System.ComponentModel.TypeConverter.GetProperties(System.Object)" /> should be called to find the properties of this object; otherwise, false.</returns>
|
|
/// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext" /> that provides a format context.</param>
|
|
// Token: 0x060005BE RID: 1470 RVA: 0x0000EE24 File Offset: 0x0000D024
|
|
public override bool GetPropertiesSupported(ITypeDescriptorContext context)
|
|
{
|
|
if (this.underlyingTypeConverter != null)
|
|
{
|
|
return this.underlyingTypeConverter.GetCreateInstanceSupported(context);
|
|
}
|
|
return base.GetCreateInstanceSupported(context);
|
|
}
|
|
|
|
/// <returns>A <see cref="T:System.ComponentModel.TypeConverter.StandardValuesCollection" /> that holds a standard set of valid values, or null if the data type does not support a standard set of values.</returns>
|
|
/// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext" /> that provides a format context that can be used to extract additional information about the environment from which this converter is invoked. This parameter or properties of this parameter can be null.</param>
|
|
// Token: 0x060005BF RID: 1471 RVA: 0x0000EE48 File Offset: 0x0000D048
|
|
public override TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
|
|
{
|
|
if (this.underlyingTypeConverter != null && this.underlyingTypeConverter.GetStandardValuesSupported(context))
|
|
{
|
|
TypeConverter.StandardValuesCollection standardValues = this.underlyingTypeConverter.GetStandardValues(context);
|
|
if (standardValues != null)
|
|
{
|
|
return new TypeConverter.StandardValuesCollection(new ArrayList(standardValues) { null });
|
|
}
|
|
}
|
|
return base.GetStandardValues(context);
|
|
}
|
|
|
|
/// <returns>true if the <see cref="T:System.ComponentModel.TypeConverter.StandardValuesCollection" /> returned from <see cref="M:System.ComponentModel.TypeConverter.GetStandardValues" /> is an exhaustive list of possible values; false if other values are possible.</returns>
|
|
/// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext" /> that provides a format context.</param>
|
|
// Token: 0x060005C0 RID: 1472 RVA: 0x0000EEA4 File Offset: 0x0000D0A4
|
|
public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
|
|
{
|
|
if (this.underlyingTypeConverter != null)
|
|
{
|
|
return this.underlyingTypeConverter.GetStandardValuesExclusive(context);
|
|
}
|
|
return base.GetStandardValuesExclusive(context);
|
|
}
|
|
|
|
/// <returns>true if <see cref="M:System.ComponentModel.TypeConverter.GetStandardValues" /> should be called to find a common set of values the object supports; otherwise, false.</returns>
|
|
/// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext" /> that provides a format context.</param>
|
|
// Token: 0x060005C1 RID: 1473 RVA: 0x0000EEC8 File Offset: 0x0000D0C8
|
|
public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
|
|
{
|
|
if (this.underlyingTypeConverter != null)
|
|
{
|
|
return this.underlyingTypeConverter.GetStandardValuesSupported(context);
|
|
}
|
|
return base.GetStandardValuesSupported(context);
|
|
}
|
|
|
|
/// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext" /> that provides a format context. </param>
|
|
/// <param name="value">The <see cref="T:System.Object" /> to test for validity. </param>
|
|
// Token: 0x060005C2 RID: 1474 RVA: 0x0000EEEC File Offset: 0x0000D0EC
|
|
public override bool IsValid(ITypeDescriptorContext context, object value)
|
|
{
|
|
if (this.underlyingTypeConverter != null)
|
|
{
|
|
return this.underlyingTypeConverter.IsValid(context, value);
|
|
}
|
|
return base.IsValid(context, value);
|
|
}
|
|
|
|
/// <summary>Gets the nullable type.</summary>
|
|
/// <returns>A <see cref="T:System.Type" /> that represents the nullable type.</returns>
|
|
// Token: 0x1700017F RID: 383
|
|
// (get) Token: 0x060005C3 RID: 1475 RVA: 0x0000EF10 File Offset: 0x0000D110
|
|
public Type NullableType
|
|
{
|
|
get
|
|
{
|
|
return this.nullableType;
|
|
}
|
|
}
|
|
|
|
/// <summary>Gets the underlying type.</summary>
|
|
/// <returns>A <see cref="T:System.Type" /> that represents the underlying type.</returns>
|
|
// Token: 0x17000180 RID: 384
|
|
// (get) Token: 0x060005C4 RID: 1476 RVA: 0x0000EF18 File Offset: 0x0000D118
|
|
public Type UnderlyingType
|
|
{
|
|
get
|
|
{
|
|
return this.underlyingType;
|
|
}
|
|
}
|
|
|
|
/// <summary>Gets the underlying type converter.</summary>
|
|
/// <returns>A <see cref="T:System.ComponentModel.TypeConverter" /> that represents the underlying type converter.</returns>
|
|
// Token: 0x17000181 RID: 385
|
|
// (get) Token: 0x060005C5 RID: 1477 RVA: 0x0000EF20 File Offset: 0x0000D120
|
|
public TypeConverter UnderlyingTypeConverter
|
|
{
|
|
get
|
|
{
|
|
return this.underlyingTypeConverter;
|
|
}
|
|
}
|
|
|
|
// Token: 0x040001B4 RID: 436
|
|
private Type nullableType;
|
|
|
|
// Token: 0x040001B5 RID: 437
|
|
private Type underlyingType;
|
|
|
|
// Token: 0x040001B6 RID: 438
|
|
private TypeConverter underlyingTypeConverter;
|
|
}
|
|
}
|