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


C# Queue.Single方法代码示例

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


在下文中一共展示了Queue.Single方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ReadLine

        public void ReadLine(string text)
        {
            if (text.Trim().StartsWith("#")) return;

            var tokens = new Queue<string>(StringTokenizer.Tokenize(text.Replace(',', ' ')));

            if (tokens.Count == 1)
            {
                if (_readerAction == null)
                {
                    throw new InvalidSyntaxException("Not enough tokens in the command line");
                }

                _readerAction(tokens.First());
                return;
            }

            _lastName = null;
            _readerAction = null;

            if (tokens.Count() < 3)
            {
                throw new InvalidSyntaxException("Not enough tokens in the command line");
            }

            var key = tokens.Dequeue();
            var verb = tokens.Dequeue();

            if (key == "ordered")
            {
                handleOrderedSet(tokens, verb);

                return;
            }

            switch (verb)
            {
                case "is":
                    if (tokens.Count > 1) throw new InvalidSyntaxException("Only one name can appear on the right side of the 'is' verb");
                    _registration.Alias(tokens.Dequeue(), key);
                    break;

                case "requires":
                    tokens.Each(name => _registration.Dependency(key, name));
                    break;

                case "extends":
                    if (tokens.Count > 1) throw new InvalidSyntaxException("Only one name can appear on the right side of the 'extends' verb");

                    _registration.Extension(key, tokens.Single());
                    break;

                case "includes":
                    tokens.Each(name => _registration.AddToSet(key, name));
                    break;

                case "preceeds":
                    tokens.Each(name => _registration.Preceeding(key, name));
                    break;

                default:
                    string message = "'{0}' is an invalid verb".ToFormat(verb);
                    throw new InvalidSyntaxException(message);
            }
        }
开发者ID:RobertTheGrey,项目名称:fubumvc,代码行数:65,代码来源:ScriptDslReader.cs

示例2: QueueExtensions_Single_ThrowsExceptionIfQueueIsEmpty

        public void QueueExtensions_Single_ThrowsExceptionIfQueueIsEmpty()
        {
            var queue = new Queue<Int32>();

            Assert.That(() => queue.Single(),
                Throws.TypeOf<InvalidOperationException>());
        }
开发者ID:RUSshy,项目名称:ultraviolet,代码行数:7,代码来源:QueueExtensionsTest.cs

示例3: QueueExtensions_Single_ThrowsExceptionIfQueueHasMultipleItems

        public void QueueExtensions_Single_ThrowsExceptionIfQueueHasMultipleItems()
        {
            var queue = new Queue<Int32>();
            queue.Enqueue(1);
            queue.Enqueue(2);

            Assert.That(() => queue.Single(),
                Throws.TypeOf<InvalidOperationException>());
        }
开发者ID:RUSshy,项目名称:ultraviolet,代码行数:9,代码来源:QueueExtensionsTest.cs

示例4: QueueExtensions_Single_ReturnsSingleItemInQueue

        public void QueueExtensions_Single_ReturnsSingleItemInQueue()
        {
            var queue = new Queue<Int32>();
            queue.Enqueue(4);

            var result = queue.Single();

            TheResultingValue(result).ShouldBe(4);
        }
开发者ID:RUSshy,项目名称:ultraviolet,代码行数:9,代码来源:QueueExtensionsTest.cs

示例5: QueueExtensions_Single_ThrowsExceptionIfQueueHasMultipleItems

        public void QueueExtensions_Single_ThrowsExceptionIfQueueHasMultipleItems()
        {
            var queue = new Queue<Int32>();
            queue.Enqueue(1);
            queue.Enqueue(2);

            queue.Single();
        }
开发者ID:prshreshtha,项目名称:ultraviolet,代码行数:8,代码来源:QueueExtensionsTest.cs

示例6: QueueExtensions_Single_ThrowsExceptionIfQueueIsEmpty

        public void QueueExtensions_Single_ThrowsExceptionIfQueueIsEmpty()
        {
            var queue = new Queue<Int32>();

            queue.Single();
        }
开发者ID:prshreshtha,项目名称:ultraviolet,代码行数:6,代码来源:QueueExtensionsTest.cs


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