public void WireConstructorWithInitialization(
            MutableConstructorInfo constructor,
            Tuple <FieldInfo, MethodInfo> initializationMembers,
            IProxySerializationEnabler proxySerializationEnabler)
        {
            ArgumentUtility.CheckNotNull("constructor", constructor);
            ArgumentUtility.CheckNotNull("proxySerializationEnabler", proxySerializationEnabler);

            if (initializationMembers == null || proxySerializationEnabler.IsDeserializationConstructor(constructor))
            {
                return;
            }

            // We cannot protect the decrement with try-finally because the this pointer must be initialized before entering a try block.
            // Using *IncrementAssign and *DecrementAssign results in un-verifiable code (emits stloc.0).
            constructor.SetBody(
                ctx =>
            {
                var initilizationMethod = initializationMembers.Item2;
                var counter             = Expression.Field(ctx.This, initializationMembers.Item1);
                var one  = Expression.Constant(1);
                var zero = Expression.Constant(0);

                return(Expression.Block(
                           Expression.Assign(counter, Expression.Add(counter, one)),
                           constructor.Body,
                           Expression.Assign(counter, Expression.Subtract(counter, one)),
                           Expression.IfThen(
                               Expression.Equal(counter, zero),
                               Expression.Call(ctx.This, initilizationMethod, Expression.Constant(InitializationSemantics.Construction)))));
            });
        }
Esempio n. 2
0
        public virtual void SetUp()
        {
            _mockRepository = new MockRepository();

            _mutableType = MutableTypeObjectMother.Create();
            _nestedTypeCodeGeneratorFactoryMock = _mockRepository.StrictMock <IMutableNestedTypeCodeGeneratorFactory>();
            _codeGeneratorMock             = _mockRepository.StrictMock <IReflectionEmitCodeGenerator>();
            _emittableOperandProviderMock  = _mockRepository.StrictMock <IEmittableOperandProvider> ();
            _memberEmitterMock             = _mockRepository.StrictMock <IMemberEmitter>();
            _initializationBuilderMock     = _mockRepository.StrictMock <IInitializationBuilder>();
            _proxySerializationEnablerMock = _mockRepository.StrictMock <IProxySerializationEnabler>();

            _generator = new MutableTypeCodeGenerator(
                _mutableType,
                _nestedTypeCodeGeneratorFactoryMock,
                _codeGeneratorMock,
                _emittableOperandProviderMock,
                _memberEmitterMock,
                _initializationBuilderMock,
                _proxySerializationEnablerMock);

            _typeBuilderMock        = _mockRepository.StrictMock <ITypeBuilder>();
            _debugInfoGeneratorMock = _mockRepository.StrictMock <DebugInfoGenerator>();

            _fakeInitializationField   = ReflectionObjectMother.GetSomeField();
            _fakeInitializationMethod  = ReflectionObjectMother.GetSomeMethod();
            _fakeInitializationMembers = Tuple.Create(_fakeInitializationField, _fakeInitializationMethod);
        }
Esempio n. 3
0
        public void SetUp()
        {
            _builder = new InitializationBuilder();

            _proxySerializationEnablerMock = MockRepository.GenerateStrictMock <IProxySerializationEnabler>();
            _mutableType = MutableTypeObjectMother.Create();
        }
        public MutableTypeCodeGenerator(
            MutableType mutableType,
            IMutableNestedTypeCodeGeneratorFactory nestedTypeCodeGeneratorFactory,
            IReflectionEmitCodeGenerator codeGenerator,
            IEmittableOperandProvider emittableOperandProvider,
            IMemberEmitter memberEmitter,
            IInitializationBuilder initializationBuilder,
            IProxySerializationEnabler proxySerializationEnabler)
        {
            ArgumentUtility.CheckNotNull("mutableType", mutableType);
            ArgumentUtility.CheckNotNull("nestedTypeCodeGeneratorFactory", nestedTypeCodeGeneratorFactory);
            ArgumentUtility.CheckNotNull("codeGenerator", codeGenerator);
            ArgumentUtility.CheckNotNull("emittableOperandProvider", emittableOperandProvider);
            ArgumentUtility.CheckNotNull("memberEmitter", memberEmitter);
            ArgumentUtility.CheckNotNull("initializationBuilder", initializationBuilder);
            ArgumentUtility.CheckNotNull("proxySerializationEnabler", proxySerializationEnabler);

            _mutableType = mutableType;
            _nestedTypeCodeGeneratorFactory = nestedTypeCodeGeneratorFactory;
            _codeGenerator             = codeGenerator;
            _emittableOperandProvider  = emittableOperandProvider;
            _memberEmitter             = memberEmitter;
            _initializationBuilder     = initializationBuilder;
            _proxySerializationEnabler = proxySerializationEnabler;
        }
