Answer the question
In order to leave comments, you need to log in
Collection of generic plugins. How to?
I have the following task:
there is a certain class
abstract class Plugin<T>
{
public abstract T Modify(T param);
}
Answer the question
In order to leave comments, you need to log in
sealed class CompoundPlugin<T> : Plugin<T> {
private readonly IReadOnlyList<Plugin<T>> plugins;
public CompoundPlugin(IReadOnlyList<Plugin<T>> plugins) {
Contract.Requires<ArgumentNullException>(plugins != null, "arg");
Contract.Requires<ArgumentException>(plugins.Count > 0);
this.plugins = plugins;
}
public override T Modify(T param) {
return plugins.Aggregate(param, (arg1, plugin) => plugin.Modify(arg1));
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question