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


C# List.SelectMany方法代码示例

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


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

示例1: SimpleFlatten

 public void SimpleFlatten()
 {
     List<string> Test = new List<string>();
     Test.Add("Howdy");
     Test.Add("Pal");
     var result = Test.SelectMany(x => x.ToCharArray());
     result.AssertSequenceEqual('H', 'o', 'w', 'd', 'y', 'P', 'a', 'l' );
 }
开发者ID:ungood,项目名称:EduLinq,代码行数:8,代码来源:SelectManyTests.cs

示例2: SelectManyQueryReuse

        public void SelectManyQueryReuse()
        {
            List<List<int>> data = new List<List<int>> { new List<int> { 1, 2 }, new List<int> { 3, 4 } };
            IEnumerable<int> enumerable = data.SelectMany(x => x);

            enumerable.AssertEqual(1, 2, 3, 4);

            data.Add(new List<int> { 5, 6 });
            enumerable.AssertEqual(1, 2, 3, 4, 5, 6);
        }
开发者ID:barisertekin,项目名称:LINQlone,代码行数:10,代码来源:SelectManyTests.cs

示例3: Should_Generate_One_Request_Object_Per_Not_Get_Methods

        public void Should_Generate_One_Request_Object_Per_Not_Get_Methods()
        {
            var generatorMethods = new Collection<ClientGeneratorMethod>();
            generatorMethods.Add(new ClientGeneratorMethod
                                 {
                                     Name = "m1",
                                     Verb = "get",
                                     ReturnType = "t1",
                                     UriParameters = new List<GeneratorParameter>()
                                 });

            generatorMethods.Add(new ClientGeneratorMethod
                                 {
                                     Name = "m2",
                                     Verb = "post",
                                     ReturnType = "t2",
                                     UriParameters = new List<GeneratorParameter>()
                                 });

            generatorMethods.Add(new ClientGeneratorMethod
                                 {
                                     Name = "m3",
                                     Verb = "put",
                                     ReturnType = "t3",
                                     UriParameters = new List<GeneratorParameter>()
                                 });

            var classes = new List<ClassObject>();
            classes.Add(new ClassObject
                        {
                            Name = "c1",
                            Methods = generatorMethods
                        });

            var generator = new ApiRequestObjectsGenerator();
            var apiObjects = generator.Generate(classes);

            Assert.AreEqual(2, apiObjects.Count());

            Assert.AreEqual("ApiRequest", classes.SelectMany(c => c.Methods).First(m => m.Name == "m1").RequestType);
            Assert.IsFalse(string.IsNullOrWhiteSpace(classes.SelectMany(c => c.Methods).First(m => m.Name == "m2").RequestType));
            Assert.IsFalse(string.IsNullOrWhiteSpace(classes.SelectMany(c => c.Methods).First(m => m.Name == "m3").RequestType));
        }
开发者ID:Robin--,项目名称:raml-dotnet-tools,代码行数:43,代码来源:ApiRequestObjectsGeneratorTests.cs

示例4: Test

        public void Test()
        {
            string word = "blue hades";
            var problemnum = 2;
            int unitIndex = 2;
            int seedIndex = 5;

            var problem = ProblemsSet.GetProblem(problemnum);
            var originalUnit = problem.units[unitIndex];
            var prefix = new List<MoveType>();
            var spawnedUnit = Game.SpawnUnit(originalUnit, problem).Move(MoveType.SE).Move(MoveType.SW);
            var unit = spawnedUnit;
            var units = new List<Unit> { unit };

            foreach (var c in word)
            {
                var moveType = MoveTypeExt.Convert(c);
                unit = unit.Move(moveType.Value);
                units.Add(unit);
            }
            var minX = units.SelectMany(x => x.members).Min(t => t.x);
            while (minX < 0)
            {
                prefix.Add(MoveType.E);
                minX++;
            }
            while (minX > 0)
            {
                prefix.Add(MoveType.W);
                minX--;
            }
            prefix.Add(MoveType.SE);
            prefix.Add(MoveType.SW);

            var game = new SolverGame(problem, problem.sourceSeeds[seedIndex], new string[0]);
            game.Step();
            var danananananananananananananan = "danananananananananananananan";
            game.ApplyUnitSolution(danananananananananananananan);
            if (game.state != GameBase.State.End && game.state != GameBase.State.WaitUnit)
                throw new InvalidOperationException(string.Format("Invalid game state: {0}", game.state));
            game.Step();
            Assert.That(game.spawnedUnitIndex, Is.EqualTo(unitIndex));
            var staticPowerPhraseBuilder = new StaticPowerPhraseBuilder();
            var solution = staticPowerPhraseBuilder.Build(prefix) + word;
            Console.Out.WriteLine(danananananananananananananan + solution);
            game.ApplyUnitSolution(solution);

            var output = new Output
            {
                problemId = problemnum,
                seed = problem.sourceSeeds[seedIndex],
                solution = danananananananananananananan + solution
            };
        }
