Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# @ in enum generated classes from XSD

Tags:

c#

enums

xsd

Using xsd.exe I've got an enum which has an @ symbol in front of one of the elements. I can't work out why, and I can't work out what it's for or what it means. Searching Google for a symbol isn't terribly productive.

Original XSD fragment:

  <xs:simpleType name="stopLocation">
    <xs:restriction base="xs:string">
      <xs:enumeration value="default"/>
      <xs:enumeration value="near"/>
      <xs:enumeration value="far"/>
      <xs:enumeration value="nearExact"/>
      <xs:enumeration value="farExact"/>
    </xs:restriction>
  </xs:simpleType>

Generated class fragment:

public enum stopLocation {
    @default,
    near,
    far,
    nearExact,
    farExact,
}

(Yes, the final element has a comma which VS seems happy with)

Thanks.

like image 349
GeoffM Avatar asked Dec 13 '25 05:12

GeoffM


2 Answers

It escapes the default keyword from C#.

See this question: What's the use/meaning of the @ character in variable names in C#?

like image 55
Daniel A. White Avatar answered Dec 14 '25 18:12

Daniel A. White


This is happening because the enum value name (default) is a reserved word. In C# reserved words must be appended with an @ so the compiler knows how to interpret them.

You would see the same behavior with a name like 'event' or 'public'.

like image 45
Nathan Taylor Avatar answered Dec 14 '25 20:12

Nathan Taylor