比較的頻繁に、入力として入力されたパラメーターのみが必要なメソッドがあります。誰かがメソッドを呼び出し、パラメータが正しくない場合、エラーがスローされます。
メソッドに注釈を付ける方法はありますか:特定の値の範囲のみが許可されているか、nullであってはなりませんか?
ジェネリックスには、制限の「where」句のようなものがあります(これまでのところ、値はありません)。
だから私は代わりにやりたい
private static void DoSomething(string string_in, object object_in,... )
{
if (null == object_in) throw new NullReferenceException("Input parameter of object is empty.");
if (String.IsNullOrEmpty(string )) throw new NullReferenceException("Input parameter string is empty.");
何かのようなもの
private static void DoSomething(string string_in, object object_in,... )
where string _in:!String.IsNullOrEmpty(string_in)
where object_in : object_in !=null
また
private static void DoSomething(string string_in != null, object object_in != null,... )
または(私が最も欲しい)
[Restriction string_in: value != null, value != empty]
[Restriction object_in: value != null]
[Restriction int_in: value inRange 3..9]
private static void DoSomething(string string _in, object object_in,... )
つまり、呼び出された型を特定の値に制限してから、手動で何度も何度も何かと比較するより良い方法はありますか?