Mattias said:
Type.GetType() or Assembly.GetType(). Since there can be multiple
types with the same name in different assemblies, you need to specify
which asembly to look in one way or another.
Sorry, I guess I'm a bit dense. I understand that
Type.GetType("System.Drawing.Color") will give me a Type object with all
the info about that class, but how can I use a Type object to actually
*create an instance* of that class? In my example above I suppose I
could get the PropertyInfo for the static property
System.Drawing.Colors.Red, but I'm not sure that is a generic solution
for all constant expressions of all types. I'm looking for a generic
solution to produce an instance of a constant given that constant
expression as a string and the type, like for example:
Class String Constant expression string
============ ======
"System.Drawing.Color" "Red"
"System.Int32" "0x0f"
"MyOwnClass.PiDouble" "3.14"
etc.
As far as I can see, if you want to call a method/property on an
instance via reflection, the instance has to already be created. I
suppose I could make my own factory to parse expressions and figure out
how to create them, it just seems like .NET already has that somewhere.
Either that or I have a poor understanding of the problem, which could
very well be.
-- kov