MSDNから:
すべてのArgumentExceptionには、この例外の原因となるパラメーターの名前を含める必要があります。
私の質問:プロパティセッターがをスローするArgumentException
必要がある場合、セッターのパラメーター名(デフォルト:)value
またはプロパティの名前を指定する必要がありますか?
例:
Private _myProperty As String
Public Property MyProperty As String
Get
Return _myProperty
End Get
Set(value As String)
If String.IsNullOrEmpty(value) Then
' what I've been doing for the last 2 years
Throw New ArgumentNullException("value", "value cannot be empty")
' what I think I should be doing instead
Throw New ArgumentNullException("MyProperty", "value cannot be empty")
End If
_myProperty = value
End Set
End Property
それが理にかなっていることを願っています。どう思いますか?
編集
別の解決策は、より意味のある名前に変更value
し、それをの値として使用することだと思いますparamName
。しかし、どういうわけか、それは正しいことではないようです。