K
KK
Consider the following code block:
Rectangle r = new Rectangle();
Type t0 = r.GetType()
Type t1 = typeof(System.Drawing.Rectangle);
Type t2 = Type.GetType("System.Drawing.Rectangle");
Type t3 = Type.GetType(r.GetType().ToString());
Console.WriteLine("Results:\nt0: {0}\nt1: {1}\nt2: {2}\nt3: {3}", t0, t1,
t2, t3);
<<<<<
While t0 and t1 print the results one might expect, t2 and t3 return null.
I'm really perplexed by this. If I supply the fully qualified type name,
isn't that enough to uniquely determine the type? Apparently not! My
question is this: given only a string containing fully qualified type name
(e.g. "System.Drawing.Rectangle"), is there a consistent way to get the Type
object that the string corresponds to that will work with most types?
Thanks for any help you can give!
Rectangle r = new Rectangle();
Type t0 = r.GetType()
Type t1 = typeof(System.Drawing.Rectangle);
Type t2 = Type.GetType("System.Drawing.Rectangle");
Type t3 = Type.GetType(r.GetType().ToString());
Console.WriteLine("Results:\nt0: {0}\nt1: {1}\nt2: {2}\nt3: {3}", t0, t1,
t2, t3);
<<<<<
While t0 and t1 print the results one might expect, t2 and t3 return null.
I'm really perplexed by this. If I supply the fully qualified type name,
isn't that enough to uniquely determine the type? Apparently not! My
question is this: given only a string containing fully qualified type name
(e.g. "System.Drawing.Rectangle"), is there a consistent way to get the Type
object that the string corresponds to that will work with most types?
Thanks for any help you can give!