public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { if (value == null) { return(new SortExpressionCollection()); } string str = value as string; if (str == null) { return(base.ConvertFrom(context, culture, value)); } if (str.Length < 1) { return(new SortExpressionCollection()); } string[] strArrays = str.Split(new char[] { ';' }); if ((int)strArrays.Length < 1) { return(new SortExpressionCollection()); } SortExpressionCollection sortExpressionCollection = new SortExpressionCollection(); TypeConverter converter = TypeDescriptor.GetConverter(typeof(SortExpression)); string[] strArrays1 = strArrays; for (int i = 0; i < (int)strArrays1.Length; i++) { SortExpression sortExpression = converter.ConvertFrom(strArrays1[i]) as SortExpression; if (sortExpression != null) { sortExpressionCollection.Add(sortExpression); } } return(sortExpressionCollection); }
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if (value != null && !(value is SortExpression)) { throw new Exception($"Unable to convert type '{value.GetType()}'!"); } if (destinationType != typeof(string)) { return(base.ConvertTo(context, culture, value, destinationType)); } if (value == null) { return(string.Empty); } SortExpression sortExpression = (SortExpression)value; return($"{sortExpression.Title}{','}{sortExpression.Expression}{','}{sortExpression.Direction}"); }
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if (value != null && !(value is SortExpression)) { throw new Exception(string.Format("Unable to convert type '{0}'!", value.GetType())); } if (destinationType != typeof(string)) { return(base.ConvertTo(context, culture, value, destinationType)); } if (value == null) { return(string.Empty); } SortExpression sortExpression = value as SortExpression; return(string.Format("{1}{0}{2}{0}{3}", new object[] { ',', sortExpression.Title, sortExpression.Expression, sortExpression.Direction })); }
public static string Serialize(SortExpression sortExpression) { return((string)TypeDescriptor.GetConverter(typeof(SortExpression)).ConvertTo(sortExpression, typeof(string))); }
public string Serialize() { return(SortExpression.Serialize(this)); }