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


C# ICollection.ForEach方法代码示例

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


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

示例1: ProcessEntries

        protected override IEnumerable<FileSystemConfigurationEntry> ProcessEntries(ICollection<FileSystemConfigurationEntry> entries)
        {
            entries.ForEach(
                e =>
                    {
                        Logger.Debug("Processing publisher configuration entry: {0}...", e.FileInfo.Name);

                        var configType = Type.GetType(e.Entry.ConfigurationType);
                        var config = Serialiser.FromJson(e.Entry.Data, configType);

                        if (IsDisabled(config))
                            return;

                        var name = Path.GetFileNameWithoutExtension(e.FileInfo.Name);
                        Container.RegisterInstance(configType, config, name);
                        FindAndExecuteBootstrappers(configType, config);
                        e.Entry.RequiredProperties.AddIfMissing(Tuple.Create(ConfigurationEntry.RequiredPropertyNames.NAME, name));

                        if (string.IsNullOrWhiteSpace(e.Entry.PluginType))
                            return;

                        var pluginType = Type.GetType(e.Entry.PluginType);
                        var pluginName = string.Format("{0}.{1}", pluginType.AssemblyQualifiedName, name);
                        Container.RegisterAsSingletonWithInterception<INotificationEventPublisher, IPublisherFilter>(
                            pluginType,
                            pluginName,
                            new Tuple<Type, string>(configType, name));
                    });

            return entries;
        }
开发者ID:jdruin,项目名称:Wolfpack-Redux,代码行数:31,代码来源:FileSystemPublisherLoader.cs

示例2: BMICalculator

        public BMICalculator(decimal height, decimal weight, ICollection<BMILimit> BMILimitsList)
        {
            Height = height;
            Weight = weight;

            _BMILimitsList = BMILimitsList;
            _BMILimitsList.ForEach(v => v.IsSelected = false);
        }
开发者ID:kneefer,项目名称:WindowsPhoneBMIApp,代码行数:8,代码来源:BMICalculator.cs

示例3: GetAllUserIds

        public static List<string> GetAllUserIds(ICollection<string> users)
        {
            var userIds = new List<string>();
            using (var db = new ApplicationDbContext())
            {
                users.ForEach(u => userIds.Add(db.Users.Where(l => l.UserName.Equals(u)).Select(a => a.Id).First()));
            }

            return userIds;
        }
开发者ID:mataxt,项目名称:Distlab2,代码行数:10,代码来源:UserLogic.cs

示例4: AddRandomPaths

        private void AddRandomPaths(ICollection<Location> locations)
        {
            var rnd = new Random();

            locations.ForEach(location =>
            {
                for (int i = 0; i < rnd.Next(0, 3); i++)
                {
                    location.ConnectedLocations.Add(locations.ElementAt(rnd.Next(0, locations.Count())));
                }
            });
        }
开发者ID:UnderNotic,项目名称:ShortPathAlg,代码行数:12,代码来源:RandomGraphGenerator.cs

示例5: AddPathsForSecondWay

        private void AddPathsForSecondWay(ICollection<Location> locations)
        {
            locations.ForEach(location =>
            {
                location.ConnectedLocations.ForEach(location1 =>
                {
                    locations.Where(connectableLocation => connectableLocation.Equals(location1))
                        .ForEach(connectableLocation2 => connectableLocation2.ConnectedLocations.Add(location));
                });

            });
        }
开发者ID:UnderNotic,项目名称:ShortPathAlg,代码行数:12,代码来源:RandomGraphGenerator.cs

示例6: ProcessEntries

        protected override IEnumerable<FileSystemConfigurationEntry> ProcessEntries(ICollection<FileSystemConfigurationEntry> entries)
        {
            entries.ForEach(e =>
                                {
                                    Logger.Debug("Processing schedule configuration entry: {0}...", e.FileInfo.Name);

                                    var name = Path.GetFileNameWithoutExtension(e.FileInfo.Name);
                                    var concreteType = Type.GetType(e.Entry.ConfigurationType);
                                    var instance = Serialiser.FromJson(e.Entry.Data, concreteType);

                                    Container.RegisterInstance(instance, name);

                                    e.Entry.RequiredProperties
                                        .AddIfMissing(Tuple.Create(ConfigurationEntry.RequiredPropertyNames.NAME, name));
                                });
            return entries;
        }
开发者ID:jdruin,项目名称:Wolfpack-Redux,代码行数:17,代码来源:FileSystemScheduleConfigurationRepository.cs

