I am stuck in implementation of generic class and interface. I am not sure what i wanted to do is possible or not.
here is my code:- I have defined a generic class whose type not define like
public class Response<T>
{
public T Data { get; set; }
public Response()
{
Data = default(T);
}
}
and a Interface which right now have one function
public interface IOInterface<T> where T : Response<T>
{
Response<T> ReadAdvantechChannel(Dictionary<string, string> IOParameters);
}
And one derive class who will implements this interface :-
public class AdvantechOperation : IOInterface<T>
{
public Response<AIRecordInfo> ReadAdvantechChannel(Dictionary<string, string> IOParameters)
{
Response<AIRecordInfo> resp = new Response<AIRecordInfo>();
}
}
and AIrecordinfo is again class
public class AIRecordInfo
{
double[] ArryMaxValueAIdouble;
double[] ArryMinValueAIdouble;
double[] ArryAVGValueAIdouble;
}
what i want to do that implement a class who implement define interface but return type of interface function is not clear for my future derived class thats why i have made it generic and try to implement it my present class "AdvantechOperation". My interface will have three functions and all function return type will different to each other thats why i made it generic return type Response and in my present class AdvantechOperation, T replaced by AIRecordInfo. But I am facing below Error while compiling this project
Error 7 The type 'T' cannot be used as type parameter 'T' in the generic type or method 'IOModule.IOInterface'. There is no boxing conversion or type parameter conversion from 'T' to 'IOModule.Response'. D:\MTS\SMS\DAQAdvantechdll\DAQAdvantechdll\IOCommunication.cs 28 18 IOModule Error 8 'IOModule.AdvantechOperation' does not implement interface member 'IOModule.IOInterface.ReadAdvantechChannel(System.Collections.Generic.Dictionary)'. 'IOModule.AdvantechOperation.ReadAdvantechChannel(System.Collections.Generic.Dictionary)' cannot implement 'IOModule.IOInterface.ReadAdvantechChannel(System.Collections.Generic.Dictionary)' because it does not have the matching return type of 'IOModule.Response'. D:\MTS\SMS\DAQAdvantechdll\DAQAdvantechdll\IOCommunication.cs 28 18 IOModule