Beispiel #1
0
        public static IEnumerable <SortingItem> Deserialize(string stringToParse)
        {
            if (!string.IsNullOrWhiteSpace(stringToParse) && stringToParse != "[]")
            {
                return(stringToParse.Split(delimeter).Select(x => SortingItem.CreatefromString(x)));
            }

            return(Enumerable.Empty <SortingItem>());
        }
Beispiel #2
0
        /// <summary>
        /// Создает экземпляр SortingItem из строки
        /// </summary>
        /// <param name="inputString">строка формата "[Name] asc/desc"</param>
        /// <returns></returns>
        public static SortingItem CreatefromString(string inputString)
        {
            var result = new SortingItem();
            var parts  = inputString.Contains("[") && inputString.Contains("]") ? inputString.Split(delimeter, StringSplitOptions.None) : inputString.Split(' ');

            if (parts[0] == null || parts[1] == null || parts[1] != ascending && parts[1] != descending)
            {
                result.Invalid = true;
                return(result);
            }

            result.Field = parts[0].Trim(ecranSymb);
            result.Order = parts[1] == ascending ? TemplateStrings.Ascending : TemplateStrings.Descending;

            return(result);
        }