Ejemplo n.º 1
0
        public void PropertyNameIsNotChangedOnPublicInterfaceImplementation()
        {
            var classEmitter = new CustomClassEmitter(Scope, "PropertyNameIsNotChangedOnPublicInterfaceImplementation", typeof(object), new[] { typeof(IInterfaceWithProperty) },
                                                      TypeAttributes.Public | TypeAttributes.Class, false);

            CustomPropertyEmitter property = classEmitter.CreatePublicInterfacePropertyImplementation(
                typeof(IInterfaceWithProperty).GetProperty("Property", _declaredInstanceBindingFlags));

            Assert.That(property.PropertyBuilder.Name, Is.EqualTo("Property"));

            property.SetMethod = classEmitter.CreateInterfaceMethodImplementation(
                typeof(IInterfaceWithProperty).GetMethod("set_Property", _declaredInstanceBindingFlags));
            property.SetMethod.AddStatement(new ReturnStatement());

            classEmitter.BuildType();
        }
Ejemplo n.º 2
0
        // TODO: Test
        /// <summary>
        /// Adds a forwarding property to the proxy based on the passed <see cref="PropertyInfo"/>.
        /// </summary>
        public void AddForwardingPropertyFromClassOrInterfacePropertyInfoCopy(PropertyInfo propertyInfo)
        {
            ArgumentUtility.CheckNotNull("propertyInfo", propertyInfo);

            CustomPropertyEmitter propertyEmitter;

            if (propertyInfo.DeclaringType.IsInterface)
            {
                propertyEmitter = _classEmitter.CreatePublicInterfacePropertyImplementation(propertyInfo);
            }
            else
            {
                propertyEmitter = _classEmitter.CreateProperty(propertyInfo.Name, PropertyKind.Instance, propertyInfo.PropertyType);
            }

            CreateGetterAndSetter(propertyInfo, propertyEmitter);
        }
Ejemplo n.º 3
0
        public void CreatePublicInterfacePropertyImplementation()
        {
            var classEmitter = new CustomClassEmitter(Scope, "CreatePublicInterfacePropertyImplementation", typeof(object), new[] { typeof(IInterfaceWithProperty) },
                                                      TypeAttributes.Public | TypeAttributes.Class, false);

            CustomPropertyEmitter property = classEmitter.CreatePublicInterfacePropertyImplementation(
                typeof(IInterfaceWithProperty).GetProperty("Property", _declaredInstanceBindingFlags));

            Assert.That(property.GetMethod, Is.Null);
            Assert.That(property.SetMethod, Is.Null);

            property.SetMethod = classEmitter.CreateInterfaceMethodImplementation(
                typeof(IInterfaceWithProperty).GetMethod("set_Property", _declaredInstanceBindingFlags));
            property.SetMethod.AddStatement(new ReturnStatement());

            Type builtType = classEmitter.BuildType();

            var instance = (IInterfaceWithProperty)Activator.CreateInstance(builtType);

            instance.Property = 7;
        }