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


C# System.Linq.SelectMany方法代码示例

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


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

示例1: RegisterServices

        public void RegisterServices(Container container)
        {
            var serviceAssemblies = new[]
            {
                typeof(IService).Assembly,
                Assembly.Load(AssemblyConstants.ServicesData),
                Assembly.Load(AssemblyConstants.ServicesAdministration),
            };

            var registrations = serviceAssemblies
                .SelectMany(a => a.GetExportedTypes())
                .Where(t => typeof(IService).IsAssignableFrom(t) && !t.IsAbstract && !t.IsGenericTypeDefinition)
                .Select(t => new { Service = t.GetInterfaces().Single(i => i != typeof(IService)), Implementation = t })
                .ToList();

            var webRequestLifestyle = new WebRequestLifestyle();
            foreach (var registration in registrations)
            {
                container.AddRegistration(
                    registration.Service,
                    webRequestLifestyle.CreateRegistration(registration.Service, registration.Implementation, container));
            }

            //// TODO: Register with LINQ!

            ////container.Register<ICacheService, HttpRuntimeCacheService>(webRequestLifestyle);
            ////container.Register<ICacheItemsProviderService, CacheItemsProviderService>(webRequestLifestyle);
            ////container.Register<ITagsDataService, TagsDataService>(webRequestLifestyle);
            ////container.Register<IPostsDataService, PostsDataService>(webRequestLifestyle);
            ////container.Register<ICommentsDataService, CommentsDataService>(webRequestLifestyle);
        }
开发者ID:plamenyovchev,项目名称:Bloggable,代码行数:31,代码来源:ServicesPackage.cs

示例2: Install

        public void Install(IWindsorContainer container, IConfigurationStore store)
        {
            var metadataProviderContributorsAssemblies = new[] { typeof (QueryProcessor).Assembly };

                container.Register(AllTypes.From(metadataProviderContributorsAssemblies.SelectMany(a => a.GetExportedTypes()))
                               	.Where(t => t.Name.EndsWith("Handler") && t.IsAbstract == false)
                               	.Configure(x => x.LifestyleSingleton())
                );
            container.Register(Component.For<IProcessQuery>().ImplementedBy<QueryProcessor>().LifeStyle.Singleton);
            container.Register(Component.For<IProcessCommand>().ImplementedBy<CommandProcessor>().LifeStyle.Singleton);
        }
开发者ID:mravinale,项目名称:simple-cqrs,代码行数:11,代码来源:HandlersInstaller.cs

示例3: GeoShapeLineString_Deserializes

		public void GeoShapeLineString_Deserializes()
		{
			var coordinates = new[] { new[] { 13.0, 53.0 }, new[] { 14.0, 52.0 } };

			var q = this.SerializeThenDeserialize(
				f => f.GeoShape,
				f => f.GeoShapeLineString(gq => gq
					.OnField(p => p.MyGeoShape)
					.Coordinates(coordinates)
					)
				);

			var query = q as IGeoShapeLineStringQuery;
			query.Should().NotBeNull();
			query.Field.Should().Be("myGeoShape");
			query.Shape.Should().NotBeNull();
			query.Shape.Type.Should().Be("linestring");
			query.Shape.Coordinates.SelectMany(c => c).Should()
				.BeEquivalentTo(coordinates.SelectMany(c => c));
		}
开发者ID:BiYiTuan,项目名称:elasticsearch-net,代码行数:20,代码来源:GeoShapeQueryTests.cs

示例4: Execute

        public void Execute(DataSetCollection dataSets)
        {
            var export = Wiki;

            // Pages des listes d'objets
            var objectLists = new[]
            {
                "pathfinder-rpg.objets merveilleux",
                "pathfinder-rpg.objets merveilleux apg"
            }.Select(pn => export.Pages[new WikiName(pn)]);

            // Liste des pages décrivant des objets magiques
            var objectPages = objectLists
                .SelectMany(p => p.OutLinks)
                .Distinct()
                .ToList();

            // Feats dataset
            //var ds = dataSets.ResolveDataSet("feats");
        }
开发者ID:Pathfinder-Fr,项目名称:WikiExportParser,代码行数:20,代码来源:GenerateMagicItemsCommand.cs

示例5: GeoShapeMultiLineString_Deserializes

		public void GeoShapeMultiLineString_Deserializes()
		{
			var coordinates = new[] 
			{ 
				new[] { new[] { 102.0, 2.0 }, new[] { 103.0, 2.0 }, new[] { 103.0, 3.0 }, new[] { 102.0, 3.0 } },
				new[] { new[] { 100.0, 0.0 }, new[] { 101.0, 0.0 }, new[] { 101.0, 1.0 }, new[] { 100.0, 1.0 } },
				new[] { new[] { 100.2, 0.2 }, new[] { 100.8, 0.2 }, new[] { 100.8, 0.8 }, new[] { 100.2, 0.8 } } 
			};

			var q = this.SerializeThenDeserialize(
				f => f.GeoShape,
				f => f.GeoShapeMultiLineString(gq => gq
					.OnField(p => p.MyGeoShape)
					.Coordinates(coordinates)
					)
				);

			var query = q as IGeoShapeMultiLineStringQuery;
			query.Should().NotBeNull();
			query.Field.Should().Be("myGeoShape");
			query.Shape.Should().NotBeNull();
			query.Shape.Type.Should().Be("multilinestring");
			query.Shape.Coordinates.SelectMany(c => c.SelectMany(cc => cc)).Should()
				.BeEquivalentTo(coordinates.SelectMany(c => c.SelectMany(cc => cc)));
		}
