I am creating classes for the Stack Exchange API. The filter_object type contains a member filter_type
which will be either safe
, unsafe
, or invalid
. So I created an enum like this:
[JsonConverter(typeof(StringEnumConverter))]
public enum FilterType
{
safe,
@unsafe, // Here lies the problem.
invalid
}
Since unsafe
is a keyword, I had to add some prefix to it. But how can I make the value "unsafe" to automatically map to @unsafe
? Example JSON:
{
"filter": "....",
"filter_type": "unsafe",
"included_fields": [
"...",
"....",
"....."
]
}
How can I deserialize it, such that the filter_type
is automatically converted to FilterType.@unsafe
?
Update - Solved:
Using the @ symbol before an identifier makes it possible to be the same as keywords. It works fine even though the @ appears in intellisense.