获取.NET核心中的类的公共属性

use*_*372 9 c# .net-core

我注意到.NET核心不允许,myObj.GetType().GetProperties()因为没有GetProperties方法存在.有没有其他方法通过反射获得类的属性?

use*_*372 19

似乎myObj.GetType().GetProperties()IS有效.我只需要引入System.Reflection using System.Reflection.


Mos*_*aou 11

只是总结给其他人,只是添加using System.Reflection到页面顶部是不够的.您将必须System.Reflection.TypeExtensions按问题注释中的描述添加NuGet包.

PM> Install-Package System.Reflection.TypeExtensions -Version 4.3.0