Windows应用程序参考

问题描述:

大家好,



对于运行时,您需要使用反射.请点击链接
反射(C#编程指南)

问候
AR
Hi,

for Runtime, You need to use reflection. Please go through with the link
Reflection (C# Programming Guide)

Regards
AR


您好,

System.Reflection是您的朋友在这里.这是在运行时获取引用程序集的方式.
Hi there,

System.Reflection is your friend here. This is how you get the referenced assemblies in run-time.
StringBuilder builder = new StringBuilder();

Assembly currentAssembly = Assembly.GetExecutingAssembly();
AssemblyName[] referencedAssemblies = currentAssembly.GetReferencedAssemblies();
foreach (AssemblyName assembly in referencedAssemblies)
{
    builder.AppendLine(assembly.FullName);
}

MessageBox.Show(builder.ToString());


这里要注意的一件事是,该列表 可能与VS的解决方案资源管理器中的引用列表不完全相同 .造成这种情况的原因有很多,但是主要原因是,即使您将引用添加到项目中,也不会在您的代码中使用它们.这些程序集将不会在运行时被引用或加载,因此不会列出.

希望对您有所帮助:)问候


One thing to note here is that, this list may not be exactly equal to the the list of references in the Solution Explorer of VS. There are numerous reasons for this, but the main reason is that, even though you add references to a project, they won''t be used in your code. Those assemblies will not be referenced or loaded in run time, hence they won''t be listed.

Hope this helps :) Regards


这里是您的另一个例子

Here is another example for you

Assembly a = Assembly.LoadFrom("c:\\COPYPROT.exe");
           Type[] types = a.GetTypes();
           foreach (Type typ in types)
           {
               object obj;
               if (typ.Name.ToUpper() == "READENCRYPTION")
               {
                   obj = Activator.CreateInstance(typ);
                   MethodInfo mi = typ.GetMethod("EncryptFile");
                   mi.Invoke(obj, new object[] { (string)"1", (string)"2", (string)"0408" });
               }
           }



这里 EncryptFile 方法具有3个参数



Here EncryptFile method have 3 parameters