c# - Implementing generic interface that takes a generic interface as a parameter -
i have these 2 interfaces
/// <summary> /// represents interface knows how 1 type can transformed type. /// </summary> /// <typeparam name="tinput"></typeparam> /// <typeparam name="toutput"></typeparam> public interface itransformer<in tinput,out toutput> { toutput transform(tinput input); } public interface itransform { toutput transform<tinput,toutput>(itransformer<tinput, toutput> transformer); }
i have class in in want implement itranform this.
public class messagelogs :itransform { // am not able implement itransform interface // messagelogs getting binded in param not getting binded // tinput in transform<tin,tout> // public t transform<messagelogs, t>(itransformer<messagelogs, t> transformer) { return transformer.transform(this); } }
how correctly without losing genericness of 2 interfaces? have many tranformers.
the interface requires implemented method generic in both tinput , toutput. in other words, messagelogs must able accept other types tinput well. that's not want. you're going need like:
public interface itransformer<in tinput,out toutput> { toutput transform(tinput input); } public interface itransform<tinput> { toutput transform<toutput>(itransformer<tinput, toutput> transformer); } public class messagelogs : itransform<messagelogs> { public toutput transform<toutput>(itransformer<messagelogs, toutput> transformer) { return transformer.transform(this); } }
Comments
Post a Comment