本文整理汇总了C#中Direction.ThrowIfInvalid方法的典型用法代码示例。如果您正苦于以下问题:C# Direction.ThrowIfInvalid方法的具体用法?C# Direction.ThrowIfInvalid怎么用?C# Direction.ThrowIfInvalid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Direction
的用法示例。
在下文中一共展示了Direction.ThrowIfInvalid方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DiscardRequest
public DiscardRequest(
Direction direction = Direction.FirstToLast,
int? quantity = null,
int? skip = null,
int? offset = null,
int? value = null,
IEnumerable<int> values = null,
bool? nullValues = null,
Card card = null,
IEnumerable<Card> cards = null,
Suit? suit = null,
IEnumerable<Suit> suits = null,
Rank? rank = null,
IEnumerable<Rank> ranks = null)
{
direction.ThrowIfInvalid(nameof(direction));
if (quantity != null) {
quantity.ThrowIfZeroOrLess(nameof(quantity));
}
if (suits != null) {
if (suit != null) throw new ArgumentException($"Must not specify both {nameof(suit)} and {nameof(suits)}");
suits.ThrowIfEmpty(nameof(suits));
suits.ThrowIfAnyInvalidEnums(nameof(suits));
}
if (ranks != null) {
if (rank != null) throw new ArgumentException($"Must not specify both {nameof(rank)} and {nameof(ranks)}");
ranks.ThrowIfEmpty(nameof(ranks));
ranks.ThrowIfAnyInvalidEnums(nameof(ranks));
}
if (values != null) {
if (value != null) throw new ArgumentException($"Must not specify both {nameof(value)} and {nameof(values)}");
values.ThrowIfEmpty(nameof(values));
}
if (cards != null) {
if (card != null) throw new ArgumentException($"Must not specify both {nameof(card)} and {nameof(cards)}");
cards.ThrowIfEmptyOrContainsNulls(nameof(cards));
}
if (suit != null) {
suit.ThrowIfInvalid(nameof(suit));
}
if (rank != null) {
rank.ThrowIfInvalid(nameof(rank));
}
if (skip != null) {
if (nullValues == true) throw new ArgumentException($"Must not specify both {nameof(skip)} and {nameof(nullValues)}");
if (suits != null) throw new ArgumentException($"Must not specify both {nameof(skip)} and {nameof(suits)}");
if (ranks != null) throw new ArgumentException($"Must not specify both {nameof(skip)} and {nameof(ranks)}");
if (values != null) throw new ArgumentException($"Must not specify both {nameof(skip)} and {nameof(values)}");
if (cards != null) throw new ArgumentException($"Must not specify both {nameof(skip)} and {nameof(cards)}");
if (suit != null) throw new ArgumentException($"Must not specify both {nameof(skip)} and {nameof(suit)}");
if (rank != null) throw new ArgumentException($"Must not specify both {nameof(skip)} and {nameof(rank)}");
if (value != null) throw new ArgumentException($"Must not specify both {nameof(skip)} and {nameof(value)}");
if (card != null) throw new ArgumentException($"Must not specify both {nameof(skip)} and {nameof(card)}");
skip.ThrowIfNegative(nameof(skip));
}
if (offset != null) {
if (nullValues == true) throw new ArgumentException($"Must not specify both {nameof(offset)} and {nameof(nullValues)}");
if (suits != null) throw new ArgumentException($"Must not specify both {nameof(offset)} and {nameof(suits)}");
if (ranks != null) throw new ArgumentException($"Must not specify both {nameof(offset)} and {nameof(ranks)}");
if (values != null) throw new ArgumentException($"Must not specify both {nameof(offset)} and {nameof(values)}");
if (cards != null) throw new ArgumentException($"Must not specify both {nameof(offset)} and {nameof(cards)}");
if (suit != null) throw new ArgumentException($"Must not specify both {nameof(offset)} and {nameof(suit)}");
if (rank != null) throw new ArgumentException($"Must not specify both {nameof(offset)} and {nameof(rank)}");
if (value != null) throw new ArgumentException($"Must not specify both {nameof(offset)} and {nameof(value)}");
if (card != null) throw new ArgumentException($"Must not specify both {nameof(offset)} and {nameof(card)}");
offset.ThrowIfNegative(nameof(offset));
}
if (quantity == null && skip == null && offset == null &&
nullValues == null &&
suit == null && suits == null &&
rank == null && ranks == null &&
card == null && cards == null &&
value == null && values == null)
{
throw new ArgumentException("Must have at least one discard criterion");
}
Direction = direction;
Quantity = quantity;
Skip = skip ?? 0;
Offset = offset ?? 0;
NullValues = nullValues ?? false;
if (suits != null) Suits = suits;
else if (suit != null) Suits = new[] { suit.GetValueOrDefault() };
else Suits = new Suit[0];
if (ranks != null) Ranks = ranks;
else if (rank != null) Ranks = new[] { rank.GetValueOrDefault() };
else Ranks = new Rank[0];
if (cards != null) Cards = cards;
else if (card != null) Cards = new[] { card };
else Cards = new Card[0];
if (values != null) Values = values;
else if (value != null) Values = new[] { value.GetValueOrDefault() };
else Values = new int[0];
}