示例7: ProcessEntries

        protected override IEnumerable<FileSystemConfigurationEntry> ProcessEntries(ICollection<FileSystemConfigurationEntry> entries)
        {
            entries.ForEach(
                e =>
                    {
                        Logger.Debug("Processing bootstrap configuration entry: {0}...", e.FileInfo.Name);

                        var configType = Type.GetType(e.Entry.ConfigurationType);
                        var config = Serialiser.FromJson(e.Entry.Data, configType);

                        if (IsDisabled(config))
                            return;

                        var name = Path.GetFileNameWithoutExtension(e.FileInfo.Name);
                        Container.RegisterInstance(configType, config, name);
                        FindAndExecuteBootstrappers(configType, config);
                        e.Entry.RequiredProperties.AddIfMissing(Tuple.Create(ConfigurationEntry.RequiredPropertyNames.NAME, name));

                        if (string.IsNullOrWhiteSpace(e.Entry.PluginType))
                            return;

                        var interfaceType = string.IsNullOrWhiteSpace(e.Entry.InterfaceType)
                            ? null
                            : Type.GetType(e.Entry.InterfaceType);
                        var pluginType = Type.GetType(e.Entry.PluginType);
                        if (pluginType == null)
                        {
                            Logger.Warning("Unable to create pluginType '{0}'", e.Entry.PluginType);
                            return;
                        }

                        var plugin = Activator.CreateInstance(pluginType, config);

                        if (interfaceType != null)
                            Container.RegisterInstance(interfaceType, plugin);
                        else
                            Container.RegisterInstance(plugin);
                    });

            return entries;
        }
开发者ID:jdruin,项目名称:Wolfpack-Redux,代码行数:41,代码来源:FileSystemBootstrapLoader.cs

示例8: ProcessBatchAsync

        public override async Task ProcessBatchAsync(ICollection<EventContext> contexts) {
            var stacks = new Dictionary<string, Tuple<bool, Stack>>();
            foreach (var ctx in contexts) {
                if (String.IsNullOrEmpty(ctx.Event.StackId)) {
                    // only add default signature info if no other signature info has been added
                    if (ctx.StackSignatureData.Count == 0) {
                        ctx.StackSignatureData.AddItemIfNotEmpty("Type", ctx.Event.Type);
                        ctx.StackSignatureData.AddItemIfNotEmpty("Source", ctx.Event.Source);
                    }

                    string signatureHash = ctx.StackSignatureData.Values.ToSHA1();
                    ctx.SignatureHash = signatureHash;

                    Tuple<bool, Stack> value;
                    if (stacks.TryGetValue(signatureHash, out value)) {
                        ctx.Stack = value.Item2;
                    } else {
                        ctx.Stack = await _stackRepository.GetStackBySignatureHashAsync(ctx.Event.ProjectId, signatureHash).AnyContext();
                        if (ctx.Stack != null)
                            stacks.Add(signatureHash, Tuple.Create(false, ctx.Stack));
                    }

                    if (ctx.Stack == null) {
                        _logger.Trace("Creating new event stack.");
                        ctx.IsNew = true;
                        
                        string title = _formattingPluginManager.GetStackTitle(ctx.Event);
                        var stack = new Stack {
                            OrganizationId = ctx.Event.OrganizationId,
                            ProjectId = ctx.Event.ProjectId,
                            SignatureInfo = new SettingsDictionary(ctx.StackSignatureData),
                            SignatureHash = signatureHash,
                            Title = title?.Truncate(1000),
                            Tags = ctx.Event.Tags ?? new TagSet(),
                            Type = ctx.Event.Type,
                            TotalOccurrences = 1,
                            FirstOccurrence = ctx.Event.Date.UtcDateTime,
                            LastOccurrence = ctx.Event.Date.UtcDateTime,
                            IsHidden = ctx.Event.IsHidden
                        };

                        ctx.Stack = stack;
                        stacks.Add(signatureHash, Tuple.Create(true, ctx.Stack));
                    }
                } else {
                    ctx.Stack = await _stackRepository.GetByIdAsync(ctx.Event.StackId, true).AnyContext();
                    if (ctx.Stack == null || ctx.Stack.ProjectId != ctx.Event.ProjectId) {
                        ctx.SetError("Invalid StackId.");
                        continue;
                    }

                    ctx.SignatureHash = ctx.Stack.SignatureHash;

                    if (!stacks.ContainsKey(ctx.Stack.SignatureHash))
                        stacks.Add(ctx.Stack.SignatureHash, Tuple.Create(false, ctx.Stack));
                    else
                        stacks[ctx.Stack.SignatureHash] = Tuple.Create(false, ctx.Stack);
                }

                if (!ctx.IsNew && ctx.Event.Tags != null && ctx.Event.Tags.Count > 0) {
                    if (ctx.Stack.Tags == null)
                        ctx.Stack.Tags = new TagSet();

                    List<string> newTags = ctx.Event.Tags.Where(t => !ctx.Stack.Tags.Contains(t)).ToList();
                    if (newTags.Count > 0) {
                        ctx.Stack.Tags.AddRange(newTags);
                        // make sure the stack gets saved
                        if (!stacks.ContainsKey(ctx.Stack.SignatureHash))
                            stacks.Add(ctx.Stack.SignatureHash, Tuple.Create(true, ctx.Stack));
                        else
                            stacks[ctx.Stack.SignatureHash] = Tuple.Create(true, stacks[ctx.Stack.SignatureHash].Item2);
                    }
                }

                ctx.Event.IsFirstOccurrence = ctx.IsNew;

                // sync the fixed and hidden flags to the error occurrence
                ctx.Event.IsFixed = ctx.Stack.DateFixed.HasValue;
                ctx.Event.IsHidden = ctx.Stack.IsHidden;
            }

            var stacksToAdd = stacks.Where(kvp => kvp.Value.Item1 && String.IsNullOrEmpty(kvp.Value.Item2.Id)).Select(kvp => kvp.Value.Item2).ToList();
            if (stacksToAdd.Count > 0) {
                await _stackRepository.AddAsync(stacksToAdd, true, sendNotification: stacksToAdd.Count == 1).AnyContext();
                if (stacksToAdd.Count > 1)
                    await _publisher.PublishAsync(new ExtendedEntityChanged { ChangeType = ChangeType.Added, Type = typeof(Stack).Name, OrganizationId = contexts.First().Organization.Id, ProjectId = contexts.First().Project.Id }).AnyContext();
            }

            var stacksToSave = stacks.Where(kvp => kvp.Value.Item1 && !String.IsNullOrEmpty(kvp.Value.Item2.Id)).Select(kvp => kvp.Value.Item2).ToList();
            if (stacksToSave.Count > 0)
                await _stackRepository.SaveAsync(stacksToSave, true, sendNotification: false).AnyContext(); // notification will get sent later in the update stats step

            // Set stack ids after they have been saved and created
            contexts.ForEach(ctx => {
                ctx.Event.StackId = ctx.Stack?.Id;
            });
        }
