In this post, I’ll explain how you can provide string values for an enum. Usually, we’ll assign integer (by default), long or as a bit field using FlagAttribute.
For assigning a string value first you need to create a class inherited from Attribute class.
Image may be NSFW.
Clik here to view.
Once your attribute class is ready. You can use the attribute and your string values as below:
Image may be NSFW.
Clik here to view.
Now, for accessing the enum string value and converting the string values to respective enum , it’s good to have an extension so that you can convert back and forth seamlessly.
Image may be NSFW.
Clik here to view.
Now, you are fully occupied for using the enum and its custom values. Below is an example on how to use it.
Image may be NSFW.
Clik here to view.
Image may be NSFW.
Clik here to view.
Hope this helps.
Thanks.
Image may be NSFW.Clik here to view.
