/// <summary>
        /// Deserializes the specified configuration in an <see cref="IsNotEmpty"/> object
        /// </summary>
        /// <param name="configuration">The configuration.</param>
        /// <returns></returns>
        public override SqlTag Deserialize(IConfiguration configuration)
        {
            IsNotEmpty isNotEmpty = new IsNotEmpty(accessorFactory);

            isNotEmpty.Prepend  = ConfigurationUtils.GetStringAttribute(configuration.Attributes, "prepend");
            isNotEmpty.Property = ConfigurationUtils.GetStringAttribute(configuration.Attributes, "property");

            return(isNotEmpty);
        }
Example #2
0
        public SqlTag Deserialize(XmlNode node)
        {
            IsNotEmpty          empty      = new IsNotEmpty(this._configScope.DataExchangeFactory.AccessorFactory);
            NameValueCollection attributes = NodeUtils.ParseAttributes(node, this._configScope.Properties);

            empty.Prepend  = NodeUtils.GetStringAttribute(attributes, "prepend");
            empty.Property = NodeUtils.GetStringAttribute(attributes, "property");
            return(empty);
        }
Example #3
0
        public void ReturnSql()
        {
            IsNotEmpty isNotEmpty = new IsNotEmpty
            {
                //BodyText = "",
                Prepend  = "And Id",
                Property = "Ids"
            };
            string sql = isNotEmpty.BuildSql(new RequestContext
            {
            });

            Assert.NotNull(sql);
        }
Example #4
0
        public void ReturnSql()
        {
            IsNotEmpty isNotEmpty = new IsNotEmpty
            {
                //BodyText = "",
                Prepend  = "And Id",
                Property = "Ids",
                In       = true
            };
            string sql = isNotEmpty.BuildSql(new Abstractions.RequestContext
            {
            }, "@");

            Assert.NotNull(sql);
        }
Example #5
0
 public override void BuildSql()
 {
     if (Property == "IsNotEmpty")
     {
         if (empty == null)
         {
             empty = CreateBuilder(this.Statement.SqlContext.Context, this.Sql);
         }
     }
     else if (expression == null)
     {
         object obj = Statement.SqlContext.Context;
         expression = DynamicExpressionParser.ParseLambda(obj.GetType(), typeof(bool), this.Sql);
     }
 }
Example #6
0
        public static IsNotEmpty <T> CreateBuilder <T>(T obj, string name)
        {
            //  var dynamicBuilder = new TDynamicBuilder<T>();
            var type = obj.GetType();
            //定义一个名为DynamicCreate的动态方法,返回值typof(T),参数typeof(IDataRecord)
            var method    = new DynamicMethod("DynamicCreate", typeof(bool), new[] { typeof(T) });
            var generator = method.GetILGenerator();//创建一个MSIL生成器,为动态方法生成代码

            generator.DeclareLocal(type);
            generator.Emit(OpCodes.Ldarg_0);
            generator.Emit(OpCodes.Isinst, type);
            generator.Emit(OpCodes.Stloc_0);
            generator.Emit(OpCodes.Ldloc_0);
            generator.Emit(OpCodes.Call, type.GetProperty(name).GetGetMethod());
            generator.Emit(OpCodes.Call, typeof(string).GetMethod("IsNullOrEmpty"));
            generator.Emit(OpCodes.Ret);//方法结束,返回

            //完成动态方法的创建,并且创建执行该动态方法的委托,赋值到全局变量handler,handler在Build方法里Invoke
            IsNotEmpty <T> dynamicBuilder = (IsNotEmpty <T>)method.CreateDelegate(typeof(IsNotEmpty <T>));

            return(dynamicBuilder);
        }
