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

If an IDisposable field is readonly it cannot be set to null in the Dispose(bool) method #43

Open
sonnemaf opened this issue Jan 9, 2025 · 0 comments

Comments

@sonnemaf
Copy link

sonnemaf commented Jan 9, 2025

Issue Details

If an IDisposable field is readonly it cannot be set to null in the Dispose(bool) method. You get a compiler error.
image

Line 18 should not be generated when the field is readonly.

image

[GenerateDispose(false)]
public partial class LogWriter  {

    [DisposeField(false)]
    private readonly StreamWriter _streamWriter;

    public LogWriter(string path) {
        _streamWriter = new StreamWriter(path);
    }

    public void WriteLine(string text) => _streamWriter.WriteLine(text.ToUpper());
}
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