私はこのようなことをしようとしています:
public static class Validate
{
public static void AgainstNull(string str)
{
if (String.IsNullOrWhiteSpace(str))
{
// how do I know the property name in the calling code?
throw new ArgumentNullException("property name from caller");
}
}
}
私のコードベースでこれに似たパターンを使用できるように:
public void Foo(string bar)
{
Validate.AgainstNull(bar);
// other processing here
}
検証メソッド内の呼び出しコードから渡されたプロパティの名前を知るにはどうすればよいですか?