.net core 类型不包含';GetProperties';
我正在将库项目迁移到.net标准,当我尝试使用.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
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()
这需要使用System.Reflection添加typeof(对象).GetTypeInfo().GetProperties()
代码>
请注意,此属性返回的是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
仅返回在类型本身上声明的属性,不包括从父级继承的属性