public static string Serialize(SortExpression sortExpression) { TypeConverter converter = TypeDescriptor.GetConverter(typeof(SortExpression)); return((string)converter.ConvertTo(sortExpression, typeof(string))); }
public static string AddSortExpression( string sortMetaData, SortExpression sortExpression) { // De-serialize the SortExpressionCollection meta data SortExpressionCollection collection = GetSortExpressions(sortMetaData); int index = collection.FindIndex( s => s.Expression == sortExpression.Expression); if (index == 0) { collection[0].ToggleDirection(); } else { if (index > 0) { collection.RemoveAt(index); } collection.Insert(0, sortExpression); if (collection.Count > MaxSortSpecifications) { collection.RemoveRange(MaxSortSpecifications, 1); } } // Re-serialize the SortExpressionCollection back into meta data return(collection.Serialize()); }
public override object ConvertTo( ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType) { if ((value != null) && (!(value is SortExpression))) { string msg = $"Unable to convert type '{value.GetType()}'!"; throw new Exception(msg); } if (destinationType == typeof(string)) { if (value == null) { return(String.Empty); } SortExpression sort = value as SortExpression; string data = String.Format( "{1}{0}{2}{0}{3}", SortExpressionFieldDelimiter, sort.Title, sort.Expression, sort.Direction); return(data); } return(base.ConvertTo(context, culture, value, destinationType)); }
public PagingInfo AddSortExpression(string metaData) { SortExpression sortExpression = SortExpression.DeSerialize(metaData); AddSortExpression(sortExpression); return(this); }
public PagingInfo AddSortExpression( string title, string sortExpression, SortDirection direction = SortDirection.Ascending) { SortExpression exp = new SortExpression( title, sortExpression, direction); AddSortExpression(exp); return(this); }
public override object ConvertFrom( ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { if (value == null) { return(new SortExpressionCollection()); } string data = value as string; if (data == null) { return(base.ConvertFrom(context, culture, value)); } if (data.Length < 1) { return(new SortExpressionCollection()); } string[] elements = data.Split(new char[] { SortExpressionDelimiter }); if (elements.Length < 1) { return(new SortExpressionCollection()); } SortExpressionCollection collection = new SortExpressionCollection(); TypeConverter converter = TypeDescriptor.GetConverter(typeof(SortExpression)); foreach (string element in elements) { SortExpression sortExpression = converter.ConvertFrom(element) as SortExpression; if (sortExpression != null) { collection.Add(sortExpression); } } return(collection); }
public override object ConvertFrom( ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { if (value == null) { return(new SortExpression()); } string data = value as string; if (data != null) { if (data.Length < 1) { return(new SortExpression()); } string[] elements = data.Split(new char[] { SortExpressionFieldDelimiter }); if (elements.Length != 3) { throw new Exception("Invalid data format!"); } string title = elements[0]; string expression = elements[1]; SortDirection direction = (SortDirection) Enum.Parse(typeof(SortDirection), elements[2], true); SortExpression sortExpression = new SortExpression( title, expression, direction); return(sortExpression); } return(base.ConvertFrom(context, culture, value)); }
public static string AddSortExpression( string sortMetaData, SortExpression sortExpression) { // De-serialize the SortExpressionCollection meta data SortExpressionCollection collection = GetSortExpressions(sortMetaData); int index = collection.FindIndex( s => s.Expression == sortExpression.Expression); if (index == 0) { collection[0].ToggleDirection(); } else { if (index > 0) { collection.RemoveAt(index); } collection.Insert(0, sortExpression); if (collection.Count > MaxSortSpecifications) { collection.RemoveRange(MaxSortSpecifications, 1); } } // Re-serialize the SortExpressionCollection back into meta data return collection.Serialize(); }
public PagingInfo AddSortExpression(SortExpression sortExpression) { SortMetaData = AddSortExpression( SortMetaData, sortExpression); return this; }
public PagingInfo AddSortExpression( string title, string sortExpression, SortDirection direction = SortDirection.Ascending) { SortExpression exp = new SortExpression( title, sortExpression, direction); AddSortExpression(exp); return this; }
public static string Serialize(SortExpression sortExpression) { TypeConverter converter = TypeDescriptor.GetConverter(typeof (SortExpression)); return (string) converter.ConvertTo(sortExpression, typeof (string)); }
public override object ConvertFrom( ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { if (value == null) { return new SortExpression(); } string data = value as string; if (data != null) { if (data.Length < 1) { return new SortExpression(); } string[] elements = data.Split(new char[] {SortExpressionFieldDelimiter}); if (elements.Length != 3) { throw new Exception("Invalid data format!"); } string title = elements[0]; string expression = elements[1]; SortDirection direction = (SortDirection) Enum.Parse(typeof (SortDirection), elements[2], true); SortExpression sortExpression = new SortExpression( title, expression, direction); return sortExpression; } return base.ConvertFrom(context, culture, value); }
public PagingInfo AddSortExpression(SortExpression sortExpression) { SortMetaData = AddSortExpression( SortMetaData, sortExpression); return(this); }