本文整理汇总了C#中System.AsEnumerable方法的典型用法代码示例。如果您正苦于以下问题:C# System.AsEnumerable方法的具体用法?C# System.AsEnumerable怎么用?C# System.AsEnumerable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System
的用法示例。
在下文中一共展示了System.AsEnumerable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ByValue_Enumerable_CanDisallowNull
public void ByValue_Enumerable_CanDisallowNull()
{
var data = new[]
{
new EmailAddress { Value = FakeData.Email(), },
new EmailAddress { Value = FakeData.Email(), },
new EmailAddress { Value = FakeData.Email(), },
};
data.AsEnumerable().ByValue(data[0].Value, false).ShouldNotBeNull();
var exception = Assert.Throws<InvalidOperationException>(() =>
data.AsEnumerable().ByValue(FakeData.Email(), false));
Assert.NotNull(exception);
exception.Message.IndexOf("Sequence contains no matching element", StringComparison.CurrentCulture)
.ShouldEqual(0);
}
示例2: Merge
private static void Merge(System.Data.DataTable DestTable, System.Data.DataTable SrcTable)
{
string pk = DestTable.PrimaryKey[0].ColumnName;
System.Data.DataRow[] pkChangedRows = DestTable.AsEnumerable().Where(p => p.RowState == DataRowState.Modified
&& !p[pk, DataRowVersion.Original].Equals(p[pk, DataRowVersion.Current])).ToArray();
try
{
//When PK has changed, move row to added state
foreach (System.Data.DataRow dr in pkChangedRows)
{
dr.AcceptChanges();
dr.SetAdded();
}
DestTable.Merge(SrcTable);
}
finally
{
//And when back to modifyed
foreach (System.Data.DataRow dr in pkChangedRows)
{
dr.AcceptChanges();
dr.SetModified();
}
}
}
示例3: ToList_GivenAMultiDimensionalArray_ReturnsAnArrayWithAllItemsInIt
public void ToList_GivenAMultiDimensionalArray_ReturnsAnArrayWithAllItemsInIt()
{
var array = new[,] { { 1, 2 }, { 3, 4 } };
var list = array.AsEnumerable();
CollectionAssert.AreEquivalent(list, array);
}
示例4: Main
static void Main(string[] args)
{
var a = new[] { new Program() };
// https://sites.google.com/a/jsc-solutions.net/backlog/knowledge-base/2014/201401/20140120/avg
var w = a.AsEnumerable().Where(x => x.Visible);
}
示例5: ByName_Enumerable_CanAllowNull
public void ByName_Enumerable_CanAllowNull()
{
var data = new[]
{
new User { Name = FakeData.String() },
new User { Name = FakeData.String() },
new User { Name = FakeData.String() },
};
data.AsEnumerable().ByName(FakeData.String()).ShouldBeNull();
}
示例6: ByValue_Enumerable_CanAllowNull
public void ByValue_Enumerable_CanAllowNull()
{
var data = new[]
{
new EmailAddress { Value = FakeData.Email(), },
new EmailAddress { Value = FakeData.Email(), },
new EmailAddress { Value = FakeData.Email(), },
};
data.AsEnumerable().ByValue(FakeData.Email()).ShouldBeNull();
}
示例7: ByTicket_Enumerable_CanAllowNull
public void ByTicket_Enumerable_CanAllowNull()
{
var data = new[]
{
new EmailVerification { Ticket = FakeData.String(), },
new EmailVerification { Ticket = FakeData.String(), },
new EmailVerification { Ticket = FakeData.String(), },
};
data.AsEnumerable().ByTicket(FakeData.String()).ShouldBeNull();
}
示例8: Get_All_Persons
public void Get_All_Persons()
{
// Arrange
var allPersons = new[]
{
new Library.Entity.Person {FirstName = "John", LastName = "McClung", MiddleName = "Paul", Notes = "Crazy as can be"},
new Library.Entity.Person {FirstName = "Katie", LastName = "McClung", MiddleName = "Elane", Notes = "Just as crazy as John"}
};
var service = Mock.Of<IPersonService>(s => s.All(null, null, "LastName") == allPersons.AsEnumerable());
var controller = new PersonController(service);
// Act
var result = controller.Get(null, null, "LastName") as OkNegotiatedContentResult<IEnumerable<Web.Models.Person>>;
var personModels = allPersons.AsEnumerable().ToModel();
// Assert
Assert.NotNull(result);
Assert.True(personModels.SequenceEqual(result.Content));
}
示例9: ToList_GivenAMultiDimensionalArray_ReturnsAnArrayWithAllItemsInTheCorrectOrder
public void ToList_GivenAMultiDimensionalArray_ReturnsAnArrayWithAllItemsInTheCorrectOrder()
{
var array = new[,] { { 1, 2 }, { 3, 4 } };
var list = array.AsEnumerable().ToList();
Assert.AreEqual(list[0], array[0, 0]);
Assert.AreEqual(list[1], array[1, 0]);
Assert.AreEqual(list[2], array[0, 1]);
Assert.AreEqual(list[3], array[1, 1]);
}
示例10: ByUserId_Enumerable_CanDisallowNull
public void ByUserId_Enumerable_CanDisallowNull()
{
var userId = FakeData.Id();
var otherUserId1 = FakeData.Id(userId);
var otherUserId2 = FakeData.Id(userId, otherUserId1);
var data = new[]
{
new LocalMembership { User = new ProxiedUser(otherUserId1), },
new LocalMembership { User = new ProxiedUser(userId), },
new LocalMembership { User = new ProxiedUser(otherUserId2), },
};
data.AsEnumerable().ByUserId(data[1].User.Id, false).ShouldNotBeNull();
var otherUserId3 = FakeData.Id(userId, otherUserId1, otherUserId2);
var exception = Assert.Throws<InvalidOperationException>(() =>
data.AsEnumerable().ByUserId(otherUserId3, false));
Assert.NotNull(exception);
exception.Message.IndexOf("Sequence contains no matching element", StringComparison.CurrentCulture)
.ShouldEqual(0);
}
示例11: ConstructorShouldAddFileTypeFilters
public void ConstructorShouldAddFileTypeFilters()
{
// arrange
var expected = new[] { "*.*", "*.txt", "*.csv" };
// act
var interaction = new SelectFolderInteraction( "", expected );
var actual = interaction.FileTypeFilter;
// assert
Assert.Equal( expected.AsEnumerable(), actual.AsEnumerable() );
}
示例12: Point
public void When_the_sequence_contains_more_than_a_single_point_the_Min_point_equals_the_element_wise_minimum_of_the_sequence()
{
var points = new[] {
new Point(1, 2, 3),
new Point(2, 3, 4),
new Point(4, 5, 6),
new Point(-1, 3, 7),
new Point(0, 0, -10)
};
var aabb = AxisAlignedBoundingBox.FromPoints(points.AsEnumerable());
Assert.Equal(new Point(-1, 0, -10), aabb.Min);
}
示例13: ByUserId_Enumerable_CanAllowNull
public void ByUserId_Enumerable_CanAllowNull()
{
var userId = FakeData.Id();
var otherUserId1 = FakeData.Id(userId);
var otherUserId2 = FakeData.Id(userId, otherUserId1);
var data = new[]
{
new LocalMembership { User = new ProxiedUser(otherUserId1), },
new LocalMembership { User = new ProxiedUser(userId), },
new LocalMembership { User = new ProxiedUser(otherUserId2), },
};
var otherUserId3 = FakeData.Id(userId, otherUserId1, otherUserId2);
data.AsEnumerable().ByUserId(otherUserId3).ShouldBeNull();
}
示例14: TestTryEnumerable
public void TestTryEnumerable()
{
var expected = new[] {2, 3, 4, 5, 6};
var initital = new[] {1, 2, 3, 4, 5};
var @try = Try.Attempt(() => initital.AsEnumerable()).ToTryEnumerable();
var temp =
(from num in @try
select num + 1)
.Out();
var result = temp.Match(
success: BasicFunctions.Identity,
failure: ex => Enumerable.Empty<int>());
Assert.IsTrue(TestUtils.AreEqual(result, expected));
}
示例15: ByUserId_Enumerable_FiltersByUserId
public void ByUserId_Enumerable_FiltersByUserId()
{
var userId = FakeData.Id();
var data = new[]
{
new RemoteMembership { UserId = FakeData.Id(canNotBe: userId), },
new RemoteMembership { UserId = userId, },
new RemoteMembership { UserId = userId, },
new RemoteMembership { UserId = FakeData.Id(canNotBe: userId), },
new RemoteMembership { UserId = FakeData.Id(canNotBe: userId), },
new RemoteMembership { UserId = userId, },
};
var results = data.AsEnumerable().ByUserId(userId).ToArray();
results.ShouldNotBeNull();
results.Length.ShouldEqual(3);
}