How to add classes to a list?

c# collections entity-framework entity-framework-plus list

Question

If i have a set of Entities (Classes) like this :

Employee, Department, Room ... etc

How to add these classes to a list instead of a list of objects :

Like this :

{Employee, Department, Room}

I want to get these classes because i have a method with the following signature :

AuditManager.DefaultConfiguration.Exclude<T>();

So How to loop on a list of classes and Pass them to this method e.g :

AuditManager.DefaultConfiguration.Exclude<Employee>();

Accepted Answer

Easy:

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

Or you can get type from existed object:

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

I will try to explain difference between Employee and typeof(Employee) but better will be read this link:

Employee it's like your data contract. It have fields like X and Y.

typeof(Employee) is your type of 'contract', it have information about fields - information that contains a description about X and Y fields.


MSDN: Type




Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why