Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
类似于Java for.NET中的反射_.net_C# 4.0_Reflection - Fatal编程技术网

类似于Java for.NET中的反射

类似于Java for.NET中的反射,.net,c#-4.0,reflection,.net,C# 4.0,Reflection,参考这个 或 在.Net平台中有类似的功能吗?反射提供了封装程序集、模块和类型的对象(类型)。可以使用反射动态创建类型实例、将类型绑定到现有对象、从现有对象获取类型并调用其方法或访问其字段和属性 我使用反射动态加载程序集,并在反射的帮助下显示其表单 Step 1: Loading an assembly form the specified path. string path = Directory.GetCurrentDirectory() + @"\dynamicdll.dll"; tr

参考这个


在.Net平台中有类似的功能吗?

反射提供了封装程序集、模块和类型的对象(类型)。可以使用反射动态创建类型实例、将类型绑定到现有对象、从现有对象获取类型并调用其方法或访问其字段和属性

我使用反射动态加载程序集,并在反射的帮助下显示其表单

Step 1: Loading an assembly form the specified path.

string path = Directory.GetCurrentDirectory() + @"\dynamicdll.dll";
try
{
    asm = Assembly.LoadFrom(path);
}
catch (Exception)
{
}

Step 2: Getting all forms of an assembly dynamically & adding them to the list type.

List<Type> FormsToCall = new List<Type>();
Type[] types = asm.GetExportedTypes();
foreach (Type t in types)
{
    if (t.BaseType.Name == "Form")
        FormsToCall.Add(t);
}

Step 3:

int FormCnt = 0;
Type ToCall;
while (FormCnt < FormsToCall.Count)
{
     ToCall = FormsToCall[FormCnt];
     //Creates an instance of the specified type using the constructor that best matches the specified parameters.
     object ibaseObject = Activator.CreateInstance(ToCall);
     Form ToRun = ibaseObject as Form;
     try
     {
          dr = ToRun.ShowDialog();
          if (dr == DialogResult.Cancel)
          {
             cancelPressed = true;
             break;
          }
          else if (dr == DialogResult.Retry)
          {
             FormCnt--;
             continue;
          }
     }
     catch (Exception)
     {
     }
     FormCnt++;
}
步骤1:从指定路径加载程序集表单。
字符串路径=Directory.GetCurrentDirectory()++“\dynamicdl.dll”;
尝试
{
asm=汇编.LoadFrom(路径);
}
捕获(例外)
{
}
步骤2:动态获取程序集的所有表单&将它们添加到列表类型。
List FormsToCall=new List();
Type[]types=asm.GetExportedTypes();
foreach(类型中的类型t)
{
if(t.BaseType.Name==“Form”)
FormsToCall.Add(t);
}
步骤3:
int-FormCnt=0;
类型ToCall;
while(FormCnt
可能吗?是的,它被称为反射。关于它,你想知道什么?有没有关于如何在.Net中使用它的教程?你可以在谷歌上轻松搜索并自己找到答案。请原谅我说我发现你在这方面没有付出任何努力。。。谷歌:“.NET反射”@Jeff:谢谢你的删除提示:)