CSharpInvokeConstructorBinder
sealed class CSharpInvokeConstructorBinder : DynamicMetaObjectBinder, ICSharpInvokeOrInvokeMemberBinder, ICSharpBinder
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 CSharpInvokeConstructorBinder : DynamicMetaObjectBinder, ICSharpInvokeOrInvokeMemberBinder, ICSharpBinder
{
private readonly CSharpArgumentInfo[] _argumentInfo;
private readonly RuntimeBinder _binder;
private readonly Type _callingContext;
public BindingFlag BindingFlags => (BindingFlag)0;
public bool IsBinderThatCanHaveRefReceiver => true;
public CSharpCallFlags Flags { get; }
public bool StaticCall => true;
public Type[] TypeArguments => Array.Empty<Type>();
public string Name => ".ctor";
bool ICSharpInvokeOrInvokeMemberBinder.ResultDiscarded {
get {
return false;
}
}
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 CSharpInvokeConstructorBinder(CSharpCallFlags flags, Type callingContext, IEnumerable<CSharpArgumentInfo> argumentInfo)
{
Flags = flags;
_callingContext = callingContext;
_argumentInfo = BinderHelper.ToArray(argumentInfo);
_binder = new RuntimeBinder(callingContext, false);
}
public int GetGetBinderEquivalenceHash()
{
int h = _callingContext?.GetHashCode() ?? 0;
h = HashHelpers.Combine(h, (int)Flags);
h = HashHelpers.Combine(h, Name.GetHashCode());
return BinderHelper.AddArgHashes(h, TypeArguments, _argumentInfo);
}
public bool IsEquivalentTo(ICSharpBinder other)
{
CSharpInvokeConstructorBinder cSharpInvokeConstructorBinder = other as CSharpInvokeConstructorBinder;
if (cSharpInvokeConstructorBinder == null)
return false;
if (Flags != cSharpInvokeConstructorBinder.Flags || _callingContext != cSharpInvokeConstructorBinder._callingContext || Name != cSharpInvokeConstructorBinder.Name || TypeArguments.Length != cSharpInvokeConstructorBinder.TypeArguments.Length || _argumentInfo.Length != cSharpInvokeConstructorBinder._argumentInfo.Length)
return false;
return BinderHelper.CompareArgInfos(TypeArguments, cSharpInvokeConstructorBinder.TypeArguments, _argumentInfo, cSharpInvokeConstructorBinder._argumentInfo);
}
public override DynamicMetaObject Bind(DynamicMetaObject target, DynamicMetaObject[] args)
{
BinderHelper.ValidateBindArgument(target, "target");
BinderHelper.ValidateBindArgument(args, "args");
return BinderHelper.Bind(this, _binder, BinderHelper.Cons(target, args), _argumentInfo, null);
}
}
}