MS 문서인데




CA1069: Enums should not have duplicate values
enum E { Field1 = 1, AnotherNameForField1 = Field1, // This is fine Field2 = 2, Field3 = 2, // CA1069: This is not fine. Either assign a different constant value or 'Field2' to indicate explicit intent of sharing value. }

This rule helps in catching functional bugs introduced from the following scenarios:

  • Accidental typing mistakes, where the user accidentally typed the same constant value for multiple members.
  • Copy paste mistakes, where the user copied an existing member definition, then renamed the member but forgot to change the value.
  • Merge resolution from multiple branches, where a new member was added with a different name but the same value in different branches.


이 규칙은 다음과 같은 시나리오에서 발생하는 기능적 버그를 포착하는 데 도움이 됩니다:

    사용자가 실수로 여러 멤버에 동일한 상수 값을 입력한 타이핑 오류.
    기존 멤버 정의를 복사한 후 멤버 이름을 변경했지만 값 변경을 잊은 복사 붙여넣기 오류.
    서로 다른 브랜치에서 이름은 다르지만 동일한 값을 가진 새 멤버가 추가된 병합 해결 시 발생하는 오류.


https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1069



 ms 가 c++ 에서는 그냥 둔걸

c# 에서는 잡기로 결정한걸까

win api 는 레거시 취급인가



-------------------



댓글에 스위프트에 관해봤는데 얘네는 경고 수준이 아니고 걍 컴파일 오류내고 막아놓음


<stdin>:3:15: error: raw value for enum case is not unique
1 | enum Status: Int {
2 |     case success = 200
  |                    `- note: raw value previously used here
3 |     case ok = 200 // 값 중복 
  |               `- error: raw value for enum case is not unique
4 |     case failure = 500
5 | }



그래서 static 으로 별칭 만들어야됨

enum SomeEnum {
case SomeLengthyCaseName
// Workaround: Use a static constant as an "alias"
static let SLCN = SomeEnum.SomeLengthyCaseName
}

print(SomeEnum.SLCN);



이건 php 에서도 따라할 수있음.

enum ShowWindowCmd: int
{
 case HIDE = 0;
 case SHOWNORMAL = 1;
 case SHOWMINIMIZED = 2;
 case MAXIMIZE = 3;
   
 // 별칭 (Win API의 중복된 상수 이름 처리)
 public const NORMAL = self::SHOWNORMAL; 
   
 // SW_MAXIMIZE도 3
 public const SHOWMAXIMIZED = self::MAXIMIZE; 
}

print ( ShowWindowCmd::NORMAL->value);