Exemple #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ArithmeticCriteria"/> class.
        /// </summary>
        /// <param name="fieldName">Name of the field.</param>
        /// <param name="value">The value.</param>
        /// <param name="operand">The operand.</param>
        public ArithmeticCriteria(string fieldName, IComparable value, ArithmeticOperandEnum operand)
            : base(fieldName)
        {
            if (value == null)
            {
                ThrowHelper.ThrowArgumentNullException("value");
            }

            Type valueType = value.GetType();
            if (valueType.IsGenericType && valueType.GetGenericTypeDefinition().Equals(typeof(EntityBaseGenericId<>)))
            {
                dynamic dynValue = value;
                if (dynValue.Id == null)
                {
                    ThrowHelper.ThrowArgumentException(String.Format("Provided entity has not got identifier. Entity type: '{0}'.", valueType.FullName), "value");
                }
                if (fieldName.ToLower().Equals("id"))
                {
                    this.FieldName = fieldName;
                }
                else
                {
                    this.FieldName = fieldName.ToLower().EndsWith(".id") ? fieldName : String.Format("{0}.id", fieldName);
                }
                this.mValue = dynValue.Id;
            }
            else
            {
                this.mValue = value;
            }
            this.mOperand = operand;
        }
Exemple #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ArithmeticCriteria"/> class.
        /// </summary>
        /// <param name="fieldName">Name of the field.</param>
        /// <param name="value">The value.</param>
        /// <param name="operand">The operand.</param>
        public ArithmeticCriteria(string fieldName, IComparable value, ArithmeticOperandEnum operand)
            : base(fieldName)
        {
            if (value == null)
            {
                ThrowHelper.ThrowArgumentNullException("value");
            }

            Type valueType = value.GetType();

            if (valueType.IsGenericType && valueType.GetGenericTypeDefinition().Equals(typeof(EntityBaseGenericId <>)))
            {
                dynamic dynValue = value;
                if (dynValue.Id == null)
                {
                    ThrowHelper.ThrowArgumentException(String.Format("Provided entity has not got identifier. Entity type: '{0}'.", valueType.FullName), "value");
                }
                if (fieldName.ToLower().Equals("id"))
                {
                    this.FieldName = fieldName;
                }
                else
                {
                    this.FieldName = fieldName.ToLower().EndsWith(".id") ? fieldName : String.Format("{0}.id", fieldName);
                }
                this.mValue = dynValue.Id;
            }
            else
            {
                this.mValue = value;
            }
            this.mOperand = operand;
        }