开发者ID:BiYiTuan,项目名称:elasticsearch-net,代码行数:25,代码来源:GeoShapeQueryTests.cs

示例6: Test

        //public class A
        //{
        //    public string Name { get; set; }
        //}
        public static void Test(Assert assert)
        {
            assert.Expect(8);

            // TEST
            var numbers = new[] { 1, 3, 5, 7 };
            var numberPlusOne = (from n in numbers select n + 1).ToArray();
            assert.DeepEqual(numberPlusOne, new[] { 2, 4, 6, 8 }, "A sequence of ints one higher than the numbers[]");

            // TEST
            var persons = Person.GetPersons();
            var names = (from p in persons select p.Name).ToArray();
            assert.DeepEqual(names, new[] { "Frank", "Zeppa", "John", "Billy", "Dora", "Ian", "Mary", "Nemo" }, "Selects names as instance field");

            // TEST
            string[] strings = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" };

            var textNumbers = (from n in numbers select strings[n]).ToArray();
            assert.DeepEqual(textNumbers, new[] { "one", "three", "five", "seven" }, "Selects names as items of another array");

            // TEST
            var anonimNames = (from p in persons select new { Name = p.Name }).ToArray();

            object[] anonimNamesToCompare = {
                                                new { Name = "Frank" }, new { Name = "Zeppa" }, new { Name = "John" },
                                                new { Name = "Billy" }, new { Name = "Dora" }, new { Name = "Ian" },
                                                new { Name = "Mary" }, new { Name = "Nemo" } };

            assert.DeepEqual(anonimNames, anonimNamesToCompare, "Selects names as an anonymous type");

            // TEST
            numbers = new[] { 0, 1, 3, 3 };

            var numberssInPlace = numbers
                                    .Select((n, index) => new
                                        {
                                            Number = n,
                                            IsIndex = n == index
                                        })
                                    .ToArray();

            object[] anonimNumbersToCompare = { new { Number = 0, IsIndex = true },
                                                  new { Number = 1, IsIndex = true },
                                                  new { Number = 3, IsIndex = false },
                                                  new { Number = 3, IsIndex = true }
                                              };

            assert.DeepEqual(numberssInPlace, anonimNumbersToCompare, "Selects numbers as an anonymous type");

            // TEST
            var numbersA = new[] { 1, 5, 2 };
            var numbersB = new[] { 3, 4, 2 };
            var simplePairs =
                (from a in numbersA
                 from b in numbersB
                 where a < b
                 select new { A = a, B = b }
                ).ToArray();

            object[] expectedSimplePairs = { new { A = 1, B = 3 }, new { A = 1, B = 4 }, new { A = 1, B = 2 }, new { A = 2, B = 3 }, new { A = 2, B = 4 } };

            assert.DeepEqual(simplePairs, expectedSimplePairs, "Join two numeric arrays with one where clause");

            // TEST
            numbersA = new[] { 1, 5, 2, 4, 3 };
            numbersB = new[] { 3, 4, 2, 5, 1 };

            var pairs =
                (from a in numbersA
                where a > 1
                from b in numbersB
                where b < 4 && a > b
                select new { Sum = a + b }
                ).ToArray();

            object[] expectedPairs = { new { Sum = 8}, new { Sum = 7}, new { Sum = 6}, new { Sum = 3},
                                     new { Sum = 7}, new { Sum = 6}, new { Sum = 5},
                                     new { Sum = 5}, new { Sum = 4},};

            assert.DeepEqual(pairs, expectedPairs, "Join two numeric arrays with two where clauses");

            // TEST
            numbersA = new[] { 1, 5, 2, 4, 3 };
            numbersB = new[] { 3, 4, 2, 5, 1 };

            var manyNumbers = numbersA
                .SelectMany((a, aIndex) => numbersB.Where(b => a == b && b > aIndex).Select(b => new { A = a, B = b, I = aIndex }))
                .ToArray();

            object[] expectedManyNumbers = { new { A = 1, B = 1, I = 0 },
                                           new { A = 5, B = 5, I = 1 },
                                           new { A = 4, B = 4, I = 3 }};

            assert.DeepEqual(manyNumbers, expectedManyNumbers, "SelectMany() two number arrays");
        }
开发者ID:txdv,项目名称:Testing,代码行数:99,代码来源:TestLinqProjectionOperators.cs

示例7: DuplicateAttributes_SingleProperty_SameKey_ThrowsException

 public void DuplicateAttributes_SingleProperty_SameKey_ThrowsException()
 {
     var model = new[] { typeof(ModelWithDuplicateResourceKeys) };
     Assert.Throws<DuplicateResourceKeyException>(() => model.SelectMany(t => _sut.ScanResources(t)).ToList());
 }
