【发布时间】:2011-12-27 14:06:05
【问题描述】:
我目前正在学习 .NET 和 C#,所以我对它很陌生,我必须创建一个包含服务器和客户端的“通讯录”。我创建了一个服务器使用的接口,描述了此通讯录可用的操作,如下所示:
bool AjouterContact(string num, string nom, string prenom, string mail, string telephone);
bool SupprimerContact(string num);
bool ModifierContact(string num, string nom, string prenom, string mail, string telephone);
List<string[]> RecupererContacts();
我曾经在我的客户端中引用该接口的 .dll,它工作正常,但我现在需要动态加载这个 .dll。这就是我正在做的:
Assembly a = Assembly.LoadFrom("../../../RemotingInterfaces/bin/Debug/RemotingInterfaces.dll");
Module[] modules = a.GetModules();
Module module = modules[0];
Type[] types = module.GetTypes();
foreach (Type type in types)
{
Console.WriteLine(" Le type {0} a cette (ces ) methode (s) : ", type.Name);
Console.WriteLine("Type information for:" + type.FullName);
Console.WriteLine("\tIs Class = " + type.IsClass);
Console.WriteLine("\tIs Enum = " + type.IsEnum);
Console.WriteLine("\tAttributes = " + type.Attributes);
MethodInfo[] mInfo = type.GetMethods();
foreach (MethodInfo mi in mInfo)
Console.WriteLine(" {0}", mi);
}
这工作并在控制台中写入所有方法。但我想知道如何使用这些方法。
我希望我已经足够清楚了。同样,我是 .NET 和 C# 的新手,所以我真的不知道它是如何工作的。
【问题讨论】:
标签: c# .net reflection interface