I would like to use my own enum in a project setting (from Visual studio, menu project, properties, tab settings).
I can select a lot of default types there, but even types from other projects in my solution, but not the project itsself.
Is it possible to use an enumeration type from the project itsself as type for a setting?
There are two ways to convert an Enum to String in Java, first by using the name() method of Enum which is an implicit method and available to all Enum, and second by using toString() method.
By default enums have their own string values, we can also assign some custom values to enums.
If the enum is only used within one class, it should be placed within that class, but if the enum is used between two or more classes, it ought to either be in it's own code file, or in a conglomerated code file that contains all the enum for a particular assembly.
The default value of an enum E is the value produced by the expression (E)0 . Without overriding the default values, printing default(E) returns Foo since it's the first-occurring element.
Yes, but it takes a bit of twiddling. See this article for pointers on how to accomplish it.
Not as far as I would know.
But you could do something like:
string setting = ConfigurationManager.AppSettings.Get("yourSetting");
YourEnum yourEnumVariable = (YourEnum)Enum.Parse(typeof(YourEnum), setting);
(Written just here without IDE sytax checking, please forgive any syntax mistakes.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With