Esempio n. 5
0
        public void SetUp()
        {
            _memberEmitterFactoryMock      = MockRepository.GenerateStrictMock <IMemberEmitterFactory>();
            _codeGeneratorMock             = MockRepository.GenerateStrictMock <IReflectionEmitCodeGenerator>();
            _initializationBuilderMock     = MockRepository.GenerateStrictMock <IInitializationBuilder>();
            _proxySerializationEnablerMock = MockRepository.GenerateStrictMock <IProxySerializationEnabler>();

            _factory = new MutableTypeCodeGeneratorFactory(
                _memberEmitterFactoryMock, _codeGeneratorMock, _initializationBuilderMock, _proxySerializationEnablerMock);
        }
        public MutableTypeCodeGeneratorFactory(
            IMemberEmitterFactory memberEmitterFactory,
            IReflectionEmitCodeGenerator codeGenerator,
            IInitializationBuilder initializationBuilder,
            IProxySerializationEnabler proxySerializationEnabler)
        {
            ArgumentUtility.CheckNotNull("memberEmitterFactory", memberEmitterFactory);
            ArgumentUtility.CheckNotNull("codeGenerator", codeGenerator);
            ArgumentUtility.CheckNotNull("initializationBuilder", initializationBuilder);
            ArgumentUtility.CheckNotNull("proxySerializationEnabler", proxySerializationEnabler);

            _memberEmitterFactory      = memberEmitterFactory;
            _codeGenerator             = codeGenerator;
            _initializationBuilder     = initializationBuilder;
            _proxySerializationEnabler = proxySerializationEnabler;
        }
        public MutableNestedTypeCodeGeneratorFactory(
            IReflectionEmitCodeGenerator reflectionEmitCodeGenerator,
            IEmittableOperandProvider emittableOperandProvider,
            IMemberEmitter memberEmitter,
            IInitializationBuilder initializationBuilder,
            IProxySerializationEnabler proxySerializationEnabler)
        {
            ArgumentUtility.CheckNotNull("reflectionEmitCodeGenerator", reflectionEmitCodeGenerator);
            ArgumentUtility.CheckNotNull("emittableOperandProvider", emittableOperandProvider);
            ArgumentUtility.CheckNotNull("memberEmitter", memberEmitter);
            ArgumentUtility.CheckNotNull("initializationBuilder", initializationBuilder);
            ArgumentUtility.CheckNotNull("proxySerializationEnabler", proxySerializationEnabler);

            _reflectionEmitCodeGenerator = reflectionEmitCodeGenerator;
            _emittableOperandProvider    = emittableOperandProvider;
            _memberEmitter             = memberEmitter;
            _initializationBuilder     = initializationBuilder;
            _proxySerializationEnabler = proxySerializationEnabler;
        }
Esempio n. 8
0
        public MutableNestedTypeCodeGenerator(
            ITypeBuilder enclosingTypeBuilder,
            MutableType mutableType,
            IMutableNestedTypeCodeGeneratorFactory nestedTypeCodeGeneratorFactory,
            IReflectionEmitCodeGenerator codeGenerator,
            IEmittableOperandProvider emittableOperandProvider,
            IMemberEmitter memberEmitter,
            IInitializationBuilder initializationBuilder,
            IProxySerializationEnabler proxySerializationEnabler)
            : base(
                mutableType,
                nestedTypeCodeGeneratorFactory,
                codeGenerator,
                emittableOperandProvider,
                memberEmitter,
                initializationBuilder,
                proxySerializationEnabler)
        {
            ArgumentUtility.CheckNotNull("enclosingTypeBuilder", enclosingTypeBuilder);

            _enclosingTypeBuilder = enclosingTypeBuilder;
        }