列表计数的条件和空值

我有以下构造函数,如下所示:

public Delivery(DeliveryPeriodEnum deliveryPeriod, IEnumerable<DayOfWeek> days)
{
       _deliveryPeriod = deliveryPeriod;
       _days = days;

        if (_deliveryPeriod == DeliveryPeriodEnum.Nothing && (_days != null || _days.Any())) throw new GeneralException("There cannot be days for given period");

        if (_deliveryPeriod != DeliveryPeriodEnum.Nothing && (_days == null || !_days.Any())) throw new GeneralException("Period has to have at elast one item in list");
}

有两个业务条件:

//if DeliveryPeriodEnum.Nothing:
then days have to be either null or not null but with count = 0 otherwise show message

//if DeliveryPeriodEnum <> DeliveryPeriodEnum.Nothing:
then days cannot be null and have to have count > 0 otherwise show message

I have problems with it for instance in my first if statment if DeliveryPeriodEnum = DeliveryPeriodEnum .Nothing and days is null it also evalueates to _days.Any() which certainly raise error of instance not exist.

请记住,如果可能,我希望将两个条件同时放在两行中,以免出现其他较大的陈述等。

评论