本文整理汇总了C#中Dictionary.Any方法的典型用法代码示例。如果您正苦于以下问题:C# Dictionary.Any方法的具体用法?C# Dictionary.Any怎么用?C# Dictionary.Any使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Dictionary
的用法示例。
在下文中一共展示了Dictionary.Any方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Search
private void Search(Dictionary<int, int> count, IList<int> temp, IList<IList<int>> results)
{
if (!count.Any() && temp.Any())
{
results.Add(new List<int>(temp));
return;
}
var keys = count.Keys.ToList();
foreach (var key in keys)
{
temp.Add(key);
--count[key];
if (count[key] == 0) count.Remove(key);
Search(count, temp, results);
temp.RemoveAt(temp.Count - 1);
if (count.ContainsKey(key))
{
++count[key];
}
else
{
count[key] = 1;
}
}
}
示例2: GetChangeLog
public static IDictionary<Version, ChangeLogVersionDetails> GetChangeLog(Version fromVersion, Version toVersion, XDocument changeLogContent)
{
var changeLog = new Dictionary<Version, ChangeLogVersionDetails>();
foreach (var changeVersion in changeLogContent.Descendants("Version"))
{
var changeLogItem = BuildChangeLogItem(changeVersion);
if (!changeLog.ContainsKey(changeLogItem.Key))
{
changeLog.Add(changeLogItem.Key, changeLogItem.Value);
}
}
if (fromVersion < toVersion && changeLog.Any(x => x.Key > fromVersion && x.Key <= toVersion))
{
return changeLog.Where(x => x.Key > fromVersion && x.Key <= toVersion).OrderByDescending(detail => detail.Key).ToDictionary(detail => detail.Key, detail => detail.Value);
}
if (fromVersion < toVersion && changeLog.Any() && toVersion > changeLog.Keys.Max())
{
return changeLog.Where(x => x.Key == changeLog.Keys.Max()).ToDictionary(detail => detail.Key, detail => detail.Value);
}
if (fromVersion < toVersion && toVersion.Revision > 0 && changeLog.Any() && toVersion < changeLog.Keys.Max())
{
var versionWithoutRevision = new Version(toVersion.Major, toVersion.Minor, toVersion.Build);
return changeLog.Where(x => x.Key > versionWithoutRevision).ToDictionary(detail => detail.Key, detail => detail.Value);
}
return changeLog.OrderByDescending(detail => detail.Key).ToDictionary(detail => detail.Key, detail => detail.Value);
}
示例3: FillData
/// <summary>метод который формирует данные для chart-а на основе колекции серий,
/// поинтов и их пересечений </summary>
private SeriesCollection FillData(
Dictionary<string, float> seriesDef,
Dictionary<string, float> pointDef,
Dictionary<Intersection, float> intersections)
{
SeriesCollection result = new SeriesCollection();
if (!subDiagramMode)
{
switch (this.DiagramType)
{
case DiagramTypeEnum.Graph:
result.Add(CreateDataForFullDiagram(seriesDef, pointDef, intersections, true));
break;
case DiagramTypeEnum.ColumnDetail:
result.Add(CreateDataForFullDiagram(seriesDef, pointDef, intersections, false));
break;
case DiagramTypeEnum.ColumnGeneral:
result.Add(CreateDataForColumnGeneral(seriesDef));
break;
case DiagramTypeEnum.PieGeneral:
result.Add(CreateDataForPieGeneral(seriesDef));
break;
case DiagramTypeEnum.Speedometer:
case DiagramTypeEnum.TrafficLight:
if (seriesDef.Any( s => s.Key.Equals(defaultSeries)))
result.Add(FillSeriesData(seriesDef.First(s => s.Key.Equals(defaultSeries))));
break;
case DiagramTypeEnum.PieDetail:
if (seriesDef.Any(s => s.Key.Equals(defaultSeries)))
result.Add(FillPointsData(seriesDef.First(s => s.Key.Equals(defaultSeries)),
pointDef, intersections, false));
break;
}
}
else
{
if (string.IsNullOrEmpty(detalizedSeriesName)) detalizedSeriesName = this.defaultSeries;
if (seriesDef.Any(s => s.Key.Equals(detalizedSeriesName)))
{
switch (this.SubDiagramType)
{
case SubDiagramTypeEnum.Graph:
case SubDiagramTypeEnum.ColumnDetail:
case SubDiagramTypeEnum.PieDetail:
result.Add(FillPointsData(seriesDef.First(s => s.Key.Equals(detalizedSeriesName)),
pointDef, intersections, false));
break;
}
}
}
FillEmptyVisibleSeries(seriesDef.Keys.ToList());
return result;
}
示例4: AssertAditionals
private void AssertAditionals(Dictionary<string, string> additionals)
{
if(additionals == null)
return;
if(additionals.Count > MaxAdditionalsCount)
throw new ArgumentException();
if(additionals.Any( a => a.Key.Length > MaxAdditionalKeyLenght))
throw new ArgumentException();
if(additionals.Any(( a => a.Value.Length > MaxAdditionalValueLenght)))
throw new ArgumentException();
}
示例5: GetNonCollectible
internal static ClassDeclarationSyntax GetNonCollectible()
{
while(true)
{
var newNamingConflicts = new Dictionary<string, List<string>>();
var classDecl = ClassDeclaration("NonCollectible").AddModifiers(Token(PublicKeyword));
foreach(var c in ClassNames)
{
var className = c == "DREAM" ? "DreamCards" : CultureInfo.InvariantCulture.TextInfo.ToTitleCase(c.ToLower());
var cCard = ClassDeclaration(className).AddModifiers(Token(PublicKeyword));
var anyCards = false;
foreach(var card in
Cards.All.OrderBy(x => x.Value.Set)
.ThenBy(x => x.Key)
.Select(x => x.Value)
.Where(x => !x.Collectible && x.Class.ToString().Equals(c)))
{
var name = CultureInfo.InvariantCulture.TextInfo.ToTitleCase(card.Name.ToLower());
name = Regex.Replace(name, @"[^\w\d]", "");
name = ResolveNameFromId(card, name);
name = ResolveNamingConflict(name, card, newNamingConflicts);
cCard = cCard.AddMembers(GenerateConst(name, card.Id));
anyCards = true;
}
if(anyCards)
classDecl = classDecl.AddMembers(cCard);
}
if(!newNamingConflicts.Any(x => x.Value.Count > 1))
return classDecl;
foreach(var pair in newNamingConflicts.Where(x => x.Value.Count > 1).ToDictionary(pair => pair.Key, pair => pair.Value))
_namingConflicts.Add(pair.Key, pair.Value);
}
}
示例6: GetBexisRights
internal List<Right> GetBexisRights(string dataBase, Dictionary<int, int> dataSetsMapping)
{
List<Right> bexisRights = new List<Right>();
string datasetQuery = "";
foreach (var dataSetMapping in dataSetsMapping)
{
datasetQuery += "DATASETID = "+ dataSetMapping.Key;
if (dataSetsMapping.Last().Key != dataSetMapping.Key)
datasetQuery += " or ";
}
if (dataSetsMapping.Any())
{
datasetQuery = "where " + datasetQuery + "";
}
// DB query
string mySelectQuery = "SELECT ROLENAME, DATASETID, FOREDIT, APPLICATIONNAME FROM \"PROVIDER\".\"RIGHTS\" "+ datasetQuery;
DB2Connection connect = new DB2Connection(dataBase);
DB2Command myCommand = new DB2Command(mySelectQuery, connect);
connect.Open();
DB2DataReader myReader = myCommand.ExecuteReader();
while (myReader.Read())
{
bexisRights.Add(new Right()
{
RoleName = myReader.GetString(0),
DataSetId = (int)(myReader.GetValue(1)),
CanEdit = myReader.GetString(2)=="N"?false:true
});
}
myReader.Close();
connect.Close();
return bexisRights;
}
示例7: GetBatchSentimentAsync
public async Task<IDictionary<string, Result>> GetBatchSentimentAsync(Dictionary<string, string> textBatch)
{
ValidateBatchRequest(textBatch);
if (!textBatch.Any())
{
return new Dictionary<string, Result>();
}
string content;
using (var response = await _requestor.PostAsync(Constants.SentimentBatchRequest, BuildInputString(textBatch)))
{
content = await response.Content.ReadAsStringAsync();
if (!response.IsSuccessStatusCode)
{
return textBatch.ToDictionary(r => r.Key, r => AzureMachineLearningResult.Build(_errorMessageGenerator.GenerateError(response.StatusCode, content)));
}
}
var result = JsonConvert.DeserializeObject<SentimentBatchResult>(content);
var parsedResults = result.SentimentBatch.ToDictionary(sr => sr.Id, sr => AzureMachineLearningResult.Build(sr.Score, ScoreToSentiment(sr.Score)));
foreach (var error in result.Errors)
{
parsedResults.Add(error.Id, AzureMachineLearningResult.Build(error.Message));
}
return parsedResults;
}
示例8: GetRecognizeData
public virtual Dictionary<string, object> GetRecognizeData(byte[] image, string condition = "")
{
Dictionary<string, object> dic = new Dictionary<string, object>();
try
{
DateTime timestamp = DateTime.Now;
var templates = Directory.EnumerateFiles(_templatePath).Where(f => new[] { ".xml" }.Contains(Path.GetExtension(f)));
foreach (string template in templates.Where(t => t.Contains(condition)))
{
OnTry(template);
dic = GetRecognizeDataByTemplate(image, template);
if (dic.Any())
{
OnRecognizeData(DateTime.Now - timestamp, template);
return dic;
}
}
}
catch(Exception ex)
{
OnError(ex);
}
return dic;
}
示例9: Deserialize
internal static void Deserialize(CharacterFilterBase filter, Dictionary<string, object> fieldDict)
{
if (fieldDict == null || !fieldDict.Any())
return;
filter.Version = fieldDict.GetDoubleOrNull(_VERSION);
}
示例10: InstallPackagesAsync
/// <summary>
/// Ensures the appropriate version of the specified packages are installed. If an existing version of the package
/// already exists the following will happen:
/// If a semantically compatible version already exists, no change is made to the package.
/// If an older major version exists, a warning is logged and the package is upgraded.
/// If an older minor/build version exists, an information message is logged and the package is upgraded.
/// If a newer major version exists, a warning is logged and no change is made to the package.
/// </summary>
public static async Task InstallPackagesAsync(
Dictionary<string, string> packages,
string extensionId,
ConnectedServiceLogger logger,
Project project,
IVsPackageInstallerServices packageInstallerServices,
IVsPackageInstaller packageInstaller)
{
Dictionary<string, string> packagesToInstall = new Dictionary<string, string>();
await NuGetUtilities.InstallPackagesAsync(
project,
packages,
(packageId, packageVersion) =>
{
packagesToInstall.Add(packageId, packageVersion);
return Task.FromResult<object>(null);
},
logger,
packageInstallerServices);
if (packagesToInstall.Any())
{
packageInstaller.InstallPackagesFromVSExtensionRepository(extensionId, false, false, project, packagesToInstall);
}
}
示例11: Progress
public void Progress(Dictionary<string, string> namedParameters, string[] parameters)
{
if (parameters.Length != 2 && parameters.Length != 1)
{
throw new ArgumentOutOfRangeException("parameters", "Parameter count must be at least one");
}
bool deleteParents =
namedParameters.Any(
a => string.Compare("--delete-parents", a.Key, StringComparison.InvariantCultureIgnoreCase) == 0);
string maxDepthResult = CommandHelper.GetProperty(namedParameters, "--max-depth", null);
int maxDepth = maxDepthResult == null ? 0 : int.Parse(maxDepthResult);
var issuer = CommandHelper.GetProperty (namedParameters, "--issuer", Environment.UserName);
string comment = CommandHelper.GetProperty(namedParameters, "--comment", "Backup combination");
string zip = parameters[0];
string resultPath = parameters.Length == 2 ? parameters[1] : Path.GetTempFileName ();
bool overrideZip = parameters.Length == 1;
Backup.Combine(zip, resultPath, maxDepth, issuer, comment);
if (overrideZip)
File.Move(zip, resultPath);
}
示例12: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
MyProjects = RequestContext.CurrentUserProjects;
InitControls();
IsProjectAdmin = Page.Participant.IsAdmin;
IsFullAdmin = Page.Participant.IsFullAdmin;
IsOutsider = Page.Participant.UserInfo.IsOutsider();
ParticipantSecurityInfo = new Dictionary<string, bool>
{
{"Project", IsProjectAdmin},
{"Milestone", RequestContext.CanCreateMilestone()},
{"Task", RequestContext.CanCreateTask()},
{"Discussion", RequestContext.CanCreateDiscussion()},
{"Time", RequestContext.CanCreateTime()},
{"ProjectTemplate", IsProjectAdmin}
};
ShowCreateButton = (ParticipantSecurityInfo.Any(r => r.Value) || Page is TMDocs) && !Page.Participant.UserInfo.IsOutsider();
var mobileAppRegistrator = new CachedMobileAppInstallRegistrator(new MobileAppInstallRegistrator());
var currentUser = CoreContext.UserManager.GetUsers(SecurityContext.CurrentAccount.ID);
var isRegistered = mobileAppRegistrator.IsInstallRegistered(currentUser.Email, null);
DisplayAppsBanner =
SetupInfo.DisplayMobappBanner("projects")
&& !CoreContext.Configuration.Standalone
&& !isRegistered;
}
示例13: VisaData
public void VisaData(IList<AktivPeriod> perioder)
{
panel1.Controls.Clear();
var lista = new Dictionary<DateTime, double>();
foreach (var dag in perioder.Select(o => o.Starttid.Date).Distinct())
{
var summeradDag = dag;
lista.Add(dag,
perioder.Where(o => o.Starttid.Date.Equals(summeradDag)).Sum(o => o.Tidsmängd.TotalMinutes));
}
if (!lista.Any()) return;
var max = lista.Max(o => o.Value);
var xposition = 10;
foreach (var d in lista)
{
var stapel = new Dagstapel
{
Height = panel1.Height - 20,
Top = 10,
Left = xposition
};
stapel.VisaUppgifter(d.Key, d.Value, max);
xposition += stapel.Width;
panel1.Controls.Add(stapel);
}
}
示例14: Executar
public override IEnumerable<string> Executar(Grafo grafo)
{
grafo.Direcionado = true;
var retorno = new List<string>();
Dictionary<string, Vertice> Q = new Dictionary<string, Vertice>();
var primeiro = grafo.Vertices.First();
Q.Add(primeiro.Key, primeiro.Value);
while (Q.Any())
{
var U = Q.First();
Q.Remove(Q.Keys.First());
foreach (var vertice in grafo.GetAdj(U.Key))
{
if (vertice.Value.Cor == CoresEnum.Branco)
{
vertice.Value.Descoberta = U.Value.Descoberta + 1;
vertice.Value.Pai = U.Value;
vertice.Value.Cor = CoresEnum.Cinza;
Q.Add(vertice.Key, vertice.Value);
}
}
retorno.Add(String.Format("{0} {1} {2}", grafo.Vertices.First().Key, U.Value.Id, U.Value.Descoberta));
U.Value.Cor = CoresEnum.Preto;
}
return retorno;
}
示例15: GetBracketMismatch
//Returns the location of bracket mismatch
//Rewrite this to make use of better suited container for brackets
public int GetBracketMismatch(string code)
{
Dictionary<char, char> bracketMap = new Dictionary<char, char>()
{ {'{', '}'}, {'(', ')'}, {'[', ']'}, {'<', '>'} };//, {'\'', '\''} }; //{} () [] <> "" ''
Stack<char> bracketStack = new Stack<char>();
int counter = 0;
foreach (char c in code)
{
if("(){}<>".Contains(c))
{
if (!")}>".Contains(c))
{
bracketStack.Push(c);
}
else if (bracketMap.Any(q => q.Key == bracketMap[bracketStack.Last()]))
{
bracketStack.Pop();
}
else
{
return counter;
}
}
counter++;
}
return -1;
}