コード例 #1
0
        public static string Serialize(SortExpressionCollection collection)
        {
            TypeConverter converter =
                TypeDescriptor.GetConverter(typeof(SortExpressionCollection));

            return((string)converter.ConvertTo(collection, typeof(string)));
        }
コード例 #2
0
ファイル: PagingInfo.cs プロジェクト: samdubey/URF-Identity
        public static string GetSortDescription(string sortMetaData)
        {
            SortExpressionCollection collection =
                GetSortExpressions(sortMetaData);

            return(collection.ToString());
        }
コード例 #3
0
ファイル: PagingInfo.cs プロジェクト: samdubey/URF-Identity
        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());
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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));
        }
コード例 #6
0
ファイル: PagingInfo.cs プロジェクト: samdubey/URF-Identity
 public static SortExpressionCollection GetSortExpressions(
     string sortMetaData)
 {
     return(SortExpressionCollection.DeSerialize(sortMetaData));
 }