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

New analyzer: [MustBeLocked] attribute to ensure all callers lock an argument before invoking a method #49

Open
ronnygunawan opened this issue Mar 8, 2021 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@ronnygunawan
Copy link
Owner

ronnygunawan commented Mar 8, 2021

class Foo {
    private object? _obj = null;
    private readonly ConcurrentDictionary<int, object> _dictionary = new();

    void M() {
        if (_dictionary.TryGetValue(100, out object? obj)) {
            N(obj); // warning: obj must be locked before calling this method
            
            lock (obj) {
                N(obj); // no warning
            }
        }
    }
    
    void N([MustBeLocked] object x) {
        if (x is List<int> list) {
            list.Add(0);
        }
    }
}
@ronnygunawan ronnygunawan added the enhancement New feature or request label Mar 8, 2021
@ronnygunawan ronnygunawan self-assigned this Mar 8, 2021
@ronnygunawan ronnygunawan changed the title New analyzer: [MustLock] attribute to ensure all callers lock a field or parameter before invoking a method New analyzer: [MustBeLocked] attribute to ensure all callers lock a field or parameter before invoking a method Mar 11, 2021
@ronnygunawan ronnygunawan changed the title New analyzer: [MustBeLocked] attribute to ensure all callers lock a field or parameter before invoking a method New analyzer: [MustBeLocked] attribute to ensure all callers lock an argument before invoking a method Mar 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant