Stopbyte

Where is Type.IsSubclassOf? I can’t find it in UWP!

I decided to move my application from WPF to Universal Windows Platform (UWP) so that I can port it to the store!

But while converting my app I couldn’t find Type.IsSubclassOf() method!
I get Missing reference exception on that one!

Any help?!

1 Like

Type Class has been replaced with TypeInfo Class in UWP and WinRT.

You should be able to find TypeInfo under System.Reflection.TypeInfo

You can use it the same way as Type under .Net framework for WPF, something like this should work:

using System.Reflection;

System.Reflection.TypeInfo type_info = new System.Reflection.TypeInfo();
type_info.IsSubclassOf(typeof (/** YourClass */));

Or


System.Reflection.TypeInfo.IsSubclassOf(typeof (/** YourClass */));
2 Likes

The answer above is almost what you are looking for, though I wanted to note that you used TypeInfo class wrongly.

Here is a C# snippet example:

using System.Reflection;


/* The 2 lines below is what you did wrong, as we need a TypeInfo Class instance not the class itself (as it's not static). */
var MyTypeInfoInstance = typeof (/* Inherited Child Class */);

/* The change in UWP is that you have to use GetTypeInfo() to get the TypeInfo than access the methods. */
MyTypeInfoInstance.GetTypeInfo().IsSubclassOf(typeof (/* Parent Class */));

You can read more about GetTypeInfo() on msdn.

1 Like