How to add classes to a list?

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

Question

If I have this group of Entities (Classes):

Employee, Department, Room ... etc

In order to add these classes to a list as opposed to an object list:

akin to this

{Employee, Department, Room}

I need these classes for a method I have that has the following signature:

AuditManager.DefaultConfiguration.Exclude<T>();

Therefore, how can I provide a list of classes to this function in a loop? For example:

AuditManager.DefaultConfiguration.Exclude<Employee>();
1
2
4/19/2017 9:07:56 AM

Accepted Answer

Easy:

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

The type of an existing item may also be obtained.

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

I'll attempt to clarify the distinctions betweenEmployee and typeof(Employee) but it will be clearer to read such a link:

Employee it's like your data agreement. There are X and Y fields in it.

Your 'Contract' type is typeof(Employee); it provides information about fields, including a description of X and Y fields.


Using MSDN:

11
4/19/2017 8:41:35 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow