Example #1
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        internal override IDisposable CreateTypeTemplateScope()
        {
            var reflectionCache = DelegateShortcuts.GetReflectionCache(m_Declaration.EventHandlerType);

            return(TypeTemplate.CreateScope(
                       typeof(TypeTemplate.TEventHandler), m_Declaration.EventHandlerType,
                       typeof(TypeTemplate.TEventArgs), reflectionCache.Invoke.GetParameters()[1].ParameterType));
        }
Example #2
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        public DelegateOperand(IOperand target, MethodInfo method, Type delegateTypeOverride = null)
        {
            m_Target = target;
            m_Method = method;

            var effectiveDelegateType = delegateTypeOverride ?? base.OperandType;

            m_Constructor = DelegateShortcuts.GetDelegateConstructor(effectiveDelegateType);
        }
Example #3
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        protected override void OnEmitLoad(ILGenerator il)
        {
            if (m_CallSite.IsDefined())
            {
                m_CallSite.EmitLoad(il);
            }
            else
            {
                var target = GetTargetOperand();
                var delegateConstructor = DelegateShortcuts.GetDelegateConstructor(OperandType);

                target.EmitTarget(il);
                target.EmitLoad(il);

                il.Emit(OpCodes.Ldftn, (MethodBuilder)m_Method.MethodFactory.Builder);
                il.Emit(OpCodes.Newobj, delegateConstructor);
            }
        }
Example #4
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        private bool TryEmitStaticDelegateValue(ILGenerator il, Delegate @delegate)
        {
            if (@delegate != null)
            {
                if ([email protected])
                {
                    throw new NotSupportedException("Constants of delegate types can only point to static methods.");
                }

                il.Emit(OpCodes.Ldnull);
                il.Emit(OpCodes.Ldftn, @delegate.Method);
                il.Emit(OpCodes.Newobj, DelegateShortcuts.GetDelegateConstructor(@delegate.GetType()));

                return(true);
            }
            else
            {
                return(false);
            }
        }