public static void CheckCondition(this ICondition conditionItem, Dictionary <string, object> variables) { string condition = conditionItem.GetCondition(); if (!resolveSet(condition, variables)) { throw new UnauthorizedAccessException(); } }
public override void GenerateMappingCode(CodeGenerationContext ctx, CodeMemberMethod method) { Guard.NotNull(_condition, "'Condition' property can't be null in If mapping"); Guard.NotNull(_true, "'True' property can't be null in If mapping"); CodeMemberMethod trueMethod = ctx.Builder.NewElementMappingMethod(ctx, _true); if (_false != null) { CodeMemberMethod falseMethod = ctx.Builder.NewElementMappingMethod(ctx, _false); method.Statements.Add(new CodeConditionStatement(_condition.GetCondition(ctx, method), new CodeStatement[] { new CodeSnippetStatement(String.Format("this.{0}();", trueMethod.Name)) }, new CodeStatement[] { new CodeSnippetStatement(String.Format("this.{0}();", falseMethod.Name)) })); } else { method.Statements.Add(new CodeConditionStatement(_condition.GetCondition(ctx, method), new CodeStatement[] { new CodeSnippetStatement(String.Format("this.{0}();", trueMethod.Name)) })); } }
/// <summary> /// 添加查询条件 /// </summary> /// <typeparam name="TEntity">实体类型</typeparam> /// <param name="query">数据源</param> /// <param name="condition">查询条件对象</param> /// <exception cref="ArgumentNullException"></exception> public static IQueryable <TEntity> Where <TEntity>(this IQueryable <TEntity> query, ICondition <TEntity> condition) where TEntity : class { if (query == null) { throw new ArgumentNullException(nameof(query)); } if (condition == null) { throw new ArgumentNullException(nameof(condition)); } var predicate = condition.GetCondition(); if (predicate == null) { return(query); } return(query.Where(predicate)); }
public override void GenerateMappingCode(CodeGenerationContext ctx, CodeMemberMethod method) { Guard.NotNull(_while, "While property can't be null in Do mapping"); //bool conditionResult = true; //do //{ // // code // conditionResult = (1 > 2); //} while (condition); method.Statements.Add(new CodeSnippetStatement("bool conditionResult = true;")); CodeVariableReferenceExpression conditionResult = new CodeVariableReferenceExpression("conditionResult"); method.Statements.Add(new CodeSnippetStatement("do {")); base.GenerateMappingCode(ctx, method); method.Statements.Add(new CodeAssignStatement(conditionResult, _while.GetCondition(ctx, method))); method.Statements.Add(new CodeSnippetStatement("} while (conditionResult);")); }
public override void GenerateMappingCode(CodeGenerationContext ctx, CodeMemberMethod method) { Guard.NotNull(_condition, "While property can't be null in Do mapping"); //bool conditionResult = condition; //while(condition) //{ // // code // conditionResult = condition; //} CodeExpression condition = _condition.GetCondition(ctx, method); method.Statements.Add(new CodeVariableDeclarationStatement( typeof(bool), "conditionResult", condition)); CodeVariableReferenceExpression conditionResult = new CodeVariableReferenceExpression("conditionResult"); method.Statements.Add(new CodeSnippetStatement("while (conditionResult) {")); base.GenerateMappingCode(ctx, method); method.Statements.Add(new CodeAssignStatement(conditionResult, condition)); method.Statements.Add(new CodeSnippetStatement("}")); }
/// <summary> /// 获取查询条件 /// </summary> /// <returns></returns> public string GetCondition() { return(_condition?.GetCondition()); }
/// <summary> /// 复制Where子句 /// </summary> /// <param name="builder">Sql生成器</param> /// <param name="register">实体别名注册器</param> /// <param name="parameterManager">参数管理器</param> public virtual IWhereClause Clone(ISqlBuilder builder, IEntityAliasRegister register, IParameterManager parameterManager) { return(new WhereClause(builder, _dialect, _resolver, register, parameterManager, new SqlCondition(_condition?.GetCondition()))); }
/// <summary> /// 初始化一个<see cref="OrCondition"/>类型的实例 /// </summary> /// <param name="left">左操作数</param> /// <param name="right">右操作数</param> public OrCondition(ICondition left, ICondition right) { _left = left?.GetCondition(); _right = right?.GetCondition(); }
/// <summary> /// 复制Where子句 /// </summary> public IWhereClause Clone() { return(new WhereClause(_dialect, _resolver, _register, _parameterManager, new SqlCondition(_condition?.GetCondition()))); }