<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />

CSharpInvokeBinder

using Microsoft.CSharp.RuntimeBinder.Semantics; using System; using System.Collections.Generic; using System.Dynamic; using System.Numerics.Hashing; namespace Microsoft.CSharp.RuntimeBinder { internal sealed class CSharpInvokeBinder : InvokeBinder, ICSharpInvokeOrInvokeMemberBinder, ICSharpBinder { private readonly CSharpCallFlags _flags; private readonly CSharpArgumentInfo[] _argumentInfo; private readonly RuntimeBinder _binder; private readonly Type _callingContext; 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"; } } Type[] ICSharpInvokeOrInvokeMemberBinder.TypeArguments { get { return Array.Empty<Type>(); } } CSharpCallFlags ICSharpInvokeOrInvokeMemberBinder.Flags { get { return _flags; } } 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(Type callingType, ArgumentObject[] arguments) { RuntimeBinder.PopulateSymbolTableWithPayloadInformation(this, callingType, arguments); } CSharpArgumentInfo ICSharpBinder.GetArgumentInfo(int index) { return _argumentInfo[index]; } public CSharpInvokeBinder(CSharpCallFlags flags, Type callingContext, IEnumerable<CSharpArgumentInfo> argumentInfo) : base(BinderHelper.CreateCallInfo(ref argumentInfo, 1)) { _flags = flags; _callingContext = callingContext; _argumentInfo = (argumentInfo as CSharpArgumentInfo[]); _binder = new RuntimeBinder(callingContext, false); } public int GetGetBinderEquivalenceHash() { int h = _callingContext?.GetHashCode() ?? 0; h = HashHelpers.Combine(h, (int)_flags); return BinderHelper.AddArgHashes(h, _argumentInfo); } public bool IsEquivalentTo(ICSharpBinder other) { CSharpInvokeBinder cSharpInvokeBinder = other as CSharpInvokeBinder; if (cSharpInvokeBinder == null) return false; if (_flags != cSharpInvokeBinder._flags || _callingContext != cSharpInvokeBinder._callingContext || _argumentInfo.Length != cSharpInvokeBinder._argumentInfo.Length) return false; return BinderHelper.CompareArgInfos(_argumentInfo, cSharpInvokeBinder._argumentInfo); } public override DynamicMetaObject FallbackInvoke(DynamicMetaObject target, DynamicMetaObject[] args, DynamicMetaObject errorSuggestion) { BinderHelper.ValidateBindArgument(target, "target"); BinderHelper.ValidateBindArgument(args, "args"); return BinderHelper.Bind(this, _binder, BinderHelper.Cons(target, args), _argumentInfo, errorSuggestion); } } }