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

Michael Sync picture Michael Sync · Jan 4, 2012 · Viewed 9.4k times · Source

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;
}

Answer

James McNellis picture James McNellis · Jan 7, 2012

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)