Example #7
0
        public static ITag LoadTag(XmlNode xmlNode, IList <Include> includes)
        {
            ITag tag          = null;
            bool isIn         = xmlNode.Attributes?["In"] != null;
            var  prepend      = xmlNode.Attributes?["Prepend"]?.Value.Trim();
            var  property     = xmlNode.Attributes?["Property"]?.Value.Trim();
            var  compareValue = xmlNode.Attributes?["CompareValue"]?.Value.Trim();

            #region Init Tag
            switch (xmlNode.Name)
            {
            case "#text":
            case "#cdata-section":
            {
                var bodyText = " " + xmlNode.InnerText.Replace("\n", "").Trim();
                return(new SqlText
                    {
                        BodyText = bodyText
                    });
            }

            case "Include":
            {
                var refId       = xmlNode.Attributes?["RefId"]?.Value;
                var include_tag = new Include
                {
                    RefId   = refId,
                    Prepend = prepend
                };
                includes.Add(include_tag);
                tag = include_tag;
                break;
            }

            case "IsEmpty":
            {
                tag = new IsEmpty
                {
                    In        = isIn,
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "IsEqual":
            {
                tag = new IsEqual
                {
                    In           = isIn,
                    Prepend      = prepend,
                    Property     = property,
                    CompareValue = compareValue,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            case "IsGreaterEqual":
            {
                tag = new IsGreaterEqual
                {
                    In           = isIn,
                    Prepend      = prepend,
                    Property     = property,
                    CompareValue = compareValue,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            case "IsGreaterThan":
            {
                tag = new IsGreaterThan
                {
                    In           = isIn,
                    Prepend      = prepend,
                    Property     = property,
                    CompareValue = compareValue,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            case "IsLessEqual":
            {
                tag = new IsLessEqual
                {
                    In           = isIn,
                    Prepend      = prepend,
                    Property     = property,
                    CompareValue = compareValue,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            case "IsLessThan":
            {
                tag = new IsLessThan
                {
                    In           = isIn,
                    Prepend      = prepend,
                    Property     = property,
                    CompareValue = compareValue,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            case "IsNotEmpty":
            {
                tag = new IsNotEmpty
                {
                    In        = isIn,
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "IsNotEqual":
            {
                tag = new IsNotEqual
                {
                    In           = isIn,
                    Prepend      = prepend,
                    Property     = property,
                    CompareValue = compareValue,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            case "IsNotNull":
            {
                tag = new IsNotNull
                {
                    In        = isIn,
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "IsNull":
            {
                tag = new IsNull
                {
                    In        = isIn,
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "IsTrue":
            {
                tag = new IsTrue
                {
                    In        = isIn,
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "IsFalse":
            {
                tag = new IsFalse
                {
                    In        = isIn,
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "IsProperty":
            {
                tag = new IsProperty
                {
                    In        = isIn,
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "Switch":
            {
                tag = new Switch
                {
                    Property = property,
                    //Prepend = prepend,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "Case":
            {
                var switchNode     = xmlNode.ParentNode;
                var switchProperty = switchNode.Attributes?["Property"]?.Value.Trim();
                var switchPrepend  = switchNode.Attributes?["Prepend"]?.Value.Trim();
                tag = new Switch.Case
                {
                    CompareValue = compareValue,
                    Property     = switchProperty,
                    Prepend      = switchPrepend,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            case "Default":
            {
                var switchNode     = xmlNode.ParentNode;
                var switchProperty = switchNode.Attributes?["Property"]?.Value.Trim();
                var switchPrepend  = switchNode.Attributes?["Prepend"]?.Value.Trim();
                tag = new Switch.Defalut
                {
                    Property  = switchProperty,
                    Prepend   = switchPrepend,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "Dynamic":
            {
                tag = new Dynamic
                {
                    Prepend   = prepend,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "Where":
            {
                tag = new Where
                {
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "Set":
            {
                tag = new Set
                {
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "For":
            {
                var open      = xmlNode.Attributes?["Open"]?.Value.Trim();
                var separator = xmlNode.Attributes?["Separator"]?.Value.Trim();
                var close     = xmlNode.Attributes?["Close"]?.Value.Trim();
                var key       = xmlNode.Attributes?["Key"]?.Value.Trim();
                tag = new For
                {
                    Prepend   = prepend,
                    Property  = property,
                    Open      = open,
                    Close     = close,
                    Separator = separator,
                    Key       = key,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "Env":
            {
                var dbProvider = xmlNode.Attributes?["DbProvider"]?.Value.Trim();
                tag = new Env
                {
                    Prepend    = prepend,
                    DbProvider = dbProvider,
                    ChildTags  = new List <ITag>()
                };
                break;
            }

            case "#comment": { break; }

            default:
            {
                throw new SmartSqlException($"Statement.LoadTag unkonw tagName:{xmlNode.Name}.");
            };
            }
            #endregion
            foreach (XmlNode childNode in xmlNode)
            {
                ITag childTag = LoadTag(childNode, includes);
                if (childTag != null && tag != null)
                {
                    (tag as Tag).ChildTags.Add(childTag);
                }
            }
            return(tag);
        }
Example #8
0
        private ITag LoadTag(XmlNode xmlNode, Statement statement)
        {
            ITag tag          = null;
            var  prepend      = xmlNode.Attributes?["Prepend"]?.Value.Trim();
            var  property     = xmlNode.Attributes?["Property"]?.Value.Trim();
            var  compareValue = xmlNode.Attributes?["CompareValue"]?.Value.Trim();

            #region Init Tag
            switch (xmlNode.Name)
            {
            case "#text":
            case "#cdata-section":
            {
                var innerText = xmlNode.InnerText;
                var bodyText  = innerText;
                //bodyText += innerText.Trim().Replace("\r", " ").Replace("\n", " ");
                //bodyText += " ";
                return(new SqlText
                    {
                        Statement = statement,
                        BodyText = bodyText
                    });
            }

            case "Include":
            {
                var refId = xmlNode.Attributes?["RefId"]?.Value;
                if (refId.IndexOf('.') < 0)
                {
                    refId = $"{statement.SmartSqlMap.Scope}.{refId}";
                }
                var include_tag = new Include
                {
                    RefId   = refId,
                    Prepend = xmlNode.Attributes?["Prepend"]?.Value
                };
                statement.IncludeDependencies.Add(include_tag);
                tag = include_tag;
                break;
            }

            case "IsEmpty":
            {
                tag = new IsEmpty
                {
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "IsEqual":
            {
                tag = new IsEqual
                {
                    Prepend      = prepend,
                    Property     = property,
                    CompareValue = compareValue,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            case "IsGreaterEqual":
            {
                tag = new IsGreaterEqual
                {
                    Prepend      = prepend,
                    Property     = property,
                    CompareValue = compareValue,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            case "IsGreaterThan":
            {
                tag = new IsGreaterThan
                {
                    Prepend      = prepend,
                    Property     = property,
                    CompareValue = compareValue,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            case "IsLessEqual":
            {
                tag = new IsLessEqual
                {
                    Prepend      = prepend,
                    Property     = property,
                    CompareValue = compareValue,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            case "IsLessThan":
            {
                tag = new IsLessThan
                {
                    Prepend      = prepend,
                    Property     = property,
                    CompareValue = compareValue,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            case "IsNotEmpty":
            {
                tag = new IsNotEmpty
                {
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "IsNotEqual":
            {
                tag = new IsNotEqual
                {
                    Prepend      = prepend,
                    Property     = property,
                    CompareValue = compareValue,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            case "IsNotNull":
            {
                tag = new IsNotNull
                {
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "IsNull":
            {
                tag = new IsNull
                {
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "IsTrue":
            {
                tag = new IsTrue
                {
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "IsFalse":
            {
                tag = new IsFalse
                {
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "IsProperty":
            {
                tag = new IsProperty
                {
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "Placeholder":
            {
                tag = new Placeholder
                {
                    Prepend   = xmlNode.Attributes?["Prepend"]?.Value,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "Switch":
            {
                tag = new Switch
                {
                    Property  = property,
                    Prepend   = prepend,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "Case":
            {
                var switchNode     = xmlNode.ParentNode;
                var switchProperty = switchNode.Attributes?["Property"]?.Value.Trim();
                var switchPrepend  = switchNode.Attributes?["Prepend"]?.Value.Trim();
                tag = new Switch.Case
                {
                    CompareValue = compareValue,
                    Property     = switchProperty,
                    Prepend      = switchPrepend,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            case "Default":
            {
                var switchNode     = xmlNode.ParentNode;
                var switchProperty = switchNode.Attributes?["Property"]?.Value.Trim();
                var switchPrepend  = switchNode.Attributes?["Prepend"]?.Value.Trim();
                tag = new Switch.Defalut
                {
                    Property  = switchProperty,
                    Prepend   = switchPrepend,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "Dynamic":
            {
                tag = new Dynamic
                {
                    Prepend   = prepend,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "Where":
            {
                tag = new Where
                {
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "Set":
            {
                tag = new Set
                {
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "For":
            {
                var open      = xmlNode.Attributes?["Open"]?.Value.Trim();
                var separator = xmlNode.Attributes?["Separator"]?.Value.Trim();
                var close     = xmlNode.Attributes?["Close"]?.Value.Trim();
                var key       = xmlNode.Attributes?["Key"]?.Value.Trim();
                tag = new For
                {
                    Prepend   = prepend,
                    Property  = property,
                    Open      = open,
                    Close     = close,
                    Separator = separator,
                    Key       = key,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "Env":
            {
                var dbProvider = xmlNode.Attributes?["DbProvider"]?.Value.Trim();
                tag = new Env
                {
                    Prepend    = prepend,
                    DbProvider = dbProvider,
                    ChildTags  = new List <ITag>()
                };
                break;
            }

            case "#comment": { return(null); }

            default:
            {
                throw new SmartSqlException($"Statement.LoadTag unkonw tagName:{xmlNode.Name}.");
            };
            }
            tag.Statement = statement;
            #endregion
            foreach (XmlNode childNode in xmlNode)
            {
                ITag childTag = LoadTag(childNode, statement);
                if (childTag != null && tag != null)
                {
                    childTag.Parent = tag;
                    (tag as Tag).ChildTags.Add(childTag);
                }
            }
            return(tag);
        }
Example #9
0
        public static ITag LoadTag(XmlNode xmlNode)
        {
            ITag tag          = null;
            bool isIn         = xmlNode.Attributes?["In"] != null;
            var  prepend      = xmlNode.Attributes?["Prepend"]?.Value;
            var  property     = xmlNode.Attributes?["Property"]?.Value;
            var  compareValue = xmlNode.Attributes?["CompareValue"]?.Value;

            #region Init Tag
            switch (xmlNode.Name)
            {
            case "#text":
            case "#cdata-section":
            {
                var bodyText = xmlNode.InnerText.Replace("\n", "");
                return(new SqlText
                    {
                        BodyText = bodyText
                    });
            }

            case "IsEmpty":
            {
                tag = new IsEmpty
                {
                    In        = isIn,
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "IsEqual":
            {
                tag = new IsEqual
                {
                    In           = isIn,
                    Prepend      = prepend,
                    Property     = property,
                    CompareValue = compareValue,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            case "IsGreaterEqual":
            {
                tag = new IsGreaterEqual
                {
                    In           = isIn,
                    Prepend      = prepend,
                    Property     = property,
                    CompareValue = compareValue,
                };
                break;
            }

            case "IsGreaterThan":
            {
                tag = new IsGreaterThan
                {
                    In           = isIn,
                    Prepend      = prepend,
                    Property     = property,
                    CompareValue = compareValue,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            case "IsLessEqual":
            {
                tag = new IsLessEqual
                {
                    In           = isIn,
                    Prepend      = prepend,
                    Property     = property,
                    CompareValue = compareValue,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            case "IsLessThan":
            {
                tag = new IsLessThan
                {
                    In           = isIn,
                    Prepend      = prepend,
                    Property     = property,
                    CompareValue = compareValue,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            case "IsNotEmpty":
            {
                tag = new IsNotEmpty
                {
                    In        = isIn,
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "IsNotEqual":
            {
                tag = new IsNotEqual
                {
                    In           = isIn,
                    Prepend      = prepend,
                    Property     = property,
                    CompareValue = compareValue,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            case "IsNotNull":
            {
                tag = new IsNotNull
                {
                    In        = isIn,
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "IsNull":
            {
                tag = new IsNull
                {
                    In        = isIn,
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "IsTrue":
            {
                tag = new IsTrue
                {
                    In        = isIn,
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "IsFalse":
            {
                tag = new IsFalse
                {
                    In        = isIn,
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "Switch":
            {
                tag = new Switch
                {
                    Property = property,
                    //Prepend = prepend,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "Case":
            {
                var switchNode     = xmlNode.ParentNode;
                var switchProperty = switchNode.Attributes?["Property"]?.Value;
                var switchPrepend  = switchNode.Attributes?["Prepend"]?.Value;
                tag = new Switch.Case
                {
                    CompareValue = compareValue,
                    Property     = switchProperty,
                    Prepend      = switchPrepend,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            case "#comment": { break; }

            default: { break; };
            }
            #endregion
            foreach (XmlNode childNode in xmlNode)
            {
                ITag childTag = LoadTag(childNode);
                (tag as Tag).ChildTags.Add(childTag);
            }
            return(tag);
        }
Example #10
0
        private ITag LoadTag(XNode xmlNode, IList <Include> includes)
        {
            ITag tag          = null;
            var  prepend      = xmlNode?.GetAttribute("Prepend")?.Trim();
            var  property     = xmlNode?.GetAttribute("Property")?.Trim();
            var  compareValue = xmlNode?.GetAttribute("CompareValue")?.Trim();

            #region Init Tag
            switch (xmlNode.GetName())
            {
            case "#text":
            case "#cdata-section":
            {
                var bodyText = " " + xmlNode.GetValue().Replace("\n", "").Trim();
                return(new SqlText
                    {
                        LineInfo = XmlLineInfo.Create(xmlNode),
                        BodyText = bodyText
                    });
            }

            case "If":
            {
                tag = new IfTag
                {
                    Test = xmlNode.GetAttribute("Test")
                };
                break;
            }

            case "Include":
            {
                var refId       = xmlNode?.GetAttribute("RefId");
                var include_tag = new Include
                {
                    RefId   = refId,
                    Prepend = prepend
                };
                includes.Add(include_tag);
                tag = include_tag;
                break;
            }

            case "IsEmpty":
            {
                tag = new IsEmpty
                {
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "IsEqual":
            {
                tag = new IsEqual
                {
                    Prepend      = prepend,
                    Property     = property,
                    CompareValue = compareValue,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            case "Bind":
            {
                tag = new BindTag
                {
                    Name  = xmlNode.GetAttribute("Name"),
                    Value = xmlNode.GetAttribute("Value"),
                };
                break;
            }

            case "Trim":
            {
                tag = new TrimTag
                {
                    Prefix          = xmlNode.GetAttribute("Prefix"),
                    PrefixOverrides = xmlNode.GetAttribute("PrefixOverrides"),
                    Suffix          = xmlNode.GetAttribute("Suffix"),
                    ChildTags       = new List <ITag>(),
                };
                break;
            }

            case "IsGreaterEqual":
            {
                tag = new IsGreaterEqual
                {
                    Prepend      = prepend,
                    Property     = property,
                    CompareValue = compareValue,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            case "IsGreaterThan":
            {
                tag = new IsGreaterThan
                {
                    Prepend      = prepend,
                    Property     = property,
                    CompareValue = compareValue,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            case "IsLessEqual":
            {
                tag = new IsLessEqual
                {
                    Prepend      = prepend,
                    Property     = property,
                    CompareValue = compareValue,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            case "IsLessThan":
            {
                tag = new IsLessThan
                {
                    Prepend      = prepend,
                    Property     = property,
                    CompareValue = compareValue,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            case "IsNotEmpty":
            {
                tag = new IsNotEmpty
                {
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "IsNotEqual":
            {
                tag = new IsNotEqual
                {
                    Prepend      = prepend,
                    Property     = property,
                    CompareValue = compareValue,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            case "IsNotNull":
            {
                tag = new IsNotNull
                {
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "IsNull":
            {
                tag = new IsNull
                {
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "IsTrue":
            {
                tag = new IsTrue
                {
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "IsFalse":
            {
                tag = new IsFalse
                {
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "IsProperty":
            {
                tag = new IsProperty
                {
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "Placeholder":
            {
                tag = new Placeholder
                {
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "Switch":
            {
                tag = new Switch
                {
                    Property  = property,
                    Prepend   = prepend,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "Case":
            {
                var switchNode     = xmlNode.Parent;
                var switchProperty = xmlNode?.GetAttribute("Property")?.Trim();
                var switchPrepend  = xmlNode?.GetAttribute("Prepend")?.Trim();
                tag = new Switch.Case
                {
                    CompareValue = compareValue,
                    Property     = switchProperty,
                    Prepend      = switchPrepend,
                    Test         = xmlNode?.GetAttribute("Test")?.Trim(),
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            case "Default":
            {
                var switchNode     = xmlNode.Parent;
                var switchProperty = xmlNode?.GetAttribute("Property")?.Trim();
                var switchPrepend  = xmlNode?.GetAttribute("Prepend")?.Trim();
                tag = new Switch.Defalut
                {
                    Property  = switchProperty,
                    Prepend   = switchPrepend,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "Dynamic":
            {
                tag = new Dynamic
                {
                    Prepend   = prepend,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "Where":
            {
                tag = new Where
                {
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "Set":
            {
                tag = new Set
                {
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "For":
            {
                var open      = xmlNode?.GetAttribute("Open")?.Trim();
                var separator = xmlNode?.GetAttribute("Separator")?.Trim();
                var close     = xmlNode?.GetAttribute("Close")?.Trim();
                var key       = xmlNode?.GetAttribute("Key")?.Trim();
                var index     = xmlNode?.GetAttribute("Index")?.Trim();
                tag = new For
                {
                    Prepend   = prepend,
                    Property  = property,
                    Open      = open,
                    Close     = close,
                    Index     = index,
                    Separator = separator,
                    Key       = key,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "Env":
            {
                var dbProvider = xmlNode?.GetAttribute("DbProvider")?.Trim();
                tag = new Env
                {
                    Prepend    = prepend,
                    DbProvider = dbProvider,
                    ChildTags  = new List <ITag>()
                };
                break;
            }

            case "#comment": { break; }

            default:
            {
                throw new SmartSqlException($"Statement.LoadTag unkonw tagName:{xmlNode.GetName()}.");
            };
            }
            #endregion
            if (tag != null)
            {
                tag.LineInfo = XmlLineInfo.Create(xmlNode);
            }
            if (xmlNode is XElement ell)
            {
                foreach (XNode childNode in ell.Nodes())
                {
                    ITag childTag = LoadTag(childNode, includes);
                    if (childTag != null && tag != null)
                    {
                        childTag.Parent = tag;
                        (tag as Tag).ChildTags.Add(childTag);
                    }
                }
            }
            return(tag);
        }
Example #11
0
        public static ITag LoadTag(XNode node)
        {
            ITag tag = null;

            if (node.NodeType == System.Xml.XmlNodeType.Text || node.NodeType == System.Xml.XmlNodeType.CDATA)
            {
                tag = new SqlText
                {
                    BodyText = node.ToString()
                };
            }
            if (node.NodeType == System.Xml.XmlNodeType.Element)
            {
                XElement elenode      = node as XElement;
                bool     isIn         = elenode.Attribute("In") != null;
                var      prepend      = elenode.Attribute("Prepend")?.Value.Trim();
                var      property     = elenode.Attribute("Property")?.Value.Trim();
                var      compareValue = elenode.Attribute("CompareValue")?.Value.Trim();
                var      nodeName     = elenode.Name.LocalName;
                switch (nodeName)
                {
                case "IsEmpty":
                {
                    tag = new IsEmpty
                    {
                        Prepend  = prepend,
                        Property = property,
                        Children = new List <ITag>()
                    };
                    break;
                }

                case "IsEqual":
                {
                    tag = new IsEqual
                    {
                        Prepend      = prepend,
                        Property     = property,
                        CompareValue = compareValue,
                        Children     = new List <ITag>()
                    };
                    break;
                }

                case "IsNotEqual":
                {
                    tag = new IsNotEqual
                    {
                        Prepend      = prepend,
                        CompareValue = compareValue,
                        Property     = property,
                        Children     = new List <ITag>()
                    };
                    break;
                }

                case "IsGreaterEqual":
                {
                    tag = new IsGreaterEqual
                    {
                        Prepend      = prepend,
                        Property     = property,
                        CompareValue = compareValue,
                    };
                    break;
                }

                case "IsGreaterThan":
                {
                    tag = new IsGreaterThan
                    {
                        Prepend      = prepend,
                        Property     = property,
                        CompareValue = compareValue,
                        Children     = new List <ITag>()
                    };
                    break;
                }

                case "IsLessEqual":
                {
                    tag = new IsLessEqual
                    {
                        Prepend      = prepend,
                        Property     = property,
                        CompareValue = compareValue,
                        Children     = new List <ITag>()
                    };
                    break;
                }

                case "IsLessThan":
                {
                    tag = new IsLessThan
                    {
                        Prepend      = prepend,
                        Property     = property,
                        CompareValue = compareValue,
                        Children     = new List <ITag>()
                    };
                    break;
                }

                case "IsNotEmpty":
                {
                    tag = new IsNotEmpty
                    {
                        Prepend  = prepend,
                        Property = property,
                        Children = new List <ITag>()
                    };
                    break;
                }

                case "IsNotNull":
                {
                    tag = new IsNotNull
                    {
                        Prepend  = prepend,
                        Property = property,
                        Children = new List <ITag>()
                    };
                    break;
                }

                case "IsNull":
                {
                    tag = new IsNull
                    {
                        Prepend  = prepend,
                        Property = property,
                        Children = new List <ITag>()
                    };
                    break;
                }

                case "Switch":
                {
                    tag = new Switch
                    {
                        // Prepend = prepend,
                        Property = property,
                        Children = new List <ITag>()
                    };
                    break;
                }

                case "Case":
                {
                    var switchNode     = node.Parent;
                    var switchProperty = switchNode.Attribute("Property")?.Value.Trim();
                    var switchPrepend  = switchNode.Attribute("Prepend")?.Value.Trim();
                    tag = new Switch.Case
                    {
                        Prepend      = switchPrepend,
                        Property     = switchProperty,
                        CompareValue = compareValue,
                        Children     = new List <ITag>()
                    };
                    break;
                }

                case "Default":
                {
                    var switchNode     = node.Parent;
                    var switchProperty = switchNode.Attribute("Property")?.Value.Trim();
                    var switchPrepend  = switchNode.Attribute("Prepend")?.Value.Trim();
                    tag = new Switch.Default
                    {
                        Prepend  = switchPrepend,
                        Property = switchProperty,
                        Children = new List <ITag>()
                    };
                    break;
                }

                case "Where":
                {
                    tag = new Where
                    {
                        Children = new List <ITag>()
                    };
                    break;
                }

                case "Dynamic":
                {
                    tag = new Dynamic
                    {
                        Prepend  = prepend,
                        Children = new List <ITag>()
                    };
                    break;
                }

                case "IsProperty":
                {
                    tag = new IsProperty
                    {
                        Prepend  = prepend,
                        Children = new List <ITag>(),
                        Property = property
                    };
                    break;
                }

                default:
                {
                    throw new BaraException($"Statement can't load TagName:{nodeName}");
                }
                }
                foreach (var childNode in elenode.Nodes())
                {
                    ITag childTag = LoadTag(childNode);
                    if (childTag != null && tag != null)
                    {
                        (tag as Tag).Children.Add(childTag);
                    }
                }
            }
            return(tag);
        }
Example #12
0
        public ITag Build(XmlNode xmlNode)
        {
            ITag tag          = null;
            var  prepend      = xmlNode.Attributes?["Prepend"]?.Value.Trim();
            var  property     = xmlNode.Attributes?["Property"]?.Value.Trim();
            var  compareValue = xmlNode.Attributes?["CompareValue"]?.Value.Trim();

            #region Init Tag
            switch (xmlNode.Name)
            {
            case "#text":
            case "#cdata-section":
            {
                var bodyText = " " + xmlNode.InnerText.Replace("\n", "").Trim();
                return(new SqlText
                    {
                        BodyText = bodyText
                    });
            }

            case "Include":
            {
                var refId       = xmlNode.Attributes?["RefId"]?.Value;
                var include_tag = new Include
                {
                    RefId   = refId,
                    Prepend = prepend
                };
                //includes.Add(include_tag);
                tag = include_tag;
                break;
            }

            case "IsEmpty":
            {
                tag = new IsEmpty
                {
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "IsEqual":
            {
                tag = new IsEqual
                {
                    Prepend      = prepend,
                    Property     = property,
                    CompareValue = compareValue,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            case "IsGreaterEqual":
            {
                tag = new IsGreaterEqual
                {
                    Prepend      = prepend,
                    Property     = property,
                    CompareValue = compareValue,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            case "IsGreaterThan":
            {
                tag = new IsGreaterThan
                {
                    Prepend      = prepend,
                    Property     = property,
                    CompareValue = compareValue,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            case "IsLessEqual":
            {
                tag = new IsLessEqual
                {
                    Prepend      = prepend,
                    Property     = property,
                    CompareValue = compareValue,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            case "IsLessThan":
            {
                tag = new IsLessThan
                {
                    Prepend      = prepend,
                    Property     = property,
                    CompareValue = compareValue,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            case "IsNotEmpty":
            {
                tag = new IsNotEmpty
                {
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "IsNotEqual":
            {
                tag = new IsNotEqual
                {
                    Prepend      = prepend,
                    Property     = property,
                    CompareValue = compareValue,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            case "IsNotNull":
            {
                tag = new IsNotNull
                {
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "IsNull":
            {
                tag = new IsNull
                {
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "IsTrue":
            {
                tag = new IsTrue
                {
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "IsFalse":
            {
                tag = new IsFalse
                {
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "IsProperty":
            {
                tag = new IsProperty
                {
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "Placeholder":
            {
                tag = new Placeholder
                {
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "Switch":
            {
                tag = new Switch
                {
                    Property  = property,
                    Prepend   = prepend,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "Case":
            {
                var switchNode     = xmlNode.ParentNode;
                var switchProperty = switchNode.Attributes?["Property"]?.Value.Trim();
                var switchPrepend  = switchNode.Attributes?["Prepend"]?.Value.Trim();
                tag = new Switch.Case
                {
                    CompareValue = compareValue,
                    Property     = switchProperty,
                    Prepend      = switchPrepend,
                    Test         = xmlNode.Attributes?["Test"]?.Value.Trim(),
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            case "Bind":
            {
                tag = new BindTag
                {
                    Name  = xmlNode.Attributes["Name"]?.Value,
                    Value = xmlNode.Attributes["Value"]?.Value,
                };
                break;
            }

            case "Trim":
            {
                tag = new TrimTag
                {
                    Prefix          = xmlNode.Attributes["Prefix"]?.Value,
                    PrefixOverrides = xmlNode.Attributes["PrefixOverrides"]?.Value,
                    Suffix          = xmlNode.Attributes["Suffix"]?.Value,
                    ChildTags       = new List <ITag>()
                };
                break;
            }

            case "Default":
            {
                var switchNode     = xmlNode.ParentNode;
                var switchProperty = switchNode.Attributes?["Property"]?.Value.Trim();
                var switchPrepend  = switchNode.Attributes?["Prepend"]?.Value.Trim();
                tag = new Switch.Defalut
                {
                    Property  = switchProperty,
                    Prepend   = switchPrepend,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "Dynamic":
            {
                tag = new Dynamic
                {
                    Prepend   = prepend,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "Where":
            {
                tag = new Where
                {
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "If":
            {
                var test = xmlNode.Attributes["Test"]?.Value;
                tag = new IfTag
                {
                    Test = test
                };
            }
            break;

            case "Set":
            {
                tag = new Set
                {
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "For":
            {
                var open      = xmlNode.Attributes?["Open"]?.Value.Trim();
                var separator = xmlNode.Attributes?["Separator"]?.Value.Trim();
                var close     = xmlNode.Attributes?["Close"]?.Value.Trim();
                var key       = xmlNode.Attributes?["Key"]?.Value.Trim();
                tag = new For
                {
                    Prepend   = prepend,
                    Property  = property,
                    Open      = open,
                    Close     = close,
                    Separator = separator,
                    Key       = key,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "Env":
            {
                var dbProvider = xmlNode.Attributes?["DbProvider"]?.Value.Trim();
                tag = new Env
                {
                    Prepend    = prepend,
                    DbProvider = dbProvider,
                    ChildTags  = new List <ITag>()
                };
                break;
            }

            case "#comment": { break; }

            default:
            {
                throw new SmartSqlException($"Statement.LoadTag unkonw tagName:{xmlNode.Name}.");
            };
            }
            #endregion
            return(tag);
        }
        public override Element VisitQuery(cqlParser.QueryContext context)
        {
            var aliasedSource = context.aliasedQuerySource();
            var querySource   = (Expression)Visit(aliasedSource.querySource());
            var alias         = aliasedSource.alias().GetText();
            var result        = (Expression) new Filter {
                source = querySource, scope = alias
            };
            var condition = new And {
                operand = new List <Expression>()
            };

            foreach (var queryInclusionClause in context.queryInclusionClause())
            {
                // NOTE: This only works with "with" clauses right now. If we add "combine" it will need to be dealt with here.
                var withSource     = (Expression)VisitQuerySource(queryInclusionClause.aliasedQuerySource().querySource());
                var withAlias      = queryInclusionClause.aliasedQuerySource().alias().GetText();
                var withCondition  = (Expression)Visit(queryInclusionClause.expression());
                var withExpression = new IsNotEmpty {
                    operand = new Filter {
                        source = withSource, scope = withAlias, condition = withCondition
                    }
                };
                condition.operand.Add(withExpression);
            }

            var whereClause = context.whereClause();

            if (whereClause != null)
            {
                condition.operand.Add((Expression)Visit(whereClause.expression()));
            }

            var returnClause = context.returnClause();

            if (returnClause != null)
            {
                result = new ForEach {
                    source = result, scope = alias, element = (Expression)Visit(returnClause.expression())
                };
            }

            var sortClause = context.sortClause();

            if (sortClause != null)
            {
                var sortDirection = sortClause.sortDirection();
                if (sortDirection != null)
                {
                    if (sortDirection.GetText() != "asc")
                    {
                        // TODO: CQL-LM must be modified to support directional sort
                        throw new NotSupportedException();
                    }

                    result = new Sort {
                        source = result
                    };
                }
                else
                {
                    if (sortClause.sortByItem().Count != 1)
                    {
                        // TODO: CQL-LM must be modified to support multi-column sort
                        throw new NotSupportedException();
                    }

                    if (sortClause.sortByItem(0).sortDirection() != null && sortClause.sortByItem(0).sortDirection().GetText() != "asc")
                    {
                        // TODO: CQL-LM must be modified to support directional sort
                        throw new NotSupportedException();
                    }

                    return(new Sort {
                        source = result, orderBy = sortClause.sortByItem(0).expressionTerm().GetText()
                    });
                }
            }

            return(result);
        }
Example #14
0
        public static ITag LoadTag(XmlNode xmlNode, IList <Include> includes)
        {
            ITag tag          = null;
            bool isIn         = !string.IsNullOrEmpty(xmlNode.GetValueInXmlAttributes("In"));
            var  prepend      = xmlNode.GetValueInXmlAttributes("Prepend");
            var  property     = xmlNode.GetValueInXmlAttributes("Property");
            var  compareValue = xmlNode.GetValueInXmlAttributes("CompareValue");

            #region Init Tag
            string lowerXmlNodeName = xmlNode.Name.ToLower();
            switch (lowerXmlNodeName)
            {
            case "#text":
            case "#cdata-section":
            {
                var bodyText = " " + xmlNode.GetInnerTextInXmlAttributes();
                return(new SqlText
                    {
                        BodyText = bodyText
                    });
            }

            //case "OrderBy":
            case "orderby":
            {
                var bodyText = " " + xmlNode.GetInnerTextInXmlAttributes();
                tag = new OrderBy
                {
                    ChildTags = new List <ITag>(),

                    BodyText = bodyText
                };
                break;
            }

            //case "Include":
            case "include":
            {
                var refId       = xmlNode.GetValueInXmlAttributes("RefId");
                var include_tag = new Include
                {
                    RefId = refId
                };
                includes.Add(include_tag);
                tag = include_tag;
                break;
            }

            //case "If":
            case "if":
            {
                var Test = xmlNode.GetValueInXmlAttributes("Test");
                tag = new IfTag
                {
                    Test      = Test,
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            //case "IsEmpty":
            case "isempty":
            {
                tag = new IsEmpty
                {
                    In        = isIn,
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            //case "IsEqual":
            case "isequal":
            {
                tag = new IsEqual
                {
                    In           = isIn,
                    Prepend      = prepend,
                    Property     = property,
                    CompareValue = compareValue,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            //case "IsGreaterEqual":
            case "isgreaterequal":
            {
                tag = new IsGreaterEqual
                {
                    In           = isIn,
                    Prepend      = prepend,
                    Property     = property,
                    CompareValue = compareValue,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            //case "IsGreaterThan":
            case "isgreaterthan":
            {
                tag = new IsGreaterThan
                {
                    In           = isIn,
                    Prepend      = prepend,
                    Property     = property,
                    CompareValue = compareValue,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            //case "IsLessEqual":
            case "islessequal":
            {
                tag = new IsLessEqual
                {
                    In           = isIn,
                    Prepend      = prepend,
                    Property     = property,
                    CompareValue = compareValue,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            //case "IsLessThan":
            case "islessthan":
            {
                tag = new IsLessThan
                {
                    In           = isIn,
                    Prepend      = prepend,
                    Property     = property,
                    CompareValue = compareValue,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            //case "IsNotEmpty":
            case "isnotempty":
            {
                tag = new IsNotEmpty
                {
                    In        = isIn,
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            //case "IsNotEqual":
            case "isnotequal":
            {
                tag = new IsNotEqual
                {
                    In           = isIn,
                    Prepend      = prepend,
                    Property     = property,
                    CompareValue = compareValue,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            //case "IsNotNull":
            case "isnotnull":
            {
                tag = new IsNotNull
                {
                    In        = isIn,
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            //case "IsNull":
            case "isnull":
            {
                tag = new IsNull
                {
                    In        = isIn,
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            //case "IsTrue":
            case "istrue":
            {
                tag = new IsTrue
                {
                    In        = isIn,
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            //case "IsFalse":
            case "isfalse":
            {
                tag = new IsFalse
                {
                    In        = isIn,
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            //case "IsProperty":
            case "isproperty":
            {
                tag = new IsProperty
                {
                    In        = isIn,
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            //case "Switch":
            case "switch":
            {
                tag = new Switch
                {
                    Property = property,
                    //Prepend = prepend,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            //case "Case":
            case "case":
            {
                var switchNode     = xmlNode.ParentNode;
                var switchProperty = switchNode.GetValueInXmlAttributes("Property");
                var switchPrepend  = switchNode.GetValueInXmlAttributes("Prepend");
                tag = new Switch.Case
                {
                    CompareValue = compareValue,
                    Property     = switchProperty,
                    Prepend      = switchPrepend,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            //case "Default":
            case "default":
            {
                var switchNode     = xmlNode.ParentNode;
                var switchProperty = switchNode.GetValueInXmlAttributes("Property");
                var switchPrepend  = switchNode.GetValueInXmlAttributes("Prepend");
                tag = new Switch.Defalut
                {
                    Property  = switchProperty,
                    Prepend   = switchPrepend,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            //case "Choose":
            case "choose":
            {
                tag = new ChooseTag
                {
                    //Property = property,
                    //Prepend = prepend,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "when":
            {
                var Test = xmlNode.GetValueInXmlAttributes("Test");
                //var switchNode = xmlNode.ParentNode;
                //var switchProperty = switchNode.GetValueInXmlAttributes("Property");
                //var switchPrepend = switchNode.GetValueInXmlAttributes("Prepend");
                tag = new ChooseTag.ChooseWhenTag
                {
                    Test = Test,
                    //Property = switchProperty,
                    //Prepend = switchPrepend,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "otherwise":
            {
                //var switchNode = xmlNode.ParentNode;
                //var switchProperty = switchNode.GetValueInXmlAttributes("Property");
                //var switchPrepend = switchNode.GetValueInXmlAttributes("Prepend");
                tag = new ChooseTag.ChooseOtherwiseTag
                {
                    //Property = switchProperty,
                    //Prepend = switchPrepend,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "trim":
            {
                var Prefix          = xmlNode.GetValueInXmlAttributes("Prefix", "", false);
                var Suffix          = xmlNode.GetValueInXmlAttributes("Suffix", "", false);
                var PrefixOverrides = xmlNode.GetValueInXmlAttributes("PrefixOverrides");
                var SuffixOverrides = xmlNode.GetValueInXmlAttributes("SuffixOverrides");
                tag = new TrimTag
                {
                    Prefix          = Prefix,
                    Suffix          = Suffix,
                    PrefixOverrides = PrefixOverrides,
                    SuffixOverrides = SuffixOverrides,
                    ChildTags       = new List <ITag>()
                };
                break;
            }

            case "set":
            {
                tag = new SetTag()
                {
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "where":
            {
                tag = new WhereTag
                {
                    ChildTags = new List <ITag>()
                };
                break;
            }

            //case "Where":
            //case "where":
            //    {
            //        tag = new Where
            //        {
            //            ChildTags = new List<ITag>()
            //        };
            //        break;
            //    }
            //case "Dynamic":
            case "dynamic":
            {
                tag = new Dynamic
                {
                    Prepend   = prepend,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            //case "Variable":
            case "variable":
            {
                var bodyText = xmlNode.GetInnerTextInXmlAttributes();
                tag = new Variable
                {
                    BodyText  = bodyText,
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            //case "Bind":
            case "bind":
            {
                var Name  = xmlNode.GetValueInXmlAttributes("Name");
                var Value = xmlNode.GetValueInXmlAttributes("Value");
                //var bodyText = xmlNode.GetInnerTextInXmlAttributes();
                tag = new BindTag
                {
                    Name      = Name,
                    Value     = Value,
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            //case "Foreach":
            case "foreach":
            {
                var open      = xmlNode.GetValueInXmlAttributes("Open");
                var separator = xmlNode.GetValueInXmlAttributes("Separator");
                var close     = xmlNode.GetValueInXmlAttributes("Close");
                var item      = xmlNode.GetValueInXmlAttributes("Item");
                var index     = xmlNode.GetValueInXmlAttributes("Index");
                tag = new Foreach
                {
                    Prepend   = prepend,
                    Property  = property,
                    Open      = open,
                    Close     = close,
                    Separator = separator,
                    Item      = item,
                    Index     = index,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            //case "Env":
            case "env":
            {
                var dbProvider = xmlNode.GetValueInXmlAttributes("DbProvider");
                var DbType     = xmlNode.GetValueInXmlAttributes("DbType");
                tag = new Env
                {
                    Prepend    = prepend,
                    DbProvider = dbProvider,
                    DbType     = DbType,
                    ChildTags  = new List <ITag>()
                };
                break;
            }

            case "#comment": { break; }

            default:
            {
                throw new Exception(string.Format("Statement.LoadTag unkonw tagName:{0}.", xmlNode.Name));
            };
            }
            #endregion
            //加载组合查询条件查询
            foreach (XmlNode childNode in xmlNode)
            {
                ITag childTag = LoadTag(childNode, includes);
                if (childTag != null && tag != null)
                {
                    (tag as Tag).ChildTags.Add(childTag);
                }
            }
            return(tag);
        }