namespace Test
{
#region Not my code
public interface IAdditional
{
}
public interface ISome
{
ISomeOther<T> GetSomeother<T>() where T : class;
}
public interface ISomeOther<T> where T : class
{
void DoFoo(T obj);
}
public class AnotherClass<T> where T : class
{
}
public static class StaticClass
{
public static void DoBar<T>(AnotherClass<T> anotherClass, T obj) where T : class, IAdditional
{
}
}
#endregion
#region MyCode
public class SomeOtherImp<T> : ISomeOther<T> where T : class, IAdditional //Have to add IAdditional constraint to call StaticClass.DoBar
{
private AnotherClass<T> _anotherClass;
public void DoFoo(T obj)
{
StaticClass.DoBar<T>(_anotherClass, obj); //I do need to call StaticClass.DoBar here....
}
}
public class ISomeImp : ISome
{
public ISomeOther<T> GetSomeother<T>() where T : class
{
return new SomeOtherImp<T>(); //Can't do this no IAdditional constraint on T
}
}
#endregion
}
我被迫加IAdditional到SomeOtherImp到能夠調用StaticClass.DoBar 現在我不能SomeOtherImp實現ISome ....C#調用泛型方法
什麼是實際問題? – 2010-09-15 14:38:07
如何從ISome.Get()實現的方法調用SomeStaticClass.Create。 –
2010-09-15 14:47:41
你能提供'ISomeInterface'的代碼嗎?你只給我們展示ISome。 – 2010-09-15 14:56:43