本文整理汇总了C#中System.Collections.Generic.Each方法的典型用法代码示例。如果您正苦于以下问题:C# System.Collections.Generic.Each方法的具体用法?C# System.Collections.Generic.Each怎么用?C# System.Collections.Generic.Each使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Generic
的用法示例。
在下文中一共展示了System.Collections.Generic.Each方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Each_should_call_the_provided_action
public void Each_should_call_the_provided_action()
{
IEnumerable<int> list = new[]{ 4 };
bool isCalled = false;
list.Each(i=> isCalled = true);
Assert.True(isCalled);
}
示例2: LoadBasicStrings
protected void LoadBasicStrings(IRedisClient redis)
{
int A = 'A';
int Z = 'Z';
var letters = (Z - A + 1).Times(i => ((char)(i + A)).ToString());
var numbers = new[] { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" };
var pos = 0;
letters.Each(x => redis.Set("string:letters/" + x, x));
numbers.Each(x => redis.Set("string:numbers/" + pos++, x));
}
示例3: numbers_should_be_invalid
public void numbers_should_be_invalid()
{
var numbers = new[]
{
"1,00",
"100,1",
"100,1.01",
"A,Jun.K",
};
numbers.Each(x => x.IsValidNumber(CultureInfo.CreateSpecificCulture("en-us")).ShouldBeFalse());
}
示例4: numbers_with_commas_and_periods_should_be_valid
public void numbers_with_commas_and_periods_should_be_valid()
{
var numbers = new[]
{
"1,000",
"100.1",
"1000.1",
"1,000.1",
"10,000.1",
"100,000.1",
};
numbers.Each(x => x.IsValidNumber(CultureInfo.CreateSpecificCulture("en-us")).ShouldBeTrue());
}
示例5: LoadDifferentKeyTypes
protected void LoadDifferentKeyTypes(IRedisClient redis)
{
int A = 'A';
int Z = 'Z';
var letters = (Z - A + 1).Times(i => ((char)(i + A)).ToString());
var numbers = new[] { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" };
redis.RemoveEntry("list:letters", "list:numbers"); //don't add duplicates to existing list
letters.Each(x => redis.AddItemToList("list:letters", x));
numbers.Each(x => redis.AddItemToList("list:numbers", x));
letters.Each(x => redis.AddItemToSet("set:letters", x));
numbers.Each(x => redis.AddItemToSet("set:numbers", x));
var pos = 0;
letters.Each(x => redis.AddItemToSortedSet("zset:letters", x, pos++));
pos = 0;
numbers.Each(x => redis.AddItemToSortedSet("zset:numbers", x, pos++));
pos = 0;
letters.Each(x => redis.SetEntryInHash("hash:letters", x, (pos++).ToString()));
pos = 0;
numbers.Each(x => redis.SetEntryInHash("hash:numbers", x, (pos++).ToString()));
}
示例6: Can_support_multiple_self_references
public void Can_support_multiple_self_references()
{
var customers = new[]
{
new MultiSelfCustomer
{
Name = "Customer 1",
HomeAddress = new SelfCustomerAddress
{
AddressLine1 = "1 Home Street",
Country = "Australia"
},
WorkAddress = new SelfCustomerAddress
{
AddressLine1 = "1 Work Street",
Country = "Australia"
},
},
new MultiSelfCustomer
{
Name = "Customer 2",
HomeAddress = new SelfCustomerAddress
{
AddressLine1 = "2 Home Park",
Country = "USA"
},
WorkAddress = new SelfCustomerAddress
{
AddressLine1 = "2 Work Park",
Country = "UK"
},
},
};
customers.Each(x =>
db.Save(x, references: true));
var results = db.LoadSelect<MultiSelfCustomer>(q =>
q.HomeAddressId != null &&
q.WorkAddressId != null);
results.PrintDump();
Assert.That(results.Count, Is.EqualTo(2));
Assert.That(results[0].HomeAddress.AddressLine1, Is.StringContaining("Home"));
Assert.That(results[0].WorkAddress.AddressLine1, Is.StringContaining("Work"));
Assert.That(results[1].HomeAddress.AddressLine1, Is.StringContaining("Home"));
Assert.That(results[1].WorkAddress.AddressLine1, Is.StringContaining("Work"));
var ukAddress = db.Single<SelfCustomerAddress>(q => q.Country == "UK");
ukAddress.PrintDump();
Assert.That(ukAddress.AddressLine1, Is.EqualTo("2 Work Park"));
}
示例7: Can_load_list_of_self_references
public void Can_load_list_of_self_references()
{
var customers = new[]
{
new SelfCustomer
{
Name = "Customer 1",
PrimaryAddress = new SelfCustomerAddress
{
AddressLine1 = "1 Australia Street",
Country = "Australia"
},
},
new SelfCustomer
{
Name = "Customer 2",
PrimaryAddress = new SelfCustomerAddress
{
AddressLine1 = "2 Prospect Park",
Country = "USA"
},
},
};
db.Save(new SelfCustomer { Name = "Dummy Incrementer" });
customers.Each(x =>
db.Save(x, references: true));
var results = db.LoadSelect<SelfCustomer>(q => q.SelfCustomerAddressId != null);
Assert.That(results.Count, Is.EqualTo(2));
Assert.That(results.All(x => x.PrimaryAddress != null));
var customer1 = results.First(x => x.Name == "Customer 1");
Assert.That(customer1.PrimaryAddress.Country, Is.EqualTo("Australia"));
var customer2 = results.First(x => x.Name == "Customer 2");
Assert.That(customer2.PrimaryAddress.Country, Is.EqualTo("USA"));
results = db.LoadSelect<SelfCustomer>(q => q.Name == "Customer 1");
Assert.That(results.Count, Is.EqualTo(1));
Assert.That(results[0].PrimaryAddress.Country, Is.EqualTo("Australia"));
}
示例8: Each
public void Each()
{
var source = new[] {1, 2, 3};
var resultBuffer = new List<int>();
source.Each(resultBuffer.Add);
CollectionAssert.AreEqual(source, resultBuffer);
}
示例9: Can_Join_on_matching_Alias_convention
public void Can_Join_on_matching_Alias_convention()
{
db.DropAndCreateTable<AliasedCustomer>();
db.DropAndCreateTable<AliasedCustomerAddress>();
var customers = new[]
{
new AliasedCustomer
{
Name = "Customer 1",
PrimaryAddress = new AliasedCustomerAddress {
AddressLine1 = "1 Australia Street",
Country = "Australia"
},
},
new AliasedCustomer
{
Name = "Customer 2",
PrimaryAddress = new AliasedCustomerAddress {
AddressLine1 = "2 America Street",
Country = "USA"
},
},
new AliasedCustomer
{
Name = "Customer 3",
PrimaryAddress = new AliasedCustomerAddress {
AddressLine1 = "3 Canada Street",
Country = "Canada"
},
},
};
customers.Each(c =>
db.Save(c, references: true));
db.Insert(
new Country { CountryName = "Australia", CountryCode = "AU" },
new Country { CountryName = "USA", CountryCode = "US" },
new Country { CountryName = "Italy", CountryCode = "IT" },
new Country { CountryName = "Spain", CountryCode = "ED" });
//Normal Join
var dbCustomers = db.Select<AliasedCustomer>(q => q
.Join<AliasedCustomerAddress>()
.Join<AliasedCustomerAddress, Country>((ca, c) => ca.Country == c.CountryName));
Assert.That(dbCustomers.Count, Is.EqualTo(2));
//Left Join
dbCustomers = db.Select<AliasedCustomer>(q => q
.Join<AliasedCustomerAddress>()
.LeftJoin<AliasedCustomerAddress, Country>((ca, c) => ca.Country == c.CountryName));
Assert.That(dbCustomers.Count, Is.EqualTo(3));
//Warning: Right and Full Joins are not implemented by Sqlite3. Avoid if possible.
var dbCountries = db.Select<Country>(q => q
.LeftJoin<AliasedCustomerAddress>((c, ca) => ca.Country == c.CountryName)
.LeftJoin<AliasedCustomerAddress, AliasedCustomer>());
Assert.That(dbCountries.Count, Is.EqualTo(4));
var dbAddresses = db.Select<AliasedCustomerAddress>(q => q
.LeftJoin<Country>((ca, c) => ca.Country == c.CountryName)
.LeftJoin<AliasedCustomerAddress, AliasedCustomer>());
Assert.That(dbAddresses.Count, Is.EqualTo(3));
}
示例10: Can_do_joins_with_complex_wheres_using_SqlExpression
public void Can_do_joins_with_complex_wheres_using_SqlExpression()
{
var customers = new[]
{
new Customer
{
Name = "Customer 1",
PrimaryAddress = new CustomerAddress {
AddressLine1 = "1 Australia Street",
Country = "Australia"
},
Orders = new[] {
new Order { LineItem = "Line 1", Qty = 1, Cost = 1.99m },
new Order { LineItem = "Line 1", Qty = 2, Cost = 3.98m },
new Order { LineItem = "Line 2", Qty = 1, Cost = 1.49m },
new Order { LineItem = "Line 2", Qty = 2, Cost = 2.98m },
new Order { LineItem = "Australia Flag", Qty = 1, Cost = 9.99m },
}.ToList(),
},
new Customer
{
Name = "Customer 2",
PrimaryAddress = new CustomerAddress {
AddressLine1 = "2 Prospect Park",
Country = "USA"
},
Orders = new[] {
new Order { LineItem = "USA", Qty = 1, Cost = 20m },
}.ToList(),
},
};
customers.Each(c =>
db.Save(c, references: true));
db.Insert(
new Country { CountryName = "Australia", CountryCode = "AU" },
new Country { CountryName = "USA", CountryCode = "US" });
var results = db.Select<FullCustomerInfo, Customer>(q => q
.Join<CustomerAddress>() //implicit
.Join<Customer, Order>() //explicit
.Where(c => c.Name == "Customer 1")
.And<Order>(o => o.Cost < 2)
.Or<Order>(o => o.LineItem == "Australia Flag"));
var costs = results.ConvertAll(x => x.Cost);
Assert.That(costs, Is.EquivalentTo(new[] { 1.99m, 1.49m, 9.99m }));
var orderIds = results.ConvertAll(x => x.OrderId);
var expectedOrderIds = new []{customers[0].Orders[0].Id, customers[0].Orders[2].Id, customers[0].Orders[4].Id};
Assert.That(orderIds, Is.EquivalentTo(expectedOrderIds));
//Same as above using using db.From<Customer>()
results = db.Select<FullCustomerInfo>(db.From<Customer>()
.Join<CustomerAddress>() //implicit
.Join<Customer, Order>() //explicit
.Where(c => c.Name == "Customer 1")
.And<Order>(o => o.Cost < 2)
.Or<Order>(o => o.LineItem == "Australia Flag"));
costs = results.ConvertAll(x => x.Cost);
Assert.That(costs, Is.EquivalentTo(new[] { 1.99m, 1.49m, 9.99m }));
results = db.Select<FullCustomerInfo, Customer>(q => q
.Join<Customer, CustomerAddress>()
.Join<Customer, Order>()
.Where(c => c.Name == "Customer 2")
.And<CustomerAddress, Order>((a, o) => a.Country == o.LineItem));
costs = results.ConvertAll(x => x.Cost);
Assert.That(costs, Is.EquivalentTo(new[] { 20m }));
var countryResults = db.Select<FullCustomerInfo>(db.From<Customer>()
.Join<CustomerAddress>() //implicit join with Customer
.Join<Order>((c, o) => c.Id == o.CustomerId) //explicit join condition
.Join<CustomerAddress, Country>((ca, c) => ca.Country == c.CountryName)
.Where(c => c.Name == "Customer 2") //implicit condition with Customer
.And<CustomerAddress, Order>((a, o) => a.Country == o.LineItem));
costs = countryResults.ConvertAll(x => x.Cost);
Assert.That(costs, Is.EquivalentTo(new[] { 20m }));
Assert.That(countryResults.ConvertAll(x => x.CountryCode), Is.EquivalentTo(new[] { "US" }));
}
示例11: numbers_with_commas_and_periods_should_be_valid_in_european_culture
public void numbers_with_commas_and_periods_should_be_valid_in_european_culture()
{
var numbers = new[]
{
"1.000",
"100,1",
"1000,1",
"1.000,1",
"10.000,1",
"100.000,1",
};
numbers.Each(x => x.IsValidNumber(CultureInfo.CreateSpecificCulture("de-DE")).ShouldBeTrue());
}