本文整理汇总了C#中System.Linq.Contains方法的典型用法代码示例。如果您正苦于以下问题:C# System.Linq.Contains方法的具体用法?C# System.Linq.Contains怎么用?C# System.Linq.Contains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Linq
的用法示例。
在下文中一共展示了System.Linq.Contains方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WhereHasArtistParticipationStatus
public static IQueryable<ArtistForAlbum> WhereHasArtistParticipationStatus(this IQueryable<ArtistForAlbum> query, Artist artist, ArtistAlbumParticipationStatus participation) {
if (participation == ArtistAlbumParticipationStatus.Everything || artist == null)
return query;
var musicProducerTypes = new[] {ArtistType.Producer, ArtistType.Circle, ArtistType.OtherGroup};
if (musicProducerTypes.Contains(artist.ArtistType)) {
var producerRoles = ArtistRoles.Composer | ArtistRoles.Arranger;
switch (participation) {
case ArtistAlbumParticipationStatus.OnlyMainAlbums:
return query.Where(a => !a.IsSupport && ((a.Roles == ArtistRoles.Default) || ((a.Roles & producerRoles) != ArtistRoles.Default)) && a.Album.ArtistString.Default != ArtistHelper.VariousArtists);
case ArtistAlbumParticipationStatus.OnlyCollaborations:
return query.Where(a => a.IsSupport || ((a.Roles != ArtistRoles.Default) && ((a.Roles & producerRoles) == ArtistRoles.Default)) || a.Album.ArtistString.Default == ArtistHelper.VariousArtists);
default:
return query;
}
} else {
switch (participation) {
case ArtistAlbumParticipationStatus.OnlyMainAlbums:
return query.Where(a => !a.IsSupport);
case ArtistAlbumParticipationStatus.OnlyCollaborations:
return query.Where(a => a.IsSupport);
default:
return query;
}
}
}
示例2: OperandTypes
public void OperandTypes()
{
var OneByteOperandTypes = new byte[0xff];
var TwoByteOperandTypes = new byte[0x1f];
var typeOfOpCode = typeof(OpCode);
var reserved = new[] { "Prefix1", "Prefix2", "Prefix3", "Prefix4", "Prefix5", "Prefix6", "Prefix7", "Prefixref" };
foreach (FieldInfo fi in typeof(OpCodes).GetFields(BindingFlags.Public | BindingFlags.Static).Where(f => !reserved.Contains(f.Name)))
{
if (fi.FieldType != typeOfOpCode)
{
continue;
}
OpCode opCode = (OpCode)fi.GetValue(null);
var value = unchecked((ushort)opCode.Value);
if (value < 0x100)
{
OneByteOperandTypes[value] = (byte)opCode.OperandType;
}
else if ((value & 0xff00) == 0xfe00)
{
TwoByteOperandTypes[value & 0xff] = (byte)opCode.OperandType;
}
}
AssertEx.Equal(OneByteOperandTypes, InstructionOperandTypes.OneByte);
AssertEx.Equal(TwoByteOperandTypes, InstructionOperandTypes.TwoByte);
}
示例3: EatOptionValue
private void EatOptionValue(ISnapshot snapshot, ExpressionKind kind, ICSharpExpression optionValue)
{
var addableKinds = new[] { ExpressionKind.Target, ExpressionKind.Stub, ExpressionKind.Mock };
if (addableKinds.Contains(kind))
{
snapshot.Add(kind, optionValue);
}
}
示例4: Init_Should_Apply_Entity_Channels_To_Aspect
public void Init_Should_Apply_Entity_Channels_To_Aspect()
{
var expected = new[] {"one", "two", "three"};
var e = new DefaultEntity("Test", expected).CreateLabelAspect("Label", 0, 0);
var aspect = new LabelAspect();
aspect.Init(e);
Assert.True(aspect.Channels.All(s => expected.Contains(s)));
}
示例5: GetNextAttributeToken
private static string GetNextAttributeToken(string attributeCollection, char closingBracketChar, ref int index)
{
var terminatingChars = new[] { ',', ' ', '\t', closingBracketChar };
string nameValuePair = HtmlStringHelper.ExtractTokenFromTagString(attributeCollection, ref index,
terminatingChars);
if (terminatingChars.Contains(nameValuePair[nameValuePair.Length - 1]))
nameValuePair = nameValuePair.Substring(0, nameValuePair.Length - 1);
return nameValuePair;
}
示例6: CanSelectManyWithAssociationInWhereClause
public void CanSelectManyWithAssociationInWhereClause()
{
int[] typeCodes = new[] { 5, 15, 100 };
var query = session.Linq<Patient>().SelectMany(p => p.PatientRecords, (p, r) => r)
.Where(r => r.Gender == Gender.Male && typeCodes.Contains(r.Type.TypeCode)).ToArray();
Assert.AreEqual(2, query.Length);
}
示例7: ValidEmailValidationTest
public void ValidEmailValidationTest()
{
var errorFieldNames = new[] { "EmailWithoutTld", "EmptyString", "SimpleText", "EmailWithPlusChar" }.ToList();
var errors = ModelValidator.ValidateObject(new ExampleModel1()).Errors;
Assert.That(errors.Count, Is.EqualTo(errorFieldNames.Count));
Assert.That(errors.ToList().All(x => x.ErrorCode == ErrorCodes.EmailAddressIsNotValid.ToString()));
Assert.That(errors.ToList().All(x => errorFieldNames.Contains(x.FieldName)));
}
示例8: NullAndEmptyStringFailsRequiredTextValidationTest
public void NullAndEmptyStringFailsRequiredTextValidationTest()
{
var errorFieldNames = new[] { "EmptyString", "NullString" }.ToList();
var errors = ModelValidator.ValidateObject(new ExampleModel1()).Errors;
Assert.That(errors.Count, Is.EqualTo(errorFieldNames.Count));
Assert.That(errors.ToList().All(x => x.ErrorCode == ValidationErrorCodes.Required.ToString()));
Assert.That(errors.ToList().All(x => errorFieldNames.Contains(x.FieldName)));
}
示例9: WhenEnumerableHasItems_ReturnsItemInEnumerable
public void WhenEnumerableHasItems_ReturnsItemInEnumerable()
{
//Arrange
var list = new [] {"Michael", "Bob", "Joe"};
//Act
var result = list.Random();
//Assert
Assert.IsTrue(list.Contains(result));
}
示例10: ContainsTest
public void ContainsTest()
{
//ARRANGE
var list1 = new[] { "a", "aa", "aaa", "aaaa" };
//ACT
var contains = list1.Contains("bbb", x => x.Length);
//ASSERT
Assert.IsTrue(contains);
}
示例11: Can_select_ints_using_list_contains
public void Can_select_ints_using_list_contains()
{
var ints = new[] { 1, 2, 3 }.ToList();
using (var db = OpenDbConnection())
{
db.Select<TestType>(x => ints.Contains(x.Id));
Assert.That(db.GetLastSql(), Is.StringContaining("(1,2,3)"));
}
}
示例12: Can_select_ints_using_array_contains
public void Can_select_ints_using_array_contains()
{
var ints = new[] { 1, 2, 3 };
using (var db = OpenDbConnection())
{
db.Select<TestType>(x => ints.Contains(x.Id));
Assert.That(db.GetLastSql(), Is.StringContaining("(@0,@1,@2)").
Or.StringContaining("(:0,:1,:2)"));
}
}
示例13: IsCommitCharacter
internal static bool IsCommitCharacter(CompletionItem completionItem, char ch, string textTypedSoFar)
{
// TODO(cyrusn): Don't hardcode this in. Suck this out of the user options.
var commitCharacters = new[]
{
' ', '{', '}', '[', ']', '(', ')', '.', ',', ':',
';', '+', '-', '*', '/', '%', '&', '|', '^', '!',
'~', '=', '<', '>', '?', '@', '#', '\'', '\"', '\\'
};
return commitCharacters.Contains(ch);
}
示例14: Execute
public void Execute()
{
var refreshOn = new[]
{
BuildConfigurations.Debug.Description(),
BuildConfigurations.TestsUnit.Description()
};
if (!refreshOn.Contains(appSettings.Configuration))
return;
persistenceConfiguration.RecreateDatabase();
}
示例15: GetUrls_should_return_urls_from_provider_that_is_passed_in
public void GetUrls_should_return_urls_from_provider_that_is_passed_in()
{
var expected = new[] {new GoogleUrl(), new GoogleUrl()};
var providerFake = new Mock<IGoogleUrlProvider>();
providerFake.Setup(x => x.GetUrls())
.Returns(expected);
var provider = new GoogleSiteMapProvider(new[] {providerFake.Object});
var results = provider.GetUrls();
results.Count().ShouldEqual(2);
results.ToList().ForEach(url => expected.Contains(url).ShouldBeTrue());
}