public interface IMyClassClient
{
MyClass<T> Default();
//T cannot be found, error
}
public class MyClass<T>
{
private IMyClassClient owner;
private MyClass<T> test;
public MyClass<T> Test
{
get { return _test;}
set
{
if(value ==owner.Default())
{
//how to form this call?^^^^^
MessageBox.Show("Well that's true");
}
}
}
}
目标是实施IMyClassClient
的班级将处理IMyClassClient.Default()
我在这里缺少什么?
编辑:
经过一番思考后,以下是我需要完成的更好的措辞:
public interface IMyInterface
{
//see Instance member in SomeClass, down below? How to declare it here?
}
public class SomeClass:IMyInterface
{
public MyClass<int> Instance()
{
return new myClass<int>(); //for brevity
}
}
答案 0 :(得分:1)
你也应该在界面中使用泛型,如果你不这样做,你就不能写MyClass<T> Default()
,那里你没有T
。
public interface IMyClassClient<T>
{
MyClass<T> Default();
}
public class MyClass<T>
{
private IMyClassClient<T> owner;
private MyClass<T> test;
public MyClass<T> Test
{
get { return test; }
set
{
if (value == owner.Default())
{
MessageBox.Show("Well that's true");
}
}
}
}
编辑:当然,你可以在非通用接口中声明geeric函数
public interface IMyInterface
{
MyClass<T> Instance<T>();
}
public class SomeClass : IMyInterface
{
public MyClass<int> Instance()
{
return new myClass<int>();
}
}