本文整理汇总了C#中System.Collections.Dictionary.AddRange方法的典型用法代码示例。如果您正苦于以下问题:C# Dictionary.AddRange方法的具体用法?C# Dictionary.AddRange怎么用?C# Dictionary.AddRange使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Dictionary
的用法示例。
在下文中一共展示了Dictionary.AddRange方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Execute
protected override void Execute()
{
var projectsFilter = new string[0];
if (projects.Count > 0)
{
Log.Debug("Loading projects...");
projectsFilter = Repository.Projects.FindByNames(projects.ToArray()).Select(p => p.Id).ToArray();
}
var environmentsById = new Dictionary<string, string>();
if (environments.Count > 0)
{
Log.Debug("Loading environments...");
environmentsById.AddRange(Repository.Environments.FindByNames(environments.ToArray()).Select(p => new KeyValuePair<string, string>(p.Id, p.Name)));
}
else
{
environmentsById.AddRange(Repository.Environments.FindAll().Select(p => new KeyValuePair<string, string>(p.Id, p.Name)));
}
var deployments = Repository.Deployments.FindAll(projectsFilter, environments.Count > 0 ? environmentsById.Keys.ToArray() : new string[] { });
foreach (var deployment in deployments.Items)
{
LogDeploymentInfo(deployment, environmentsById);
}
}
示例2: AddRangeTest_ShouldAddAllElement_IfDistinctDictionaryIsPassed
public void AddRangeTest_ShouldAddAllElement_IfDistinctDictionaryIsPassed()
{
// Arrange
var dictionary = new Dictionary<string, int>();
dictionary.Add("a", 1);
dictionary.Add("d", 4);
dictionary.Add("b", 2);
dictionary.Add("c", 3);
dictionary.Add("e", 5);
var target = new Dictionary<string, int>();
// Act
target.AddRange(dictionary);
// Assert
CollectionAssert.AreEqual(
new int[] { 1, 2, 3, 4, 5 }.AsEnumerable(),
target.Union(dictionary, (_1, _2) => _1.Is(_2)).
OrderBy(_ => _.Key).
Select(_=>_.Value)
);
}
示例3: CategryDataBinding
/// <summary>
/// Sets up the data bindings to the combo box and the text box
/// Refreshes also -by deleting and rebinding
/// </summary>
private void CategryDataBinding()
{
// Clears any old data bindings
cmbIncomeCategories.DataSource = null;
txtIncomeCategoryTotal.DataBindings.Clear();
cmbExpenseCategories.DataSource = null;
txtExpenseCategoryTotal.DataBindings.Clear();
// Intializes the category total dictionarys
IncomeCategoriesTotals = new Dictionary<string, decimal>();
ExpenseCategoriesTotals = new Dictionary<string, decimal>();
ExpenseCategoriesTotals.Add("Total Expenses", _expenseService.GetMonthTotal(dtPick.Value));
ExpenseCategoriesTotals.AddRange(_expenseService.GetAllCategoryTotals(dtPick.Value));
IncomeCategoriesTotals.Add("Total Income", _incomeService.GetMonthTotal(dtPick.Value));
IncomeCategoriesTotals.AddRange(_incomeService.GetTotalIncomeByCategories(dtPick.Value));
// Sets the bindings for the controls
cmbIncomeCategories.DataSource = new ArrayList(IncomeCategoriesTotals);
cmbIncomeCategories.DisplayMember = "KEY";
txtIncomeCategoryTotal.DataBindings.Add("Text", cmbIncomeCategories.DataSource, "VALUE");
cmbExpenseCategories.DataSource = new ArrayList(ExpenseCategoriesTotals);
cmbExpenseCategories.DisplayMember = "KEY";
txtExpenseCategoryTotal.DataBindings.Add("Text", cmbExpenseCategories.DataSource, "VALUE");
}
示例4: AddSystemVariables
/// <summary>
/// Gather all windows system variables and their values
/// </summary>
/// <returns></returns>
private static void AddSystemVariables(ArtifactoryConfig artifactoryConfig, Build build)
{
if (artifactoryConfig.PropertyGroup.EnvironmentVariables == null)
return;
string enable = artifactoryConfig.PropertyGroup.EnvironmentVariables.EnabledEnvVariable;
if (string.IsNullOrWhiteSpace(enable) || !enable.ToLower().Equals("true"))
return;
// includePatterns = new List<Pattern>();
//List<Pattern> excludePatterns = new List<Pattern>();
List<Pattern> includePatterns = artifactoryConfig.PropertyGroup.EnvironmentVariables.IncludePatterns.Pattern;
List<Pattern> excludePatterns = artifactoryConfig.PropertyGroup.EnvironmentVariables.ExcludePatterns.Pattern;
StringBuilder includeRegexUnion = new StringBuilder();
StringBuilder excludeRegexUnion = new StringBuilder();
if (includePatterns != null && includePatterns.Count > 0)
{
includePatterns.ForEach(pattern => includeRegexUnion.Append(WildcardToRegex(pattern.key)).Append("|"));
includeRegexUnion.Remove(includeRegexUnion.Length - 1, 1);
}
if (excludePatterns != null && excludePatterns.Count > 0)
{
excludePatterns.ForEach(pattern => excludeRegexUnion.Append(WildcardToRegex(pattern.key)).Append("|"));
excludeRegexUnion.Remove(excludeRegexUnion.Length - 1, 1);
}
Regex includeRegex = new Regex(includeRegexUnion.ToString(), RegexOptions.IgnoreCase);
Regex excludeRegex = new Regex(excludeRegexUnion.ToString(), RegexOptions.IgnoreCase);
//System.Environment.GetEnvironmentVariables()
//EnvironmentVariableTarget
IDictionary sysVariables = Environment.GetEnvironmentVariables(EnvironmentVariableTarget.Process);
var dicVariables = new Dictionary<string, string>();
var environmentVariables = build.agent.BuildAgentEnvironment();
foreach(string key in sysVariables.Keys)
{
if (!environmentVariables.ContainsKey(string.Concat(Agent.PRE_FIX_ENV, key)) && !PathConflicts(includePatterns, excludePatterns, includeRegex, excludeRegex, key))
{
dicVariables.Add(key, (string)sysVariables[key]);
}
}
dicVariables.AddRange(environmentVariables);
build.properties = dicVariables;
}