2014-10-31 78 views
0

我可以得到一个非静态属性没问题(How to get properties of a class in WinRT)或c#.net中的静态属性,但无法弄清楚如何获得一个静态属性C3 winrt中的静态属性。如何使用反射来获取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

回答

1

这工作得很好:

PropertyInfo propertyInfo = 
    typeof(ToastNotificationManager).GetRuntimeProperty("History"); 

propertyInfo.SetValue(null, value); 

假设,当然,ToastNotificationManager类型属性名为History。 :)

请注意,访问静态属性时,只需传递null作为对象引用。由于没有实例与静态成员连接,显然你不需要将引用传递给一个实例。

+0

null是静态特殊的秘密酱,谢谢! – swinefeaster 2014-11-03 22:49:22

相关问题