Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,780,486 Members 44,784 Now Online
XDA Developers Android and Mobile Development Forum

[Q] Correct way of testing if a Type is abstract in WP8.1?

Tip us?
 
deHoDev
Old
#1  
Junior Member - OP
Thanks Meter 2
Posts: 7
Join Date: Feb 2012
Question [Q] Correct way of testing if a Type is abstract in WP8.1?

I was about to update multiple projects to be compatible with WP 8.1 when I hit multiple snags.

One of those is: Type.IsAbstract is missing in WP8.1 apps (I'm talking about the real wp8.1 apps and not Windows Phone Silverlight 8.1 apps)

Now since my project I want to convert is a portable class library that is currently targeting - .net framework 4.5, Silverlight 4 and higher, Windows Phone Silverlight 7.1 and higher, Windows 8 - I was expecting a relatively smooth transition.

When I was experimenting with different PCL targets I found a workaround for the missing Type.IsAbstract but I can't imaging that to be the correct way of testing if a type is abstract or not:

When you specificly target the following frameworks in pcl: .Net Framework 4.5, Silverlight 5, Windows 8, Windows Phone 8.1, Windows Phone Silverlight 8, then Type.IsAbstract is available in this project and therefore you can write a function to test if a type is abstract and then use that function in a Windows Phone 8.1 app to test if a type is abstract (or simple create a extension method in the pcl).
It works, I tested it. It seems really strange, especially because when you REMOVE Silverlight 5 from the pcl, Type.IsAbstract is not available anymore in the pcl project.


I'm asking because I can't use these specific pcl targets (or more exaclty I can't have Silverlight 5 as a target) because then ObservableCollections are not available and there is no Json.Net (Newtonsoft) target for these pcl targets.
(It would mean splitting my lowest project into two projects and my self written framework already consists of 25 projects)
 
deHoDev
Old
#2  
Junior Member - OP
Thanks Meter 2
Posts: 7
Join Date: Feb 2012
Ok,
after some testing I found a solution.

In WP8.1 and seemingly in all relevant (at least for me) PCL targets that include WP8.1 you have to add:
Code:
using System.Reflection;
Then you have multiple extension methods available for "Type".

Relevant in this case is "GetTypeInfo()" which then includes "IsAbstract"

and in my case many other methods I need ("GetRuntimeProperty" and more)
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes