public CustomPropertyEmitter AddForwardingProperty(PropertyInfo propertyInfo) { string propertyName = propertyInfo.Name; var propertyEmitter = _classEmitter.CreateProperty(propertyName, PropertyKind.Instance, propertyInfo.PropertyType); CreateGetterAndSetter(propertyInfo, propertyEmitter); return(propertyEmitter); }
public void CreateProperty() { var classEmitter = new CustomClassEmitter(Scope, "CreateProperty", typeof(object)); CustomPropertyEmitter property = classEmitter.CreateProperty("Check", PropertyKind.Instance, typeof(string), Type.EmptyTypes, PropertyAttributes.None); property.CreateGetMethod().AddStatement(new ReturnStatement(new ConstReference("4711"))); object instance = Activator.CreateInstance(classEmitter.BuildType()); Assert.That(instance.GetType().GetProperty("Check").GetValue(instance, null), Is.EqualTo("4711")); }
public void SimpleInstanceProperty() { CustomPropertyEmitter property = _classEmitter.CreateProperty("SimpleProperty", PropertyKind.Instance, typeof(int)); Assert.That(property.Name, Is.EqualTo("SimpleProperty")); Assert.That(property.PropertyType, Is.EqualTo(typeof(int))); Assert.That(property.PropertyKind, Is.EqualTo(PropertyKind.Instance)); Assert.That(property.IndexParameters, Is.Empty); property.CreateGetMethod(); property.CreateSetMethod(); property.ImplementWithBackingField(); object instance = BuildInstance(); Assert.That(GetPropertyValue(instance, property), Is.EqualTo(0)); SetPropertyValue(17, instance, property); Assert.That(GetPropertyValue(instance, property), Is.EqualTo(17)); var generatedPropertyInfo = GetProperty(instance, property); CheckCallingConvention(generatedPropertyInfo, CallingConventions.Standard | CallingConventions.HasThis); }