Inheritance: MonoBehaviour
Beispiel #1
0
        /// <summary>
        /// 批量获取SystemRole实体对象
        /// </summary>
        public static List <SystemRole> GetList(int top, Expression <Func <SystemRole, bool> > predicate = null, params SystemRoleColumn[] orderBy)
        {
            var where_str = string.Empty;

            if (predicate != null)
            {
                var parser = new PredicateParser();
                where_str = parser.Parse(predicate);
            }

            var sql = new StringBuilder();

            sql.Append("SELECT TOP " + top.ToString() + " * FROM [SystemRole]");
            if (where_str != string.Empty)
            {
                sql.Append(" WHERE " + where_str);
            }
            if (orderBy != null && orderBy.Length > 0)
            {
                sql.Append(" ORDER BY " + string.Join(", ", orderBy.Select(p => $"{p.Name} {p.Asc}")));
            }

            List <SystemRole> ret = null;

            using (var conn = GetOpenConnection())
            {
                ret = conn.Query <SystemRole>(sql.ToString()).ToList();
            }

            return(ret);
        }
Beispiel #2
0
 public void Test()
 {
     string predicateFormat = "1 = 2";
       PredicateParser parser = new PredicateParser(predicateFormat);
       var predicate = parser.ParsePredicate();
       Assert.NotNull(predicate);
 }
Beispiel #3
0
        /// <summary>
        /// 获取记录总数
        /// </summary>
        public static int GetCount(Expression <Func <SystemRole, bool> > predicate = null)
        {
            var where_str = string.Empty;

            if (predicate != null)
            {
                var parser = new PredicateParser();
                where_str = parser.Parse(predicate);
            }

            var sql = new StringBuilder();

            sql.Append("SELECT COUNT(1) FROM [SystemRole]");
            if (where_str != string.Empty)
            {
                sql.Append(" WHERE " + where_str);
            }

            var ret = -1;

            using (var conn = GetOpenConnection())
            {
                ret = conn.ExecuteScalar <int>(sql.ToString());
            }

            return(ret);
        }
Beispiel #4
0
        public void VerifyParseValidProperty()
        {
            var expr            = @"FirstName == ""John""";
            var parsedCorrectly = PredicateParser <Person> .TryParse(expr);

            Assert.IsTrue(parsedCorrectly);
        }
Beispiel #5
0
        /// <summary>
        /// 删除指定的SystemRole数据记录
        /// </summary>
        public static bool Delete(Expression <Func <SystemRole, bool> > predicate = null)
        {
            var where_str = string.Empty;

            if (predicate != null)
            {
                var parser = new PredicateParser();
                where_str = parser.Parse(predicate);
            }

            var sql = new StringBuilder();

            sql.Append("DELETE FROM [SystemRole]");
            if (where_str != string.Empty)
            {
                sql.Append(" WHERE " + where_str);
            }
            var ret = false;

            using (var conn = GetOpenConnection())
            {
                ret = conn.Execute(sql.ToString()) > 0;
            }

            return(ret);
        }
Beispiel #6
0
        public static bool MeetsCondition(PropertyCondition propCondition, IDictionary <string, object> entry)
        {
            var propertyName = propCondition.PropertyName.Dehumanize();
            var condition    = propCondition.Condition;
            var tryParse     = PredicateParser <dynamic> .TryParse(condition);

            if (!tryParse)
            {
                Trace.WriteLine("Failed to Parse Condition on Property (" + propertyName + "):  " + condition);
                return(false);
            }

            var propValue = entry[propertyName];

            Trace.WriteLine("Evaluating Condition (" + condition + ") on Property (" + propertyName + ") with value: " + propValue);
            var expression = PredicateParser <dynamic> .Parse(condition);

            var predicate      = expression.Compile();
            var meetsCondition = predicate(entry);

            if (!meetsCondition)
            {
                Trace.WriteLine("Failed to Meet Condition on Property (" + propertyName + ") with value (" + propValue + "):  " + condition);
            }

            return(meetsCondition);
        }
