简体   繁体   中英

How to use reflection to get a static property of a class in WinRT

I can get a non-static property no problem ( How to get properties of a class in WinRT ), or a static property in c# .net, but can't figure out how to get a static property in C3 winrt.

This is as far as I've gotten. Can anyone help?

            Type type = typeof(ToastNotificationManager);
            var typeInfo = type.GetTypeInfo();
            var historyProperty = type.GetRuntimeProperty("History");
            object history = historyProperty.get
            property.SetValue(obj, value);

I'm trying to reflect for and call ToastNotificationManager.History.Remove() which is only supported on the phone ( ToastNotificationManager.History )

This works fine:

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

propertyInfo.SetValue(null, value);

Assuming, of course, that the ToastNotificationManager type has a property named History . :)

Note that when accessing static properties, you simply pass null as the object reference. Since there's no instance connected with a static member, obviously you don't need to pass a reference to one.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM