Пример #1
0
        public static string Serialize(SortExpression sortExpression)
        {
            TypeConverter converter =
                TypeDescriptor.GetConverter(typeof(SortExpression));

            return((string)converter.ConvertTo(sortExpression, typeof(string)));
        }
Пример #2
0
        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());
        }
Пример #3
0
        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));
        }
Пример #4
0
        public PagingInfo AddSortExpression(string metaData)
        {
            SortExpression sortExpression = SortExpression.DeSerialize(metaData);

            AddSortExpression(sortExpression);
            return(this);
        }
Пример #5
0
        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);
        }
Пример #7
0
        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));
        }
Пример #8
0
        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();
        }
Пример #9
0
 public PagingInfo AddSortExpression(SortExpression sortExpression)
 {
     SortMetaData = AddSortExpression(
         SortMetaData, sortExpression);
     return this;
 }
Пример #10
0
 public PagingInfo AddSortExpression(
     string title,
     string sortExpression,
     SortDirection direction = SortDirection.Ascending)
 {
     SortExpression exp = new SortExpression(
         title, sortExpression, direction);
     AddSortExpression(exp);
     return this;
 }
Пример #11
0
 public static string Serialize(SortExpression sortExpression)
 {
     TypeConverter converter =
         TypeDescriptor.GetConverter(typeof (SortExpression));
     return (string) converter.ConvertTo(sortExpression, typeof (string));
 }
Пример #12
0
        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);
        }
Пример #13
0
 public PagingInfo AddSortExpression(SortExpression sortExpression)
 {
     SortMetaData = AddSortExpression(
         SortMetaData, sortExpression);
     return(this);
 }