public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { if (value is DateTime) { return(PersianDateTimeConverter.MiladiToShamsi((DateTime)value)); } else if (value is string) { return(PersianDateTime.Parse((string)value)); } else if (value is long) { return(PersianDateTime.FromInt64((long)value)); } throw new ArgumentException("Parameter is not of type PersinaDateTime.", "obj"); }
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { var p = (PersianDateTime)value; if (destinationType == typeof(DateTime)) { return(PersianDateTimeConverter.ShamsiToMiladi(p)); } else if (destinationType == typeof(string)) { return(p.ToString()); } else if (destinationType == typeof(long)) { return(p.ToInt64()); } throw new ArgumentException("Type are not compatible"); }
public PersianDateTime(DateTime d) : this(PersianDateTimeConverter.MiladiToShamsi(d)) { }