I have a class with some fields.
public abstract class RegisteredUser : Transformable //implements interface
{
protected int id;
protected bool active;
protected string name;
protected string lastName;
protected string email;
protected string username;
protected string password;
protected int institution;
//OTHER STUFF FROM THIS CLASS GO HERE..`
}
Assistant : RegisteredUser
{
}
Once I load all data from .txt file, I'll have a static dictionary like this:
public static Dictionary<int, Transformable> assistants = null; //this will be filed with objects and their id's
Now, my assignment is to achieve functionality of search for this console app. Since, all of sub classes will have fields from abstract class, user of this app should have a choice to search for any object Assistant, Professor or Administrator by any of its fields.
I would like to achieve this by using LINQ/lambdas. My idea is to create some generic method which will accept a selector (or some lambda expression ), based on whatever field is being searched for.
I am completely new to LINQ and C# and generally to programming, so I hope that I'm not talking nonsense here.
public static List<RegisteredUser> search(Dictionary<int, Transformable> map,
Func<bool,RegisteredUser> selector,
Transformable userType)
{
if (userType is Assistant)
{
List<RegisteredUser> list = map.Select(item => (Assistant) item.Value)
.ToList()
.Select(selector)
.ToList();
}
//other if/else statements
return list;
}
Of course, lines in Visual Studio are red :) Basically, I want to be be able send something like
user => user.Name.Contains("some string which will be entered by the end user") to generic function.