在.NET核心中获取类的公共属性
我注意到.NET核心不允许myObj.GetType().GetProperties()
因为没有GetProperties
方法存在。 有没有其他方法通过reflection获得类的属性?
似乎myObj.GetType().GetProperties()
是有效的。 我只需要using System.Reflection
引入using System.Reflection
。
只是为了总结其他任何人,仅仅using System.Reflection
添加到页面顶部是不够的。 您将必须添加System.Reflection.TypeExtensions
NuGet包,如问题注释中所述。
PM> Install-Package System.Reflection.TypeExtensions -Version 4.3.0