본문 바로가기

개발자/WPF(C#) UI

SonarLint로 정적 test 중 나오는 Warning 정리(2)

반응형

-Make this field 'private' and encapsulate it in a 'public' property.

: Public fields in public classes do not respect the encapsulation principle and has three main disadvantages:

 

public static class안의 static 변수들을 private로 바꿔달라는 말이다.

private으로 바꿔도 변하는것은 없다. 그저 가독성의 이유인듯?

 

-Change the visibility of 'auxiliaryFunctionReq' or make it 'const' or 'readonly'. 

: A static field that is neither constant nor read-only is not thread-safe. Correctly accessing these fields from different threads needs synchronization with locks. Improper synchronization may lead to unexpected results, thus publicly visible static fields are best suited for storing non-changing data shared by many consumers. To enforce this intent, these fields should be marked readonly or converted to constants.

 

해당 static field가 상수도 아니고, read-only로도 작용을 못해서 쓰레드에 안전하지 않다는 경고다.

 

 

반응형