Now my aim was to have one pair with an base type and a type definition (Requirement A). For the type definition I want to use inheritance (Requirement B). The use should be possible, without explicite knowledge over the base type (Requirement C).
After I know now that the gernic constraints are not used for solving the generic return type, I experimented a little bit:
Ok let's introducte Get2:
class ServiceGate
{
public IAccess<C, T> Get1<C, T>(C control) where C : ISignatur<T>
{
throw new NotImplementedException();
}
public IAccess<ISignatur<T>, T> Get2<T>(ISignatur<T> control)
{
throw new NotImplementedException();
}
}
class Test
{
static void Main()
{
ServiceGate service = new ServiceGate();
//var bla1 = service.Get1(new Signatur()); // CS0411
var bla = service.Get2(new Signatur()); // Works
}
}
Fine, but this solution reaches not requriement B.
Next try:
class ServiceGate
{
public IAccess<C, T> Get3<C, T>(C control, ISignatur<T> iControl) where C : ISignatur<T>
{
throw new NotImplementedException();
}
}
class Test
{
static void Main()
{
ServiceGate service = new ServiceGate();
//var bla1 = service.Get1(new Signatur()); // CS0411
var bla = service.Get2(new Signatur()); // Works
var c = new Signatur();
var bla3 = service.Get3(c, c); // Works!!
}
}
Nice! Now the compiler can infer the generic return types. But i don't like it.
Other try:
class IC<A, B>
{
public IC(A a, B b)
{
Value1 = a;
Value2 = b;
}
public A Value1 { get; set; }
public B Value2 { get; set; }
}
class Signatur : ISignatur<bool>
{
public string Test { get; set; }
public IC<Signatur, ISignatur<bool>> Get()
{
return new IC<Signatur, ISignatur<bool>>(this, this);
}
}
class ServiceGate
{
public IAccess<C, T> Get4<C, T>(IC<C, ISignatur<T>> control) where C : ISignatur<T>
{
throw new NotImplementedException();
}
}
class Test
{
static void Main()
{
ServiceGate service = new ServiceGate();
//var bla1 = service.Get1(new Signatur()); // CS0411
var bla = service.Get2(new Signatur()); // Works
var c = new Signatur();
var bla3 = service.Get3(c, c); // Works!!
var bla4 = service.Get4((new Signatur()).Get()); // Better...
}
}
My final solution is to have something like ISignature<B, C>
, where B ist the base type and C the definition...