本文整理汇总了C#中ConditionalBuilder.AddCondition方法的典型用法代码示例。如果您正苦于以下问题:C# ConditionalBuilder.AddCondition方法的具体用法?C# ConditionalBuilder.AddCondition怎么用?C# ConditionalBuilder.AddCondition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConditionalBuilder
的用法示例。
在下文中一共展示了ConditionalBuilder.AddCondition方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MakeCompareReturn
private static void MakeCompareReturn(ConditionalBuilder/*!*/ bodyBuilder, Expression retCondition, Expression/*!*/ retValue, bool isReverse, Type retType) {
if (retCondition != null) {
bodyBuilder.AddCondition(retCondition, retValue);
} else {
bodyBuilder.FinishCondition(retValue, retType);
}
}
示例2: MakeOneTarget
private static bool MakeOneTarget(PythonContext/*!*/ state, SlotOrFunction/*!*/ target, PythonTypeSlot slotTarget, ConditionalBuilder/*!*/ bodyBuilder, bool reverse, DynamicMetaObject/*!*/[]/*!*/ types) {
if (target == SlotOrFunction.Empty && slotTarget == null) return true;
if (slotTarget != null) {
MakeSlotCall(state, types, bodyBuilder, slotTarget, reverse);
return true;
} else if (target.MaybeNotImplemented) {
Debug.Assert(target.ReturnType == typeof(object));
ParameterExpression tmp = Ast.Variable(typeof(object), "slot");
bodyBuilder.AddVariable(tmp);
bodyBuilder.AddCondition(
Ast.NotEqual(
Ast.Assign(
tmp,
target.Target.Expression
),
Ast.Property(null, typeof(PythonOps).GetProperty("NotImplemented"))
),
tmp
);
return true;
} else {
bodyBuilder.FinishCondition(target.Target.Expression, typeof(object));
return false;
}
}
示例3: MakeValueCheck
private static void MakeValueCheck(int val, Expression retValue, ConditionalBuilder/*!*/ bodyBuilder, Expression retCondition) {
if (retValue.Type != typeof(bool)) {
retValue = DynamicExpression.Dynamic(
PythonContext.GetPythonContext(bodyBuilder.Action).Convert(
typeof(bool),
ConversionResultKind.ExplicitCast
),
typeof(bool),
retValue
);
}
if (retCondition != null) {
retValue = Ast.AndAlso(retCondition, retValue);
}
bodyBuilder.AddCondition(
retValue,
AstUtils.Constant(val)
);
}
示例4: DoCoerce
/// <summary>
/// calls __coerce__ for old-style classes and performs the operation if the coercion is successful.
/// </summary>
private static void DoCoerce(PythonContext/*!*/ pyContext, ConditionalBuilder/*!*/ bodyBuilder, PythonOperationKind op, DynamicMetaObject/*!*/[]/*!*/ types, bool reverse, Func<Expression, Expression> returnTransform) {
ParameterExpression coerceResult = Ast.Variable(typeof(object), "coerceResult");
ParameterExpression coerceTuple = Ast.Variable(typeof(PythonTuple), "coerceTuple");
// tmp = self.__coerce__(other)
// if tmp != null && tmp != NotImplemented && (tuple = PythonOps.ValidateCoerceResult(tmp)) != null:
// return operation(tuple[0], tuple[1])
SlotOrFunction slot = SlotOrFunction.GetSlotOrFunction(pyContext, "__coerce__", types);
if (slot.Success) {
bodyBuilder.AddCondition(
Ast.AndAlso(
Ast.Not(
Ast.TypeIs(
Ast.Assign(
coerceResult,
slot.Target.Expression
),
typeof(OldInstance)
)
),
Ast.NotEqual(
Ast.Assign(
coerceTuple,
Ast.Call(
typeof(PythonOps).GetMethod("ValidateCoerceResult"),
coerceResult
)
),
AstUtils.Constant(null)
)
),
BindingHelpers.AddRecursionCheck(
pyContext,
returnTransform(
DynamicExpression.Dynamic(
pyContext.Operation(op | PythonOperationKind.DisableCoerce),
op == PythonOperationKind.Compare ? typeof(int) : typeof(object),
reverse ? CoerceTwo(coerceTuple) : CoerceOne(coerceTuple),
reverse ? CoerceOne(coerceTuple) : CoerceTwo(coerceTuple)
)
)
)
);
bodyBuilder.AddVariable(coerceResult);
bodyBuilder.AddVariable(coerceTuple);
}
}
示例5: MakeSlotCallWorker
private static void MakeSlotCallWorker(PythonContext/*!*/ state, PythonTypeSlot/*!*/ slotTarget, Expression/*!*/ self, ConditionalBuilder/*!*/ bodyBuilder, params Expression/*!*/[]/*!*/ args) {
// Generate:
//
// SlotTryGetValue(context, slot, selfType, out callable) && (tmp=callable(args)) != NotImplemented) ?
// tmp :
// RestOfOperation
//
ParameterExpression callable = Ast.Variable(typeof(object), "slot");
ParameterExpression tmp = Ast.Variable(typeof(object), "slot");
bodyBuilder.AddCondition(
Ast.AndAlso(
Ast.Call(
typeof(PythonOps).GetMethod("SlotTryGetValue"),
AstUtils.Constant(state.SharedContext),
AstUtils.Convert(Utils.WeakConstant(slotTarget), typeof(PythonTypeSlot)),
AstUtils.Convert(self, typeof(object)),
Ast.Call(
typeof(DynamicHelpers).GetMethod("GetPythonType"),
AstUtils.Convert(self, typeof(object))
),
callable
),
Ast.NotEqual(
Ast.Assign(
tmp,
DynamicExpression.Dynamic(
state.Invoke(
new CallSignature(args.Length)
),
typeof(object),
ArrayUtils.Insert(AstUtils.Constant(state.SharedContext), (Expression)callable, args)
)
),
Ast.Property(null, typeof(PythonOps).GetProperty("NotImplemented"))
)
),
tmp
);
bodyBuilder.AddVariable(callable);
bodyBuilder.AddVariable(tmp);
}
示例6: DoCoerce
/// <summary>
/// calls __coerce__ for old-style classes and performs the operation if the coercion is successful.
/// </summary>
private static void DoCoerce(PythonContext/*!*/ state, ConditionalBuilder/*!*/ bodyBuilder, PythonOperationKind op, DynamicMetaObject/*!*/[]/*!*/ types, bool reverse, Func<Expression, Expression> returnTransform) {
ParameterExpression coerceResult = Ast.Variable(typeof(object), "coerceResult");
ParameterExpression coerceTuple = Ast.Variable(typeof(PythonTuple), "coerceTuple");
if (!bodyBuilder.TestCoercionRecursionCheck) {
// during coercion we need to enforce recursion limits if
// they're enabled and the rule's test needs to reflect this.
bodyBuilder.Restrictions = bodyBuilder.Restrictions.Merge(
BindingRestrictions.GetExpressionRestriction(
Ast.Equal(
Ast.Call(typeof(PythonOps).GetMethod("ShouldEnforceRecursion")),
AstUtils.Constant(PythonFunction.EnforceRecursion)
)
)
);
bodyBuilder.TestCoercionRecursionCheck = true;
}
// tmp = self.__coerce__(other)
// if tmp != null && tmp != NotImplemented && (tuple = PythonOps.ValidateCoerceResult(tmp)) != null:
// return operation(tuple[0], tuple[1])
SlotOrFunction slot = SlotOrFunction.GetSlotOrFunction(state, Symbols.Coerce, types);
if (slot.Success) {
bodyBuilder.AddCondition(
Ast.AndAlso(
Ast.Not(
Ast.TypeIs(
Ast.Assign(
coerceResult,
slot.Target.Expression
),
typeof(OldInstance)
)
),
Ast.NotEqual(
Ast.Assign(
coerceTuple,
Ast.Call(
typeof(PythonOps).GetMethod("ValidateCoerceResult"),
coerceResult
)
),
AstUtils.Constant(null)
)
),
BindingHelpers.AddRecursionCheck(
returnTransform(
Ast.Dynamic(
state.Operation(op | PythonOperationKind.DisableCoerce),
op == PythonOperationKind.Compare ? typeof(int) : typeof(object),
reverse ? CoerceTwo(coerceTuple) : CoerceOne(coerceTuple),
reverse ? CoerceOne(coerceTuple) : CoerceTwo(coerceTuple)
)
)
)
);
bodyBuilder.AddVariable(coerceResult);
bodyBuilder.AddVariable(coerceTuple);
}
}
示例7: MakeValueCheck
private static void MakeValueCheck(int val, Expression retValue, ConditionalBuilder/*!*/ bodyBuilder, Expression retCondition) {
if (retValue.Type != typeof(bool)) {
retValue = Ast.Dynamic(
new ConversionBinder(
BinderState.GetBinderState(bodyBuilder.Action),
typeof(bool),
ConversionResultKind.ExplicitCast
),
typeof(bool),
retValue
);
}
if (retCondition != null) {
retValue = Ast.AndAlso(retCondition, retValue);
}
bodyBuilder.AddCondition(
retValue,
Ast.Constant(val)
);
}