あなたが何をしようとしているのか完全にはわかりませんが、次のようなものがある場合:
public class FWrapper<TChild, TResult>{
private int childCount;
private string name;
private Func<TChild, TResult> function;
public Func<TChild, TResult> Function { get { return function; } }
public FWrapper(Func<TChild, TResult> Function, int ChildCount, string Name){
this.childCount = ChildCount;
this.name = Name;
this.function = Function;
}
}
public class Node<TChild, TResult>{
private FWrapper<TChild, TResult> fw;
private IEnumerable<TChild> children;
public Node(FWrapper<TChild, TResult> FW, IEnumerable<TChild> Children){
this.fw = FW;
this.children = Children;
}
public IEnumerable<TResult> Evaluate(){
var results = new List<TResult>();
foreach(var c in children){
results.Add(fw.Function(c));
}
return results;
}
}
これで、TChild をパラメーターとして取り、同じ TChild および TResult 型で動作する TResult と Node クラスを返す任意の関数を受け取る FWrapper クラスができました。たとえば、これを行うことができます (簡単な例)。
//Generic function that takes an int and returns a string
var func = new Func<int, string>(childInt => {
var str = "'" + childInt.ToString() + "'";
return str;
});
var fw = new FWrapper<int, string>(func, 10, "Foobar");
var children = new List<int>(){ 1,2,3,4,5,6,7,8,9,10 };
var node = new Node<int, string>(fw, children);
var results = node.Evaluate();
foreach(var r in results){
Console.WriteLine(r);
}
//'1'
//'2'
//..
//..
//'9'
//'10'