Beispiel #1
0
        private static Criteria GetCriteriaLeaf(CriteriaExpression criteriaExpression)
        {
            string propName       = criteriaExpression.Left.Expression;
            string operatorString = criteriaExpression.Expression;
            object value          = criteriaExpression.Right.Expression;

            Criteria.ComparisonOp comparisonOp = CreateComparisonOperator(operatorString);
            if ((comparisonOp == Criteria.ComparisonOp.In || comparisonOp == Criteria.ComparisonOp.NotIn) && value is string)
            {
                string inValuesString = value.ToString().TrimStart('(').TrimEnd(')');
                HabaneroStringBuilder valueStringBuilder = new HabaneroStringBuilder(inValuesString);
                valueStringBuilder.RemoveQuotedSections();
                List <string> finalStrings = new List <string>();
                int           commaIndex;
                int           lastIndex = 0;
                commaIndex = valueStringBuilder.IndexOf(",");
                while (commaIndex != -1)
                {
                    HabaneroStringBuilder oneValueSubstring = valueStringBuilder.Substring(lastIndex, commaIndex - lastIndex);
                    finalStrings.Add(oneValueSubstring.PutBackQuotedSections().ToString().Trim());
                    lastIndex  = commaIndex + 1;
                    commaIndex = valueStringBuilder.IndexOf(",", lastIndex);
                }
                HabaneroStringBuilder oneValueString = valueStringBuilder.Substring(lastIndex, valueStringBuilder.ToString().Length - lastIndex);
                finalStrings.Add(oneValueString.PutBackQuotedSections().ToString().Trim());
                value = new Criteria.CriteriaValues(finalStrings);
            }
            return(new Criteria(propName, comparisonOp, value));
        }
Beispiel #2
0
        private Criteria CreateCriteriaForRelationship(MemberInfo memberInfo, Criteria.ComparisonOp comparisonOp, object finalValue)
        {
            var      relationshipName = memberInfo.Name;
            var      classDef         = ClassDefCol.GetColClassDef()[memberInfo.DeclaringType];
            var      relationshipDef  = classDef.GetRelationship(relationshipName);
            var      relatedObject    = finalValue as IBusinessObject;
            Criteria criteria         = null;
            var      logicalOp        = comparisonOp == Criteria.ComparisonOp.Equals
                        ? Criteria.LogicalOp.And
                        : Criteria.LogicalOp.Or;

            foreach (var relPropDef in relationshipDef.RelKeyDef)
            {
                var propertyCriteria = new Criteria(
                    relationshipName + "." + relPropDef.OwnerPropertyName,
                    comparisonOp,
                    relatedObject.GetPropertyValue(relPropDef.RelatedClassPropName)
                    );

                if (criteria == null)
                {
                    criteria = propertyCriteria;
                }
                else
                {
                    criteria = new Criteria(criteria, logicalOp, propertyCriteria);
                }
            }
            return(criteria);
        }
Beispiel #3
0
        public void TestCreateOperator_LessThanEqual()
        {
            //---------------Set up test pack-------------------
            const string operatorString = "<=";

            //---------------Execute Test ----------------------
            Criteria.ComparisonOp comparisonOp = CriteriaParser.CreateComparisonOperator(operatorString);

            //---------------Test Result -----------------------
            Assert.AreEqual(Criteria.ComparisonOp.LessThanEqual, comparisonOp);
        }