开发者

C# - Is it possible to parse a Type from a string - e.g (Pseudo code) Type t = Type.Parse("Int32");

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 dy开发者_开发知识库namically 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");


You have to use the full-qualified name, but you can use Type.GetType

Type t = Type.GetType("System.Int32");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