2

the question probably already has been answered, but i honestly dont know what to search for, an "Reflection" did not solve my issue.

I want to call a field by a string such as:

    string str = "Green";
    Color colorForPurpose = Color.str;

Of course this does not work, but the purpose should be clear.

Anyone has an idea?

Philipp W.
  • 51
  • 5
  • 2
    Winforms? [Color.FromName](https://msdn.microsoft.com/en-us/library/system.drawing.color.fromname(v=vs.110).aspx). – Sinatr Jun 22 '18 at 11:17
  • 1
    Are you asking *in general* or specifically about `Color`? I ask because the answer to your question highly depends on this distinction. – Lasse V. Karlsen Jun 22 '18 at 11:18
  • What are you trying to access a field or enum? An attribute of a class is completely different. – L_J Jun 22 '18 at 11:27

1 Answers1

5

You can use

string str = "Green";
Color colorForPurpose = Color.FromName(str)

See this post for further information.