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
}
j'ai été obligé d'ajouter icomplémentaire à SomeOtherImp pour pouvoir appeler StaticClass.DoBar Et maintenant je ne peux pas mettre en œuvre ISome avec SomeOtherImp ....C# appel méthode générique avec la contrainte plus forte
Quelle est la question réelle? –
Comment appeler SomeStaticClass.Créez à partir de la méthode implémentée par ISome.Get(). –
Pouvez-vous fournir le code de 'ISomeInterface'? Vous nous montrez «ISome» seulement. –