Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missed "else" in property setter delegate. #77

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Fody/Cauldron.BasicInterceptors/Weaver_Property.cs
Original file line number Diff line number Diff line change
@@ -518,8 +518,8 @@ T CodeMe<T>(Func<Field, T> fieldCode, Func<Property, T> propertyCode) where T :
// Otherwise if the property is not a value type and nullable
else if (!propertyType.IsValueType || propertyType.IsNullable || propertyType.IsArray)
CodeMe<CoderBase>(
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.");

Original file line number Diff line number Diff line change
@@ -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<long> Blub()
{
return new List<long>();
Original file line number Diff line number Diff line change
@@ -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)