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

IDISP001 and IDISP004 false positives / add special case for MemoryStream #541

Open
erichiller opened this issue Nov 7, 2023 · 0 comments

Comments

@erichiller
Copy link

Use of MemoryStream triggers IDISP001 and IDISP004 however, while MemoryStream implements IDisposable it doesn't actually have disposable resources.

CA2000 has a special case for Stream types because of this. Their special cases are:

  • System.IO.Stream
  • System.IO.StringReader
  • System.IO.TextReader
  • System.IO.TextWriter
  • System.Resources.IResourceReader

It would be good if these two analyzers had the same special cases. Alternatively (and a better, more future-proofed solution) would be to have a configuration rule, ideally something matching the EditorConfig rule like CA2000's excluded_symbol_names and excluded_type_names_with_derived_types:

dotnet_code_quality.IDISPxxx.excluded_symbol_names = MyType
dotnet_code_quality.IDISPxxx.excluded_type_names_with_derived_types = MyType

Example IDISP001:

var memoryStream = new MemoryStream( "{ }"u8.ToArray() );

Example IDISP004:

var memoryStream = config.AddJsonStream( new MemoryStream( "{ }"u8.ToArray() ) );
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

1 participant