开发者ID:rpotalara,项目名称:Exceptionless,代码行数:97,代码来源:010_AssignToStackAction.cs

示例9: AddNew

 public async Task<Project> AddNew(
     Project project,
     ICollection<User> collaborators,
     IEnumerable<Tag> tags,
     IEnumerable<ProcessedImage> processedImages,
     string mainImage,
     IEnumerable<File> downloadableFiles)
 {
     collaborators.ForEach(c => project.Collaborators.Add(c));
     tags.ForEach(t => project.Tags.Add(t));
     processedImages.Select(ProcessedImage.ToImage).ForEach(image => { image = this.images.Attach(image); project.Images.Add(image); });
     project.MainImageId = this.GetMainImageId(project, mainImage);
     downloadableFiles.ForEach(file => { file = this.files.Attach(file); project.Files.Add(file); });
     this.projects.Add(project);
     await this.projects.SaveChangesAsync();
     return project;
 }
开发者ID:plamenyovchev,项目名称:ShowcaseSystem,代码行数:17,代码来源:ProjectsService.cs

示例10: CreateTupleTypeName

 private static RTypeName CreateTupleTypeName(ICollection<RTypeName> paramTypes)
 {
     RTypeName tupleType = new RTypeName(CreateTupleClassName(paramTypes.Count));
     paramTypes.ForEach(tupleType.AddGenericArgument);
     return tupleType;
 }
开发者ID:dubik,项目名称:csharprpp,代码行数:6,代码来源:RppParser.cs

示例11: CreateClosureTypeName

 /// <summary>
 /// Creates Function[paramCount] type name if return type is not Unit.
 /// If it's Unit then it creates Action[paramCount].
 /// </summary>
 private static RTypeName CreateClosureTypeName(ICollection<RTypeName> paramTypes, RTypeName returnType)
 {
     bool isAction = IsAction(returnType);
     string baseTypeName = isAction ? "Action" : "Function";
     RTypeName closureType = new RTypeName(baseTypeName + paramTypes.Count);
     paramTypes.ForEach(closureType.AddGenericArgument);
     if (!isAction)
     {
         closureType.AddGenericArgument(returnType);
     }
     return closureType;
 }
开发者ID:dubik,项目名称:csharprpp,代码行数:16,代码来源:RppParser.cs

示例12: PopulateComboBox

        private void PopulateComboBox(ICollection<ReleaseMedium> releaseMedia)
        {
            comboBoxMedia.Items.Clear();

            releaseMedia.ForEach(item => comboBoxMedia.Items.Add(item));

            var hasItems = releaseMedia.Any();

            if (hasItems)
                comboBoxMedia.SelectedIndex = 0;

            comboBoxMedia.Enabled = hasItems;
        }
开发者ID:JGTM2016,项目名称:bdhero,代码行数:13,代码来源:MediaPanel.cs

示例13: GenerateBasicCyclicGraph

 private void GenerateBasicCyclicGraph(ICollection<Location> locations)
 {
     locations.ForEach(location => location.ConnectedLocations.Add(GetClosestLocation(locations, location)));
 }
开发者ID:UnderNotic,项目名称:ShortPathAlg,代码行数:4,代码来源:RandomGraphGenerator.cs


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