ラムダ式にすばやくアクセスするためのディクショナリの定義に問題があります。
次のような有名なクラスがあるとします。
class Example
{
public string Thing1;
public DateTime Thing2;
public int Thing3;
}
やりたいことは次のようなものです:
var getters = new Dictionary<string, IDontKnowWhatGoesHere>();
getters.Add("Thing1", x => x.Thing1);
getters.Add("Thing3", x => x.Thing3);
これは可能ですか?
編集:
これは、このオブジェクトの私の使用例です:
List<Example> array = new List<Example>();
// We actually get this variable set by the user
string sortField = "Thing2";
array.Sort(getters[sortField]);
助けてくれて本当にありがとうございます。