IEnumerable<School>を設定する拡張メソッドに渡されているコレクションがありDropDownListます。DataValueFieldとを引数として渡し
DataTextFieldたいのですが、強く型付けしてほしいと思いました。
基本的に、引数にastringを渡したくないので、エラーが発生しやすくなります。DataValueFieldDataTextField
public static void populateDropDownList<T>(this DropDownList source,
IEnumerable<T> dataSource,
Func<T, string> dataValueField,
Func<T, string> dataTextField) {
source.DataValueField = dataValueField; //<-- this is wrong
source.DataTextField = dataTextField; //<-- this is wrong
source.DataSource = dataSource;
source.DataBind();
}
そのように呼ばれる...
myDropDownList.populateDropDownList(states,
school => school.stateCode,
school => school.stateName);
DataValueField私の質問は、populateDropDownListに引数としてとDataTextField強く型付けされたものを渡すにはどうすればよいですか?