I have this construct in a class in a couple setters:
this.RaiseUnselected(this.property);
this.property = value;
this.RaiseSelected(this.property);
To clean up my class I extracted this into a method like:
private void SetProperty(IType target, IType value)
{
this.RaiseUnselected(target);
target = value;
this.RaiseSelected(target);
}
This caused a couple unit tests to fail. As you can probably see the issue is that the target is passed by value and the setting does not get reflected back to the this.property passed as target.
I fixed it by changing the function to
private void SetProperty(ref IType target, IType value)
but I’m not a big fan of using ref if possible. Any other suggestions?
This is what
refis meant for; there is nothing wrong with using it here.