Example #1
0
        public override string ToString()
        {
            RequestSortField     = SortField;
            RequestSortDirection = SortDirection;
            if (QueryEntityType != null)
            {
                Dictionary <string, string> map;
                if (!_sortTypes.TryGetValue(QueryEntityType, out map))
                {
                    map = new Dictionary <string, string>();
                    PropertyInfo[] infos = QueryEntityType.GetProperties(BindingFlags.Public | BindingFlags.Instance);
                    foreach (PropertyInfo info in infos)
                    {
                        object[] attributes = info.GetCustomAttributes(typeof(SortAttribute), true);
                        if (attributes != null && attributes.Length > 0)
                        {
                            foreach (object attribute in attributes)
                            {
                                if (attribute is SortAttribute)
                                {
                                    map.Add(info.Name, (attribute as SortAttribute).Name);
                                    break;
                                }
                            }
                        }
                    }
                    _sortTypes.TryAdd(QueryEntityType, map);
                }

                string name;
                if (!string.IsNullOrEmpty(SortField) && map.TryGetValue(SortField, out name))
                {
                    RequestSortField     = name;
                    RequestSortDirection = SortDirection;
                }
            }
            return(base.ToString());
        }