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


C# IEnumerable.ForEach方法代码示例

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


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

示例1: DisableAndEnableButtons

        public DisableAndEnableButtons()
        {
            _modules = CreateMenuElementGroup() ;
            _toolbar = CreateMenuElements();

            AddAction("Enable Toolbar", () =>
                      _toolbar.ForEach(x => x.Enable()));
            AddAction("Disable Toolbar", () =>
                      _toolbar.ForEach(x => x.Disable()));
        }
开发者ID:scaredfinger,项目名称:ActiveWidgets,代码行数:10,代码来源:DisableAndEnableButtons.cs

示例2: SetupProxy

        protected Action<object> SetupProxy(Type eventType, IEnumerable<Type> constraintHandlerTypes = null)
        {
            ids = new ConcurrentBag<string>();
            events = new ConcurrentBag<object>();
            typeName = eventType.FullName;
            typeNames = new[] { typeName }.Select(t => new EventType { Type = t }).ToList();

            Action<object> handler = null;
            WhenCalling<ITypeFinder>(x => x.ListEventTypes()).Return(new[] { eventType });
            WhenCalling<ITypeFinder>(x => x.GetEventType(Arg<string>.Is.Anything)).Return(eventType);
            if (constraintHandlerTypes != null)
                constraintHandlerTypes.ForEach(t => Register(Activator.CreateInstance((Type) t)));
            WhenCalling<ITypeFinder>(x => x.GetConstraintHandlerTypes(Arg<Type>.Is.Anything))
                    .Return(constraintHandlerTypes != null ? constraintHandlerTypes : Enumerable.Empty<Type>());

            WhenCalling<IEventAggregator>(x => x.Subscribe(Arg<Action<object>>.Is.Anything)).Callback<Action<object>>(h =>
            {
                handler = h;
                return true;
            });
            WhenAccessing<IRequest, IPrincipal>(x => x.User).Return(Thread.CurrentPrincipal);

            var client = new Client(events);

            WhenCalling<IHubConnectionContext<dynamic>>(x => x.Client(Arg<string>.Is.Anything)).Return(client);
            WhenAccessing<IHubContext, IHubConnectionContext<dynamic>>(x => x.Clients).Return(Get<IHubConnectionContext<dynamic>>());
            Mock<IConnectionManager>();
            WhenCalling<IConnectionManager>(x => x.GetHubContext<EventAggregatorProxyHub>()).Return(Get<IHubContext>());

            eventProxy = new EventProxy();

            return handler;
        }
开发者ID:human06,项目名称:SignalR.EventAggregatorProxy,代码行数:33,代码来源:EventProxyTest.cs

示例3: SendEmail

        public static void SendEmail(
            IEnumerable<string> toAddresses,
            string fromAddress,
            string subject,
            string body)
        {
            if (!toAddresses.Any() ||
                string.IsNullOrEmpty(subject) ||
                string.IsNullOrEmpty(body))
            {
                throw new ArgumentNullException("SendEmail", "Invalid email request");
            }

            if (string.IsNullOrEmpty(fromAddress))
            {
                fromAddress = ConfigurationManager.AppSettings["Email.DefaultFrom"];
            }

            var message = new MailMessage();
            toAddresses.ForEach(message.To.Add);
            message.From = new MailAddress(fromAddress);
            message.Subject = subject;
            message.Body = body;
            message.BodyEncoding = Encoding.UTF8;

            string host = ConfigurationManager.AppSettings["Email.Host"];
            int port = int.Parse(ConfigurationManager.AppSettings["Email.Port"]);

            SmtpClient client = new SmtpClient(host, port);
            client.Send(message);
        }
开发者ID:fitzbigman,项目名称:CMCoreNET,代码行数:31,代码来源:EmailService.cs

示例4: AddChange

 public void AddChange(uint id, IEnumerable<RelationName> relations)
 {
     if (this.relations.ContainsKey(id) == false)
         this.relations.Add(id, new List<RelationName>());
     relations.ForEach(
         (RelationName relation) => this.relations[id].Add(relation));
 }
开发者ID:fgeraci,项目名称:CS195-Core,代码行数:7,代码来源:ChangeSet.cs

