リフレクションを使用するか、デザインを変更する必要があります。
リフレクションを使用する場合、プロセスは複雑です。
// get the type of the object variable
var objType = theObject.GetType();
// I'm assuming that LoadItems() is a method in the current class
var selfType = GetType();
// you might need to use an overload of GetMethod() -- please read the documentation!
var methodInfo = selfType.GetMethod("LoadItems");
// this fills in the generic arguments
var genericMethodInfo = methodInfo.MakeGenericMethod(new[] { objType });
// this calls LoadItems<T>() with T filled in; I'm assuming it's a method on this class
var results = genericMethodInfo.Invoke(this, null);
results
になりますのでご注意くださいobject
。特定のList<>
タイプにしたい場合は、運が悪いです。コンパイル時にタイプが何であるかはわかりません。これを非ジェネリックにキャストIList
するか、LINQ式を使用して次のようなより便利なものに変換できます。
var niceResults = results.Cast<SomeBaseType>().ToList();
いつものように、何が起こっているのかわからない場合は、上記の関数に関するドキュメントを読んでください。