実行時決定型パラメータを持つリスト<T>を生成しています。私は、リスト内の項目を反復処理するのForEachメソッドを呼び出すしたいと思います:C#:ランタイム生成リストでForEachを呼び出す<T>
//Get the type of the list elements
Type elementType = GetListElementType(finfo);
Type listType = Type.GetType("System.Collections.Generic.List`1["
+ elementType.FullName + "], mscorlib", true);
//Get the list
var list = getList.Invoke(null, new Object[] { finfo.GetValue(myObject) });
MethodInfo listForEach = listType.GetMethod("ForEach");
//How do I do this? Specifically, what takes the place of 'x'?
listForEach.Invoke(list, new object[] { delegate (x element)
{
//operate on x using reflection
}
});
私の実行時に生成されたリストのタイプに含まれるのForEachメソッドに対応するMETHODINFO考えると、使用してそれを呼び出すための適切な方法は何ですか匿名の方法?上記は私の最初のスタブですが、匿名メソッドのパラメータの型を宣言する方法はわかりません。
ニース。 +1私はそれが好きです。 –