示例5: SendMessage

 public bool SendMessage(string subject, string body, IEnumerable<string> recepients)
 {
     var smtp = new SmtpClient
     {
         Host = "smtp.gmail.com",
         Port = 587,
         EnableSsl = true,
         DeliveryMethod = SmtpDeliveryMethod.Network,
         UseDefaultCredentials = false,
         Credentials = new NetworkCredential(UserName, Password)
     };
     using (var message = new MailMessage
     {
         Subject = subject,
         Body = body,
     })
     {
         message.From = new MailAddress(FromAddress, FromName);
         message.IsBodyHtml = true;
         recepients.ForEach(x => message.To.Add(new MailAddress(x)));
         try
         {
             smtp.Send(message);
         }
         catch (Exception)
         {
             //TODO: shouild be logged
             return false;
         }
     }
     return true;
 }
开发者ID:dzhivtsov,项目名称:GangsterBank,代码行数:32,代码来源:MailService.cs

示例6: SetModelStateErrors

 protected void SetModelStateErrors(IEnumerable<IValidationError> errors)
 {
     if (errors != null)
     {
         errors.ForEach(e => { ModelState.AddModelError(e.Property, e.ErrorMessage); });
     }
 }
开发者ID:mattapayne,项目名称:Complainatron-MVC,代码行数:7,代码来源:AbstractFacebookController.cs

示例7: SaveEnumerable

        protected CommandResult SaveEnumerable( IEnumerable<object> models )
        {
            try
            {
                var list = new BulkPersist( true, false, models );
                var body = list.ToString();

                var result = Post( body );
                var updates = result.GetResultAs<SaveResponse[]>().ToDictionary( x => x.Id, x => x.Revision );
                models
                    .ForEach( x =>
                                  {
                                      var documentId = x.GetDocumentIdAsJson();
                                      string newRev = null;
                                      if ( updates.TryGetValue( documentId, out newRev ) )
                                      {
                                          x.SetDocumentRevision( newRev );
                                      }
                                  } );
                return result;
            }
            catch ( Exception ex )
            {
                throw Exception(
                    ex,
                    "An exception occurred trying to save a collection documents at {0}. \r\n\t {1}",
                    Uri.ToString(),
                    ex
                    );
            }
        }
开发者ID:h3mpti,项目名称:Relax,代码行数:31,代码来源:BaseSaveDocumentCollection.cs

示例8: CommandMediator

            internal CommandMediator( Window window, Interaction interaction, bool bindCancelToClose )
            {
                Contract.Requires( window != null );

                this.window = window;
                this.window.Closing += OnWindowClosing;

                if ( interaction == null )
                    return;

                commands = interaction.Commands;
                commands.ForEach( c => c.Executed += OnExecuted );

                if ( !bindCancelToClose )
                    return;

                // determine if behavior is already applied
                var behaviors = System.Windows.Interactivity.Interaction.GetBehaviors( this.window );
                var behavior = behaviors.OfType<WindowCloseBehavior>().FirstOrDefault();

                // add behavior which can support binding the cancel command to the window close button (X)
                if ( behavior == null )
                {
                    behavior = new WindowCloseBehavior();
                    behaviors.Add( behavior );
                }

                behavior.CloseCommand = interaction.CancelCommand;
            }
开发者ID:WaffleSquirrel,项目名称:More,代码行数:29,代码来源:WindowAction.CommandMediator.cs

示例9: UpdateChain

 private void UpdateChain(IEnumerable<IFilter> filter, bool attach)
 {
     if (filter != null)
     {
         if (attach)
         {
             filter.ForEach(f => f.RequireReaccept += filter_RequireReaccept);
             filter.ForEach(f => f.RequirePartialReaccept += filter_RequirePartialReaccept);
         }
         else
         {
             filter.ForEach(f => f.RequireReaccept -= filter_RequireReaccept);
             filter.ForEach(f => f.RequirePartialReaccept -= filter_RequirePartialReaccept);
         }
     }
 }
开发者ID:sor593,项目名称:Mystique,代码行数:16,代码来源:FilterCluster.cs

