本文整理汇总了C#中ICollection.Contains方法的典型用法代码示例。如果您正苦于以下问题:C# ICollection.Contains方法的具体用法?C# ICollection.Contains怎么用?C# ICollection.Contains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICollection
的用法示例。
在下文中一共展示了ICollection.Contains方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadList
public static void ReadList (XmlReader reader, ICollection<string> endNodes, ReaderCallbackWithData callback)
{
if (reader.IsEmptyElement)
return;
ReadCallbackData data = new ReadCallbackData ();
bool didReadStartNode = endNodes.Contains (reader.LocalName);
while (data.SkipNextRead || reader.Read()) {
data.SkipNextRead = false;
switch (reader.NodeType) {
case XmlNodeType.EndElement:
if (endNodes.Contains (reader.LocalName))
return;
IXmlLineInfo xmlInfo = (IXmlLineInfo)reader;
LoggingService.LogWarning (
"Encountered end node '{0}' when expecting one of '{1}'. Location ln:{2} col: {3}. Stack Trace:{4}",
reader.LocalName, ConcatString (endNodes), xmlInfo.LineNumber, xmlInfo.LinePosition, new System.Diagnostics.StackTrace ());
break;
case XmlNodeType.Element:
if (!didReadStartNode && endNodes.Contains (reader.LocalName)) {
didReadStartNode = true;
break;
}
bool validNode = callback (data);
if (!validNode)
LoggingService.LogWarning ("Unknown node: " + reader.LocalName);
break;
}
}
}
示例2: RegisterNamespace
protected virtual void RegisterNamespace(string ns, ICollection<string> repository)
{
if (String.IsNullOrEmpty(ns) || repository.Contains(ns))
{
return;
}
string[] parts = ns.Split('.');
StringBuilder builder = new StringBuilder();
foreach (string part in parts)
{
if (builder.Length > 0)
{
builder.Append('.');
}
builder.Append(part);
string item = builder.ToString();
if (!repository.Contains(item))
{
repository.Add(item);
}
}
}
示例3: CheckSet
private void CheckSet(ICollection<string> wordset)
{
Assert.AreEqual(3, wordset.Count);
Assert.IsTrue(wordset.Contains("ONE")); // case is not modified
Assert.IsTrue(wordset.Contains("two")); // surrounding whitespace is removed
Assert.IsTrue(wordset.Contains("three"));
Assert.IsFalse(wordset.Contains("four"));
}
示例4: ListContainsType
private static bool ListContainsType(ICollection<Type> list, Type type)
{
if (list.Contains(type))
return true;
if (type.IsGenericType)
return list.Contains(type.GetGenericTypeDefinition());
return false;
}
示例5: QuoteTable
private static void QuoteTable(Table table, ICollection<string> reservedDb)
{
if (!table.IsQuoted && reservedDb.Contains(table.Name.ToLowerInvariant()))
{
table.Name = GetNhQuoted(table.Name);
}
foreach (var column in table.ColumnIterator)
{
if (!column.IsQuoted && reservedDb.Contains(column.Name.ToLowerInvariant()))
{
column.Name = GetNhQuoted(column.Name);
}
}
}
示例6: LogDataImport
public static void LogDataImport(string mapFrom, DataTable table,ICollection<string> mappingCols)
{
StreamWriter logFileStreamWriter = null;
try
{
if(!CheckIsNeedLog(table))return;
mapFrom = mapFrom.Replace("$", "");
string file = Path.GetFileNameWithoutExtension(ExcelHelper.FilePath);
string path = Path.GetDirectoryName(ExcelHelper.FilePath)+"\\"+file+"_"+ mapFrom +"_error.csv";
FileStream fs = new FileStream(path, FileMode.OpenOrCreate);
logFileStreamWriter = new StreamWriter(fs,Encoding.Unicode);
string csvColHeader = null;
foreach (DataColumn col in table.Columns)
{
if (!mappingCols.Contains(col.ColumnName) &col.ColumnName!=Logic.Migratable.ERROR_MSG_COL) continue;
if (null != csvColHeader) csvColHeader += "\t";
csvColHeader += ConvertStringToCSV(col.ColumnName);
}
logFileStreamWriter.WriteLine(csvColHeader);
//StringBuilder sb = new StringBuilder();
//sb.AppendLine(csvColHeader);
foreach (DataRow row in table.Rows)
{
string rowString = null;
foreach (DataColumn col in table.Columns)
{
if (!mappingCols.Contains(col.ColumnName) & col.ColumnName != Logic.Migratable.ERROR_MSG_COL) continue;
if (null != rowString) rowString += "\t";
rowString += ConvertStringToCSV(row[col.ColumnName]);
}
//sb.AppendLine(rowString);
logFileStreamWriter.WriteLine(rowString);
}
//File.AppendAllText(path, sb.ToString());
logFileStreamWriter.Flush();
}
finally
{
if (null != logFileStreamWriter)
{
logFileStreamWriter.Flush();
logFileStreamWriter.Close();
logFileStreamWriter.Dispose();
logFileStreamWriter = null;
}
}
}
示例7: Initialize
public static void Initialize()
{
TradingPostItems = PriceService.Discover();
var items = LoadItemFile(HotItemController.Config.LanguageKey);
ItemDB = new Dictionary<int, Item>();
ItemTradingPostDB = new Dictionary<int, Item>();
foreach (var item in items)
{
ItemDB[item.Id] = item;
if (TradingPostItems.Contains(item.Id))
{
item.TradingPostItem = true;
ItemTradingPostDB[item.Id] = item;
}
if (HotItemController.Self != null && HotItemController.Self.DataIdToItemId.ContainsKey(item.Id))
{
int itemId = HotItemController.Self.DataIdToItemId[item.Id];
if (HotItemController.Self.CreatedIdToRecipe.ContainsKey(itemId))
{
ItemRecipesDB[item.Id] = item;
}
}
}
LoadCategories(ItemTradingPostDB);
}
示例8: LoadDone
public virtual void LoadDone(ICollection<int> doneConditions)
{
if (doneConditions.Contains(this._id))
{
this._done = true;
}
}
示例9: Empty
private static void Empty(DirectoryInfo directory, ICollection<string> filesInUse)
{
if (!directory.Exists) return;
try
{
filesInUse.Add(AggregatedFolder + PictureSlidesLabImagesList);
filesInUse.Add(LoadingImgPath);
filesInUse.Add(ChoosePicturesImgPath);
filesInUse.Add(NoPicturePlaceholderImgPath);
filesInUse.Add(SampleImg1Path);
filesInUse.Add(SampleImg2Path);
foreach (var file in directory.GetFiles())
{
if (!filesInUse.Contains(file.FullName))
{
try
{
file.Delete();
}
catch
{
// may be still in use, which is fine
}
}
}
}
catch (Exception)
{
// ignore ex, if cannot delete trash
}
}
示例10: ExtractErrorProviders
private static void ExtractErrorProviders(Control control, ICollection<ErrorProvider> errorProviders)
{
//use reflection to get to "components" field
var containerControl = control.GetContainerControl();
if (containerControl != null)
{
FieldInfo componentField = containerControl.GetType()
.GetField( "components", BindingFlags.NonPublic | BindingFlags.Instance );
if (componentField != null)
{
//get the component collection from field
object components = componentField.GetValue(containerControl);
if (components != null)
{
//locate the ErrorProvider within the collection
var container = components as IContainer;
if (container != null)
{
foreach (ErrorProvider provider in container.Components.OfType<ErrorProvider>())
{
if (!errorProviders.Contains( provider ))
errorProviders.Add( provider );
}
}
}
}
}
}
示例11: AddGeneratedMethod
private void AddGeneratedMethod(Resource resource, string url, string objectName, Method method, ICollection<string> methodsNames,
ICollection<ClientGeneratorMethod> generatorMethods)
{
var generatedMethod = BuildClassMethod(url, method, resource);
if (generatedMethod.ReturnType != "string")
{
var returnType = CollectionTypeHelper.GetBaseType(generatedMethod.ReturnType);
generatedMethod.ReturnTypeObject = schemaResponseObjects.Values
.First(o => o.Name == returnType );
generatedMethod.OkReturnType = GetOkReturnType(generatedMethod);
}
uriParametersGenerator.Generate(resource, url, generatedMethod, uriParameterObjects);
if (!IsVerbForMethod(method)) return;
if (methodsNames.Contains(generatedMethod.Name))
generatedMethod.Name = GetUniqueName(methodsNames, generatedMethod.Name, resource.RelativeUri);
GetQueryParameters(objectName, method, generatedMethod);
GetHeaders(objectName, method, generatedMethod);
GetResponseHeaders(objectName, generatedMethod, method);
generatorMethods.Add(generatedMethod);
methodsNames.Add(generatedMethod.Name);
}
示例12: Compute
/// <summary>Compute the area under the ROC curve (AUC) of a list of ranked items</summary>
/// <remarks>
/// See http://recsyswiki.com/wiki/Area_Under_the_ROC_Curve
/// </remarks>
/// <param name="ranked_items">a list of ranked item IDs, the highest-ranking item first</param>
/// <param name="relevant_items">a collection of positive/correct item IDs</param>
/// <param name="ignore_items">a collection of item IDs which should be ignored for the evaluation</param>
/// <returns>the AUC for the given data</returns>
public static double Compute(IList<int> ranked_items, ICollection<int> relevant_items, ICollection<int> ignore_items = null)
{
if (ignore_items == null)
ignore_items = new HashSet<int>();
// TODO check again! -- think about good names
var relevant_items_in_list = relevant_items.Intersect(ranked_items);
int num_relevant_items = relevant_items_in_list.Count() - ignore_items.Intersect(relevant_items_in_list).Count();
int num_eval_items = ranked_items.Count - ignore_items.Intersect(ranked_items).Count();
int num_eval_pairs = (num_eval_items - num_relevant_items) * num_relevant_items;
if (num_eval_pairs < 0)
throw new ArgumentException("correct_items cannot be larger than ranked_items");
if (num_eval_pairs == 0)
return 0.5;
int num_correct_pairs = 0;
int hit_count = 0;
foreach (int item_id in ranked_items)
{
if (ignore_items.Contains(item_id))
continue;
if (!relevant_items.Contains(item_id))
num_correct_pairs += hit_count;
else
hit_count++;
}
return (double) num_correct_pairs / num_eval_pairs;
}
示例13: AddSvgComponent
private static void AddSvgComponent(ICollection<Line> lines, ICollection<Text> texts, int startingXPosition,
int startingYPosition, Anchor anchor, ICollection<Anchor> usedAnchor)
{
var oldStartingXPosition = startingXPosition;
var oldStartingYPosition = startingYPosition;
startingXPosition += ConfigSettings.IncreamentedXPosition;
if (anchor.Children == null || anchor.Children.Count == ConfigSettings.NotAcceptableValue) return;
if (!UsedParent.Contains(anchor))
{
AddLine(lines, oldStartingXPosition + 20, startingYPosition - 5, startingXPosition - 20,
startingYPosition - 5);
}
UsedParent.Add(anchor);
foreach (var child in anchor.Children.Where(child => !usedAnchor.Contains(child)))
{
texts.Add(new Text {Content = child.Data, PositionX = startingXPosition, PositionY = startingYPosition});
usedAnchor.Add(child);
AddLine(lines, oldStartingXPosition + 30, startingYPosition - 5, startingXPosition,
startingYPosition - 5);
AddLine(lines, oldStartingXPosition + 30, oldStartingYPosition - 5, oldStartingXPosition + 30,
startingYPosition - 5);
AddSvgComponent(lines, texts, startingXPosition, startingYPosition, child, usedAnchor);
UsedParent.Add(child);
startingYPosition += ConfigSettings.IncreamentedYPosition;
_positionY += ConfigSettings.IncreamentedYPosition;
}
}
示例14: AddEntitesToBeMapped
private static void AddEntitesToBeMapped(Type rootEntity, ICollection<Type> foundEntities, IEnumerable<Type> typesToScan)
{
if(foundEntities.Contains(rootEntity))
return;
foundEntities.Add(rootEntity);
var propertyTypes = rootEntity.GetProperties()
.Select(p => p.PropertyType);
foreach (var propertyType in propertyTypes)
{
if (propertyType.GetProperty("Id") != null)
AddEntitesToBeMapped(propertyType, foundEntities,typesToScan);
if (propertyType.IsGenericType)
{
var args = propertyType.GetGenericArguments();
if(args[0].GetProperty("Id") != null)
AddEntitesToBeMapped(args[0],foundEntities,typesToScan);
}
}
var derivedTypes = typesToScan.Where(t => t.IsSubclassOf(rootEntity));
foreach (var derivedType in derivedTypes)
{
AddEntitesToBeMapped(derivedType, foundEntities, typesToScan);
}
}
示例15: VerifySeedAcceptedNodes
private void VerifySeedAcceptedNodes(
IEnumerable<CstNode> seedCsts, ICollection<CstNode> uppermostSeedAcceptedNodes,
LearningExperiment oracle) {
var anotherUppermostSeedAcceptedNodes = seedCsts
.SelectMany(cst => LearningExperimentUtil
.GetUppermostNodesByNames(cst, SelectedNodeNames))
.Where(oracle.ProtectedIsAcceptedUsingOracle)
.ToList();
var b1 = !uppermostSeedAcceptedNodes.All(oracle.IsAcceptedUsingOracle);
var b2 = anotherUppermostSeedAcceptedNodes
.Select(node => node.AncestorWithSingleChild())
.Any(e => !uppermostSeedAcceptedNodes.Contains(e));
var b3 = uppermostSeedAcceptedNodes.Count != anotherUppermostSeedAcceptedNodes.Count;
Console.WriteLine("Initial: " + string.Join(", ", oracle.OracleNames));
Console.WriteLine("Learned: " + string.Join(", ", SelectedNodeNames));
if (b1 || b2 || b3) {
Console.WriteLine("--------------------------------------------------");
foreach (var e in uppermostSeedAcceptedNodes) {
Console.WriteLine(e);
}
Console.WriteLine("--------------------------------------------------");
foreach (var e in anotherUppermostSeedAcceptedNodes) {
Console.WriteLine(e);
}
throw new Exception("Wrong Oracle.");
}
}