Exemplo n.º 1
0
        public void AddMapping(MutableMethodInfo mappedMethod, MethodInfo emittableMethod)
        {
            ArgumentUtility.CheckNotNull("mappedMethod", mappedMethod);
            ArgumentUtility.CheckNotNull("emittableMethod", emittableMethod);

            AddMapping(_mappedMethods, mappedMethod, emittableMethod);
        }
Exemplo n.º 2
0
        public void AddMethod(CodeGenerationContext context, MutableMethodInfo method)
        {
            ArgumentUtility.CheckNotNull("context", context);
            ArgumentUtility.CheckNotNull("method", method);

            var methodBuilder = context.TypeBuilder.DefineMethod(method.Name, method.Attributes);

            methodBuilder.RegisterWith(context.EmittableOperandProvider, method);
            context.MethodBuilders.Add(method, methodBuilder);

            // Generic parameters must be defined before the signature as generic parameters may be used in the signature.
            DefineGenericParameters(context, methodBuilder, method);

            methodBuilder.SetReturnType(method.ReturnType);
            methodBuilder.SetParameters(GetParameterTypes(method));

            DefineParameter(methodBuilder, method.MutableReturnParameter);
            DefineParameters(methodBuilder, method);
            DefineCustomAttributes(methodBuilder, method);

            if (!method.IsAbstract)
            {
                var bodyBuildAction = CreateBodyBuildAction(context, methodBuilder, method.ParameterExpressions, method.Body);
                context.PostDeclarationsActionManager.AddAction(bodyBuildAction);
            }

            var explicitOverrideAction = CreateExplicitOverrideBuildAction(context, method);

            context.PostDeclarationsActionManager.AddAction(explicitOverrideAction);
        }
        public IStorage AddMemberInfo(MutableMethodInfo mutableMethod)
        {
            ArgumentUtility.CheckNotNull("mutableMethod", mutableMethod);
            Assertion.IsNotNull(mutableMethod.DeclaringType);

            var mutableType = (MutableType)mutableMethod.DeclaringType;

            IStorage storage;
            Func <ThisExpression, Expression> initializationProvider;

            var property = mutableMethod.UnderlyingSystemMethodInfo.GetRelatedPropertyInfo();

            if (property != null)
            {
                storage = AddStaticStorage(mutableType, typeof(PropertyInfo), mutableMethod.Name);
                initializationProvider = thisExpression => _contextArgumentExpressionBuilder.CreatePropertyInfoInitExpression(property);
            }
            else
            {
                storage = AddStaticStorage(mutableType, typeof(MethodInfo), mutableMethod.Name);
                initializationProvider = expr => _contextArgumentExpressionBuilder.CreateMethodInfoInitExpression(mutableMethod);
            }

            mutableType.AddTypeInitialization(ctx => CreateAssignExpression(storage, initializationProvider, ctx));

            return(storage);
        }
Exemplo n.º 4
0
        public void RegisterWith(IEmittableOperandProvider emittableOperandProvider, MutableMethodInfo method)
        {
            ArgumentUtility.CheckNotNull("emittableOperandProvider", emittableOperandProvider);
            ArgumentUtility.CheckNotNull("method", method);

            emittableOperandProvider.AddMapping(method, _methodBuilder);
        }
Exemplo n.º 5
0
        public Expression CopyMethodBody(MutableMethodInfo otherMethod, params Expression[] arguments)
        {
            ArgumentUtility.CheckNotNull("otherMethod", otherMethod);
            ArgumentUtility.CheckNotNull("arguments", arguments);

            return(CopyMethodBody(otherMethod, (IEnumerable <Expression>)arguments));
        }
Exemplo n.º 6
0
        public void SetUp()
        {
            _declaringType = MutableTypeObjectMother.Create(baseType: typeof(DomainType));

            _method        = MutableMethodInfoObjectMother.Create(_declaringType, "NonVirtualMethod");
            _virtualMethod = MutableMethodInfoObjectMother.Create(_declaringType, attributes: MethodAttributes.Virtual);
        }
Exemplo n.º 7
0
        public MutablePropertyInfo CreateProperty(
            MutableType declaringType, string name, PropertyAttributes attributes, MutableMethodInfo getMethod, MutableMethodInfo setMethod)
        {
            ArgumentUtility.CheckNotNull("declaringType", declaringType);
            ArgumentUtility.CheckNotNullOrEmpty("name", name);
            // Get method may be null.
            // Set method may be null.

            MemberAttributesUtility.ValidateAttributes("properties", MemberAttributesUtility.InvalidPropertyAttributes, attributes, "attributes");

            if (getMethod == null && setMethod == null)
            {
                throw new ArgumentException("Property must have at least one accessor.", "getMethod");
            }

            var readWriteProperty = getMethod != null && setMethod != null;

            if (readWriteProperty && getMethod.IsStatic != setMethod.IsStatic)
            {
                throw new ArgumentException("Accessor methods must be both either static or non-static.", "getMethod");
            }

            if (getMethod != null && !ReferenceEquals(getMethod.DeclaringType, declaringType))
            {
                throw new ArgumentException("Get method is not declared on the current type.", "getMethod");
            }
            if (setMethod != null && !ReferenceEquals(setMethod.DeclaringType, declaringType))
            {
                throw new ArgumentException("Set method is not declared on the current type.", "setMethod");
            }

            if (getMethod != null && getMethod.ReturnType == typeof(void))
            {
                throw new ArgumentException("Get accessor must be a non-void method.", "getMethod");
            }
            if (setMethod != null && setMethod.ReturnType != typeof(void))
            {
                throw new ArgumentException("Set accessor must have return type void.", "setMethod");
            }

            var getSignature  = getMethod != null ? new PropertySignature(getMethod.ReturnType, getMethod.GetParameters().Select(p => p.ParameterType)) : null;
            var setParameters = setMethod != null?setMethod.GetParameters().Select(p => p.ParameterType).ToList() : null;

            var setSignature = setMethod != null ? new PropertySignature(setParameters.Last(), setParameters.Take(setParameters.Count - 1)) : null;

            if (readWriteProperty && !getSignature.Equals(setSignature))
            {
                throw new ArgumentException("Get and set accessor methods must have a matching signature.", "setMethod");
            }

            var signature = getSignature ?? setSignature;

            if (declaringType.AddedProperties.Any(p => p.Name == name && PropertySignature.Create(p).Equals(signature)))
            {
                throw new InvalidOperationException("Property with equal name and signature already exists.");
            }

            return(new MutablePropertyInfo(declaringType, name, attributes, getMethod, setMethod));
        }
 public MethodExecutionExpression(MutableMethodInfo method)
 {
     _method = method;
     _body   = Call(
         new ThisExpression(method.DeclaringType),
         NonVirtualCallMethodInfoAdapter.Adapt(method.UnderlyingSystemMethodInfo),
         method.ParameterExpressions.Cast <Expression>());
 }
Exemplo n.º 9
0
        public static MethodExecutionExpression Adapt(MutableMethodInfo method)
        {
            var instance   = new ThisExpression(method.DeclaringType);
            var baseMethod = NonVirtualCallMethodInfoAdapter.Adapt(method.UnderlyingSystemMethodInfo);
            var parameters = method.ParameterExpressions.Cast <Expression>();
            var body       = Call(instance, baseMethod, parameters);

            return(new MethodExecutionExpression(method, body));
        }
Exemplo n.º 10
0
 public MutableEventInfo CreateEvent(
     MutableType declaringType,
     string name,
     EventAttributes attributes,
     MutableMethodInfo addMethod,
     MutableMethodInfo removeMethod,
     MutableMethodInfo raiseMethod)
 {
     return(_eventFactory.CreateEvent(declaringType, name, attributes, addMethod, removeMethod, raiseMethod));
 }