开发者ID:spaceorc,项目名称:icfpc2015,代码行数:54,代码来源:Check_Spell.cs

示例5: ShouldScheduleFixturesForAllTeams

        public void ShouldScheduleFixturesForAllTeams()
        {
            KnockoutStageSeason season = A.KnockoutStageSeason.WithPairCount(4).Scheduled().Activated().Build();

            var fixtures = new List<Fixture>();
            season.ScheduleFixtures(f => fixtures.Add(f));

            var fixtureTeams = fixtures.SelectMany(f => new Team[] { f.Team1, f.Team2 }).ToArray();

            Assert.That(fixtureTeams, Is.EquivalentTo(season.Teams));
        }
开发者ID:MilenPavlov,项目名称:EuroManager,代码行数:11,代码来源:KnockoutStageSeasonTests.cs

示例6: Flatten

        public void Flatten()
        {
            var listA = new List<int> { 1, 2, 3, 4, 5 };
            var listB = new List<int> { 6, 7, 8, 9, 10 };
            var listC = new List<int> { 11, 12, 13, 14, 15 };

            var lists = new List<List<int>> { listA, listB, listC };

            var theList = lists.SelectMany(x => x);

            theList.Print();
        }
开发者ID:pierangelim,项目名称:advanced-c-sharp,代码行数:12,代码来源:Select.cs

示例7: LotsOfConcurrentMapRedRequestsShouldWork

        public void LotsOfConcurrentMapRedRequestsShouldWork()
        {
            var keys = new List<string>();

            for (var i = 1; i < 11; i++)
            {
                var key = "key" + i;
                var doc = new RiakObject(MapReduceBucket, key, new { value = i });
                keys.Add(key);

                var result = Client.Put(doc, new RiakPutOptions { ReturnBody = true });
                result.IsSuccess.ShouldBeTrue();
            }

            var input = new RiakBucketKeyInput();
            keys.ForEach(k => input.Add(new RiakObjectId(MapReduceBucket, k)));

            var query = new RiakMapReduceQuery()
                .Inputs(input)
                .MapJs(m => m.Source(@"function(o){return[1];}"))
                .ReduceJs(r => r.Name(@"Riak.reduceSum").Keep(true));
            query.Compile();

            var results = new List<RiakResult<RiakMapReduceResult>>[ThreadCount];
            Parallel.For(0, ThreadCount, i =>
                {
                    results[i] = DoMapRed(query);
                });

            var failures = 0;
            foreach (var r in results.SelectMany(l => l))
            {
                if (r.IsSuccess)
                {
                    var resultValue = JsonConvert.DeserializeObject<int[]>(r.Value.PhaseResults.ElementAt(1).Values.First().FromRiakString())[0];
                    resultValue.ShouldEqual(10);
                    //r.Value.PhaseResults.ElementAt(1).GetObject<int[]>()[0].ShouldEqual(10);
                }
                else
                {
                    // the only acceptable result is that it ran out of retries when
                    // talking to the cluster (trying to get a connection)
                    r.ResultCode.ShouldEqual(ResultCode.NoRetries);
                    ++failures;
                }
            }

            Console.WriteLine("Total of {0} out of {1} failed to execute due to connection contention", failures, ThreadCount * ActionCount);
        }
开发者ID:josephjeganathan,项目名称:riak-dotnet-client,代码行数:49,代码来源:LoadTests.cs

示例8: WillOuterJoinTwoSets

        public void WillOuterJoinTwoSets()
        {
            //arrange
            var data1 = new List<int>() {3, 13, 7};
            var data2 = new List<int>() {8, 7, 13, 24};

            //act
            //var join = data1.Join(data2, x => x, y => y, (x, y) => x);
            var join = data1.GroupJoin(data2, x => x, y => y, (x, y) => new {Foo = x, Bars = y});
                //.SelectMany(x => x.Bars.DefaultIfEmpty());
            var j1 = data1.SelectMany(x => data2.Where(y => y == x).DefaultIfEmpty(), (x, y) => y);
            //data1.LeftOuterJoin()

            //assert
            j1.Count().ShouldEqual(5);
        }
开发者ID:anton-abyzov,项目名称:Gists,代码行数:16,代码来源:LinqTests.cs

