2

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.

Ajay
  • 18,086
  • 12
  • 59
  • 105
  • 1
    Maybe there is none yet. You can investigate if creating custom code analysis rules worth it ([click](https://blogs.msdn.microsoft.com/codeanalysis/2010/03/26/how-to-write-custom-static-code-analysis-rules-and-integrate-them-into-visual-studio-2010/), [click](http://stackoverflow.com/q/9468601/1997232)). – Sinatr Feb 22 '17 at 13:15

0 Answers0