开发者ID:valdisiljuconoks,项目名称:LocalizationProvider,代码行数:5,代码来源:NamedModelsTests.cs

示例8: DuplicateAttributes_DiffProperties_SameKey_ThrowsException

 public void DuplicateAttributes_DiffProperties_SameKey_ThrowsException()
 {
     var model = new[] { typeof(BadResourceWithDuplicateKeysWithinClass) };
     Assert.Throws<DuplicateResourceKeyException>(() => model.SelectMany(t => _sut.ScanResources(t)).ToList());
 }
开发者ID:valdisiljuconoks,项目名称:LocalizationProvider,代码行数:5,代码来源:NamedModelsTests.cs

示例9: StructureIntegrity

        public void StructureIntegrity()
        {
            RedBlackTree<int, int> tree = new RedBlackTree<int, int>();

            int range = 10;
            int[] order = new[] { 1, 3, 2, 5, 6 };

            var q = order
                .SelectMany(x => Enumerable.Range((x - 1) * range + 1, range));


            foreach (int i in q)
            {
                Assert.IsFalse(tree.ContainsKey(i));

                tree.Add(i, i);

                AssertStructure(tree.RootElement);
                Assert.IsTrue(tree.ContainsKey(i));
            }

            foreach (int i in q)
            {
                AssertStructure(tree.RootElement);
                Assert.IsTrue(tree.ContainsKey(i));

                tree.Remove(i);

                Assert.IsFalse(tree.ContainsKey(i));
            }

        }
开发者ID:CedricDumont,项目名称:NMemory.Next,代码行数:32,代码来源:RedBlackTreeFixture.cs

示例10: Load

        protected override void Load(ContainerBuilder builder)
        {
            var assemblies = new[] { typeof(LanguageModule).Assembly, _executingAssembly };

            builder.RegisterType<ProgramState>().AsSelf().SingleInstance();

            builder.RegisterAssemblyTypes(assemblies)
                .Where(t => t.GetInterfaces().Contains(typeof(IProgramBody)))
                .AsSelf()
                .InstancePerDependency();

            // values

            var genericValueProviderTypes = assemblies.SelectMany(a => a.GetTypes()
                    .Where(t => t.IsGenericType && t.GetInterfaces().Contains(typeof(IValueProvider))));
            var nonGenericValueProviderTypes = assemblies.SelectMany(a => a.GetTypes()
                    .Where(t => !t.IsGenericType && t.GetInterfaces().Contains(typeof(IValueProvider))));

            // generic value providers
            foreach (var genericValueProviderType in genericValueProviderTypes)
            {
                builder
                    .RegisterGeneric(genericValueProviderType)
                    .As(genericValueProviderType)
                    .InstancePerDependency();
            }

            // non-generic value providers
            foreach (var nonGenericValueProviderType in nonGenericValueProviderTypes)
            {
                builder
                    .RegisterType(nonGenericValueProviderType)
                    .AsSelf()
                    .InstancePerDependency();
            }

            var genericCommandTypes = assemblies.SelectMany(a => a.GetTypes()
                    .Where(t => t.IsGenericType && typeof (BaseCommand).IsAssignableFrom(t)));
            var nonGenericCommandTypes = assemblies.SelectMany(a => a.GetTypes()
                    .Where(t => !t.IsGenericType && typeof(BaseCommand).IsAssignableFrom(t)));

            // generic commands
            foreach (var genericCommandType in genericCommandTypes)
            {
                builder
                    .RegisterGeneric(genericCommandType)
                    .As(genericCommandType)
                    .InstancePerDependency()
                    .OnActivated(activated => ((BaseCommand) activated.Instance).Execute());
            }

            // non-generic commands
            foreach (var nonGenericCommandType in nonGenericCommandTypes)
            {
                builder
                    .RegisterType(nonGenericCommandType)
                    .AsSelf()
                    .InstancePerDependency()
                    .OnActivated(activated => ((BaseCommand) activated.Instance).Execute());
            }

            var genericConditionTypes = assemblies.SelectMany(a => a.GetTypes()
                .Where(t => t.IsGenericType && t.GetInterfaces().Contains(typeof(ICondition))));
            var nonGenericConditionTypes = assemblies.SelectMany(a => a.GetTypes()
                .Where(t => !t.IsGenericType && t.GetInterfaces().Contains(typeof(ICondition))));

            foreach (var genericConditionType in genericConditionTypes)
            {
                builder
                    .RegisterGeneric(genericConditionType)
                    .As(genericConditionType)
                    .InstancePerDependency();
            }

            foreach (var nonGenericConditionType in nonGenericConditionTypes)
            {
                builder
                    .RegisterType(nonGenericConditionType)
                    .As(nonGenericConditionType)
                    .InstancePerDependency();
            }
        }
开发者ID:BaconSoap,项目名称:autofac-programming-language,代码行数:82,代码来源:LanguageModule.cs


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