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

SA1202 fires for dependent members #3808

Open
CollinAlpert opened this issue Feb 21, 2024 · 3 comments
Open

SA1202 fires for dependent members #3808

CollinAlpert opened this issue Feb 21, 2024 · 3 comments

Comments

@CollinAlpert
Copy link
Contributor

Take the following code:

internal class Program
{
	private static readonly string a = "a";
	
	public static readonly string aa = a + "a";
}

SA1202 is telling me that public members should appear before private ones, which is usually a good idea, except when the members depend on the order of declaration. Changing the order would break the code.

@CollinAlpert
Copy link
Contributor Author

I'd be happy to implement a fix, however the test project targets net452, which I don't have installed since I am working on a Mac.

@sharwell
Copy link
Member

... the test project targets net452, which I don't have installed ...

This should work seamlessly if the following package is added:
https://www.nuget.org/packages/Microsoft.NETFramework.ReferenceAssemblies

@sharwell
Copy link
Member

sharwell commented Feb 21, 2024

I'm not sure how to handle this case in general. It seems like we need to build a partial order based on dependencies, and then add links to the partial order graph based on preferred ordering rules while omitting links that would produce a cycle. We have several other issues related to this but no great solutions so far.

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

No branches or pull requests

2 participants