diff --git a/Fody/Cauldron.BasicInterceptors/Weaver_Property.cs b/Fody/Cauldron.BasicInterceptors/Weaver_Property.cs index edd9eaeec8..86b4e617a8 100644 --- a/Fody/Cauldron.BasicInterceptors/Weaver_Property.cs +++ b/Fody/Cauldron.BasicInterceptors/Weaver_Property.cs @@ -518,8 +518,8 @@ T CodeMe(Func fieldCode, Func propertyCode) where T : // Otherwise if the property is not a value type and nullable else if (!propertyType.IsValueType || propertyType.IsNullable || propertyType.IsArray) CodeMe( - field => setterCode.SetValue(field, null), - property => setterCode.Call(property.Setter, null)); + field => setterCode.SetValue(field, null).Return(), + property => setterCode.Call(property.Setter, null).Return()); else // otherwise... throw an exception then.ThrowNew(typeof(NotSupportedException), "Value types does not accept null values."); diff --git a/UnitTests/Shared/MainTests/BasicInterceptors/Property_Interceptor_Code_Validation_Tests.cs b/UnitTests/Shared/MainTests/BasicInterceptors/Property_Interceptor_Code_Validation_Tests.cs index 6d8ab4a7f9..d0ac195f24 100644 --- a/UnitTests/Shared/MainTests/BasicInterceptors/Property_Interceptor_Code_Validation_Tests.cs +++ b/UnitTests/Shared/MainTests/BasicInterceptors/Property_Interceptor_Code_Validation_Tests.cs @@ -107,6 +107,9 @@ public string ThisIsMyProperty [TestPropertyInterceptor] public long ValueTypePropertyPrivateSetter { get; private set; } + [TestPropertyInterceptor] + public int? NullableProperty { get; set; } + [TestMethod] public void Array_Property_Setter() { @@ -198,6 +201,19 @@ public void ValueType_Property() Assert.AreEqual(9999, this.ValueTypeProperty); } + [TestMethod] + public void Nullable_Property() + { + this.NullableProperty = 113; + Assert.IsNull(this.NullableProperty); + + this.NullableProperty = 121; + Assert.AreEqual(121, this.NullableProperty); + + this.NullableProperty = null; + Assert.IsNull(this.NullableProperty); + } + private List Blub() { return new List(); diff --git a/UnitTests/Shared/TestInterceptors/TestPropertyInterceptorAttribute.cs b/UnitTests/Shared/TestInterceptors/TestPropertyInterceptorAttribute.cs index 8e294886f7..090963f6ed 100644 --- a/UnitTests/Shared/TestInterceptors/TestPropertyInterceptorAttribute.cs +++ b/UnitTests/Shared/TestInterceptors/TestPropertyInterceptorAttribute.cs @@ -23,6 +23,9 @@ public void OnGet(PropertyInterceptionInfo propertyInterceptionInfo, object valu if (Comparer.Equals(value, (double)66)) propertyInterceptionInfo.SetValue(78344.8f); + + if (Comparer.Equals(value, (int)113)) + propertyInterceptionInfo.SetValue(null); } public bool OnSet(PropertyInterceptionInfo propertyInterceptionInfo, object oldValue, object newValue)