示例9: ShouldWork

        public void ShouldWork()
        {
            var ready = false;
            var bytes = new List<byte[]>();
            var obs = new ObservableFromFile(@"samples\example_1.txt");
            obs.Subscribe(bytes.Add, e => { }, () => { ready = true; });
            while (!ready)
            {
                Thread.Sleep(10);
            }

            var array = bytes.SelectMany(b => b)
                             .Skip(3) // ignore the first 3bytes
                             .ToArray();
            var result = Encoding.UTF8.GetString(array).Replace("\n", " ").Replace("\r\n", " ");
            var expected = String.Join(" ", Enumerable.Range(1, 9));
            result.Should().Be.EqualTo(expected);
        }
开发者ID:happygrizzly,项目名称:Anna,代码行数:18,代码来源:ObservableFromFileTests.cs

示例10: Original

        public void Original()
        {
            var allCsvs = new List<Csv>
            {
            new Csv
                {
                    CommaSepList = "1,2,3,4,,5"
                },
            new Csv
                {
                    CommaSepList = "4,5,7,,5,,"
                },
            };

            int[] intArray = allCsvs
            .SelectMany(c => c.CommaSepList.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
            .Select(int.Parse)
            .ToArray();
        }
开发者ID:BarakUgav61,项目名称:Scratch,代码行数:19,代码来源:CommaSeparatedList.cs

示例11: RequestCustomValidatorErrorCode_When_all_have_unique_value_Then_test_passed

        public void RequestCustomValidatorErrorCode_When_all_have_unique_value_Then_test_passed()
        {
            RequestValidatorErrorMessagesDictionary.Register<ProductRequestCustomValidatorErrorCode>();
            RequestValidatorErrorMessagesDictionary.Register<PartnerRequestCustomValidatorErrorCode>();
            RequestValidatorErrorMessagesDictionary.Register<RequestValidatorErrorCode>();
            RequestValidatorErrorMessagesDictionary.Register<CommonErrorCode>();

            var types = new List<Type>();
            types.Add(typeof(ProductRequestCustomValidatorErrorCode));
            types.Add(typeof(PartnerRequestCustomValidatorErrorCode));
            types.Add(typeof(RequestValidatorErrorCode));
            types.Add(typeof (CommonErrorCode));

            var codeConsts =
                types.SelectMany(t => t.GetFields(BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy)
                                        .Where(f => f.IsLiteral && f.FieldType == typeof(int) && f.DeclaringType == t)).ToList();

            Assert.AreEqual(codeConsts.Count, codeConsts.Select(s => (int)s.GetValue(null)).Distinct().Count(), "Error codes are not unique");
            Assert.AreEqual(codeConsts.Count, RequestValidatorErrorMessagesDictionary.Instance.Count, "Fetched error codes count is not correct");
            Assert.Pass(codeConsts.Count+" unique error codes");
        }
开发者ID:qstream-inactive,项目名称:ENTech-Store,代码行数:21,代码来源:RequestCustomValidatorTest.cs

示例12: Given_IsSensitive_is_true_then_PersonalRiskAssessment_not_returned

        public void Given_IsSensitive_is_true_then_PersonalRiskAssessment_not_returned()
        {
            //GIVEN
            var pras = new List<PersonalRiskAssessment>();
            var pra = PersonalRiskAssessment.Create("title", "reference", _companyId, new UserForAuditing() { Id = Guid.NewGuid() });
            pra.Sensitive = true;
            pra.RiskAssessmentSite = new Site();
            pras.Add(pra);

            var target = GetTarget();

            target.Setup(x => x.PersonalRiskAssessments())
                .Returns(pras.AsQueryable);

            target.Setup(x => x.RiskAssessmentReviews())
               .Returns(pras.SelectMany(x => x.Reviews).AsQueryable);

            var result = target.Object.Search(null, _companyId, null, null, null, null, null, _user.Id, false, false, 1, 10, RiskAssessmentOrderByColumn.Title, OrderByDirection.Ascending);

            //THEN
            Assert.That(result.Count(), Is.EqualTo(0));
        }
开发者ID:mnasif786,项目名称:Business-Safe,代码行数:22,代码来源:PersonalRiskAssessmentRepoTests.cs

示例13: RequestCustomValidatorErrorCode_When_all_have_stringValueAttribute_Then_test_passed

        public void RequestCustomValidatorErrorCode_When_all_have_stringValueAttribute_Then_test_passed()
        {
            RequestValidatorErrorMessagesDictionary.Register<ProductRequestCustomValidatorErrorCode>();
            RequestValidatorErrorMessagesDictionary.Register<PartnerRequestCustomValidatorErrorCode>();
            RequestValidatorErrorMessagesDictionary.Register<RequestValidatorErrorCode>();
            RequestValidatorErrorMessagesDictionary.Register<CommonErrorCode>();

            var types = new List<Type>();
            types.Add(typeof(ProductRequestCustomValidatorErrorCode));
            types.Add(typeof(PartnerRequestCustomValidatorErrorCode));
            types.Add(typeof(RequestValidatorErrorCode));
            types.Add(typeof(CommonErrorCode));

            var codeConsts =
                types.SelectMany(t => t.GetFields(BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy)
                                        .Where(f => f.IsLiteral && f.FieldType == typeof(int) && f.DeclaringType == t)).ToList();

            foreach (var codeConst in codeConsts)
            {
                Assert.IsTrue(codeConst.CustomAttributes
                    .SingleOrDefault(s => s.AttributeType == typeof(StringValueAttribute)) != null);
            }
        }
开发者ID:qstream-inactive,项目名称:ENTech-Store,代码行数:23,代码来源:RequestCustomValidatorTest.cs

示例14: SeedStackOverflowData

        private void SeedStackOverflowData(IDbConnectionFactory dbConnectionFactory)
        {
            var client = new JsonServiceClient();
            int numberOfPages = 80;
            int pageSize = 100;
            var dbQuestions = new List<Question>();
            var dbAnswers = new List<Answer>();
            try
            {
                for (int i = 1; i < numberOfPages + 1; i++)
                {
                    //Throttle queries
                    Thread.Sleep(100);
                    var questionsResponse =
                        client.Get("https://api.stackexchange.com/2.2/questions?page={0}&pagesize={1}&site={2}&tagged=servicestack"
                                .Fmt(i, pageSize, "stackoverflow"));

                    QuestionsResponse qResponse;
                    using (new ConfigScope())
                    {
                        var json = questionsResponse.ReadToEnd();
                        qResponse = json.FromJson<QuestionsResponse>();
                        dbQuestions.AddRange(qResponse.Items.Select(q => q.ConvertTo<Question>()));
                    }

                    var acceptedAnswers =
                        qResponse.Items
                        .Where(x => x.AcceptedAnswerId != null)
                        .Select(x => x.AcceptedAnswerId).ToList();

                    var answersResponse = client.Get("https://api.stackexchange.com/2.2/answers/{0}?sort=activity&site=stackoverflow"
                        .Fmt(acceptedAnswers.Join(";")));

                    using (new ConfigScope())
                    {
                        var json = answersResponse.ReadToEnd();
                        var aResponse = JsonSerializer.DeserializeFromString<AnswersResponse>(json);
                        dbAnswers.AddRange(aResponse.Items.Select(a => a.ConvertTo<Answer>()));
                    }
                }
            }
            catch (Exception ex)
            {
                //ignore
            }

            //Filter duplicates
            dbQuestions = dbQuestions.GroupBy(q => q.QuestionId).Select(q => q.First()).ToList();
            dbAnswers = dbAnswers.GroupBy(a => a.AnswerId).Select(a => a.First()).ToList();
            var questionTags = dbQuestions.SelectMany(q =>
                q.Tags.Select(t => new QuestionTag { QuestionId = q.QuestionId, Tag = t }));

            using (var db = dbConnectionFactory.OpenDbConnection())
            {
                db.InsertAll(dbQuestions);
                db.InsertAll(dbAnswers);
                db.InsertAll(questionTags);
            }
        }
开发者ID:wickdninja,项目名称:StackApis,代码行数:59,代码来源:UnitTests.cs

示例15: _SetupLargeDataset

        private void _SetupLargeDataset()
        {
            _largeDataset = new List<string>();
            HashSet<SearchResult> searchResults = new HashSet<SearchResult>();
            StreamReader reader = new StreamReader(@"results.csv");
            reader.ReadLine(); //do not process header

            while (!reader.EndOfStream)
            {
                string line = reader.ReadLine();
                string[] entries = line.Split(new [] {','}, System.StringSplitOptions.None);
                SearchResult sr = new SearchResult(entries[0]);
                searchResults.Add(sr);
            }

            _largeDataset.AddRange(searchResults.Where(x => !string.IsNullOrEmpty(x.Name)).Select(x => x.Name));
            List<string> intermediateDataSet = new List<string>();
            intermediateDataSet.AddRange(_largeDataset.SelectMany(x => x.Split(new[] {' '})));

            _sortedDataSet = new SortedList(
                intermediateDataSet.Where(x => !string.IsNullOrWhiteSpace(x)).
                                    Select(x => x.ToLower().Trim()).
                                    Distinct().
                                    ToDictionary(str => str));
        }
开发者ID:Skookum,项目名称:SearchAlgorithms,代码行数:25,代码来源:LevenshteinAutomataStringStrategyTest.cs


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