本文整理汇总了C#中System.Linq.ForEach方法的典型用法代码示例。如果您正苦于以下问题:C# System.Linq.ForEach方法的具体用法?C# System.Linq.ForEach怎么用?C# System.Linq.ForEach使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Linq
的用法示例。
在下文中一共展示了System.Linq.ForEach方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CanForwardToMultipleRecipients
public async Task CanForwardToMultipleRecipients()
{
var network = new InMemNetwork();
var activator = new BuiltinHandlerActivator();
Using(activator);
var recipients = new[] { "recipient-A", "recipient-B" }.ToList();
recipients.ForEach(network.CreateQueue);
Configure.With(activator)
.Transport(t => t.UseInMemoryTransport(network, "forwarder"))
.Routing(t =>
{
t.AddTransportMessageForwarder(async transportMessage => ForwardAction.ForwardTo(recipients));
})
.Start();
await activator.Bus.SendLocal("HEJ MED DIG!!!");
var transportMessages = await Task.WhenAll(recipients.Select(async queue =>
{
var message = await network.WaitForNextMessageFrom(queue);
return message;
}));
Assert.That(transportMessages.Length, Is.EqualTo(2));
}
示例2: SaveOrLoad
public void SaveOrLoad(Serializer ser)
{
var snmTriggerEntries = new []
{
LoadAndSaveEntry.Create(r => Sound = r.ReadInt16(), w => w.WriteInt16(Sound), 54),
LoadAndSaveEntry.Create(r => Id = r.ReadByte(), w => w.WriteByte(Id), 54),
LoadAndSaveEntry.Create(r => Expire = r.ReadUInt16(), w => w.WriteUInt16(Expire), 54),
LoadAndSaveEntry.Create(r => Command = r.ReadUInt16s(8).Select(i => (int)i).ToArray(), w => w.WriteUInt16s(Command.Select(i => (ushort)i).ToArray(), 8), 54),
};
snmTriggerEntries.ForEach(e => e.Execute(ser));
}
示例3: Initialize
public void Initialize(IScriptPackSession session)
{
var namespaces = new[]
{
"Microsoft.Xrm.Sdk.Client",
"Microsoft.Xrm.Sdk",
"Microsoft.Xrm.Sdk.Query",
"Microsoft.Xrm.Sdk.Messages",
"Microsoft.Crm.Sdk.Messages"
}.ToList();
namespaces.ForEach(session.ImportNamespace);
session.AddReference("System.Runtime.Serialization");
}
示例4: Should_Deny_Urls
public void Should_Deny_Urls()
{
var service = new DefaultUrlService(null, null);
var invalidUrls = new[]
{
@"//",
@"a//a",
@"b//a/",
@"c/a/a/a/a/a/a/žaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1/a",
@"dsdasd\asdasdasdas",
@"esdas$asdasdasdasd",
}.ToList();
invalidUrls.ForEach(url => Assert.IsFalse(service.ValidateUrl(url), string.Format("URL must be invalid: '{0}'", url)));
}
示例5: Should_Allow_Urls
public void Should_Allow_Urls()
{
var service = new DefaultUrlService(null, null);
var validUrls = new[]
{
@"/",
@"/a/",
@"bsd-asd",
@"c/a",
@"d/a/a/a/a/a/a/žaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/a",
@"e/a/a/a/a/a/a/žaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/aaa/a",
@"/fasd/aasd/aasd/aasdasdad/aasdasd/asdasda/žaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/a",
@"gsad/aa",
@"/hasd",
@"/j",
@"/ksdasdasd/",
@"/شسیللانتلان/",
@"/уцкевапрнгш-енгшен/",
}.ToList();
validUrls.ForEach(url => Assert.IsTrue(service.ValidateUrl(url), string.Format("URL must be valid: '{0}'", url)));
}
示例6: WhenGettingSpeakerSessionsOnlySessionsForThatSpeakerAreReturned
public void WhenGettingSpeakerSessionsOnlySessionsForThatSpeakerAreReturned()
{
var speaker1FirstName = "Test";
var speaker1LastName = "Speaker";
var speaker1SessionNames = "Sessions by Speaker 1";
var speaker2FirstName = "Other";
var speaker2LastName = "Presenter";
var speaker2SessionNames = "Sessions by Speaker 2";
// Assemble
var dbContext = new InMemoryOCCDB()
.WithEvent("Test Code Camp")
.WithPerson(speaker1FirstName, speaker1LastName)
.WithPerson(speaker2FirstName, speaker2LastName);
var @event = dbContext.Events.First();
var speaker1 = dbContext.People.First(p => p.FirstName.Equals(speaker1FirstName) && p.LastName.Equals(speaker1LastName));
var speaker2 = dbContext.People.First(p => p.FirstName.Equals(speaker2FirstName) && p.LastName.Equals(speaker2LastName));
var sessions = new[]
{
new Data.Session
{
Event_ID = @event.ID,
Name = speaker1SessionNames,
Speaker_ID = speaker1.ID,
},
new Data.Session
{
Event_ID = @event.ID,
Name = speaker1SessionNames,
Speaker_ID = speaker1.ID,
},
new Data.Session
{
Event_ID = @event.ID,
Name = speaker1SessionNames,
Speaker_ID = speaker1.ID,
},
new Data.Session
{
Event_ID = @event.ID,
Name = speaker2SessionNames,
Speaker_ID = speaker2.ID,
},
new Data.Session
{
Event_ID = @event.ID,
Name = speaker2SessionNames,
Speaker_ID = speaker2.ID,
}
};
sessions.ForEach(s=>dbContext.Sessions.Add(s));
dbContext.SaveChanges();
var service = TestHelper.GetTestService(dbContext);
// Act
var speaker2Sessions = service.GetSpeakerSessions(@event.ID,speaker2.ID);
// Assert
Assert.AreEqual(speaker2Sessions.Count(), 2);
speaker2Sessions.ForEach(s =>
{
Assert.AreEqual(s.Name,speaker2SessionNames);
});
}