これは間違った方法と方向に近づいています。C# 'System.DateTime'から 'object []'に変換できません。methodinfo.invoke
すべてのStart
メソッドを私のソリューションで起動しようとしています。私はエラーに遭遇し、「起動」のパラメータとして日付を渡そうとしたときに
は、Startメソッドは
ただし日時を要し
のSystem.DateTimeから変換することはできませんと、[]
オブジェクトに
任意の考えは
GWS感謝を歓迎します
scheduleDate = new DateTime(2010, 03, 11);
Type[] typelist = GetTypesInNamespace(Assembly.GetExecutingAssembly(), "AssetConsultants");
foreach (Type t in typelist)
{
var methodInfo = t.GetMethod("Start", new Type[] {typeof(DateTime)});
if (methodInfo == null) // the method doesn't exist
{
// throw some exception
}
var o = Activator.CreateInstance(t);
methodInfo.Invoke(o, scheduleDate);
}
可能性のある重複した[C#のリフレクション呼び出し - タイプ 'XXX' のオブジェクトは、 'System.Objectの\ [\]' 型に変換できない](のhttp://のstackoverflowを。 com/questions/21855840/c-sharp-reflection-invoke-object-of-type-xxx-can-be-to-type-sy) –