Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Type.BaseType in Portable Class Library

  • In VS2013: Create a Portable Class Library
  • Target .NET Framework 4.5, Windows Phone 8.1 & Windows 8
  • Write the following code:

    public class Class1
    {
        public static Type GetBaseType(Type type)
        {
            return type.BaseType;
        }
    }
    

Observe that you cannot compile: "'System.Type' does not contain a definition for 'BaseType' and no extension method 'BaseType' accepting a first argument of type 'System.Type' could be found (are you missing a using directive or an assembly reference?)"

Strange since the MSDN documentation clearly states this property should be present: http://msdn.microsoft.com/en-us/library/system.type.basetype(v=vs.110).aspx

like image 343
Rick Beerendonk Avatar asked Aug 17 '14 17:08

Rick Beerendonk


Video Answer


1 Answers

It is not available in WinRT apps. Properties and methods supported in WinRT have this mentioned explicitly (look at the store icon) - http://msdn.microsoft.com/en-us/library/system.type(v=vs.110).aspx

This answer provides a workaround for WinRT - What is the equivalent to Type.BaseType in WinRT?

Type.GetTypeInfo().BaseType
like image 199
Stilgar Avatar answered Sep 29 '22 20:09

Stilgar