Beispiel #7
0
 public Result(PredicateParser parser, int index, int length, string input, Predicate value)
 {
     m_parser = parser;
     m_index  = index;
     m_length = length;
     m_input  = input;
     Value    = value;
 }
        public static bool Evaluate <TSourceObj>(string expression, TSourceObj source)
        {
            var predicate = PredicateParser <TSourceObj> .Parse(expression);

            var compiledPredicate = predicate.Compile();

            Trace.WriteLine("Expression:  " + expression);
            Trace.WriteLine(predicate);
            return(compiledPredicate(source));
        }
Beispiel #9
0
 // Use this for initialization
 public virtual void Start()
 {
     Debug.Log("E " + gameObject);
     Debug.Log("E " + GetComponent <Collider>());
     HomeCoords = transform.position;
     HomeRot    = transform.eulerAngles;
     controller = GameObject.Find("MinSimController").GetComponent <PredicateParser>();
     renderer   = gameObject.GetComponent <MeshRenderer> ();
     InUse      = false;
 }
Beispiel #10
0
    public JSONParser()
    {
        typeParser      = TypeParser.Instance;
        predicateParser = PredicateParser.Instance;
        operatorParser  = OperatorParser.Instance;

        objectParser    = ObjectParser.Instance;
        initStateParser = StateParser.Instance;
        goalStateParser = StateParser.Instance;
    }
Beispiel #11
0
        static void Main(string[] args)
        {
            var predicates = new List <IPredicate>
            {
                Predicates.Field <Car>(f => f.Type, Operator.Eq, "Sedan"),
                Predicates.Field <Car>(f => f.Type, Operator.Eq, "Hatchback"),
            };

            var testdata   = Car.PrepareTestData();
            var expression = PredicateParser <Car> .ParseOr(predicates).Compile();

            var result = testdata.Where(expression);
        }
Beispiel #12
0
    private void CallRecursive(PredicateGroup predicateGroup)
    {
        var  nodes = predicateGroup.Predicates;
        bool isSet = true;

        ++level;

        foreach (var n in nodes)
        {
            if (n is PredicateGroup @group)
            {
                CallRecursive(@group);
                --level;
            }
            else
            {
                var expr = PredicateParser <T> .Parse((IFieldPredicate)n);

                if (level > 0)
                {
                    if (isSet)
                    {
                        higherQuery = t => predicateGroup.Operator == GroupOperator.And;
                        isSet       = false;
                    }

                    higherQuery = predicateGroup.Operator == GroupOperator.And
                                        ? higherQuery.And(expr)
                                        : higherQuery.Or(expr);
                }
                else
                {
                    previousOperator = predicateGroup.Operator;

                    finalQuery = predicateGroup.Operator == GroupOperator.And
                                        ? finalQuery.And(expr)
                                        : finalQuery.Or(expr);
                }
            }
        }

        if (higherQuery != null)
        {
            finalQuery = previousOperator == GroupOperator.And
                                ? finalQuery.And(higherQuery)
                                : finalQuery.Or(higherQuery);
        }

        higherQuery = null;
    }
Beispiel #13
0
        public void ParseIsPredicateTest()
        {
            //Create parser
            PredicateParser  predicateParser   = new PredicateParser(Init(".string?"));
            ExpressionParser expressionParser  = new ExpressionParser(Init("test"));
            Expression       parsedExpression  = expressionParser.ParseExpression();
            IsPredicate      parsedIsPredicate = predicateParser.ParseIsPredicate(parsedExpression);

            //Check expression
            Assert.AreEqual(typeof(VarExpression), parsedIsPredicate.GetExpression().GetType());
            Assert.AreEqual("test", parsedIsPredicate.GetExpression().ToString());

            //Check type
            Assert.AreEqual(typeof(StringType), parsedIsPredicate.GetType().GetType());
        }