Exemplo n.º 11
0
        public void SetUp()
        {
            _declaringType   = MutableTypeObjectMother.Create();
            _name            = "Property";
            _attributes      = (PropertyAttributes)7;
            _type            = ReflectionObjectMother.GetSomeType();
            _indexParameters = ParameterDeclarationObjectMother.CreateMultiple(2);
            _getMethod       = MutableMethodInfoObjectMother.Create(returnType: _type, parameters: _indexParameters);
            _setMethod       =
                MutableMethodInfoObjectMother.Create(parameters: _indexParameters.Concat(new[] { ParameterDeclarationObjectMother.Create(_type) }));

            _property = new MutablePropertyInfo(_declaringType, _name, _attributes, _getMethod, _setMethod);
        }
        public static MutableEventInfo Create(
            MutableType declaringType = null,
            string name = "UnspecifiedEvent",
            EventAttributes attributes     = EventAttributes.None,
            MutableMethodInfo addMethod    = null,
            MutableMethodInfo removeMethod = null,
            MutableMethodInfo raiseMethod  = null)
        {
            Assertion.IsTrue(addMethod != null && removeMethod != null);
            declaringType = declaringType ?? MutableTypeObjectMother.Create();

            return(new MutableEventInfo(declaringType, name, attributes, addMethod, removeMethod, raiseMethod));
        }
Exemplo n.º 13
0
        private void CheckBodyOfAddedOverride(MethodInfo baseMethod, MutableMethodInfo mutableMethod)
        {
            Assert.That(mutableMethod.Body, Is.InstanceOf <MethodCallExpression>());
            var methodCallExpression = (MethodCallExpression)mutableMethod.Body;

            Assert.That(methodCallExpression.Object, Is.TypeOf <ThisExpression>());
            var thisExpression = ((ThisExpression)methodCallExpression.Object);

            Assert.That(thisExpression.Type, Is.SameAs(mutableMethod.DeclaringType));

            Assert.That(methodCallExpression.Method, Is.TypeOf <NonVirtualCallMethodInfoAdapter> ());
            Assert.That(((NonVirtualCallMethodInfoAdapter)methodCallExpression.Method).AdaptedMethod, Is.EqualTo(baseMethod));
        }
Exemplo n.º 14
0
        public void SetUp()
        {
            _delegateProviderMock = new Mock <IDelegateProvider> (MockBehavior.Strict);

            _provider = new EmittableOperandProvider(_delegateProviderMock.Object);

            _mutableType             = MutableTypeObjectMother.Create();
            _mutableGenericParameter = MutableGenericParameterObjectMother.Create();
            _mutableField            = MutableFieldInfoObjectMother.Create();
            _mutableConstructor      = MutableConstructorInfoObjectMother.Create();
            _mutableMethod           = MutableMethodInfoObjectMother.Create();

            _emittableType = ReflectionObjectMother.GetSomeType();
        }
Exemplo n.º 15
0
        private IMutableMember ImplementEventOverride(EventDefinition @event)
        {
            MutableMethodInfo addMethodOverride = null, removeMethodOverride = null;

            if (@event.AddMethod.Overrides.Count > 0)
            {
                addMethodOverride = ImplementMethodOverride(@event.AddMethod);
            }
            if (@event.RemoveMethod.Overrides.Count > 0)
            {
                removeMethodOverride = ImplementMethodOverride(@event.RemoveMethod);
            }

            return(_concreteTarget.AddEvent(@event.Name, EventAttributes.None, addMethodOverride, removeMethodOverride));
        }
        public static MutablePropertyInfo Create(
            MutableType declaringType = null,
            string name = "UnspecifiedProperty",
            PropertyAttributes attributes = PropertyAttributes.None,
            MutableMethodInfo getMethod   = null,
            MutableMethodInfo setMethod   = null)
        {
            declaringType = declaringType ?? MutableTypeObjectMother.Create();
            if (getMethod == null && setMethod == null)
            {
                getMethod = MutableMethodInfoObjectMother.Create(declaringType, "Getter", returnType: typeof(int));
            }

            return(new MutablePropertyInfo(declaringType, name, attributes, getMethod, setMethod));
        }
Exemplo n.º 17
0
        public static MutablePropertyInfo AddProperty2(
            this MutableType mutableType,
            string name = null,
            PropertyAttributes attributes = PropertyAttributes.None,
            MutableMethodInfo getMethod   = null,
            MutableMethodInfo setMethod   = null)
        {
            name = name ?? "Property_" + ++s_counter;
            if (getMethod == null && setMethod == null)
            {
                getMethod = MutableMethodInfoObjectMother.Create(mutableType, "Getter", returnType: typeof(int));
            }

            return(mutableType.AddProperty(name, attributes, getMethod, setMethod));
        }
Exemplo n.º 18
0
        private IMutableMember ImplementPropertyOverride(PropertyDefinition property)
        {
            MutableMethodInfo getMethodOverride = null, setMethodOverride = null;

            if (property.GetMethod != null && property.GetMethod.Overrides.Count > 0)
            {
                getMethodOverride = ImplementMethodOverride(property.GetMethod);
            }
            if (property.SetMethod != null && property.SetMethod.Overrides.Count > 0)
            {
                setMethodOverride = ImplementMethodOverride(property.SetMethod);
            }

            return(_concreteTarget.AddProperty(property.Name, PropertyAttributes.None, getMethodOverride, setMethodOverride));
        }
Exemplo n.º 19
0
        public MutablePropertyInfo CreateProperty(
            MutableType declaringType,
            string name,
            Type type,
            IEnumerable <ParameterDeclaration> indexParameters,
            MethodAttributes accessorAttributes,
            Func <MethodBodyCreationContext, Expression> getBodyProvider,
            Func <MethodBodyCreationContext, Expression> setBodyProvider)
        {
            ArgumentUtility.CheckNotNull("declaringType", declaringType);
            ArgumentUtility.CheckNotNullOrEmpty("name", name);
            ArgumentUtility.CheckNotNull("type", type);
            ArgumentUtility.CheckNotNull("indexParameters", indexParameters);
            // Get body provider may be null.
            // Set body provider may be null.

            MemberAttributesUtility.ValidateAttributes(
                "property accessor methods", MemberAttributesUtility.InvalidMethodAttributes, accessorAttributes, "accessorAttributes");

            if (getBodyProvider == null && setBodyProvider == null)
            {
                throw new ArgumentException("At least one accessor body provider must be specified.", "getBodyProvider");
            }

            var indexParams = indexParameters.ToList();
            var signature   = new PropertySignature(type, indexParams.Select(pd => pd.Type));

            if (declaringType.AddedProperties.Any(p => p.Name == name && PropertySignature.Create(p).Equals(signature)))
            {
                throw new InvalidOperationException("Property with equal name and signature already exists.");
            }

            var attributes = accessorAttributes | MethodAttributes.SpecialName;
            MutableMethodInfo getMethod = null, setMethod = null;

            if (getBodyProvider != null)
            {
                getMethod = CreateAccessor(declaringType, "get_" + name, attributes, type, indexParams, getBodyProvider);
            }
            if (setBodyProvider != null)
            {
                var setterParams = indexParams.Concat(new[] { new ParameterDeclaration(type, "value") });
                setMethod = CreateAccessor(declaringType, "set_" + name, attributes, typeof(void), setterParams, setBodyProvider);
            }

            return(new MutablePropertyInfo(declaringType, name, PropertyAttributes.None, getMethod, setMethod));
        }
