How can i get enum to contain a dash (-)?

后端 未结 3 633
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-04 00:44

I\'m generating business objects from this schema using Enterprise Architect.

The schema has the following enumeration specification:



        
3条回答
  •  有刺的猬
    2021-01-04 01:20

    A C# identifier must start with an underscore, a character in the Unicode class Lu, Ll, Lt, Lm, Lo, or Nl, or an escape for one of those. All other characters must be from Unicode class Lu, Ll, Lt, Lm, Lo, Nl, Mn, Mc, Nd, Pc or Cf, or an escape for one of those.

    Hyphen-minus is of category Pd.

    If C# did allow it, you still couldn't use it on a public identifier if you needed to be CLS compliant, as it wouldn't fit its rules either.

    This is just as well, as how are you meant to distinguish CD-ROM meaning a particular item in the enum from CD-ROM meaning to apply the - operator with CD as the left hand operand and ROM as the right hand operand?

    If that list of possibilities is hard-coded, I'd just remove the hyphen-minus and have CDROM as the label. If it's not hard-coded I'd use a dictionary, as it's resiliant in the face of even more cases where something can't be an identifier.

提交回复
热议问题