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(); }
// 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); }
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; }