Exemplo n.º 20
0
        public static MutableEventInfo AddEvent2(
            this MutableType mutableType,
            string name = null,
            EventAttributes attributes     = EventAttributes.None,
            MutableMethodInfo addMethod    = null,
            MutableMethodInfo removeMethod = null,
            MutableMethodInfo raiseMethod  = null)
        {
            name = name ?? "Event_" + ++s_counter;
            var handlerMethod = addMethod ?? removeMethod;
            var handlerType   = handlerMethod != null?handlerMethod.GetParameters().Single().ParameterType : typeof(Action);

            addMethod    = addMethod ?? MutableMethodInfoObjectMother.Create(mutableType, "Adder", parameters: new[] { ParameterDeclarationObjectMother.Create(handlerType) });
            removeMethod = removeMethod ?? MutableMethodInfoObjectMother.Create(mutableType, "Adder", parameters: new[] { ParameterDeclarationObjectMother.Create(handlerType) });

            return(mutableType.AddEvent(name, attributes, addMethod, removeMethod, raiseMethod));
        }
        public void GetNonVirtualCallTrampoline()
        {
            int i;
            var method = NormalizingMemberInfoFromExpressionUtility.GetMethod((DomainType obj) => obj.Abc(out i, 0.7));
            MutableMethodInfo mutableMethod = null;

            _memberEmitterMock
            .Setup(mock => mock.AddMethod(_context, It.IsAny <MutableMethodInfo>()))
            .Callback((CodeGenerationContext context, MutableMethodInfo methodArg) => mutableMethod = methodArg)
            .Verifiable();

            var result = _provider.GetNonVirtualCallTrampoline(_context, method);

            _memberEmitterMock.Verify();
            Assert.That(result, Is.SameAs(mutableMethod));
            Assert.That(_mutableType.AddedMethods, Has.Member(result));

            var name = "Remotion.TypePipe.UnitTests.CodeGeneration.ReflectionEmit.MethodTrampolineProviderTest+DomainType.Abc_NonVirtualCallTrampoline";

            Assert.That(result.Name, Is.EqualTo(name));
            Assert.That(result.Attributes, Is.EqualTo(MethodAttributes.Private));
            Assert.That(result.ReturnType, Is.SameAs(typeof(string)));

            var parameters         = result.GetParameters().Select(p => new { p.ParameterType, p.Name, p.Attributes });
            var expectedParameters = new[]
            {
                new { ParameterType = typeof(int).MakeByRefType(), Name = "i", Attributes = ParameterAttributes.Out },
                new { ParameterType = typeof(double), Name = "d", Attributes = ParameterAttributes.None }
            };

            Assert.That(parameters, Is.EqualTo(expectedParameters));

            Assert.That(result.GetBaseDefinition(), Is.SameAs(result));
            Assert.That(result.IsGenericMethod, Is.False);
            Assert.That(result.IsGenericMethodDefinition, Is.False);
            Assert.That(result.ContainsGenericParameters, Is.False);

            Assert.That(mutableMethod.Body, Is.InstanceOf <MethodCallExpression>());
            var methodCallExpression = ((MethodCallExpression)mutableMethod.Body);

            Assert.That(methodCallExpression.Object, Is.TypeOf <ThisExpression>().And.Property("Type").SameAs(_mutableType));
            Assert.That(methodCallExpression.Method, Is.TypeOf <NonVirtualCallMethodInfoAdapter>().And.Property("AdaptedMethod").SameAs(method));
            Assert.That(methodCallExpression.Arguments, Is.EqualTo(mutableMethod.ParameterExpressions));
        }
Exemplo n.º 22
0
        public MutableEventInfo CreateEvent(
            MutableType declaringType,
            string name,
            Type handlerType,
            MethodAttributes accessorAttributes,
            Func <MethodBodyCreationContext, Expression> addBodyProvider,
            Func <MethodBodyCreationContext, Expression> removeBodyProvider,
            Func <MethodBodyCreationContext, Expression> raiseBodyProvider)
        {
            ArgumentUtility.CheckNotNull("declaringType", declaringType);
            ArgumentUtility.CheckNotNullOrEmpty("name", name);
            ArgumentUtility.CheckNotNullAndTypeIsAssignableFrom("handlerType", handlerType, typeof(Delegate));
            ArgumentUtility.CheckNotNull("addBodyProvider", addBodyProvider);
            ArgumentUtility.CheckNotNull("removeBodyProvider", removeBodyProvider);
            // Raise body provider may be null.

            MemberAttributesUtility.ValidateAttributes(
                "event accessor methods", MemberAttributesUtility.InvalidMethodAttributes, accessorAttributes, "accessorAttributes");

            var signature = new EventSignature(handlerType);

            if (declaringType.AddedEvents.Any(e => e.Name == name && EventSignature.Create(e).Equals(signature)))
            {
                throw new InvalidOperationException("Event with equal name and signature already exists.");
            }

            var attributes          = accessorAttributes | MethodAttributes.SpecialName;
            var addRemoveParameters = new[] { new ParameterDeclaration(handlerType, "handler") };

            var addMethod    = CreateAccessor(declaringType, "add_" + name, attributes, typeof(void), addRemoveParameters, addBodyProvider);
            var removeMethod = CreateAccessor(declaringType, "remove_" + name, attributes, typeof(void), addRemoveParameters, removeBodyProvider);

            MutableMethodInfo raiseMethod = null;

            if (raiseBodyProvider != null)
            {
                var invokeMethod    = GetInvokeMethod(handlerType);
                var raiseParameters = invokeMethod.GetParameters().Select(p => new ParameterDeclaration(p.ParameterType, p.Name, p.Attributes));
                raiseMethod = CreateAccessor(declaringType, "raise_" + name, attributes, invokeMethod.ReturnType, raiseParameters, raiseBodyProvider);
            }

            return(new MutableEventInfo(declaringType, name, EventAttributes.None, addMethod, removeMethod, raiseMethod));
        }
