CSharpBinaryOperationBinder
using Microsoft.CSharp.RuntimeBinder.Semantics;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Dynamic;
using System.Linq.Expressions;
namespace Microsoft.CSharp.RuntimeBinder
{
internal sealed class CSharpBinaryOperationBinder : BinaryOperationBinder, ICSharpBinder
{
private readonly CSharpBinaryOperationFlags _binopFlags;
private readonly CSharpArgumentInfo[] _argumentInfo;
private readonly RuntimeBinder _binder;
[ExcludeFromCodeCoverage]
public string Name {
get {
return null;
}
}
public BindingFlag BindingFlags => (BindingFlag)0;
public bool IsBinderThatCanHaveRefReceiver => false;
internal bool IsLogicalOperation => (_binopFlags & CSharpBinaryOperationFlags.LogicalOperation) != CSharpBinaryOperationFlags.None;
public Expr DispatchPayload(RuntimeBinder runtimeBinder, ArgumentObject[] arguments, LocalVariableSymbol[] locals)
{
return runtimeBinder.BindBinaryOperation(this, arguments, locals);
}
public void PopulateSymbolTableWithName(Type callingType, ArgumentObject[] arguments)
{
string cLROperatorName = base.Operation.GetCLROperatorName();
SymbolTable.PopulateSymbolTableWithName(cLROperatorName, null, arguments[0].Type);
SymbolTable.PopulateSymbolTableWithName(cLROperatorName, null, arguments[1].Type);
}
CSharpArgumentInfo ICSharpBinder.GetArgumentInfo(int index)
{
return _argumentInfo[index];
}
public CSharpBinaryOperationBinder(ExpressionType operation, bool isChecked, CSharpBinaryOperationFlags binaryOperationFlags, Type callingContext, IEnumerable<CSharpArgumentInfo> argumentInfo)
: base(operation)
{
_binopFlags = binaryOperationFlags;
_argumentInfo = BinderHelper.ToArray(argumentInfo);
_binder = new RuntimeBinder(callingContext, isChecked);
}
public override DynamicMetaObject FallbackBinaryOperation(DynamicMetaObject target, DynamicMetaObject arg, DynamicMetaObject errorSuggestion)
{
BinderHelper.ValidateBindArgument(target, "target");
BinderHelper.ValidateBindArgument(arg, "arg");
return BinderHelper.Bind(this, _binder, new DynamicMetaObject[2] {
target,
arg
}, _argumentInfo, errorSuggestion);
}
}
}