I'm making a method to define (create in memory for later use) an object with a few specific variables and another of the same object that I'll be using to compare.
For example:
public class User
{
public int UserID { get; set; }
public string Name { get; set; }
public int Age { get; set; }
}
// - The method
public bool IDontKnowWhatImDoing<T>(??) where T : class
{
}
The ??
is where I'm having the issue. I have another method as:
public ThisWorks<T>(Expression<Func<T, bool>> expression) where T : class
{
}
And I call it like:
ThisWorks<User>(u => u.UserID == 1 && u.Age >= 20);
To obtain all users where UserID
is 1 and Age
is equal or over 20.
Now I'd like something to be able to do this or something close to this:
NoClue<User>(u => { u.UserID = 1, u.Name = "Whois" });
public void TheFunctionIWishFor<T>(??, Expression<Func<T, bool>> expression) where T : class
{
// - The ?? part is where I want to get a T from
// - with the specified values above (UserID 1 and "Whois" Name)
}
How can I achieve this, if possible?
Reason: I have a method that returns all T
elements that matches the expression from a list/database, now I want to set/update said matching list/database with only the values I specify.
Like this:
// - Setting all user's names and age whose have null as Name.
NotSureIfItsAGoodIdea<User>(u => { u.Name = "AllAsOne", u.Age = 20 }, f => f.Name == null);