我想調用另一個調用方法的返回類中的方法。C#鑄造從調用返回的對象並調用該對象上的方法
我想從ConnectionProfile
類中調用GetConnectionCost()方法。通過調用NetworkInformation類中的GetInternetConnectionProfile
方法返回ConnectionProfile
對象。
下面是到目前爲止我的代碼:
using System.Reflection;
var t = Type.GetType("Windows.Networking.Connectivity.NetworkInformation, Windows, ContentType=WindowsRuntime");
var profile = t.GetTypeInfo().GetDeclaredMethod("GetInternetConnectionProfile").Invoke(null, null);
var cost = profile.GetTypeInfo().GetDeclaredMethod("GetConnectionCost").Invoke(null, null); //This does not work of course since profile is of type object.
我很少使用反射在我的代碼,所以我不會在此事的專家,但我試圖找到一種方法來區分的profile
對象,然後調用GetConnectionCost
方法就可以了。
任何建議
這正是我所做的5秒前。感謝你的回答 –