예제 #1
0
        public static bool TryCreate(object value, ModelPropertyInfo property, out Criteria criteria)
        {
            if (value == null)
            {
                criteria = null;
                return(true);
            }

            Type type = value.GetType();

            if (value is Criteria)
            {
                criteria = (Criteria)value;
            }
            else if (value is string)
            {
                criteria = String((string)value, property);
            }
            else if (value == DBNull.Value)
            {
                criteria = IsNull();
            }
            else if (value is IRange range)
            {
                RangePolicyAttribute attr = property?.GetCustomAttribute <RangePolicyAttribute>();

                criteria = Between(range, attr?.Policy ?? default(RangePolicy));
            }
            else if (type.IsArray)
            {
                criteria = Contain((Array)value);
            }
            else if (type.IsGenericType)
            {
                var info = TypeHelpers.GetCollectionInfo(type);

                if (info.IsCollection)
                {
                    criteria = Contain((ICollection)value);
                }
                else
                {
                    Type type1 = Nullable.GetUnderlyingType(type);

                    if (type1 != null)
                    {
                        type = type1;
                    }

                    criteria = null;
                }
            }
            else
            {
                criteria = null;
            }

            if (criteria == null && value is IComparable comparable)
            {
                criteria = Equal(comparable);
            }

            return(criteria != null);
        }
예제 #2
0
 public static bool TryCreate(object value, out Criteria criteria)
 {
     return(TryCreate(value, null, out criteria));
 }