.net core 类型不包含';GetProperties';

.net core 类型不包含';GetProperties';,.net-core,.net-standard,.net Core,.net Standard,我正在将库项目迁移到.net标准,当我尝试使用System.ReflectionAPI调用Type:GetProperties()时,出现以下编译错误: 类型不包含“GetProperties”的定义 这是我的project.json: { "version": "1.0.0-*", "buildOptions": { "debugType": "portable" }, "dependencies": {}, "frameworks": { "netstan

我正在将库项目迁移到.net标准,当我尝试使用
System.Reflection
API调用
Type:GetProperties()
时,出现以下编译错误:

类型不包含“GetProperties”的定义

这是我的
project.json

{
  "version": "1.0.0-*",
  "buildOptions": {
    "debugType": "portable"
  },
  "dependencies": {},
  "frameworks": {
    "netstandard1.6": {
      "dependencies": {
        "NETStandard.Library": "1.6.0"
      }
    }
  }
}

我错过了什么

更新:使用.NET COre 2.0发布的
系统。键入
返回,因此这两个选项都可用:

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

    这需要使用System.Reflection添加

  • typeof(Object).GetTypeInfo().DeclaredProperties

    请注意,此属性返回的是
    IEnumerable
    ,而不是前面两个方法返回的
    PropertyInfo[]


System.Type
上大多数与反射相关的成员现在都在
System.reflection.TypeInfo

首先调用
GetTypeInfo
Type
获取
TypeInfo
实例:

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

另外,不要忘记使用
和System.Reflection

撰写本文时,
GetProperties()
现在是:


typeof(Object).GetTypeInfo().DeclaredProperties

没错。但我认为你的答案有错。它是
typeof(Object.GetTypeInfo().GetProperties()
DeclaredProperties
仅返回在类型本身上声明的属性,不包括从父级继承的属性