CSharpIsEventBinder
using Microsoft.CSharp.RuntimeBinder.Semantics;
using System;
using System.Dynamic;
using System.Numerics.Hashing;
namespace Microsoft.CSharp.RuntimeBinder
{
internal sealed class CSharpIsEventBinder : DynamicMetaObjectBinder, ICSharpBinder
{
private readonly RuntimeBinder _binder;
private readonly Type _callingContext;
public BindingFlag BindingFlags => (BindingFlag)0;
public bool IsBinderThatCanHaveRefReceiver => false;
public string Name { get; }
public override Type ReturnType => typeof(bool);
public Expr DispatchPayload(RuntimeBinder runtimeBinder, ArgumentObject[] arguments, LocalVariableSymbol[] locals)
{
return runtimeBinder.BindIsEvent(this, arguments, locals);
}
public void PopulateSymbolTableWithName(Type callingType, ArgumentObject[] arguments)
{
SymbolTable.PopulateSymbolTableWithName(Name, null, arguments[0].Info.IsStaticType ? (arguments[0].Value as Type) : arguments[0].Type);
}
CSharpArgumentInfo ICSharpBinder.GetArgumentInfo(int index)
{
return CSharpArgumentInfo.None;
}
public CSharpIsEventBinder(string name, Type callingContext)
{
Name = name;
_callingContext = callingContext;
_binder = new RuntimeBinder(callingContext, false);
}
public int GetGetBinderEquivalenceHash()
{
int h = _callingContext?.GetHashCode() ?? 0;
return HashHelpers.Combine(h, Name.GetHashCode());
}
public bool IsEquivalentTo(ICSharpBinder other)
{
CSharpIsEventBinder cSharpIsEventBinder = other as CSharpIsEventBinder;
if (cSharpIsEventBinder == null)
return false;
if (_callingContext != cSharpIsEventBinder._callingContext || Name != cSharpIsEventBinder.Name)
return false;
return true;
}
public override DynamicMetaObject Bind(DynamicMetaObject target, DynamicMetaObject[] args)
{
BinderHelper.ValidateBindArgument(target, "target");
return BinderHelper.Bind(this, _binder, new DynamicMetaObject[1] {
target
}, null, null);
}
}
}