Beispiel #14
0
        public async Task <PredicateEvaluationOperation <CandidateSearchResult> > Evaluate(string predicateExpression)
        {
            var charStream = new AntlrInputStream(predicateExpression);
            var lexer      = new PredicateLexer(charStream);
            var stream     = new CommonTokenStream(lexer);

            stream.Fill();
            var tokens = stream.Get(0, stream.Size);

            stream.Reset();

            if (tokens.Any(x => x.Type == PredicateLexer.Discardable))
            {
                throw new Exception("Contains unknown tokens");
            }

            var parser = new PredicateParser(stream);

            parser.RemoveErrorListeners();
            parser.AddErrorListener(new ThrowingErrorListener());
            var treeBuilder = new PredicateSyntaxTreeBuilderVisitor();
            var tree        = treeBuilder.Visit(parser.expr());

            var searchBuilder = new ElasticSearchQueryBuilder(_propertyDetailsProvider);
            var query         = searchBuilder.BuildNestQuery(tree);

            var searchResult = await _elasticClient.SearchAsync <CandidateDocument>(new SearchRequest(_index)
            {
                Query = query
            });

            var resultItems = searchResult.Documents
                              .Select(x => new CandidateSearchResultItem
            {
                CurrentJobTitle   = x.CurrentJobTitle,
                Salary            = x.Salary,
                ExperienceInYears = x.ExperienceInYears
            })
                              .ToList();

            return(new PredicateEvaluationOperation <CandidateSearchResult>(new CandidateSearchResult
            {
                Items = resultItems
            }));
        }
Beispiel #15
0
        /// <summary>
        /// 是否存在指定的SystemRole实体对象
        /// </summary>
        public static bool Exists(Expression <Func <SystemRole, bool> > predicate)
        {
            var parser    = new PredicateParser();
            var where_str = parser.Parse(predicate);

            var sql = new StringBuilder();

            sql.Append("SELECT COUNT(1) FROM [SystemRole]");
            sql.Append(" WHERE " + where_str);
            var ret = false;

            using (var conn = GetOpenConnection())
            {
                ret = conn.ExecuteScalar <int>(sql.ToString()) > 0;
            }

            return(ret);
        }
Beispiel #16
0
        /// <summary>
        /// 获取指定的SystemRole实体对象
        /// </summary>
        public static SystemRole GetModel(Expression <Func <SystemRole, bool> > predicate)
        {
            var parser    = new PredicateParser();
            var where_str = parser.Parse(predicate);

            var sql = new StringBuilder();

            sql.Append("SELECT TOP 1 * FROM [SystemRole] ");
            sql.Append(" WHERE " + where_str);
            SystemRole ret = null;

            using (var conn = GetOpenConnection())
            {
                ret = conn.QueryFirstOrDefault <SystemRole>(sql.ToString());
            }

            return(ret);
        }
Beispiel #17
0
        public void ParseNotPredicateTest()
        {
            //Create parser
            PredicateParser predicateParser = new PredicateParser(Init("! condition1 && test.list?"));
            Predicate       parsedPredicate = predicateParser.ParsePredicate();

            //Check Predicates
            Assert.AreEqual(typeof(NotPredicate), parsedPredicate.GetType());

            //Check AndPredicate
            Predicate parsedInnerPredicate = ((NotPredicate)parsedPredicate).GetPredicate();

            Assert.AreEqual(typeof(AndPredicate), parsedInnerPredicate.GetType());
            AndPredicate parsedInnerAndPredicate = (AndPredicate)parsedInnerPredicate;

            Assert.AreEqual(typeof(ExpressionPredicate), parsedInnerAndPredicate.GetLeftPredicate().GetType());
            Assert.AreEqual(typeof(IsPredicate), parsedInnerAndPredicate.GetRightPredicate().GetType());
        }
Beispiel #18
0
        public static Executor GetInstance(string databaseName = Constants.FILE_NAME)
        {
            if (_instance == null)
            {
                lock (_lockObject)
                {
                    if (databaseName != null)
                    {
                        if (!File.Exists(databaseName))
                        {
                            using (File.Create(databaseName));
                        }
                    }

                    var updateParser    = new UpdateParser();
                    var stringParser    = new StringParser();
                    var reader          = new Reader();
                    var writer          = new Writer(reader);
                    var lockManager     = new LockManager(writer, reader);
                    var schemaFetcher   = new SchemaFetcher(reader);
                    var selectParser    = new SelectParser();
                    var insertParser    = new InsertParser(schemaFetcher);
                    var generalParser   = new GeneralParser();
                    var createParser    = new CreateParser();
                    var predicateParser = new PredicateParser();

                    var interpreter = new Interpreter(
                        selectParser,
                        insertParser,
                        updateParser,
                        schemaFetcher,
                        generalParser,
                        createParser,
                        stringParser,
                        lockManager,
                        reader,
                        predicateParser);

                    _instance = new Executor(interpreter);
                }
            }

            return(_instance);
        }
Beispiel #19
0
        public void Parse_CollectionOfCars_ThreeTypeOfCars()
        {
            //Arrange
            var testdata = Car.PrepareTestData();

            var groupPredicate = new PredicateGroup
            {
                Operator   = GroupOperator.Or,
                Predicates = new List <IPredicate>()
            };

            var predicateGroup1 = new PredicateGroup
            {
                Operator   = GroupOperator.And,
                Predicates = new List <IPredicate>()
                {
                    Predicates.Field <Car>(f => f.Name, Operator.Eq, "Fiat"),
                    Predicates.Field <Car>(f => f.Model, Operator.Eq, "Bravo")
                }
            };

            var predicateGroup2 = new PredicateGroup
            {
                Operator   = GroupOperator.And,
                Predicates = new List <IPredicate>()
                {
                    Predicates.Field <Car>(f => f.Cost, Operator.Gt, 20000),
                    Predicates.Field <Car>(f => f.Type, Operator.Eq, "Sedan"),
                }
            };

            groupPredicate.Predicates.Add(Predicates.Field <Car>(f => f.Type, Operator.Eq, "Hatchback"));
            groupPredicate.Predicates.Add(predicateGroup1);
            groupPredicate.Predicates.Add(predicateGroup2);

            //Act
            var expression = PredicateParser <Car> .Parse(groupPredicate).Compile();

            var result = testdata.Where(expression);

            //Assert
            Assert.AreEqual(3, result.Count());
        }
Beispiel #20
0
        public void ParseOr_CollectionOfCars_TwoTypeOfCars()
        {
            //Arrange
            var testdata = Car.PrepareTestData();

            var predicates = new List <IPredicate>
            {
                Predicates.Field <Car>(f => f.Type, Operator.Eq, "Sedan"),
                Predicates.Field <Car>(f => f.Type, Operator.Eq, "Hatchback"),
            };

            //Act
            var expression = PredicateParser <Car> .ParseOr(predicates).Compile();

            var result      = testdata.Where(expression);
            var typesNumber = result.GroupBy(b => b.Type).Count();

            //Assert
            Assert.AreEqual(2, typesNumber);
        }
Beispiel #21
0
        public void ParseOrPredicateTest()
        {
            //Create parser
            PredicateParser predicateParser = new PredicateParser(Init("condition1 || condition2 || condition3"));
            Predicate       parsedPredicate = predicateParser.ParsePredicate();

            //Check Predicates
            Assert.AreEqual(typeof(OrPredicate), parsedPredicate.GetType());

            //Check OrPredicate
            OrPredicate parsedOrPredicate = (OrPredicate)parsedPredicate;

            Assert.AreEqual(typeof(ExpressionPredicate), parsedOrPredicate.GetLeftPredicate().GetType());
            Assert.AreEqual(typeof(OrPredicate), parsedOrPredicate.GetRightPredicate().GetType());

            //Check nested OrPredicate
            OrPredicate parsedNestedOrPredicate = (OrPredicate)parsedOrPredicate.GetRightPredicate();

            Assert.AreEqual(typeof(ExpressionPredicate), parsedNestedOrPredicate.GetLeftPredicate().GetType());
            Assert.AreEqual(typeof(ExpressionPredicate), parsedNestedOrPredicate.GetRightPredicate().GetType());
        }
Beispiel #22
0
 public Interpreter(SelectParser selectParser,
                    InsertParser insertParser,
                    UpdateParser updateParser,
                    SchemaFetcher schemaFetcher,
                    GeneralParser generalParser,
                    CreateParser createParser,
                    StringParser stringParser,
                    LockManager lockManager,
                    Reader reader,
                    PredicateParser predicateParser)
 {
     _selectParser    = selectParser;
     _insertParser    = insertParser;
     _updateParser    = updateParser;
     _schemaFetcher   = schemaFetcher;
     _generalParser   = generalParser;
     _createParser    = createParser;
     _stringParser    = stringParser;
     _lockManager     = lockManager;
     _reader          = reader;
     _predicateParser = predicateParser;
 }
Beispiel #23
0
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public static PageDataView <SystemRole> GetPage(
            Expression <Func <SystemRole, bool> > predicate,
            int pageSize,
            int currentPage,
            IList <SystemRoleColumn> orderBy,
            params SystemRoleColumn[] columns)
        {
            var where_str = string.Empty;

            if (predicate != null)
            {
                var parser = new PredicateParser();
                where_str = parser.Parse(predicate);
            }

            var orderby_str = string.Empty;

            if (orderBy != null && orderBy.Count > 0)
            {
                orderby_str = string.Join(", ", orderBy.Select(p => $"[{p.Name}] {p.Asc}"));
            }

            var column_str = "*";

            if (columns != null && columns.Length > 0)
            {
                column_str = string.Join(", ", columns.Select(p => $"[{p.Name}]"));
            }

            return(Paged <SystemRole>(
                       "[SystemRole]",
                       where_str,
                       orderby_str,
                       column_str,
                       pageSize,
                       currentPage));
        }
Beispiel #24
0
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public static PageDataView <RoleAuthMapping> GetPage(
            Expression <Func <RoleAuthMapping, bool> > predicate = null,
            int pageSize    = 20,
            int currentPage = 1,
            RoleAuthMappingColumn orderBy = null,
            params RoleAuthMappingColumn[] columns)
        {
            var where_str = string.Empty;

            if (predicate != null)
            {
                var parser = new PredicateParser();
                where_str = parser.Parse(predicate);
            }

            var orderby_str = string.Empty;

            if (orderBy != null)
            {
                orderby_str = $"[{orderBy.Name}] {orderBy.Asc}";
            }

            var column_str = "*";

            if (columns != null && columns.Length > 0)
            {
                column_str = string.Join(", ", columns.Select(p => $"[{p.Name}]"));
            }

            return(Paged <RoleAuthMapping>(
                       "[RoleAuthMapping]",
                       where_str,
                       orderby_str,
                       column_str,
                       pageSize,
                       currentPage));
        }
