本文整理汇总了C#中System.Collections.Generic.Contains方法的典型用法代码示例。如果您正苦于以下问题:C# System.Collections.Generic.Contains方法的具体用法?C# System.Collections.Generic.Contains怎么用?C# System.Collections.Generic.Contains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Generic
的用法示例。
在下文中一共展示了System.Collections.Generic.Contains方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: should_check_if_sequence_contains_element
public void should_check_if_sequence_contains_element()
{
var sequence = new[] {1, 2, 3, 4, 5};
bool containsTwo = sequence.Contains(2);
bool containsTen = sequence.Contains(10);
// please update variable values of the following 2 lines to fix the test.
const bool expectedContainsTwo = false;
const bool expectedContainsTen = true;
Assert.Equal(expectedContainsTwo, containsTwo);
Assert.Equal(expectedContainsTen, containsTen);
}
示例2: BuildFilter
private ElementFilter<ClientCompanyColumnName, ClientCompany, ClientCompaniesListFilter> BuildFilter(ClientCompaniesListFilter filter)
{
var companyActiveStatus = ClientCompanyStatus.Active.ToString();
var companyInactiveStatus = ClientCompanyStatus.Inactive.ToString();
IEnumerable<string> filterStatuses = new[] { companyActiveStatus, companyInactiveStatus };
if (filter.FilterByActiveStatus || filter.FilterByInactiveStatus)
{
if (!filter.FilterByActiveStatus)
{
filterStatuses = filterStatuses.Where(e => e != companyActiveStatus);
}
if (!filter.FilterByInactiveStatus)
{
filterStatuses = filterStatuses.Where(e => e != companyInactiveStatus);
}
}
return ShorFilter.AddFilter<ClientCompanyColumnName, ClientCompany, ClientCompaniesListFilter>(f => !string.IsNullOrWhiteSpace(f.CompanyName), c => c.CompanyName.ToUpper().Contains(filter.CompanyName.ToUpper())).
AddFilter(f => !string.IsNullOrWhiteSpace(f.CompanyId), c => c.CompanyId.ToUpper().Contains(filter.CompanyId.ToUpper())).
AddFilter(f => true, c => filterStatuses.Contains(c.StatusId)).
AddFilter(f => filter.IsWholesaleChannel, c => c.Profile.IsWholesale).
AddFilter(f => filter.IsLender, c => c.Profile.IsLender).
AddOrders(ClientCompanyColumnName.CompanyNameOrder, c => c.CompanyName).
AddOrders(ClientCompanyColumnName.CompanyIdOrder, c => c.CompanyId).
AddOrders(ClientCompanyColumnName.Status, c => c.StatusId);
}
示例3: Copy_Razor_files_to_AWS_Bucket
public void Copy_Razor_files_to_AWS_Bucket()
{
var fs = new FileSystemVirtualPathProvider(appHost, "~/../RazorRockstars.WebHost".MapHostAbsolutePath());
var skipDirs = new[] { "bin", "obj" };
var matchingFileTypes = new[] { "cshtml", "md", "css", "js", "png", "jpg" };
var replaceHtmlTokens = new Dictionary<string, string> {
{ "title-bg.png", "title-bg-aws.png" }, //Title Background
{ "https://gist.github.com/3617557.js", "https://gist.github.com/mythz/396dbf54ce6079cc8b2d.js" }, //AppHost.cs
{ "https://gist.github.com/3616766.js", "https://gist.github.com/mythz/ca524426715191b8059d.js" }, //S3 RockstarsService.cs
{ "RazorRockstars.WebHost/RockstarsService.cs", "RazorRockstars.S3/RockstarsService.cs" }, //S3 RockstarsService.cs
{ "http://github.com/ServiceStackApps/RazorRockstars/",
"https://github.com/ServiceStackApps/RazorRockstars/tree/master/src/RazorRockstars.S3" } //Link to GitHub project
};
foreach (var file in fs.GetAllFiles())
{
if (skipDirs.Any(x => file.VirtualPath.StartsWith(x))) continue;
if (!matchingFileTypes.Contains(file.Extension)) continue;
if (file.Extension == "cshtml")
{
var html = file.ReadAllText();
replaceHtmlTokens.Each(x => html = html.Replace(x.Key, x.Value));
s3.WriteFile(file.VirtualPath, html);
}
else
{
s3.WriteFile(file);
}
}
}
示例4: InitControlKeyMap
private void InitControlKeyMap()
{
var validTypes = new[]
{
typeof (Label),
typeof (Button),
typeof (CheckBox),
typeof (RadioButton),
typeof (GroupBox),
//typeof (ObjectListView),
};
foreach (var control in GetControls(this).Where(c => validTypes.Contains(c.GetType())))
{
// if (control is ObjectListView)
// {
// var listView = control as ObjectListView;
// for (var i = 0; i < listView.Columns.Count; i++)
// {
// var column = listView.Columns[i];
// _map.Add(column, column.Text);
// }
// }
// else
{
_map.Add(control, control.Text);
}
}
_map.Add(this, Text);
}
示例5: ContainsQueriedData
public void ContainsQueriedData()
{
int n = 20;
IEnumerable<TestObj> cq = from i in Enumerable.Range(1, n)
select new TestObj
{
Name = i.ToString()
};
var db = new TestDb(new SQLitePlatformWin32(), TestPath.GetTempFileName());
db.InsertAll(cq);
db.Trace = true;
var tensq = new[] {"0", "10", "20"};
List<TestObj> tens = (from o in db.Table<TestObj>() where tensq.Contains(o.Name) select o).ToList();
Assert.AreEqual(2, tens.Count);
var moreq = new[] {"0", "x", "99", "10", "20", "234324"};
List<TestObj> more = (from o in db.Table<TestObj>() where moreq.Contains(o.Name) select o).ToList();
Assert.AreEqual(2, more.Count);
// https://github.com/praeclarum/SQLite.Net/issues/28
List<string> moreq2 = moreq.ToList();
List<TestObj> more2 = (from o in db.Table<TestObj>() where moreq2.Contains(o.Name) select o).ToList();
Assert.AreEqual(2, more2.Count);
}
示例6: Process
private static IEnumerable<Token> Process(IEnumerator<Token> eTokens, char? expectedTerminator)
{
var openNesting = new[] {"[", "("};
while (eTokens.MoveNext())
{
var token = eTokens.Current;
if (expectedTerminator != null && token.Characters.Length == 1)
{
if (token.Characters[0] == expectedTerminator)
yield break;
}
if (token.CharacterType != CodeCharacterType.ControlCharacters)
{
yield return token;
continue;
}
if (openNesting.Contains(token.Characters))
{
var terminator = token.Characters == "[" ? ']' : ')';
token.Characters += terminator;
token.Children = Process(eTokens, terminator).ToList();
yield return token;
}
else yield return token;
}
}
示例7: ContainsForProperty_ReturnsCorrectReql
public void ContainsForProperty_ReturnsCorrectReql()
{
var strings = new[]
{
"Hello"
};
var data = new List<TestObject>
{
new TestObject
{
Name = "Hello"
}
};
;
SpawnData( data );
var expected = RethinkDB.R.Table( TableName )
.Filter( x => RethinkDB.R.Expr( RethinkDB.R.Array( strings ) ).Contains( x["Name"] ) );
var queryable = GetQueryable<TestObject>( TableName, expected );
var result = queryable
.Where( x => strings.Contains( x.Name ) )
.ToList();
Assert.AreEqual( 1, result.Count );
}
示例8: GetConfiguration
public object GetConfiguration(string type, int id)
{
var objectType = Mappings.TreeNodeObjectTypes[new TreeNodeType("settings", type)];
var contentTypes = ContentTypeService.GetAllContentTypes().ToList();
var mediaTypes = ApplicationContext.Services.ContentTypeService.GetAllMediaTypes().ToList();
var types = new[]
{
(objectType == UmbracoObjectTypes.DocumentType ? UmbracoObjectTypes.Document : UmbracoObjectTypes.Media).GetGuid(),
};
var relationTypes = ApplicationContext.Services.RelationService.GetAllRelationTypes()
.Where(rt => types.Contains(rt.ParentObjectType))
;
var contentType = objectType == UmbracoObjectTypes.DocumentType ?
(IContentTypeBase)contentTypes.Single(ct => ct.Id == id) :
mediaTypes.Single(ct => ct.Id == id);
var contentObjectType = objectType == UmbracoObjectTypes.DocumentType
? UmbracoObjectTypes.Document
: UmbracoObjectTypes.Media;
return new
{
contentTypes,
mediaTypes,
relationTypes,
configuration = RelationEditor.Configuration.Get(contentObjectType, contentType.Alias)
};
}
示例9: ParentDeclaration
private Declaration ParentDeclaration(IdentifierReference reference)
{
var declarationTypes = new[] {DeclarationType.Function, DeclarationType.Procedure, DeclarationType.Property};
return UserDeclarations.SingleOrDefault(d =>
reference.ParentScoping.Equals(d) && declarationTypes.Contains(d.DeclarationType) &&
d.QualifiedName.QualifiedModuleName.Equals(reference.QualifiedModuleName));
}
示例10: GetTotalDamageEBDB
public static float GetTotalDamageEBDB(this Obj_AI_Base target)
{
var slots = new[] {SpellSlot.Q, SpellSlot.W, SpellSlot.E, SpellSlot.R};
var dmg =
Player.Instance.Spellbook.Spells.Where(s => s.IsReady && slots.Contains(s.Slot))
.Sum(s => Player.Instance.GetSpellDamage(target, s.Slot));
var aaDmg = Orbwalker.CanAutoAttack ? Player.Instance.GetAutoAttackDamage(target) : 0f;
return dmg + aaDmg;
}
示例11: Index
public ActionResult Index(HttpPostedFileBase files)
{
if (files == null)
{
return new EmptyResult();
}
if (string.IsNullOrEmpty(files.FileName))
{
return new EmptyResult();
}
var allowedTypes = new[] { ".xlsx" };
var extension = Path.GetExtension(files.FileName).ToLower();
if (files.ContentLength > 0 && allowedTypes.Contains(extension))
{
using (var excelReader = ExcelReaderFactory.CreateOpenXmlReader(files.InputStream))
{
var testPages = new List<TestPage>();
excelReader.IsFirstRowAsColumnNames = true;
DataSet result = excelReader.AsDataSet();
for (int i = 0; i < result.Tables.Count; i++)
{
var headers = result.Tables[i].Columns;
if (headers.Count == 0)
{
break;
}
if (!headers[0].ColumnName.ToLowerInvariant().Equals("url"))
{
break;
}
foreach (DataRow row in result.Tables[i].Rows)
{
var testPage = new TestPage() { URL = row[0].ToString() };
for (int a = 1; a < row.ItemArray.Length; a++)
{
testPage.ElementList.Add(new Element
{
Name = headers[a].ToString(),
ExpectedValue = row[a].ToString().Trim()
});
}
testPages.Add(testPage);
}
}
TestPagesService.Process(testPages);
}
}
return View();
}
示例12: Contains
public static void Contains()
{
Qunit.RunTest("Contains", () =>
{
var testClass = new TestClass();
IList<TestClass> array = new [] {testClass};
Qunit.IsTrue(array.Contains(testClass));
});
}
示例13: GetAlliesDamagesNear
public static float GetAlliesDamagesNear(this Obj_AI_Base target, float percent = 0.7f, int range = 700, int delay = 250)
{
var dmg = 0f;
var slots = new[] {SpellSlot.Q, SpellSlot.W, SpellSlot.E, SpellSlot.R};
foreach (var a in EntityManager.Heroes.Allies.Where(a => a.IsInRange(target, range)))
{
dmg += a.GetAutoAttackDamage(target);
dmg += a.Spellbook.Spells.Where(s => slots.Contains(s.Slot) && s.IsReady).Sum(s => a.GetSpellDamage(target, s.Slot));
}
return dmg*percent;
}
示例14: PropertyFilter_finds_all_properties_on_base_type
public void PropertyFilter_finds_all_properties_on_base_type()
{
var propertyNames = new[]
{
"PublicBase",
"PublicBaseForNew",
"PublicVirtualBase",
"PublicVirtualBase2",
"InterfaceImplicit",
};
var properties = new PropertyFilter().GetProperties(
typeof(PropertyFilterTests_Base), true, null);
Assert.True(properties.All(x => propertyNames.Contains(x.Name)));
properties = new PropertyFilter().GetProperties(
typeof(PropertyFilterTests_Base), false, Enumerable.Empty<PropertyInfo>());
Assert.Equal(propertyNames.Length, properties.Count());
Assert.True(properties.All(x => propertyNames.Contains(x.Name)));
}
示例15: PropertyFilter_finds_declared_properties_on_derived_type
public void PropertyFilter_finds_declared_properties_on_derived_type()
{
var propertyNames = new[]
{
"PublicDerived"
};
var properties = new PropertyFilter().GetProperties(
typeof(PropertyFilterTests_Derived), true, Enumerable.Empty<PropertyInfo>());
Assert.Equal(propertyNames.Length, properties.Count());
Assert.True(properties.All(x => propertyNames.Contains(x.Name)));
}