如何将String变量转换为ControlType

本文关键字:转换 ControlType 变量 String | 更新日期: 2023-09-27 18:00:56

我有一个包含控件类型的String变量。示例:"按钮"、"文本框"或"标签"。我想从这个变量中获取PropertyInfo。我已经运行了这个代码,但在第一行返回Null:

Type type = Type.GetType(ControlType);
PropertyInfo[] properties = type.GetProperties();

知道吗?

如何将String变量转换为ControlType

Type.GetType()需要程序集限定名称,并且区分大小写。

因此,对于windows窗体应用程序来说,它将采用以下格式:

Type.GetType("System.Windows.Forms.TextBox, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"`

对于Web表单,它将是System.Web.UI.WebControls命名空间等。