CSharpInvokeBinder
using Microsoft.CSharp.RuntimeBinder.Semantics;
using System;
using System.Collections.Generic;
using System.Dynamic;
namespace Microsoft.CSharp.RuntimeBinder
{
internal sealed class CSharpInvokeBinder : InvokeBinder, ICSharpInvokeOrInvokeMemberBinder, ICSharpBinder
{
private readonly CSharpCallFlags _flags;
private readonly List<CSharpArgumentInfo> _argumentInfo;
private readonly RuntimeBinder _binder;
public BindingFlag BindingFlags => (BindingFlag)0;
public bool IsBinderThatCanHaveRefReceiver => true;
bool ICSharpInvokeOrInvokeMemberBinder.StaticCall {
get {
if (_argumentInfo[0] != null)
return _argumentInfo[0].IsStaticType;
return false;
}
}
string ICSharpBinder.Name {
get {
return "Invoke";
}
}
IList<Type> ICSharpInvokeOrInvokeMemberBinder.TypeArguments {
get {
return Array.Empty<Type>();
}
}
CSharpCallFlags ICSharpInvokeOrInvokeMemberBinder.Flags {
get {
return _flags;
}
}
public Type CallingContext { get; }
public bool IsChecked => false;
bool ICSharpInvokeOrInvokeMemberBinder.ResultDiscarded {
get {
return (_flags & CSharpCallFlags.ResultDiscarded) != CSharpCallFlags.None;
}
}
public Expr DispatchPayload(RuntimeBinder runtimeBinder, ArgumentObject[] arguments, LocalVariableSymbol[] locals)
{
return runtimeBinder.DispatchPayload(this, arguments, locals);
}
public void PopulateSymbolTableWithName(SymbolTable symbolTable, Type callingType, ArgumentObject[] arguments)
{
RuntimeBinder.PopulateSymbolTableWithPayloadInformation(symbolTable, this, callingType, arguments);
}
CSharpArgumentInfo ICSharpBinder.GetArgumentInfo(int index)
{
return _argumentInfo[index];
}
public CSharpInvokeBinder(CSharpCallFlags flags, Type callingContext, IEnumerable<CSharpArgumentInfo> argumentInfo)
: base(BinderHelper.CreateCallInfo(argumentInfo, 1))
{
_flags = flags;
CallingContext = callingContext;
_argumentInfo = BinderHelper.ToList(argumentInfo);
_binder = RuntimeBinder.GetInstance();
}
public override DynamicMetaObject FallbackInvoke(DynamicMetaObject target, DynamicMetaObject[] args, DynamicMetaObject errorSuggestion)
{
return BinderHelper.Bind(this, _binder, BinderHelper.Cons(target, args), _argumentInfo, errorSuggestion);
}
}
}