How to create a value in enum with '&'
I need to create a enum value something like this' DESIGN & BUILD'. I am writing an importer service and that imports the types like above. I need to compare it with ones in the Db.
Is it possible to create enum values like above? Moreover, I think we could also do it by taking a regex e开发者_开发知识库xpression that yields only text but not any sort of symbols, I mean we only get 'DESIGNBUILD'.
You can't. Enum value names have to be valid C# identifiers, and that excludes &
. I suggest you use DescriptionAttribute
or something similar to provide more flexible metadata for the enum values.
While you could use a regular expression to perform the mapping, I believe you'll end up with a more flexible result if you use metadata. You can then easily build a Dictionary<string, YourAttributeType>
and vice versa.
精彩评论