public static string Serialize(SortExpressionCollection collection) { TypeConverter converter = TypeDescriptor.GetConverter(typeof(SortExpressionCollection)); return((string)converter.ConvertTo(collection, typeof(string))); }
public static string GetSortDescription(string sortMetaData) { SortExpressionCollection collection = GetSortExpressions(sortMetaData); return(collection.ToString()); }
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 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 ConvertTo( ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType) { if ((value != null) && (!(value is SortExpressionCollection))) { string msg = String.Format( "Unable to convert type '{0}'!", value.GetType()); throw new Exception(msg); } SortExpressionCollection collection = value as SortExpressionCollection; if (destinationType == typeof(string)) { if (value == null) { return(String.Empty); } StringBuilder sb = new StringBuilder(); TypeConverter converter = TypeDescriptor.GetConverter(typeof(SortExpression)); foreach (SortExpression sortExpression in collection) { if (sb.Length > 0) { sb.Append(SortExpressionDelimiter); } string s = (string) converter.ConvertTo(sortExpression, typeof(string)); sb.Append(s); } return(sb.ToString()); } return(base.ConvertTo(context, culture, value, destinationType)); }
public static SortExpressionCollection GetSortExpressions( string sortMetaData) { return(SortExpressionCollection.DeSerialize(sortMetaData)); }