是否可以使用dll共享类定义?我有主程序类定义和SQL连接。我需要一些DLL将数据导出到xml。但我不知道如何向dll发送数据收集。如果此类在" main"中定义程序
例如 主要代码:
namespace A
{
public void callMethod()
{
B.method(aa);
}
public class aa
{
public aa()
{
this.abList = new List<ab>();
}
public int number {get; set;}
public List<ab> abList {get;set;}
}
public class ab
{
public string text {get; set;}
}
}
DLL库:
namespace B
{
public static void method(aa atribute) // ??
{
aa. //??
}
}
答案 0 :(得分:1)
您需要创建一个包含类或实现的接口的公共库,并在两个项目中引用它。
所以而不是
因此,您将aa
类放在Common
项目中,并通过所有其他项目引用它。
如果您无法将aa
移出MainProj
,则可以使用通用界面
在Common
中定义类似:
public interface Iaa
{
int number { get; set;}
List<ab> abList { get; }
}
并在aa中实现:
public class aa : Iaa
{
public aa()
{
this.abList = new List<ab>();
}
public int number {get; set;}
public List<ab> abList {get;set;}
}
您可以在DllProject
中定义以下内容:
public static void method(Iaa atribute) // ??
{
aa.number = ...
}