FxCop라는 프로그램으로 내가 만든 프로그램을 분석해 보면서 나온 내용들 정리

재미 있는 점은 Microsoft에서 만든 SqlHelper도 FxCop에서 제시하는 Rule을 어긴게 종종 보이네요 ^^''

 

발견된 건 무지 많은데... 공감도 가고 이해도 가고 수정도 했던 부분만 간략히 정리하는 중이다..

 

<<Performance Rule>>

- Properties should not return arrays

이유 : 비록 readonly 속성이라도 넘겨받은 배열의 값을 변경할 수 있기 때문

해결책 : clone해서 넘긴다.

출처 : http://www.gotdotnet.com/team/fxcop/docs/rules.aspx?version=1.32&url=/Performance/PropertiesShouldNotReturnArrays.html

 

- Do not initialize unnecessarily

이유 : CLR이 생성자를 실행하기 전에 모든 fields를 기본값으로 초기화를 한다. 대부분의 경우 생성자 안에서 field들을 기본값으로 초기화 하는일은 중복된 작업이다.

해결책 : 생성자 안에서 기본값으로 초기화하는 코드를 삭제

출처 : http://www.gotdotnet.com/team/fxcop/docs/rules.aspx?version=1.32&url=/Performance/DoNotInitializeUnnecessarily.html

 

<< Usage Rulse >>

- Non-constant fields should not be visible

이유 : read-only가 아닌 static field 상수는 쓰레드에 안전하지 않으므로..

해결책 : read-only로 만들거나 public을 제거하여 노출하지 않는다.

출처 : http://www.gotdotnet.com/team/fxcop/docs/rules.aspx?version=1.32&url=/Usage/NonConstantFieldsShouldNotBeVisible.html

 

<< Design Ruls >>

- Abstract types should not have constructors

이유 : 추상 type의 생성자는 상속받은 type에서만 호출할 수 있으므로 추상 type은 public 생성자를 갖으면 안된다.

해결책 : public생성자를 protected 생성자로 변경

출처 : http://www.gotdotnet.com/team/fxcop/docs/rules.aspx?version=1.32&url=/Design/AbstractTypesShouldNotHaveConstructors.html

?? : 그다지 공감가지는 않는데... 어짜피 추상 type의 객체를 바로 만들 수가 없는데...

'programming > c#' 카테고리의 다른 글

10가지 .Net용 무료 개발 툴  (0) 2005.11.03
열거형 클래스 예제  (0) 2005.10.22
.NET Test Driven Development의 모든것...  (0) 2005.10.03

+ Recent posts