In my project I have the following three interfaces, which are implemented by classes that manage merging of a variety of business objects that have different structures.
public interface IMerger<TSource, TDestination>
{
TDestination Merge(TSource source, TDestination destination);
}
public interface ITwoWayMerger<TSource1, TSource2, TDestination>
{
TDestination Merge(TSource1 source1, TSource2 source2, TDestination destination);
}
public interface IThreeWayMerger<TSource1, TSource2, TSource3, TDestination>
{
TDestination Merge(TSource1 source1, TSource2 source2, TSource3 source3, TDestination destination);
}
This works well, but I would rather have one IMerger
interface which specifies a variable number of TSource
parameters, something like this (example below uses params
; I know this is not valid C#):
public interface IMerger<params TSources, TDestination>
{
TDestination Merge(params TSource sources, TDestination destination);
}
It there any way to achieve this, or something functionally equivalent?