关于System.Type.GetType()和typeof()
关于System.Type.GetType()和typeof()
我在动态创建控件的时候,遇到这样的问题:
s1=控件类型.这个控件类型字符串的写法跟 创建该控件时new 后面的字符串一样,也即等于typeof(控件).Name
问题是我如何根据s1=控件类型字符串去创建该控件?
我现在只能用区分两种的方法去做:
1.系统自带控件:
string assemblyQualifiedName = typeof(System.Windows.Forms.Control).AssemblyQualifiedName;
string assemblyInformation = assemblyQualifiedName.Substring(assemblyQualifiedName.IndexOf(","));
2.自定义控件:
string assemblyQualifiedName = System.Type.GetType(s1).AssemblyQualifiedName;
string assemblyInformation = assemblyQualifiedName.Substring(assemblyQualifiedName.IndexOf(","));
也即自定义控件用gettype,系统自带控件用typeof.
如何做在一起?