Cauldron
Cauldron copied to clipboard
Missed "else" in property setter delegate.
I have nullable property
[MyAttribute]
public int? NullableProperty { get; set; }
with simple attribute
public class MyAttribute : Attribute, IPropertyInterceptor
{
public void OnGet(PropertyInterceptionInfo propertyInterceptionInfo, object value)
{
int? newValue = CalculateValue();
propertyInterceptionInfo.SetValue(newValue);
}
...
}
When the newValue is null and I set it to propertyInterceptionInfo, then the NullableProperty returns 0 instead of null. This is because the "else" is missing in the generated method, after the first "if"
private void \u003CNullableProperty\u003Em__setterMethod([In] object obj0)
{
if (obj0 == null)
this.\u003CNullableProperty\u003Ek__BackingField = new int?();
if (obj0 is int?)
this.\u003CNullableProperty\u003Ek__BackingField = new int?(Convert.ToInt32(obj0));
else
this.\u003CNullableProperty\u003Ek__BackingField = new int?(Convert.ToInt32(obj0));
}