У меня есть следующий класс:Какое/когда исключение выбрано, если свойство равно null?
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
?
относится к обзору кода. –
также вы не можете создать новый интерфейс. –
"* Метод GetSingleBar - единственный метод, который использует свойство Bars *" ... для * now *! –