Beispiel #25
0
        /// <summary>
        /// 条件を表す式からSQLを生成します
        /// </summary>
        /// <typeparam name="T">テーブルの型</typeparam>
        /// <param name="targetDatabase">対象となるデータベース</param>
        /// <param name="predicate">条件式</param>
        /// <returns>条件SQL</returns>
        public static This From <T>(DbKind targetDatabase, Expression <Func <T, bool> > predicate)
        {
            //--- 解析実行
            var root = PredicateParser.Parse(predicate);

            //--- SQL文 / パラメーター生成の定義
            uint index          = 0;
            var  columnMap      = TableMappingInfo.Create <T>().Columns.ToDictionary(x => x.PropertyName);
            var  prefix         = targetDatabase.GetBindParameterPrefix();
            var  parameterCount = root.DescendantsAndSelf().Count(x =>
            {
                return(x.Operator != PredicateOperator.AndAlso &&
                       x.Operator != PredicateOperator.OrElse &&
                       x.Value != null);
            });
            var digit       = (parameterCount - 1).ToString().Length;
            var digitFormat = $"D{digit}";
            IDictionary <string, object>    parameter  = new ExpandoObject();
            Func <PredicateElement, string> sqlBuilder = null;

            sqlBuilder = element =>
            {
                if (element.HasChildren)
                {
                    var left  = sqlBuilder(element.Left);
                    var right = sqlBuilder(element.Right);
                    if (element.Operator != element.Left.Operator && element.Left.HasChildren)
                    {
                        left = $"({left})";
                    }
                    if (element.Operator != element.Right.Operator && element.Right.HasChildren)
                    {
                        right = $"({right})";
                    }
                    if (element.Operator == PredicateOperator.AndAlso)
                    {
                        return($"{left} and {right}");
                    }
                    if (element.Operator == PredicateOperator.OrElse)
                    {
                        return($"{left} or {right}");
                    }
                    throw new InvalidOperationException();
                }
                else
                {
                    var builder = new StringBuilder();
                    builder.Append(columnMap[element.PropertyName].ColumnName);
                    switch (element.Operator)
                    {
                    case PredicateOperator.Equal:
                        if (element.Value == null)
                        {
                            builder.Append(" is null");
                            return(builder.ToString());
                        }
                        builder.Append(" = ");
                        break;

                    case PredicateOperator.NotEqual:
                        if (element.Value == null)
                        {
                            builder.Append(" is not null");
                            return(builder.ToString());
                        }
                        builder.Append(" <> ");
                        break;

                    case PredicateOperator.LessThan:            builder.Append(" < ");  break;

                    case PredicateOperator.LessThanOrEqual:     builder.Append(" <= "); break;

                    case PredicateOperator.GreaterThan:         builder.Append(" > ");  break;

                    case PredicateOperator.GreaterThanOrEqual:  builder.Append(" >= "); break;

                    case PredicateOperator.Contains:            builder.Append(" in "); break;

                    default:                                    throw new InvalidOperationException();
                    }

                    var parameterName = $"p{index.ToString(digitFormat)}";
                    ++index;
                    parameter.Add(parameterName, element.Value);  //--- cache parameter
                    builder.Append($"{prefix}{parameterName}");
                    return(builder.ToString());
                }
            };

            //--- 組み立て
            return(new This(sqlBuilder(root), parameter as ExpandoObject));
        }
Beispiel #26
0
 public void TestComparisonOptions()
 {
     string predicateFormat = "'Hello World' =[cd] 'hello world'";
       PredicateParser parser = new PredicateParser(predicateFormat);
       var predicate = parser.ParsePredicate();
       Assert.NotNull(predicate);
 }
Beispiel #27
0
 // Use this for initialization
 public override void Start()
 {
     base.Start();
     Controller = GameObject.Find("MinSimController").GetComponent <PredicateParser>();
 }
