In Visual C++, we have set of annotation attributes - for example _Guarded_by_
can be used to state that given variable is being protected by synchronization object given in this macro. Code from MSDN:
CRITICAL_SECTION gCS;
_Guarded_by_(gCS) int gData;
It simply means that integer variable is guarded by given Critical Section. The Code Analysis tool will detect and render a warning if variable is used without guarding the integer variable with this CS.
What is the equivalent in C# to state the same? I am not willing to use lock
keyword, since I'm using ReaderWriterLockSlim
(lighter than lock
). Hence I require some attribute/annotation against the variable(s) that I want to have synchronized access, backed by given Reader-Writer lock.