当前位置: 首页>>代码示例>>C#>>正文


C# Suit.ThrowIfInvalid方法代码示例

本文整理汇总了C#中Suit.ThrowIfInvalid方法的典型用法代码示例。如果您正苦于以下问题:C# Suit.ThrowIfInvalid方法的具体用法?C# Suit.ThrowIfInvalid怎么用?C# Suit.ThrowIfInvalid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Suit的用法示例。


在下文中一共展示了Suit.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];
        }
开发者ID:LazyBui,项目名称:BoringCardLib,代码行数:100,代码来源:DiscardRequest.cs


注:本文中的Suit.ThrowIfInvalid方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。