Is it possible to parse a Type from a string in C# - e.g (Pseudo code)
Type t = Type.Parse("Int32");
This is for an application that dynamically maps data from varying formats to our inhouse format, and I need to be able to dynamically determine type to do this.
(.NET 3.5)
Yes, you want Type.GetType
(the static method, not the instance one inherited from object
).
For example:
Type t = Type.GetType("System.Int32");
Note that for types outside the current assembly or mscorlib, you'll need to specify the type's fully qualified name, which will be the full name (with namespace) and the display name of the assembly containing that type, separated by a comma—for example:
Type t = Type.GetType("System.Collections.Specialized.StringCollection,System");
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