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


C# System.Collections.Generic.AsEnumerable方法代码示例

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


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

示例1: AnonymousType

        public void AnonymousType()
        {
            var list = new[] {
                new { FirstName = "Jon", Surname = "Skeet" },
                new { FirstName = "Holly", Surname = "Skeet" }
            }.ToList();

            // We can't cast to IEnumerable<T> as we can't express T.
            var sequence = list.AsEnumerable();
            // This will now use Enumerable.Contains instead of List.Contains
            Assert.IsFalse(sequence.Contains(new { FirstName = "Tom", Surname = "Skeet" }));
        }
开发者ID:mafm,项目名称:edulinq,代码行数:12,代码来源:AsEnumerableTest.cs

示例2: FormatMessage

        public void FormatMessage()
        {
            const string Pattern = "{name} has {messages, plural, 123}.";
            const string Expected = "Jeff has 123 messages.";
            var args = new Dictionary<string, object> { { "name", "Jeff" }, { "messages", 1 } };
            var requests = new[]
            {
                new FormatterRequest(
                    new Literal(0, 5, 1, 7, new StringBuilder("name")), 
                    "name", 
                    null, 
                    null), 
                new FormatterRequest(
                    new Literal(11, 33, 1, 7, new StringBuilder("messages, plural, 123")), 
                    "messages", 
                    "plural", 
                    " 123")
            };

            this.formatterMock1.Setup(x => x.Format("en", requests[0], args, "Jeff", this.subject)).Returns("Jeff");
            this.formatterMock2.Setup(x => x.Format("en", requests[1], args, 1, this.subject)).Returns("123 messages");
            this.collectionMock.Setup(x => x.GetEnumerator()).Returns(requests.AsEnumerable().GetEnumerator());
            this.libraryMock.Setup(x => x.GetFormatter(requests[0])).Returns(this.formatterMock1.Object);
            this.libraryMock.Setup(x => x.GetFormatter(requests[1])).Returns(this.formatterMock2.Object);
            this.patternParserMock.Setup(x => x.Parse(It.IsAny<StringBuilder>())).Returns(this.collectionMock.Object);

            // First request, and "name" is 4 chars.
            this.collectionMock.Setup(x => x.ShiftIndices(0, 4)).Callback(

                // The '- 2' is also done in the used implementation.
                (int index, int length) => requests[1].SourceLiteral.ShiftIndices(length - 2, requests[0].SourceLiteral));

            var actual = this.subject.FormatMessage(Pattern, args);
            this.collectionMock.Verify(x => x.ShiftIndices(0, 4), Times.Once);
            this.libraryMock.VerifyAll();
            this.formatterMock1.VerifyAll();
            this.formatterMock2.VerifyAll();
            this.patternParserMock.VerifyAll();
            Assert.Equal(Expected, actual);
        }
开发者ID:Metallium,项目名称:messageformat.net,代码行数:40,代码来源:MessageFormatterTests.cs

示例3: VerifyFormatMessageThrowsWhenVariablesAreMissing

        public void VerifyFormatMessageThrowsWhenVariablesAreMissing()
        {
            const string Pattern = "{name} has {messages, plural, 123}.";

            // Note the missing "name" variable.
            var args = new Dictionary<string, object> { { "messages", 1 } };
            var requests = new[]
            {
                new FormatterRequest(
                    new Literal(0, 5, 1, 7, new StringBuilder("name")), 
                    "name", 
                    null, 
                    null), 
                new FormatterRequest(
                    new Literal(11, 33, 1, 7, new StringBuilder("messages, plural, 123")), 
                    "messages", 
                    "plural", 
                    " 123")
            };

            this.collectionMock.Setup(x => x.GetEnumerator()).Returns(() => requests.AsEnumerable().GetEnumerator());
            this.patternParserMock.Setup(x => x.Parse(It.IsAny<StringBuilder>())).Returns(this.collectionMock.Object);

            // First request, and "name" is 4 chars.
            this.collectionMock.Setup(x => x.ShiftIndices(0, 4)).Callback(

                // The '- 2' is also done in the used implementation.
                (int index, int length) => requests[1].SourceLiteral.ShiftIndices(length - 2, requests[0].SourceLiteral));

            var ex = Assert.Throws<VariableNotFoundException>(() => this.subject.FormatMessage(Pattern, args));
            Assert.Equal("name", ex.MissingVariable);    
        }
开发者ID:Metallium,项目名称:messageformat.net,代码行数:32,代码来源:MessageFormatterTests.cs


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