Microsoft.CSharp.RuntimeBinder.RuntimeBinder.BindIsEvent C# (CSharp) Method

BindIsEvent() private method

private BindIsEvent ( CSharpIsEventBinder binder, ArgumentObject arguments, LocalVariableSymbol>.Dictionary dictionary ) : EXPR
binder CSharpIsEventBinder
arguments ArgumentObject
dictionary LocalVariableSymbol>.Dictionary
return Microsoft.CSharp.RuntimeBinder.Semantics.EXPR
        private EXPR BindIsEvent(
            CSharpIsEventBinder binder,
            ArgumentObject[] arguments,
            Dictionary<int, LocalVariableSymbol> dictionary)
        {
            // The IsEvent binder will never be called without an instance object. This 
            // is because the compiler only gen's this code for dynamic dots.

            EXPR callingObject = CreateLocal(arguments[0].Type, false, dictionary[0]);
            MemberLookup mem = new MemberLookup();
            CType boolType = SymbolLoader.GetReqPredefType(PredefinedType.PT_BOOL);
            bool result = false;

            if (arguments[0].Value == null)
            {
                throw Error.NullReferenceOnMemberException();
            }

            Debug.Assert(_bindingContext.ContextForMemberLookup() != null);
            SymWithType swt = _symbolTable.LookupMember(
                    binder.Name,
                    callingObject,
                    _bindingContext.ContextForMemberLookup(),
                    0,
                    mem,
                    false,
                    false);

            // If lookup returns an actual event, then this is an event.
            if (swt != null && swt.Sym.getKind() == SYMKIND.SK_EventSymbol)
            {
                result = true;
            }

            // If lookup returns the backing field of a field-like event, then
            // this is an event. This is due to the Dev10 design change around
            // the binding of +=, and the fact that the "IsEvent" binding question
            // is only ever asked about the LHS of a += or -=.
            if (swt != null && swt.Sym.getKind() == SYMKIND.SK_FieldSymbol && swt.Sym.AsFieldSymbol().isEvent)
            {
                result = true;
            }

            return _exprFactory.CreateConstant(boolType, ConstValFactory.GetBool(result));
        }
        #endregion