Beispiel #28
0
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();

        if (!prompts.Contains("slide(Box1)"))
        {
            prompts.Add("slide(Box1)");
        }
        if (!prompts.Contains("roll(Ball1)"))
        {
            prompts.Add("roll(Ball1)");
        }
        if (!prompts.Contains("cross(Box1, Floor)"))
        {
            prompts.Add("cross(Box1, Floor)");
        }
        if (!prompts.Contains("cross(Ball1, Floor)"))
        {
            prompts.Add("cross(Ball1, Floor)");
        }
        if (!prompts.Contains("cross(Ball3, Floor)"))
        {
            prompts.Add("cross(Ball3, Floor)");
        }
        if (!prompts.Contains("reach(Ball1, Left)"))
        {
            prompts.Add("reach(Ball1, Left)");
        }
        if (!prompts.Contains("reach(Ball1, Center)"))
        {
            prompts.Add("reach(Ball1, Center)");
        }
        if (!prompts.Contains("reach(Ball2, Center)"))
        {
            prompts.Add("reach(Ball2, Center)");
        }

        if (GUILayout.Button("Prompt", GUILayout.Height(30)))
        {
            if (target.GetType() == typeof(PredicateParser))
            {
                PredicateParser getterSetter = (PredicateParser)target;
                getterSetter.InputStringProperty = getterSetter.inputString;
            }
        }

        foreach (string prompt in prompts)
        {
            if (GUILayout.Button(prompt))
            {
                if (target.GetType() == typeof(PredicateParser))
                {
                    PredicateParser getterSetter = (PredicateParser)target;
                    getterSetter.InputStringProperty = prompt;
                }
            }
        }

        if (GUILayout.Button("Reset", GUILayout.Height(30)))
        {
            if (target.GetType() == typeof(PredicateParser))
            {
                PredicateParser getterSetter = (PredicateParser)target;
                getterSetter.DynamicIntroduction = false;
                getterSetter.ShowTrails          = false;

                object[] entities = Resources.FindObjectsOfTypeAll(typeof(OldEntityClass));
                foreach (OldEntityClass entity in entities)
                {
                    entity.Reset();
                }
            }
        }
    }
Beispiel #29
0
 // Use this for initialization
 public virtual void Start()
 {
     Debug.Log ("E " + gameObject);
     Debug.Log ("E " + GetComponent<Collider>());
     HomeCoords = transform.position;
     HomeRot = transform.eulerAngles;
     controller = GameObject.Find ("MinSimController").GetComponent<PredicateParser>();
     renderer = gameObject.GetComponent<MeshRenderer> ();
     InUse = false;
 }
Beispiel #30
0
        /// <summary>
        /// 更新SystemRole数据记录
        /// </summary>
        /// <param name="model">SystemRole实体对象</param>
        /// <param name="fields">需要更新的字段名字</param>
        /// <param name="reverse">反转给定的更新字段</param>
        /// <returns>是否成功,true为成功</returns>
        public static bool Update(SystemRole model, Expression <Func <SystemRole, bool> > predicate, bool reverse, SqlConnection conn, SqlTransaction transaction, params SystemRoleColumn[] fields)
        {
            var where_str = string.Empty;

            if (predicate != null)
            {
                var parser = new PredicateParser();
                where_str = parser.Parse(predicate);
            }
            else
            {
                where_str = "[Id] = @Id";
            }

            var sql = new StringBuilder();

            sql.Append("UPDATE [SystemRole]");
            if (fields == null || fields.Length == 0)
            {
                sql.Append(" SET [Name] = @Name, [Remark] = @Remark, [CreatedTime] = @CreatedTime");
            }
            else
            {
                if (reverse == true)
                {
                    fields = (SystemRoleColumn[])Columns.All.Except(fields);
                }
                sql.Append(" SET ");
                for (int i = 0; i < fields.Length; i++)
                {
                    if (fields[i].IsAddEqual)
                    {
                        sql.Append("[" + fields[i].Name + "] += @" + fields[i].Name + "");
                        fields[i].SetAddEqual();
                    }
                    else
                    {
                        sql.Append("[" + fields[i].Name + "] = @" + fields[i].Name + "");
                    }

                    if (i != fields.Length - 1)
                    {
                        sql.Append(",");
                    }
                }
            }
            sql.Append(" WHERE " + where_str);
            var ret = false;

            if (conn != null)
            {
                if (transaction == null)
                {
                    throw new ArgumentNullException("transaction");
                }
                ret = conn.Execute(sql.ToString(), model, transaction) > 0;
            }
            else
            {
                using (var conn1 = GetOpenConnection())
                {
                    ret = conn1.Execute(sql.ToString(), model) > 0;
                }
            }

            return(ret);
        }