本文整理汇总了C#中Dictionary.AddRange方法的典型用法代码示例。如果您正苦于以下问题:C# Dictionary.AddRange方法的具体用法?C# Dictionary.AddRange怎么用?C# Dictionary.AddRange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Dictionary
的用法示例。
在下文中一共展示了Dictionary.AddRange方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Clone
public object Clone()
{
BeanConfig bc = null;
try
{
bc = (BeanConfig) Activator.CreateInstance(GetType());
}
catch (TargetInvocationException e)
{
throw new ConfigException(e);
}
catch (MemberAccessException e)
{
throw new ConfigException(e);
}
if (bc == null)
{
return null;
}
bc.ClassName = ClassName;
bc.Name = Name;
var @params = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
@params.AddRange(@params);
[email protected] = @params;
return bc;
}
示例2: GetTotalFlowPerCategoriesForMonth
public Dictionary<string, decimal> GetTotalFlowPerCategoriesForMonth(DateTime month)
{
Dictionary<string, decimal> categoryTotals = new Dictionary<string, decimal>
{
{"Total Expenses", GetTotalExpenseForMonth(month)}
};
categoryTotals.AddRange(_expenseService.GetAllCategoryTotals(month));
categoryTotals.Add("Total Income", GetTotalIncomeForMonth(month));
foreach (var totalIncomeByCategory in _incomeService.GetTotalIncomeByCategories(month))
{
if (categoryTotals.ContainsKey(totalIncomeByCategory.Key))
{
var placeholder = categoryTotals[totalIncomeByCategory.Key];
categoryTotals.Remove(totalIncomeByCategory.Key);
#warning Verify that part.. >.<
categoryTotals.Add(string.Format("{0} - Expense", totalIncomeByCategory.Key), placeholder);
categoryTotals.Add(string.Format("{0} - Income", totalIncomeByCategory.Key), placeholder);
}
else
{
categoryTotals.Add(totalIncomeByCategory.Key, totalIncomeByCategory.Value);
}
}
return categoryTotals;
}
示例3: GetTotalsOfMonthByCategory
public Dictionary<string, double> GetTotalsOfMonthByCategory()
{
Dictionary<string, double> categoryTotals = new Dictionary<string, double>();
categoryTotals.Add("Total Expenses", GetMonthesExpenseTotal());
categoryTotals.AddRange(ExpenseHandler.GetAllCategoryTotals(MonthRepresented));
categoryTotals.Add("Total Income", GetMonthesIncomeTotal());
foreach (KeyValuePair<string, double> curIncomeCatTotal in IncomeHandler.GetAllCategoryTotals(MonthRepresented))
{
if (categoryTotals.ContainsKey(curIncomeCatTotal.Key))
{
double placeholder = categoryTotals[curIncomeCatTotal.Key];
categoryTotals.Remove(curIncomeCatTotal.Key);
categoryTotals.Add(string.Format("{0} - {1}", curIncomeCatTotal.Key, "Expense"), placeholder);
categoryTotals.Add(string.Format("{0} - {1}", curIncomeCatTotal.Key, "Income"), curIncomeCatTotal.Value);
}
else
{
categoryTotals.Add(curIncomeCatTotal.Key, curIncomeCatTotal.Value);
}
}
return categoryTotals;
}
示例4: Translate
private static Dictionary<string, string> Translate(HashSet<string> toTranslate, string fromCulture, string toCulture)
{
var translated = Translation.TranslationClient.Translator.TranslateBatch(toTranslate.ToList(), fromCulture, toCulture);
Dictionary<string, string> dic = new Dictionary<string, string>();
dic.AddRange(toTranslate.ToList(), translated);
return dic;
}
示例5: Redirect
public static void Redirect()
{
redirects = new Dictionary<MethodInfo, RedirectCallsState>();
foreach (var type in Assembly.GetExecutingAssembly().GetTypes())
{
redirects.AddRange(RedirectionUtil.RedirectType(type));
}
}
示例6: Evaluate6
public ICollection<Number640> Evaluate6(IDictionary<PeerAddress, IDictionary<Number640, byte>> rawKeys)
{
var result = new Dictionary<Number640, byte>();
foreach (var dictionary in rawKeys.Values)
{
result.AddRange(dictionary);
}
return result.Keys;
}
示例7: GetGenericArgsMapping
// say, we have a type Type<(1) T1, (2) T2> with the method of the following signature:
// T3[,][] Meth<(3) T3>(T1 o1, Func<T1, T3> o2) that has the following public type points:
//
// ReturnValue = T3 (a)[,][]
// Args = T1 (b), Func<T1 (c), T3 (d)>
//
// to be perfectly fine we need the following typelinks to be built:
// (3) <-> (a), (1) <-> (b), (1) <-> (c), (3) <-> (d)
//
// after some analysis we build the following mapping:
// (key <- value)
// a0 <- t[0]
// a1[0] <- t[0]
// a1[1] <- m[0]
// ret[0][0] <- m[0]
public static Dictionary<String, String> GetGenericArgsMapping(this MethodInfo method)
{
if (method == null)
{
return null;
}
else
{
var pattern = (MethodInfo)method.Module.ResolveMethod(method.MetadataToken);
var methodGenericArgs = pattern.XGetGenericArguments();
var typeGenericArgs = pattern.DeclaringType.XGetGenericArguments();
var mapping = new Dictionary<String, String>();
mapping.AddRange(AppendMethodMapping(pattern, methodGenericArgs, "m"));
mapping.AddRange(AppendMethodMapping(pattern, typeGenericArgs, "t"));
return mapping;
}
}
示例8: Evaluate2
public IDictionary<Number640, Data> Evaluate2(IDictionary<PeerAddress, IDictionary<Number640, Data>> rawData)
{
var result = new Dictionary<Number640, Data>();
foreach (var dictionary in rawData.Values)
{
result.AddRange(dictionary);
}
return result;
}
示例9: BuildOrder
public IDictionary<BetSheet, IList<BetOrder>> BuildOrder(User user, LotterySpecies specie,
IEnumerable<AutoBetItem> betList, IDictionary<string, object> parameters)
{
this._betResult = new BetResult();
BetResult returnResult = new Models.BetResult();
var todayLotteryCompany = TodayLotteryCompany.Instance.GetTodayCompany(); //获取今日开奖公司
var memberComm = CommManager.GetMemberCommissionInSession(user, specie); //获取会员的佣金
IDictionary<BetSheet, IList<BetOrder>> betSheetDic = new Dictionary<BetSheet, IList<BetOrder>>();
IDictionary<BetSheet, IList<BetOrder>> resultDic = new Dictionary<BetSheet, IList<BetOrder>>();
foreach (var betOrder in betList)
{
int[] nums;
switch (betOrder.BetType)
{
case AutoBetType.TwelveZodiac: nums = LotterySystem.Current.TwelveZodiac; break;
case AutoBetType.EvenEven: nums = LotterySystem.Current.EvenEven; break;
case AutoBetType.EvenOdd: nums = LotterySystem.Current.EvenOdd; break;
case AutoBetType.OddEven: nums = LotterySystem.Current.OddEven; break;
case AutoBetType.OddOdd: nums = LotterySystem.Current.OddOdd; break;
case AutoBetType.Small: nums = LotterySystem.Current.Small; break;
case AutoBetType.Big: nums = LotterySystem.Current.Big; break;
default: throw new InvalidDataException("不可到达,数据异常!");
}
var sheet = BuildAutoElectionCodeOrder(user, specie, betOrder.CompanyList, betOrder.WagerList, nums);
betSheetDic.AddRange(sheet);
returnResult.Append(this.BetResult);
List<BetOrder> orderList = new List<BetOrder>();
foreach (var item in betSheetDic)
orderList.AddRange(item.Value);
StringBuilder companySb = new StringBuilder();
foreach (var companyId in betOrder.CompanyList)
{
var company = todayLotteryCompany.Find(it => it.CompanyId == companyId);
if (company == null)
throw new InvalidDataException("CompanyId:" + companyId);
companySb.AppendFormat("{0} ", company.Abbreviation);
}
BetSheet orderSheet = new BetSheet
{
Num = betOrder.BetType.ToString(),
Turnover = orderList.Sum(it => it.Turnover),
NetAmount = orderList.Sum(it => it.NetAmount),
Commission = orderList.Sum(it => it.Commission),
UserId = user.UserId,
Status = BetStatus.Valid,
IPAddress = IPHelper.IPAddress,
BetCompany = companySb.ToString(),
BetAmount = JoinSheetBetAmount(sheet.Keys)
};
resultDic.Add(orderSheet, orderList);
betSheetDic.Clear();
}
this._betResult = returnResult;
return resultDic;
}
示例10: Update
public Dictionary<string, List<string>> Update()
{
Dictionary<string, List<string>> updateChanges = new Dictionary<string, List<string>>();
foreach (GameData gameData in Games)
{
var gameUpdateChanges = gameData.Update();
updateChanges.AddRange(gameUpdateChanges.Select
(e => new KeyValuePair<string, List<string>>(e.Key, e.Value)) );
}
return updateChanges;
}
示例11: then_range_added_to_existing_dictionary_adds_correctly
public void then_range_added_to_existing_dictionary_adds_correctly()
{
Dictionary<string, string> stuff = new Dictionary<string, string> {{"ONE", "one"}};
stuff.AddRange(s => s.ToUpperInvariant(), new[] { "two", "three" });
Assert.AreEqual(3, stuff.Count);
Assert.IsTrue(stuff.ContainsKey("TWO"));
Assert.AreEqual("two", stuff["TWO"]);
Assert.IsTrue(stuff.ContainsKey("THREE"));
Assert.AreEqual("three", stuff["THREE"]);
}
示例12: ExecuteBindingAsync
public override Task ExecuteBindingAsync(ModelMetadataProvider metadataProvider, HttpActionContext actionContext, CancellationToken cancellationToken) {
var binding = actionContext.ActionDescriptor.ActionBinding;
var parameterBinding = binding.ParameterBindings.FirstOrDefault(b => b.Descriptor.ParameterBinderAttribute is QueryStringParametersAttribute);
if (parameterBinding == null || !(typeof(IDictionary<string, string>).IsAssignableFrom(parameterBinding.Descriptor.ParameterType)))
return Task.FromResult(0);
var parameters = new Dictionary<string, string>();
parameters.AddRange(actionContext.Request.GetQueryNameValuePairs().Where(kvp => !kvp.Key.Equals("access_token", StringComparison.OrdinalIgnoreCase)));
SetValue(actionContext, parameters);
return Task.FromResult(0);
}
示例13: AddRange_KeyValuePair_Test
public static void AddRange_KeyValuePair_Test()
{
var dictionary = new Dictionary<int, string>();
var collection2 = new List<KeyValuePair<int, string>>
{
new KeyValuePair<int, string>(1, "test")
};
dictionary.AddRange(collection2);
Assert.That(dictionary.ContainsKey(1));
Assert.That(dictionary.ContainsValue("test"));
}
示例14: then_range_added_to_empty_dictionary_adds_correctly
public void then_range_added_to_empty_dictionary_adds_correctly()
{
Dictionary<string, string> stuff = new Dictionary<string, string>();
stuff.AddRange(s => s.ToUpperInvariant().Remove(2), new[]{"one", "two", "three"});
Assert.AreEqual(3, stuff.Count);
Assert.IsTrue(stuff.ContainsKey("ON"));
Assert.AreEqual("one", stuff["ON"]);
Assert.IsTrue(stuff.ContainsKey("TW"));
Assert.AreEqual("two", stuff["TW"]);
Assert.IsTrue(stuff.ContainsKey("TH"));
Assert.AreEqual("three", stuff["TH"]);
}
示例15: AssemblyInfoViewModel
public AssemblyInfoViewModel(AssemblyInfo assemblyInfo)
{
this.assemblyInfo = assemblyInfo;
NewGuidCommand = new RelayCommand(() => Guid = System.Guid.NewGuid());
var cultures = CultureInfo.GetCultures(CultureTypes.AllCultures);
Languages = new Dictionary<string, string>();
Languages.Add(
NONE_LANGUAGE_CODE,
string.Format("({0})", StringParser.Parse("${res:Dialog.ProjectOptions.AssemblyInfo.None}")));
Languages.AddRange(cultures.ToDictionary(x => x.Name, x => x.DisplayName).Distinct().OrderBy(x => x.Value));
}