Inheritance: AbstractMemberReferenceEmitter
        public override AstNode Emit()
        {
            AstNode astNode = null;

            switch (Member.MemberType)
            {
            case MemberTypes.Event:

                Member  = Target.GetField(Node.MemberName, ReflectionUtils.AllFlags);
                astNode = new EventReferenceReflectionEmitter(Node, Target, Member, ILGenerator, InstructionsIndexer, Visitor, Locals).Emit();
                break;

            case MemberTypes.Field:

                astNode = new FieldReferenceReflectionEmitter(Node, Target, Member, ILGenerator, InstructionsIndexer, Visitor, Locals, _isSetter).Emit();
                break;

            case MemberTypes.Property:

                if (Type.Equals(typeof(Type)))
                {
                    astNode = Node.Target.AcceptVisitor(ILGenerator, Visitor);
                }
                else
                {
                    astNode = new PropertyReferenceReflectionEmitter(Node, Target, Member, ILGenerator, InstructionsIndexer, Visitor, Locals, _isSetter).Emit();
                }

                break;
            }

            return(astNode);
        }
Beispiel #2
0
        private void EmitEventRegistration(LocalBuilder localbuilder)
        {
            FieldInfo fieldInfo                = Target.GetField(Member.Name, BindingFlags.NonPublic | BindingFlags.Static);
            var       dynamicMethod            = new DynamicMethod("EmitEventRegistration", TypeSystem.Void, Type.EmptyTypes, true);
            var       dynamicMethodILGenerator = dynamicMethod.GetILGenerator();
            var       emitter = new FieldReferenceReflectionEmitter(Node, Target, fieldInfo, ILGenerator, InstructionsIndexer, Visitor, Locals);

            _assignorExpression.AcceptVisitor(Visitor, dynamicMethodILGenerator);
            dynamicMethodILGenerator.Emit(OpCodes.Stsfld, fieldInfo);
            dynamicMethodILGenerator.Emit(OpCodes.Ret);
            dynamicMethod.CreateDelegate(typeof(Action)).DynamicInvoke();
            emitter.Emit();
        }
        private void EmitEventRegistration(LocalBuilder localbuilder) {
            FieldInfo fieldInfo = Target.GetField(Member.Name, BindingFlags.NonPublic | BindingFlags.Static);
            var dynamicMethod = new DynamicMethod("EmitEventRegistration", TypeSystem.Void, Type.EmptyTypes, true);
            var dynamicMethodILGenerator = dynamicMethod.GetILGenerator();
            var emitter = new FieldReferenceReflectionEmitter(Node, Target, fieldInfo, ILGenerator, InstructionsIndexer, Visitor, Locals);

            _assignorExpression.AcceptVisitor(Visitor, dynamicMethodILGenerator);
            dynamicMethodILGenerator.Emit(OpCodes.Stsfld, fieldInfo);
            dynamicMethodILGenerator.Emit(OpCodes.Ret);
            dynamicMethod.CreateDelegate(typeof(Action)).DynamicInvoke();
            emitter.Emit();
        }