コード例 #1
0
        private FilterObj getFilterObject(PropertyInfo p, string idPrefix = null)
        {
            FilterObj result = null;

            string propName = p.Name;

            if (idPrefix != null)
            {
                propName = $"{idPrefix}_{propName}";
            }

            string displayName;

            IEnumerable <DisplayNameAttribute> sequence = p.GetCustomAttributes(typeof(DisplayNameAttribute), true).Cast <DisplayNameAttribute>();

            if (sequence != null && sequence.Any())
            {
                displayName = sequence.Single().DisplayName;
            }
            else
            {
                displayName = propName;
            }

            if (p.PropertyType == typeof(string))
            {
                result = new FilterObj {
                    id = propName, operators = OperatorsProvider.OperatorsString, label = displayName, type = "string"
                };
            }
            else if (p.PropertyType == typeof(int) || p.PropertyType == typeof(byte) || p.PropertyType == typeof(Nullable <byte>) || p.PropertyType == typeof(Nullable <int>))
            {
                result = new FilterObj {
                    id = propName, operators = OperatorsProvider.OperatorsInt, label = displayName, type = "integer"
                };
            }
            else if (p.PropertyType == typeof(decimal) || p.PropertyType == typeof(Nullable <decimal>))
            {
                result = new FilterObj {
                    id = propName, operators = OperatorsProvider.OperatorsInt, label = displayName, type = "double"
                };
            }
            else if (p.PropertyType == typeof(DateTime) || p.PropertyType == typeof(Nullable <DateTime>))
            {
                result = new FilterObj  {
                    id = propName, operators = OperatorsProvider.OperatorsDate, label = displayName, type = "datetime"
                };
            }
            else if (p.PropertyType == typeof(bool) || p.PropertyType == typeof(Nullable <bool>))
            {
                result = new FilterObj {
                    id = propName, operators = OperatorsProvider.OperatorsBool, label = displayName, type = "boolean"
                };
            }

            return(result);
        }
コード例 #2
0
        private void SetFilters(PropertyInfo[] props, string ClassName = null)
        {
            foreach (PropertyInfo p in props)
            {
                FilterObj filtObj = getFilterObject(p, ClassName);

                if (filtObj != null)
                {
                    Filters.Add(filtObj);
                }
            }
        }