コントローラーでいくつかのパラメーターを返すメソッドが必要です。これはその実装です。
public List<Parameter> GetParameters(FormCollection collection) {
List<Parameter> parameters = new List<Parameter>();
List<string> parameterNames = new List<string>();
//Get Parameters Names and Values
return parameters;
}
私はすべてのコントローラーでこのメソッドを使用するので、定義する必要がある 3 つのオプションについて考えます。
1-コントローラークラスの場合、そのコントローラーで次のように定義します。
public class ProductController : Controller {
public List<Parameter> GetParameters(FormCollection collection) {
//
}
}
2-静的クラスで静的メソッドとして定義します。
public static class GeneralMethods {
public static List<Parameter> GetParameters(FormCollection collection) {
//
}
}
3-それを None Static として定義します:
public class GeneralMethods {
public List<Parameter> GetParameters(FormCollection collection) {
//
}
}
どちらの方がよいですか?どれがより良いパフォーマンスを持っていますか?または、多くのコントローラーで使用されるメソッドを定義するためのその他のオプションはありますか? あなたの提案は何ですか?