10using System.ComponentModel;
27 public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
29 if (sourceType == typeof(
string))
31 else if (sourceType == typeof(DateTime))
33 else if (sourceType == typeof(DateTimeOffset))
35 else if (sourceType == typeof(System.DateTime?))
37 return base.CanConvertFrom(context, sourceType);
48 public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture,
object value)
51 return new SmartDate(System.Convert.ToString(value));
52 else if (value is DateTime)
53 return new SmartDate(System.Convert.ToDateTime(value));
54 else if (value ==
null)
56 else if (value is System.DateTime?)
57 return new SmartDate((System.DateTime?)value);
58 else if (value is DateTimeOffset)
59 return new SmartDate(((DateTimeOffset)value).DateTime);
60 return base.ConvertFrom(context, culture, value);
71 public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type destinationType)
73 if (destinationType == typeof(
string))
75 else if (destinationType == typeof(DateTime))
77 else if (destinationType == typeof(DateTimeOffset))
79 else if (destinationType == typeof(System.DateTime?))
81 return base.CanConvertTo(context, destinationType);
94 System.ComponentModel.ITypeDescriptorContext context,
95 System.Globalization.CultureInfo culture,
object value, System.Type destinationType)
98 if (destinationType == typeof(
string))
100 else if (destinationType == typeof(DateTime))
102 else if (destinationType == typeof(DateTimeOffset))
103 return new DateTimeOffset(sd.
Date);
104 else if (destinationType == typeof(System.DateTime?))
105 return new System.DateTime?(sd.
Date);
106 return base.ConvertTo(context, culture, value, destinationType);
Converts values to and from a SmartDate.
override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type destinationType)
Determines if a SmartDate can be convert to a value.
override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
Converts values to a SmartDate.
override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType)
Converts a SmartDate to a value.
override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
Determines if a value can be converted to a SmartDate.
Provides a date data type that understands the concept of an empty date value.
DateTime? Date
Gets or sets the date value.
string Text
Gets or sets the date value.