比方说,我有以下几点:泛型类
public class DataType1
{
public DataType1() { }
public string Read() { return "dt1"; }
}
public class DataType2
{
public DataType2() { }
public string Read() { return "dt2"; }
}
和公用类:
然后,在我的主要应用程序:
class Program
{
static void Main(string[] args)
{
var test1 = new Logger<DataType1>();
test1.Read(); // I want this to equal "dt1";
var test2 = new Logger<DataType2>();
test2.Read(); // I want this to equal "dt2";
}
}
我认识到,我正在尝试做一种协变。但是,我不能从Logger继承DataType1/DataType2 - 这会违反体系结构(即DataType1/DataType2位于DAL,程序员需要通过Logger才能访问DAL)。
有关如何完成此任务的任何想法?
谢谢。
'类记录仪其中T:SomeInterfaceWithReadMethod' –
leppie
2015-02-11 05:53:02