我正在开展一个项目,任务是创建一个 DLL 项目。在这个项目中,我有一个现有的 DLL,其中包含一组方法。使用现有的 DLL,我可以调用一些方法并在新的 DLL 中创建一些方法。
在 C# 中是否可能?创建这样一个项目的可能性和方法是什么?
我正在开展一个项目,任务是创建一个 DLL 项目。在这个项目中,我有一个现有的 DLL,其中包含一组方法。使用现有的 DLL,我可以调用一些方法并在新的 DLL 中创建一些方法。
在 C# 中是否可能?创建这样一个项目的可能性和方法是什么?
using System;
using System.Reflection;
public class Asmload0
{
public static void Main()
{
// Use the file name to load the assembly into the current
// application domain.
Assembly a = Assembly.Load("example");
// Get the type to use.
Type myType = a.GetType("Example");
// Get the method to call.
MethodInfo myMethod = myType.GetMethod("MethodA");
// Create an instance.
object obj = Activator.CreateInstance(myType);
// Execute the method.
myMethod.Invoke(obj, null);
}
}