/// <summary>
        ///     Parses the generator condition for this syntax.
        /// </summary>
        /// <param name="genDataDef">The generator data definition.</param>
        /// <param name="condition">The condition being parsed.</param>
        public override ConditionParameters ParseCondition(GenDataDef genDataDef, string condition)
        {
            var genCondition = new ConditionParameters();
            var s            = condition.Trim();
            var i            = s.ToLowerInvariant().IndexOf(" exists", StringComparison.Ordinal);

            if (i > 0)
            {
                var v1 = s.Substring(0, i);
                genCondition.Var1          = genDataDef.GetId(v1);
                genCondition.GenComparison = GenComparison.Exists;
            }
            else
            {
                var v1 = GetOperand(ref s);
                if (v1 != "" && s != "")
                {
                    genCondition.Var1          = genDataDef.GetId(v1, true);
                    genCondition.GenComparison = GetOperator(ref s);

                    if (genCondition.GenComparison != GenComparison.NotExists)
                    {
                        var v2 = s;
                        genCondition.UseLit = v2[0] == '\'' || (v2[0] >= '0' && v2[0] <= '9') || !v2.ToCharArray().Contains('.');

                        if (!genCondition.UseLit)
                        {
                            try
                            {
                                genCondition.Var2 = genDataDef.GetId(v2);
                            }
                            catch (Exception)
                            {
                                genCondition.Var2 = new GenDataId {
                                    ClassId = -1, PropertyId = -1
                                };
                            }
                        }
                        if (genCondition.UseLit || genCondition.Var2.ClassId == -1 || genCondition.Var2.PropertyId == -1)
                        {
                            if (v2[0] == '\'')
                            {
                                if (v2[v2.Length - 1] == '\'')
                                {
                                    genCondition.Lit = v2.Substring(1, v2.Length - 2);
                                }
                                else
                                {
                                    throw new Exception("<<<<Missing closing quote in condition value>>>>");
                                }
                            }
                            else
                            {
                                genCondition.Lit    = v2;
                                genCondition.UseLit = true;
                            }
                        }
                    }
                }
                else
                {
                    genCondition.Var1          = genDataDef.GetId(v1, true);
                    genCondition.GenComparison = GenComparison.Exists;
                }
            }
            return(genCondition);
        }
Ejemplo n.º 2
0
 public GenConditionParams(GenDataDef genDataDef, GenContainerFragmentBase parentContainer, ConditionParameters conditionParameters, bool isPrimary = true)
     : base(genDataDef, parentContainer, FragmentType.Condition, isPrimary: isPrimary)
 {
     Var1          = conditionParameters.Var1;
     Var2          = conditionParameters.Var2;
     GenComparison = conditionParameters.GenComparison;
     UseLit        = conditionParameters.UseLit;
     Lit           = conditionParameters.Lit;
 }