Exemplo n.º 23
0
        public Expression CopyMethodBody(MutableMethodInfo otherMethod, IEnumerable <Expression> arguments)
        {
            ArgumentUtility.CheckNotNull("otherMethod", otherMethod);
            ArgumentUtility.CheckNotNull("arguments", arguments);

            // ReSharper disable PossibleUnintendedReferenceComparison
            if (otherMethod.DeclaringType != _declaringType)
            // ReSharper restore PossibleUnintendedReferenceComparison
            {
                var message = string.Format("The specified method is declared by a different type '{0}'.", otherMethod.DeclaringType);
                throw new ArgumentException(message, "otherMethod");
            }

            if (IsStatic && !otherMethod.IsStatic)
            {
                throw new ArgumentException("The body of an instance method cannot be copied into a static method.", "otherMethod");
            }

            return(BodyContextUtility.ReplaceParameters(otherMethod.ParameterExpressions, otherMethod.Body, arguments));
        }
Exemplo n.º 24
0
        public void Initialization()
        {
            var declaringType = MutableTypeObjectMother.Create();
            var name          = "abc";
            var attributes    = (MethodAttributes)7 | MethodAttributes.Virtual;
            var returnType    = ReflectionObjectMother.GetSomeType();
            var parameters    = ParameterDeclarationObjectMother.CreateMultiple(2);
            var baseMethod    = ReflectionObjectMother.GetSomeVirtualMethod();
            var body          = ExpressionTreeObjectMother.GetSomeExpression(returnType);

            var method = new MutableMethodInfo(
                declaringType, name, attributes, new MutableGenericParameter[0], returnType, parameters.AsOneTime(), baseMethod, body);

            Assert.That(method.DeclaringType, Is.SameAs(declaringType));
            Assert.That(method.MutableDeclaringType, Is.SameAs(declaringType));
            Assert.That(method.Name, Is.EqualTo(name));
            Assert.That(method.Attributes, Is.EqualTo(attributes));
            Assert.That(method.IsGenericMethod, Is.False);

            CustomParameterInfoTest.CheckParameter(method.ReturnParameter, method, -1, null, returnType, ParameterAttributes.None);
            Assert.That(method.MutableReturnParameter, Is.SameAs(method.ReturnParameter));

            var actualParameters = method.GetParameters();

            Assert.That(actualParameters, Has.Length.EqualTo(2));
            CustomParameterInfoTest.CheckParameter(actualParameters[0], method, 0, parameters[0].Name, parameters[0].Type, parameters[0].Attributes);
            CustomParameterInfoTest.CheckParameter(actualParameters[1], method, 1, parameters[1].Name, parameters[1].Type, parameters[1].Attributes);
            Assert.That(method.MutableParameters, Is.EqualTo(actualParameters));

            var paramExpressions = method.ParameterExpressions;

            Assert.That(paramExpressions, Has.Count.EqualTo(2));
            Assert.That(paramExpressions[0], Has.Property("Name").EqualTo(parameters[0].Name).And.Property("Type").SameAs(parameters[0].Type));
            Assert.That(paramExpressions[1], Has.Property("Name").EqualTo(parameters[1].Name).And.Property("Type").SameAs(parameters[1].Type));

            Assert.That(method.BaseMethod, Is.SameAs(baseMethod));
            Assert.That(method.Body, Is.SameAs(body));
        }
