2

如果我有一组这样的实体(类):

Employee, Department, Room ... etc

如何将这些添加到列表而不是对象列表:

像这样 :

{Employee, Department, Room}

我想获得这些类,因为我有一个具有以下签名的方法:

AuditManager.DefaultConfiguration.Exclude<T>();

那么如何循环一个类列表并将它们传递给这个方法,例如:

AuditManager.DefaultConfiguration.Exclude<Employee>();
4

1 回答 1

11

简单的:

List<Type> types = new List<Type> {typeof(Employee), typeof(Department), typeof(Room)};

或者您可以从现有对象中获取类型:

List<Type> types = new List<Type> {EmployeeInstance.GetType(), DepartmentInstance.GetType(), RoomInstance.GetType()};

我将尝试解释两者之间的区别Employeetypeof(Employee)但最好阅读此链接

员工就像您的数据合同。它有像 X 和 Y 这样的字段。

typeof(Employee)是您的“合同”类型,它包含有关字段的信息 - 包含有关 X 和 Y 字段的描述的信息。


MSDN:类型

于 2017-04-19T08:28:46.197 回答