I found plenty of solutions for Enum-Parsing into given types and given enums. But I wonder what shall I do when I only have the Name of the Enum I want the values? My current solution for this is a pretty dumb switch-case scenario That does the following:
string[] result = new string[0];
switch (lvKategorie.SelectedItem.ToString())
{
case "Warten":
result = Enum.GetNames(typeof(Warten));
break;
case "Maus":
result = Enum.GetNames(typeof(Maus));
break;
I now wish a better Method because my switch case is getting way too long. I only get the Name of the Enum by a string. This is being generated by my program before and I don't even know the name of the Enum I want to get before this point of my program. So how do I choose in-code which Enum shall be taken to get the values of? (In case my solution is also parsing I just did not get it right and need FURTHER explanations on how this works.)
To be absolutely clear: I want to replace the "typeof(xyz)"-parts in the Enum.GetNames-Methods with an automatic pick of the correct enum by the string of it's name.