本文整理汇总了C#中BinaryOperatorKind.WithType方法的典型用法代码示例。如果您正苦于以下问题:C# BinaryOperatorKind.WithType方法的具体用法?C# BinaryOperatorKind.WithType怎么用?C# BinaryOperatorKind.WithType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BinaryOperatorKind
的用法示例。
在下文中一共展示了BinaryOperatorKind.WithType方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BindDynamicBinaryOperator
private BoundExpression BindDynamicBinaryOperator(
BinaryExpressionSyntax node,
BinaryOperatorKind kind,
BoundExpression left,
BoundExpression right,
DiagnosticBag diagnostics)
{
// This method binds binary * / % + - << >> < > <= >= == != & ! ^ && || operators where one or both
// of the operands are dynamic.
Debug.Assert((object)left.Type != null && left.Type.IsDynamic() || (object)right.Type != null && right.Type.IsDynamic());
bool hasError = false;
bool leftValidOperand = IsLegalDynamicOperand(left);
bool rightValidOperand = IsLegalDynamicOperand(right);
if (!leftValidOperand || !rightValidOperand)
{
// Operator '{0}' cannot be applied to operands of type '{1}' and '{2}'
Error(diagnostics, ErrorCode.ERR_BadBinaryOps, node, node.OperatorToken.Text, left.Display, right.Display);
hasError = true;
}
MethodSymbol userDefinedOperator = null;
if (kind.IsLogical() && leftValidOperand)
{
// We need to make sure left is either implicitly convertible to Boolean or has user defined truth operator.
// left && right is lowered to {op_False|op_Implicit}(left) ? left : And(left, right)
// left || right is lowered to {op_True|!op_Implicit}(left) ? left : Or(left, right)
HashSet<DiagnosticInfo> useSiteDiagnostics = null;
if (!IsValidDynamicCondition(left, isNegative: kind == BinaryOperatorKind.LogicalAnd, useSiteDiagnostics: ref useSiteDiagnostics, userDefinedOperator: out userDefinedOperator))
{
// Dev11 reports ERR_MustHaveOpTF. The error was shared between this case and user-defined binary Boolean operators.
// We report two distinct more specific error messages.
Error(diagnostics, ErrorCode.ERR_InvalidDynamicCondition, node.Left, left.Type, kind == BinaryOperatorKind.LogicalAnd ? "false" : "true");
hasError = true;
}
diagnostics.Add(node, useSiteDiagnostics);
}
return new BoundBinaryOperator(
syntax: node,
operatorKind: (hasError ? kind : kind.WithType(BinaryOperatorKind.Dynamic)).WithOverflowChecksIfApplicable(CheckOverflowAtRuntime),
left: left,
right: right,
constantValueOpt: ConstantValue.NotAvailable,
methodOpt: userDefinedOperator,
resultKind: LookupResultKind.Viable,
type: Compilation.DynamicType,
hasErrors: hasError);
}