Exemplo n.º 25
0
        public void SetUp()
        {
            _declaringType = MutableTypeObjectMother.Create();
            _name          = "Event";
            _attributes    = (EventAttributes)7;
            _argumentType  = ReflectionObjectMother.GetSomeType();
            _returnType    = ReflectionObjectMother.GetSomeOtherType();
            _handlerType   = typeof(Func <,>).MakeGenericType(_argumentType, _returnType);
            _addMethod     = MutableMethodInfoObjectMother.Create(
                attributes: MethodAttributes.Public,
                returnType: typeof(void),
                parameters: new[] { new ParameterDeclaration(_handlerType, "handler") });
            _removeMethod = MutableMethodInfoObjectMother.Create(
                attributes: MethodAttributes.Public,
                returnType: typeof(void),
                parameters: new[] { new ParameterDeclaration(_handlerType, "handler") });
            _raiseMethod = MutableMethodInfoObjectMother.Create(
                attributes: MethodAttributes.Public,
                returnType: _returnType,
                parameters: new[] { new ParameterDeclaration(_argumentType, "") });

            _event = new MutableEventInfo(_declaringType, _name, _attributes, _addMethod, _removeMethod, _raiseMethod);
        }
Exemplo n.º 26
0
        private void ImplementIntroducedProperty(Expression implementer, PropertyIntroductionDefinition introducedProperty)
        {
            var interfaceProperty    = introducedProperty.InterfaceMember;
            var implementingProperty = introducedProperty.ImplementingMember;
            var visibility           = introducedProperty.Visibility;

            MutableMethodInfo getMethod = null, setMethod = null;

            if (introducedProperty.IntroducesGetMethod)
            {
                getMethod = ImplementIntroducedMethod(implementer, interfaceProperty.GetGetMethod(), implementingProperty.GetMethod, visibility);
            }
            if (introducedProperty.IntroducesSetMethod)
            {
                setMethod = ImplementIntroducedMethod(implementer, interfaceProperty.GetSetMethod(), implementingProperty.SetMethod, visibility);
            }

            var name = GetIntroducedMemberName(visibility, interfaceProperty);
            var property = _concreteTarget.AddProperty(name, PropertyAttributes.None, getMethod, setMethod);

            _attributeGenerator.AddIntroducedMemberAttribute(property, interfaceProperty, implementingProperty);
            _attributeGenerator.ReplicateAttributes(implementingProperty, property);
        }
Exemplo n.º 27
0
 public MethodInfo GetGeneratedMethod(MutableMethodInfo mutableMethod)
 {
     return((MethodInfo)GetGeneratedMember(mutableMethod));
 }
Exemplo n.º 28
0
        private void CheckExplicitOverrideAction(Action testedAction, MethodInfo overriddenMethod, MutableMethodInfo overridingMethod)
        {
            _emittableOperandProviderMock.BackToRecord();
            _typeBuilderMock.BackToRecord();

            var fakeOverriddenMethod = ReflectionObjectMother.GetSomeMethod();
            var fakeOverridingMethod = ReflectionObjectMother.GetSomeMethod();

            _emittableOperandProviderMock.Expect(mock => mock.GetEmittableMethod(overriddenMethod)).Return(fakeOverriddenMethod);
            _emittableOperandProviderMock.Expect(mock => mock.GetEmittableMethod(overridingMethod)).Return(fakeOverridingMethod);

            _typeBuilderMock.Expect(mock => mock.DefineMethodOverride(fakeOverridingMethod, fakeOverriddenMethod));

            _emittableOperandProviderMock.Replay();
            _typeBuilderMock.Replay();

            testedAction();

            _emittableOperandProviderMock.VerifyAllExpectations();
            _typeBuilderMock.VerifyAllExpectations();
        }
Exemplo n.º 29
0
 public MutablePropertyInfo CreateProperty(
     MutableType declaringType, string name, PropertyAttributes attributes, MutableMethodInfo getMethod, MutableMethodInfo setMethod)
 {
     return(_propertyFactory.CreateProperty(declaringType, name, attributes, getMethod, setMethod));
 }
 public void AddMapping(MutableMethodInfo mappedMethod, MethodInfo emittableMethod)
 {
     _emittableOperandProvider.AddMapping(mappedMethod, emittableMethod);
 }