예제 #1
0
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = (int)ComparisonType;
         hashCode = (hashCode * 397) ^ (ComparisonTypeName != null ? ComparisonTypeName.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (ComparisonAttribute != null ? ComparisonAttribute.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (int)Operator;
         hashCode = (hashCode * 397) ^ (Value != null ? Value.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (int)LogicalOperator;
         return(hashCode);
     }
 }
예제 #2
0
    public Dictionary <FieldInfo, IComparer> searchFields(Type klass)
    {
        Dictionary <FieldInfo, IComparer> dictionary = new Dictionary <FieldInfo, IComparer>();

        FieldInfo[]   fieldInfos = klass.GetFields();
        FieldComparer cmp        = new FieldComparer();

        foreach (FieldInfo f in fieldInfos)
        {
            ComparisonAttribute attribute = (ComparisonAttribute)f.GetCustomAttribute(typeof(ComparisonAttribute));
            if (attribute != null)
            {
                dictionary.Add(f, (IComparer)Activator.CreateInstance(attribute.klass));
            }
            else if (typeof(IComparable).IsAssignableFrom(f.FieldType))
            {
                dictionary.Add(f, cmp);
            }
        }
        return(dictionary);
    }
예제 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="table"></param>
        /// <param name="expression"></param>
        /// <param name="condition"></param>
        /// <returns></returns>
        public static bool TryParse(ITable table, string expression, out Condition condition)
        {
            const char match_begin = '[';
            const char match_end   = ']';

            condition = default;

            if (string.IsNullOrEmpty(expression))
            {
                return(false);
            }

            if (expression[0] != match_begin)
            {
                return(false);
            }

            var match_length = expression.IndexOf(match_end);

            if (match_length < 0)
            {
                return(false);
            }

            var index = "0";
            var type  = ConditionTypes.And;

            var match_index = 1;

            var index_length = 0;

            for (int i = match_index; i < match_length; i++)
            {
                if (expression[i] >= '0' && expression[i] <= '9')
                {
                    ++index_length;
                }
                else
                {
                    break;
                }
            }

            if (index_length >= 1)
            {
                index = expression.Substring(match_index, index_length);
            }

            match_index += index_length;

            var type_length = 0;

            switch (char.ToUpper(expression[match_index]))
            {
            case 'A':
                if (expression.IndexOf("AND", StringComparison.OrdinalIgnoreCase) == match_index)
                {
                    type_length += 3;
                }
                break;

            case 'O':
                if (expression.IndexOf("OR", StringComparison.OrdinalIgnoreCase) == match_index)
                {
                    type_length += 2;
                }
                break;

            case '&':
            case '|':
                ++type_length;
                break;
            }

            if (type_length >= 1)
            {
                switch (expression.Substring(match_index, type_length).ToUpper())
                {
                case "AND":
                case "&":
                case "&&":
                    type = ConditionTypes.And;
                    break;

                case "OR":
                case "|":
                case "||":
                    type = ConditionTypes.Or;
                    break;

                default:
                    type_length = 0;
                    break;
                }
            }

            match_index += type_length;

            var comparison_length = 0;

            for (int i = match_index; i < match_length; i++)
            {
                switch (expression[i])
                {
                case var lower when lower >= 'a' && lower <= 'z':
                case var upper when upper >= 'A' && upper <= 'Z':
                case '>':
                case '<':
                case '=':
                case '!':
                    ++comparison_length;
                    continue;
                }

                break;
            }

            if (!(comparison_length >= 1))
            {
                return(false);
            }

            if (!ComparisonAttribute.TryGetComparison(expression.Substring(match_index, comparison_length), out var comparison))
            {
                return(false);
            }

            match_index += comparison_length;

            if (match_index != match_length)
            {
                return(false);
            }

            var equal_index = expression.IndexOf('=', match_length);

            string before;
            string after = null;

            if (equal_index >= 0)
            {
                before = expression.Substring(match_length + 1, equal_index - match_length - 1);
                after  = expression.Substring(equal_index + 1);
            }
            else
            {
                before = expression.Substring(match_length + 1);
            }

            condition = new Condition(index, type, comparison, new Column(table, before), SqlHelper.ValueOf(after));

            return(true);
        }
예제 #4
0
 public NotEqualityCondition(ComparisonAttribute attr, awaDAL.DAL dal, WatiN.Core.IE ie)
     : base(dal, ie)
 {
     this.ca = attr;
 }