Fix MA0102 code fix copying the modifiers of the reported accessor to the other accessor
What
When MA0102 reports an accessor and the other accessor is already readonly, the code fix moves readonly to the property. It rewrote every accessor with the modifiers of the reported accessor (accessor.Modifiers instead of item.Modifiers), so the accessibility of one accessor was copied onto the other:
struct Test
{
int a;
public int A
{
readonly get => a;
private {|MA0102:set|} { }
}
}
Expected:
public readonly int A
{
get => a;
private set { }
}
Actual: private get => a;, which does not compile (CS0274: both accessors cannot have an accessibility modifier).
Fix
Each accessor keeps its own modifiers and only readonly is removed. The accessors are replaced with ReplaceNodes, instead of calling ReplaceNode in a loop with nodes of the original tree.
Tests
Added CanBeReadOnly_PropertyFullSetterWithAccessibilityReferenceField and CanBeReadOnly_PropertyFullGetterWithAccessibilityReferenceField. Both failed before the fix.
Ran MakeMemberReadOnlyAnalyzerTests on roslyn5.9 and roslyn4.8 (33/33 passing on both).