除非是当前程序集或是mscorlib,不然需要指定程序集 var asm = Assembly.LoadFile(@"C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Drawing.dll"); Type myType = asm.GetType("System.Drawing.Color");
代码是这样的 myBehaviorType 是类中的一个属性 初始为null 通过set typeName 得到type 需要在什么地方指定程序集? 还有其他方法吗? private Type myBehaviorType = null; public string behaviorType { get { return myBehaviorType.ToString(); } set { myBehaviorType = System.Type.GetType(value, true);} }
构造时候指定,或者在public string behaviorType内指定不也行码?
但是 如果每个都要手动去指定那不是很麻烦,而其以后遇到别的类型也要在手动制动啊,没有自动的什么方法吗? 我在类头文件中 添加 using System.Drawing;的引用也不行!
不能这样吗?private Type myBehaviorType = null; public Type behaviorType { get { return myBehaviorType; } set { myBehaviorType = value; } }用的时候this.behaviorType = typeof(T);
我在设置属性behaviorType的时候 只知道Type的string 随意只能设置string
那可能要定义一个列表吧,例如 static Dictionary<string, string> asmDicts = new Dictionary<string, string>() { {"System.Drawing",@"C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Drawing.dll"} };然后用的时候 string typeStr = "System.Drawing.Color"; string asmStr=null; Type myType; int index = typeStr.LastIndexOf('.'); if (index > -1) asmStr = typeStr.Substring(0, index); var asm = Assembly.LoadFile(asmDicts[asmStr]); if(asm!=null) myType = asm.GetType();
Type myType = asm.GetType("System.Drawing.Color");
myBehaviorType 是类中的一个属性
初始为null 通过set typeName 得到type
需要在什么地方指定程序集? 还有其他方法吗? private Type myBehaviorType = null;
public string behaviorType
{
get { return myBehaviorType.ToString(); }
set { myBehaviorType = System.Type.GetType(value, true);}
}
我在类头文件中 添加 using System.Drawing;的引用也不行!
public Type behaviorType
{
get { return myBehaviorType; }
set { myBehaviorType = value; }
}用的时候this.behaviorType = typeof(T);
我在设置属性behaviorType的时候 只知道Type的string 随意只能设置string
{
{"System.Drawing",@"C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Drawing.dll"}
};然后用的时候 string typeStr = "System.Drawing.Color";
string asmStr=null;
Type myType;
int index = typeStr.LastIndexOf('.');
if (index > -1)
asmStr = typeStr.Substring(0, index);
var asm = Assembly.LoadFile(asmDicts[asmStr]);
if(asm!=null)
myType = asm.GetType();