私は次のクラスを持っています:
class Foo
{
public Foo()
: this(new List<Bar>())
{
}
public Foo(IEnumerable<Bar> bars)
{
Bars = bars;
}
public IEnumerable<Bar> Bars { get; set; }
public Bar GetSingleBar(Data data)
{
// this method returns a single Bar from the Bars property above
// this method returns the Bar which matches the data parameter
// this method should not return null
// this method throws a NoBarsFoundException if
// (a) Bars is empty or
// (b) no bar in Bars matches the data
}
}
Barsの場合はどうすればよいですnullか? のセッターで例外をスローする必要がありますかBars、または で例外をスローする必要がありGetSingleBarますか? (このメソッドは、プロパティGetSingleBarを使用する唯一のメソッドです。)Bars
ArgumentException、ArgumentNullException、InvalidOperationException、またはをスローする必要がありNoBarsFoundExceptionますか?