[英]Get return value after invoking a method from dll using reflection
我正在使用反射加載一個DLL並嘗試調用一個返回List<customType>
。 如何調用方法並獲取返回值。 我試過這個,但說entry point not found exception
。
MethodInfo[] info= classType.GetMethods();
MethodInfo method = mInfo.FirstOrDefault(c => c.Name == "GetDetails");
object values = method.Invoke(classInstance, new object[] { param1});
值entry point not found
異常entry point not found
。
Assembly assembly = Assembly.LoadFile(@"assembly location"); // you can change the way you load the assembly
Type type = assembly.GetType("mynamespace.NameOfTheClass");
ConstructorInfo constructor = type.GetConstructor(Type.EmptyTypes);
object classObject = constructor.Invoke(new object[] { });
MethodInfo methodInfo = type.GetMethod("GetDetails");
var returnValue = (List<customType>)methodInfo.Invoke(classObject, new object[] { param1});
根據您的類是否為靜態以及構造函數是否采用任何參數,可能需要進行一些更改。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.