【发布时间】:2017-01-21 15:45:47
【问题描述】:
我有一个模型:
public class Message
{
public string CustomerName { get; set; }
public DateTime Date { get; set; }
public string RegistrationCode { get; set; }
}
我想动态获取它的属性,在之前版本的.Net 中我们通过:obj.GetType().GetProperties(); 来实现,但在.Net Core 中我们没有.GetProperties(),我该怎么做?
【问题讨论】:
-
试试
obj.GetType().GetTypeInfo().DeclaredProperties -
使用 System.Reflection;编写的代码是正确的,不需要额外的包。
标签: asp.net-core