I have a 4 classes:
Person - Abstract Class
Student - Class which inherit from Person
Teacher - Class which inherit from Person
PersonProvider - Static class which creates a list<A>
and this list keep objects of Student and Teacher
Now, problem is, I have below query which show the user that his choice is either he has to choose between student or teacher but how to pass what he has chosen to next query (so list all student or all teachers)? I can't just read from the console and pass it to my query as typeOf() and getType() does not work with string :).
Below query return distinct types from the list but I do not know how to proceed further:
var listOfPersons = PersonProvider
.AvailablePersons
.Where(p => p.GetType().BaseType == typeof(Person))
.GroupBy(p => p.GetType().Name)
.Select(g => g.First())
.ToList();
foreach (var item in listOfPersons )
{
Console.WriteLine(item.GetType().Name);
}
This returns:
Student
Techaer
And now user should type in the console "Student" or Teacher so I could pass it to the next query which I dont know how to build. I was thinking about generic extension method with **Func<T, bool> predicate**
but I'm not sure about it.