public class Base<S>
{
public static Derived<S, T> Create<T>()
{
return new Derived<S, T>(); //if not public, I wont get it here.
}
}
public class Derived<S, T> : Base<S>
{
public Derived() //the problem, dont want it public
{
}
}
这是我得到的基本结构。
要求:
1)我根本不希望Derived<,>
构造调用Derived<,>
类的实例,无论是通过构造函数还是静态方法。我希望它只能通过Base<>
. 所以这就出来了:
public class Derived<S, T> : Base<S>
{
Derived()
{
}
public static Derived<S, T> Create()
{
return new Derived<S, T>();
}
}
2)Derived<,>
类本身必须是公共的(这意味着我不能私有嵌套Derived<,>
在里面Base<>
)。只有这样我才能Derived<,>
从Create
.Base<>
可能吗?