いくつかの特定の変数を持つオブジェクトと、比較するために使用する同じオブジェクトの別のオブジェクトを定義して(後で使用するためにメモリに作成する)メソッドを作成しています。例えば複数のパラメータのC#ラムダ式
:私は問題を抱えているところ
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
{
}
??
です。私は別の方法を持っている:
public ThisWorks<T>(Expression<Func<T, bool>> expression) where T : class
{
}
そして、私は好きでそれを呼び出す:
ThisWorks<User>(u => u.UserID == 1 && u.Age >= 20);
UserID
は1とAge
あるすべてのユーザーを取得するには今と同じか 20を超えている私が好きなものにこれに近いことができるか:
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)
}
できるだけこれを達成できますか?
理由:私は今、私は、マッチングリスト/ のみ値を使用してデータベースを指定し、請求/更新を設定するには、リスト/データベースからの発現と一致するすべてのT
の要素を返すメソッドを持っています。複数の条件で
// - 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);
可能なDUP:http://stackoverflow.com/questions/6624811/how-to-pass-anonymous-types-as-parameters – aqwert