2

Is there any annotation or analyzer that marks a member which requires to always be used inside a specific lock.

public class Example
{
    private readonly object _lock = new object();
    
    // Some annotation that requires this to be used inside a lock of _lock
    private readonly List<int> _collection = new List<int>();

    public void Add(int value)
    {
        lock (_lock)
        {
            _collection.Add(value);
        }
    }

    public void Remove(int value)
    {
        lock (_lock)
        {
            _collection.Remove(value);
        }
    }
}
Michal Ciechan
  • 13,492
  • 11
  • 76
  • 118

0 Answers0