[英]Use reflection to get value of inherited static property that changed on cctor of child class
[英]How to use reflection to get a static property of a class in WinRT
我可以毫無問題地獲取非靜態屬性( 如何在WinRT中獲取類的屬性 ),也可以在c#.net中獲取靜態屬性,但無法弄清楚如何在C3 winrt中獲取靜態屬性。
據我所知。 有人可以幫忙嗎?
Type type = typeof(ToastNotificationManager);
var typeInfo = type.GetTypeInfo();
var historyProperty = type.GetRuntimeProperty("History");
object history = historyProperty.get
property.SetValue(obj, value);
我試圖反映並調用僅在電話上支持的ToastNotificationManager.History.Remove()( ToastNotificationManager.History )
這工作正常:
PropertyInfo propertyInfo =
typeof(ToastNotificationManager).GetRuntimeProperty("History");
propertyInfo.SetValue(null, value);
當然,假設ToastNotificationManager
類型具有一個名為History
的屬性。 :)
請注意,在訪問靜態屬性時,只需將null
用作對象引用。 由於沒有實例與靜態成員連接,因此顯然您不需要將引用傳遞給靜態成員。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.