Type does not contain a definition for 'GetProperties'

别说谁变了你拦得住时间么 提交于 2019-12-04 22:59:11

As of writing this, GetProperties() is now:

typeof(Object).GetTypeInfo().DeclaredProperties;

Update: with .NET COre 2.0 release the System.Type come back and so both options are available:

  • typeof(Object).GetType().GetProperties()
  • typeof(Object).GetTypeInfo().GetProperties()

    This one requires adding using System.Reflection;

  • typeof(Object).GetTypeInfo().DeclaredProperties

    Notice that this property returns IEnumerable<PropertyInfo>, not PropertyInfo[] as previous two methods.


Most reflection-related members on System.Type are now on System.Reflection.TypeInfo.

First call GetTypeInfo to get a TypeInfo instance from a Type:

typeof(Object).GetTypeInfo().GetProperties();

Also, don't forget to use using System.Reflection;

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!