Inheritance: SymWithType
Example #1
0
        public ExprEvent CreateEvent(CType pType, Expr pOptionalObject, EventWithType EWT)
        {
            ExprEvent rval = new ExprEvent(pType);

            rval.OptionalObject = pOptionalObject;
            rval.EventWithType  = EWT;
            return(rval);
        }
        public EXPREVENT CreateEvent(CType pType, EXPR pOptionalObject, EventWithType EWT)
        {
            EXPREVENT rval = new EXPREVENT();

            rval.kind           = ExpressionKind.EK_EVENT;
            rval.type           = pType;
            rval.flags          = 0;
            rval.OptionalObject = pOptionalObject;
            if (EWT != null)
            {
                rval.ewt = EWT;
            }
            Debug.Assert(rval != null);
            return(rval);
        }
Example #3
0
        public ExprEvent CreateEvent(CType pType, Expr pOptionalObject, EventWithType EWT)
        {
            ExprEvent rval = new ExprEvent();

            rval.Kind           = ExpressionKind.EK_EVENT;
            rval.Type           = pType;
            rval.Flags          = 0;
            rval.OptionalObject = pOptionalObject;
            if (EWT != null)
            {
                rval.EventWithType = EWT;
            }
            Debug.Assert(rval != null);
            return(rval);
        }
Example #4
0
        private EXPR BindWinRTEventAccessor(EventWithType ewt, EXPR callingObject, ArgumentObject[] arguments, Dictionary<int, LocalVariableSymbol> dictionary, bool isAddAccessor)
        {
            // We want to generate either:
            // WindowsRuntimeMarshal.AddEventHandler<delegType>(new Func<delegType, EventRegistrationToken>(x.add_foo), new Action<EventRegistrationToken>(x.remove_foo), value)
            // or
            // WindowsRuntimeMarshal.RemoveEventHandler<delegType>(new Action<EventRegistrationToken>(x.remove_foo), value)

            Type evtType = ewt.Event().type.AssociatedSystemType;

            // Get new Action<EventRegistrationToken>(x.remove_foo)
            MethPropWithInst removemwi = new MethPropWithInst(ewt.Event().methRemove, ewt.Ats);
            EXPRMEMGRP removeMethGrp = _exprFactory.CreateMemGroup(callingObject, removemwi);
            removeMethGrp.flags &= ~EXPRFLAG.EXF_USERCALLABLE;
            Type eventRegistrationTokenType = SymbolTable.EventRegistrationTokenType;
            Type actionType = Expression.GetActionType(eventRegistrationTokenType);
            EXPR removeMethArg = _binder.mustConvert(removeMethGrp, _symbolTable.GetCTypeFromType(actionType));

            // The value
            EXPR delegateVal = CreateArgumentEXPR(arguments[1], dictionary[1]);
            EXPRLIST args;
            string methodName;

            if (isAddAccessor)
            {
                // Get new Func<delegType, EventRegistrationToken>(x.add_foo)
                MethPropWithInst addmwi = new MethPropWithInst(ewt.Event().methAdd, ewt.Ats);
                EXPRMEMGRP addMethGrp = _exprFactory.CreateMemGroup(callingObject, addmwi);
                addMethGrp.flags &= ~EXPRFLAG.EXF_USERCALLABLE;
                Type funcType = Expression.GetFuncType(evtType, eventRegistrationTokenType);
                EXPR addMethArg = _binder.mustConvert(addMethGrp, _symbolTable.GetCTypeFromType(funcType));

                args = _exprFactory.CreateList(addMethArg, removeMethArg, delegateVal);
                methodName = SymbolLoader.GetNameManager().GetPredefName(PredefinedName.PN_ADDEVENTHANDLER).Text;
            }
            else
            {
                args = _exprFactory.CreateList(removeMethArg, delegateVal);
                methodName = SymbolLoader.GetNameManager().GetPredefName(PredefinedName.PN_REMOVEEVENTHANDLER).Text;
            }

            // WindowsRuntimeMarshal.Add\RemoveEventHandler(...)
            Type windowsRuntimeMarshalType = SymbolTable.WindowsRuntimeMarshalType;
            _symbolTable.PopulateSymbolTableWithName(methodName, new List<Type> { evtType }, windowsRuntimeMarshalType);
            EXPRCLASS marshalClass = _exprFactory.CreateClass(_symbolTable.GetCTypeFromType(windowsRuntimeMarshalType), null, null);
            EXPRMEMGRP addEventGrp = CreateMemberGroupEXPR(methodName, new List<Type> { evtType }, marshalClass, SYMKIND.SK_MethodSymbol);
            EXPR expr = _binder.BindMethodGroupToArguments(
                BindingFlag.BIND_RVALUEREQUIRED | BindingFlag.BIND_STMTEXPRONLY,
                addEventGrp,
                args);

            return expr;
        }
Example #5
0
 public EXPREVENT CreateEvent(CType pType, EXPR pOptionalObject, EventWithType EWT)
 {
     EXPREVENT rval = new EXPREVENT();
     rval.kind = ExpressionKind.EK_EVENT;
     rval.type = pType;
     rval.flags = 0;
     rval.OptionalObject = pOptionalObject;
     if (EWT != null)
     {
         rval.ewt = EWT;
     }
     Debug.Assert(rval != null);
     return (rval);
 }
Example #6
0
 public ExprEvent CreateEvent(CType type, Expr optionalObject, EventWithType eventWithType) =>
 new ExprEvent(type, optionalObject, eventWithType);