Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any alternative for IsSubclassOf or IsAssignableFrom in C# Metro-style

Is there any alternative for IsSubclassOf or IsAssignableFrom in C# Metro-style?

I'm trying to make this code run on Metro but can't find alternative.

if ((ui.GetType() == type) || (ui.GetType().IsSubclassOf(type)))
{
    return true;
}
like image 208
Michael Sync Avatar asked Jan 04 '12 16:01

Michael Sync


2 Answers

Many of the reflection methods can be found in the System.Reflection.TypeInfo class.

You can get an instance of TypeInfo for your Type using the GetTypeInfo extension method, provided by System.Reflection.IntrospectionExtensions:

using System.Reflection;

// ...

ui.GetType().GetTypeInfo().IsSubclassOf(type)
like image 163
James McNellis Avatar answered Oct 20 '22 20:10

James McNellis


You can use this:

using System.Reflection;

// ...

ui.GetTypeInfo().IsAssignableFrom(type.GetTypeInfo());

This works in Metro.

like image 17
Rhett Avatar answered Oct 20 '22 21:10

Rhett