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

Conversation

Rumyash
Copy link

@Rumyash Rumyash commented Dec 22, 2018

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

@jauntus
Copy link

jauntus commented May 1, 2019

This fixes the bug that you cannot set for example string values to null by calling propertyInterceptionInfo.SetValue(null) because of the missing return statements in Fody/Cauldron.BasicInterceptors/Weaver_Property.cs in CreateSetterDelegate!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants