首先声明在问此弱智的问题前没进行思考。问题是:
有没有这样的功能?
//1
Namespace ns=Application.Namespaces[0];
foreach(Assembly asm in ns) { }
//2
Assembly asm = Assembly.GetEntryAssembly();
foreach(string sNamespace in asm.Namespaces) { }
有没有这样的功能?
//1
Namespace ns=Application.Namespaces[0];
foreach(Assembly asm in ns) { }
//2
Assembly asm = Assembly.GetEntryAssembly();
foreach(string sNamespace in asm.Namespaces) { }
Assembly asm = Assembly.GetEntryAssembly();
foreach(string sNamespace in asm.Namespaces) { }这个不就是反射么//1
Namespace ns=Application.Namespaces[0];
Application.Namespaces有这个属性么?? 刚试了下没点出来。MSDN也没查到。。OUT了。
为了系统的灵活(框架化),想在数据库中保存这些条件,因此需要用最少的条件创建一个窗体,
如果能做到只保存窗体类名那将是最理想的了。void LoadForm()
{
Type tp = ftCommon.GetTypeByStr(cd2, path2, namespace2); //数据库中的字符串转为类
Form frm = ftApp.ShowChild(tp, sp2, true, false);
}public static Type GetTypeByStr(string sType, string sAssembly, string sNamespace)
{
Assembly asm = null;
asm = GetAssemblyByName(sAssembly);
if (sNamespace != "") { sNamespace += "."; }
Type tp = asm.GetType(sNamespace + sType);
return tp;
}public static Assembly GetAssemblyByName(string sAssembly)
{
//为空,取当前可执行文件的
if (sAssembly == "") { return Assembly.GetEntryAssembly(); } //在已加载的中查找
Assembly[] asms = AppDomain.CurrentDomain.GetAssemblies();
foreach (Assembly asm in asms) //基本上没什么意义,因为在项目中虽有引用但没加载过的在此找不到
{
string sName = "";
sName = asm.GetName().Name;
if (sName == sAssembly) { return asm; }
} //加载文件
try
{
return Assembly.Load(sAssembly);
}
catch (Exception ex) { throw ex; }
}