c#求指点DLL 文件中类的继承
如果我有个主程序里面有 5个类 class A,B,C,D,E,还有一个类E,但是E 是从D继承过来的,我想把E写成封装的DLL 文件,然后由外部载入使用Assembly动态加载 。可是D的这个类跟A.B.C都有关系,E要如何写呢? c#
[解决办法]
public class D
{
public A a { get; set; }
public B b { get; set; }
public C c { get; set; }
}
public class E : D {}
......
static void Main()
{
Console.WriteLine(DoSomething(new E()));
Console.WriteLine(DoSomething(new D()));
}
static string DoSomething(D obj)
{
......
}
public interface IDoSomething
{
public string DoSomething();
}
public class E : IDoSomething
{
...... <- 把实现接口的时候需要用到的东西放过来
public string DoSomething()
{
...... <- 具体干活,参考以前的DoSomething(D obj)
}
}
public class D : IDoSomething
{
...... <- 和以前一样
public string DoSomething()
{
...... <- 具体干活,参考以前的DoSomething(D obj)
}
}
static void Main()
{
Console.WriteLine(DoSomething(new E()));
Console.WriteLine(DoSomething(new D()));
}
static string DoSomething(IDoSomething obj) <- 传入的是接口,所以D和E都能用
{
...... <- 不用管obj具体是什么,只要拿到obj.DoSomething()就可以了
}