Reputation: 1854
I want to create a baseclass, which has a few default methods. This baseclass should use a generic interface.
Is this possible? (because code-example below doesn't compile, the problem lies within T1,T2,T3 -> first line)
public abstract class ServiceBase<T> where T: IService<T1,T2,T3>
{
public abstract IEnumerable<T3> Search(T1 query);
public abstract T3 Add(T2 input);
public bool Monitor()
{
return true;
}
}
The reason I want to use is, is for a service, I can type:
public class WhatEverService : ServiceBase<IWhatEverService>
With IWhatEverService inheriting from IService<T1,T2,T3> (with T1,T2,T3 some different types)
FYI:
public interface IWhatEverService: IService<WhatEverType1, WhatEverType2, WhatEverType3>
Upvotes: 1
Views: 118
Reputation: 11549
You have not told compiler what T1, T2 and T3 are and it is not able to infer these types from usage.
public abstract class ServiceBase<T,T1,T2,T3> where T : IService<T1,T2,T3>
Upvotes: 2