示例10: Check

        private void Check(IEnumerable<Tuple<int, int, int>> gen)
        {
            gen.ForEach(t =>
            {
                var len = t.Item1;
                var win = t.Item2;
                var step = t.Item3;

                var af = Source.FromEnumerator(() => Enumerable.Range(0, int.MaxValue).Take(len).GetEnumerator())
                    .Sliding(win, step)
                    .RunAggregate(new List<IEnumerable<int>>(), (ints, e) =>
                    {
                        ints.Add(e);
                        return ints;
                    }, Materializer);

                var input = Enumerable.Range(0, int.MaxValue).Take(len).ToList();
                var cf = Source.FromEnumerator(() => Sliding(input, win, step).GetEnumerator())
                    .RunAggregate(new List<IEnumerable<int>>(), (ints, e) =>
                    {
                        ints.Add(e);
                        return ints;
                    }, Materializer);

                af.Wait(TimeSpan.FromSeconds(30)).Should().BeTrue();
                cf.Wait(TimeSpan.FromSeconds(30)).Should().BeTrue();
                af.Result.ShouldAllBeEquivalentTo(cf.Result);
            });
        }
开发者ID:Micha-kun,项目名称:akka.net,代码行数:29,代码来源:FlowSlidingSpec.cs

示例11: CreateMessage

 private static string CreateMessage(object message, IEnumerable<Type> handlerTypes)
 {
     var exceptionMessage = "There are multiple handlers registered for the message type:{0}.\nIf you are getting this because you have registered a listener as a test spy have your listener implement ISynchronousBusMessageSpy and the exception will disappear"
         .FormatWith(message.GetType());
     handlerTypes.ForEach(handlerType => exceptionMessage += "{0}{1}".FormatWith(Environment.NewLine, handlerType.FullName));
     return exceptionMessage;
 }
开发者ID:RichieYang,项目名称:Composable.Monolithic,代码行数:7,代码来源:MultipleMessageHandlersRegisteredException.cs

示例12: RegisterDeasy

 public void RegisterDeasy(IEnumerable<AttributeInfo<DeasyAttribute>> deasyList)
 {
     deasyList.ForEach(d =>
     {
         Register(d);
     });
 }
开发者ID:khiemnd777,项目名称:deasy,代码行数:7,代码来源:DeasyAttributeRegistrator.cs

示例13: Create

        public static Type Create(Type parent, IEnumerable<Type> interfaces)
        {
            var proxy = module.DefineType(moduleName + '.' + parent.Name,
                                          TypeAttributes.Public | TypeAttributes.Class | TypeAttributes.AutoLayout,
                                          parent);

            interfaces.ForEach(
                @interface =>
                    {
                        proxy.AddInterfaceImplementation(@interface);
                        @interface.GetMethods().ForEach(method => method.ImplementIn(proxy));
                    });
            proxy.GetConstructors(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)
                .ForEach(
                    constructor =>
                        {
                            switch (constructor.Attributes & MethodAttributes.MemberAccessMask)
                            {
                                case MethodAttributes.Family:
                                case MethodAttributes.Public:
                                case MethodAttributes.FamORAssem:
                                    constructor.ImplementIn(proxy);
                                    break;
                            }
                        });

            return proxy.CreateType();
        }
开发者ID:VlaTo,项目名称:EmpRe.NET,代码行数:28,代码来源:TypeProxy.cs

示例14: PluginManager

 /// <summary>
 /// Initializes a new instance of the <see cref="PluginManager"/> class.
 /// </summary>
 /// <param name="Repositories">The repositories.</param>
 /// <param name="Bootstrapper">The bootstrapper.</param>
 public PluginManager(IEnumerable<string> Repositories, IBootstrapper Bootstrapper)
 {
     Contract.Requires<ArgumentNullException>(Repositories != null, "Repositories");
     this.Bootstrapper = Bootstrapper;
     PackageRepositories = Repositories.ForEach(x => PackageRepositoryFactory.Default.CreateRepository(x));
     Initialize();
 }
开发者ID:modulexcite,项目名称:Craig-s-Utility-Library,代码行数:12,代码来源:PluginManager.cs

示例15: MigrationsManager

 public MigrationsManager(IEnumerable<IMigrateSchema> schemas, IRunMigrations runner)
 {
     schemas.MustNotBeNull();
     schemas.ForEach(s => s.Runner = runner);
     _schemas = Sort(schemas);
     _runner = runner;
 }
开发者ID:eugman,项目名称:SqlFu,代码行数:7,代码来源:MigrationsManager.cs


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