简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM