codemaid
codemaid copied to clipboard
Conflicting modifiers on partial classes
Environment
- Visual Studio version: 2019 Enterprise
- CodeMaid version: 12.0
- Code language: C#
Description
When having a partial class over 2 files and in one file the class is defined as public
and in the other it does not have an accessibility modifier, CodeMaid adds an internal
modifier, which results in a compile error CS2062 "Partial declarations of '<Type>' have conflicting accessibility modifiers"
Steps to recreate
public partial class Foo {
}
partial class Foo {
}
Current behavior
CodeMaid changes the accessibility modifier of the class that is not declaring any accessibility modifiers to internal
, which is incorrect and leads to a compile error:
public partial class Foo {
}
internal partial class Foo {
}
Expected behavior
CodeMaid should respect the already on any partial class part defined accessibility modifier and use that instead of internal
:
public partial class Foo {
}
public partial class Foo {
}
or, as a quick fix, ignore adding accessibility modifiers to partial classes.
Thanks for reporting the issue. I am able to reproduce it.
We do have explicit logic to handle this scenario (see https://github.com/codecadwallader/codemaid/blob/dev/CodeMaidShared/Logic/Cleaning/InsertExplicitAccessModifierLogic.cs#L61-L65)
However I think this is being impacted by the known SDK issue with access modifiers. Please see #879 for more information as well as a link to the Roslyn SDK issue.