本文整理汇总了C#中MultiDictionary.Add方法的典型用法代码示例。如果您正苦于以下问题:C# MultiDictionary.Add方法的具体用法?C# MultiDictionary.Add怎么用?C# MultiDictionary.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MultiDictionary
的用法示例。
在下文中一共展示了MultiDictionary.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Remove
public void Remove()
{
MultiDictionary<string, string> dictionary = new MultiDictionary<string, string>(StringComparer.OrdinalIgnoreCase);
dictionary.Add("x", "x1");
dictionary.Add("x", "x2");
dictionary.Add("y", "y1");
Assert.Equal(true, dictionary.Remove("x", "x1"));
Assert.Equal(2, dictionary.KeyCount);
Assert.Equal(2, dictionary.ValueCount);
Assert.Equal(true, dictionary.Remove("x", "x2"));
Assert.Equal(1, dictionary.KeyCount);
Assert.Equal(1, dictionary.ValueCount);
Assert.Equal(true, dictionary.Remove("y", "y1"));
Assert.Equal(0, dictionary.KeyCount);
Assert.Equal(0, dictionary.ValueCount);
dictionary.Add("x", "x1");
dictionary.Add("x", "x2");
Assert.Equal(true, dictionary.Remove("x", "x2"));
Assert.Equal(1, dictionary.KeyCount);
Assert.Equal(1, dictionary.ValueCount);
}
示例2: ParseArgs
public ParseResult ParseArgs(string[] args)
{
MultiDictionary<string, string> parsedArguments = new MultiDictionary<string, string>();
ExecutionLog errorLog = ExecutionLog.CreateErrorLog();
for (int i = 0; i < args.Length; ++i)
{
string currentArg = args[i];
Match match = argRegex.Match(currentArg);
if (match.Success)
{
if (match.Groups.Count == 3)
{
if (string.IsNullOrEmpty(match.Groups[2].Value))
{
// Special case for the --help string.
// TODO(ruibm): Potentially just support args with zero arguments.
if (currentArg == "--help")
{
parsedArguments.Add(match.Groups[1].Value, true.ToString());
}
// The value must come after the space in the next args position.
else if (i + 1 >= args.Length)
{
errorLog.Add("Argument [{0}] is not set to a value.", currentArg);
}
else
{
parsedArguments.Add(match.Groups[1].Value, args[++i]);
}
}
else
{
// The current Arg is contains both key and value separated by '='.
parsedArguments.Add(match.Groups[1].Value, match.Groups[2].Value);
}
}
else
{
Assertions.Fail(
"Invalid parsed argument [{0}]. The group count was [{1}].",
currentArg,
match.Groups.Count);
}
}
else
{
errorLog.Add("Unparseable argument [{0}].", currentArg);
}
}
return new ParseResult(errorLog.Count == 0, parsedArguments, errorLog);
}
示例3: IndexedArgInstances
public IndexedArgInstances(List<ArgInstance> instances)
{
_mandatoryFullNames = new HashSet<string>();
_argInstancesByName = new MultiDictionary<string, ArgInstance>();
HashSet<string> tempNames = new HashSet<string>();
foreach (ArgInstance currentInstance in instances)
{
if (currentInstance.Arg.IsMandatory)
{
_mandatoryFullNames.Add(currentInstance.FullName);
}
tempNames.Clear();
tempNames.Add(currentInstance.Name);
tempNames.Add(currentInstance.FullName);
if (currentInstance.ShortName != null)
{
tempNames.Add(currentInstance.ShortName);
}
foreach (string name in tempNames)
{
_argInstancesByName.Add(name, currentInstance);
}
}
}
示例4: AddEvent
private static void AddEvent(string command)
{
var currentEvent = new Event(DateTime.Now, "title", "location");
///GetParameters(command, "AddEvent", out date, out title, out location);
var events = new MultiDictionary<string, Event>(true); ///added that to make it stop crashing too
events.Add("title", currentEvent);
}
示例5: ReadContactsFromFile
private static void ReadContactsFromFile(string file, MultiDictionary<string, string> contactsName, MultiDictionary<string, string> contactsTown)
{
StreamReader reader = new StreamReader(file);
string line = reader.ReadLine();
using (reader)
{
while (line != null)
{
var details = line.Split('|');
string names = details[0].Trim();
string town = details[1].Trim();
string phone = details[2].Trim();
contactsTown.Add(town, phone);
var namesSeparated = names.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
foreach (var name in namesSeparated)
{
contactsName.Add(name, phone);
}
line = reader.ReadLine();
}
}
}
示例6: WithPrimaryConstructorParametersBinder
internal WithPrimaryConstructorParametersBinder(MethodSymbol primaryCtor, Binder next)
: base(next)
{
Debug.Assert((object)primaryCtor != null);
this.primaryCtor = primaryCtor;
var parameters = primaryCtor.Parameters;
var definitionMap = new SmallDictionary<string, ParameterSymbol>();
for (int i = parameters.Length - 1; i >= 0; i--)
{
var parameter = parameters[i];
definitionMap[parameter.Name] = parameter;
}
this.definitionMap = definitionMap;
var parameterMap = new MultiDictionary<string, ParameterSymbol>(parameters.Length, EqualityComparer<string>.Default);
foreach (var parameter in parameters)
{
parameterMap.Add(parameter.Name, parameter);
}
this.parameterMap = parameterMap;
}
示例7: FastInvokerBase
protected FastInvokerBase(Type type)
{
ObjectType = type;
MethodNameCache = new MultiDictionary<string, MethodInfo>(false);
type.GetMethods(_methodBindingFlags).Each(method => MethodNameCache.Add(method.Name, method));
}
示例8: CreateParseResult
public ParseResult CreateParseResult(bool successfull, params string[] keyValues)
{
MultiDictionary<string, string> parsedValues = new MultiDictionary<string, string>();
for (int i = 0; i < keyValues.Length / 2; ++i)
{
parsedValues.Add(keyValues[i * 2], keyValues[i * 2 + 1]);
}
return new ParseResult(successfull, parsedValues, ExecutionLog.CreateErrorLog());
}
示例9: WithQueryLambdaParametersBinder
public WithQueryLambdaParametersBinder(LambdaSymbol lambdaSymbol, RangeVariableMap rangeVariableMap, Binder next)
: base(lambdaSymbol, next)
{
_rangeVariableMap = rangeVariableMap;
_parameterMap = new MultiDictionary<string, RangeVariableSymbol>();
foreach (var qv in rangeVariableMap.Keys)
{
_parameterMap.Add(qv.Name, qv);
}
}
示例10: GetIdentityMembership
public IEnumerable<string> GetIdentityMembership(string username)
{
if (_membership == null)
{
_membership = new MultiDictionary<string, string>();
foreach (var pair in _userGroupMembership.Split(' '))
_membership.Add(System.Environment.UserDomainName + @"\" + pair.Split('-')[0], pair.Split('-')[1]);
}
return _membership.Get(username).ToList();
}
示例11: AugmentGraphWithLanguageRules
/// <summary>
/// Modifies the graph by adding dependencies corresponding to language rules that apply in a looser
/// sense: TRUE forms depend on NEXT forms and DOES forms depend on LEGAL forms.
/// </summary>
private static MultiDictionary<ISentenceForm, ISentenceForm> AugmentGraphWithLanguageRules(
MultiDictionary<ISentenceForm, ISentenceForm> dependencyGraph, ICollection<ISentenceForm> sentenceForms)
{
var newGraph = new MultiDictionary<ISentenceForm, ISentenceForm>(true);
foreach (KeyValuePair<ISentenceForm, ICollection<ISentenceForm>> kv in dependencyGraph)
newGraph[kv.Key] = kv.Value;
foreach (ISentenceForm form in sentenceForms)
{
if (form.Name == GameContainer.Parser.TokTrue)
{
ISentenceForm nextForm = form.WithName(GameContainer.Parser.TokNext);
if (sentenceForms.Contains(nextForm))
newGraph.Add(form, nextForm);
}
else if (form.Name == GameContainer.Parser.TokDoes)
{
ISentenceForm legalForm = form.WithName(GameContainer.Parser.TokLegal);
if (sentenceForms.Contains(legalForm))
newGraph.Add(form, legalForm);
}
}
return newGraph;
}
示例12: FillPhoneBook
private static MultiDictionary<string, MultiDictionary<string, string>> FillPhoneBook()
{
const string PhonesPath = "phones.txt";
StreamReader phonesReader = new StreamReader(PhonesPath);
var phoneBook = new MultiDictionary<string, MultiDictionary<string, string>>(true);
using (phonesReader)
{
string line = phonesReader.ReadLine();
while (line != null)
{
var splittedEntry = line.Split('|');
string name = splittedEntry[0].Trim();
string town = splittedEntry[1].Trim();
string phoneNumber = splittedEntry[2].Trim();
if (phoneBook.ContainsKey(name))
{
var nameInPhoneBook = phoneBook[name].First();
if (nameInPhoneBook.ContainsKey(town))
{
nameInPhoneBook[town].Add(phoneNumber);
}
else
{
nameInPhoneBook.Add(town, phoneNumber);
}
}
else
{
phoneBook.Add(name, new MultiDictionary<string, string>(true));
var nameInPhoneBook = phoneBook[name].First();
nameInPhoneBook.Add(town, phoneNumber);
}
line = phonesReader.ReadLine();
}
return phoneBook;
}
}
示例13: Main
static void Main(string[] args)
{
StreamReader reader = new StreamReader("phones.txt", Encoding.GetEncoding("windows-1251"));
StreamReader commands = new StreamReader("commands.txt", Encoding.GetEncoding("windows-1251"));
using (reader)
{
using (commands)
{
char[] separator = { '|','\n', '\r'};
MultiDictionary<Tuple<string, string>, string> phonesFile = new MultiDictionary<Tuple<string, string>, string>(true);
string text = reader.ReadToEnd();
string[] parts = text.Split(separator, StringSplitOptions.RemoveEmptyEntries);
TrimTheParts(parts);
for (int i = 0; i < parts.Length; i += 3)
{
phonesFile.Add(new Tuple<string, string>(parts[i], parts[i + 1]), parts[i + 2]);
}
Console.WriteLine("Only by name----------------------------");
var peopleByName = phonesFile.FindAll(key => key.Key.Item1 == "Moro");
foreach (var people in peopleByName)
{
Console.WriteLine(people);
}
Console.WriteLine("By name and town----------------------------");
var peopleByNameAndTown = phonesFile.FindAll(key => key.Key.Item1 == "Kireto" && key.Key.Item2 == "Varna");
foreach (var people in peopleByNameAndTown)
{
Console.WriteLine(people);
}
Console.WriteLine("Only by name but diferent towns----------------------------");
var peopleByNameDifTowns = phonesFile.FindAll(key => key.Key.Item1 == "Kireto");
foreach (var people in peopleByNameDifTowns)
{
Console.WriteLine(people);
}
}
}
}
示例14: PhoneBook
public PhoneBook(List<PhoneEntry> entries)
{
firstNames = new MultiDictionary<string, PhoneEntry>(true);
middleNames = new MultiDictionary<string, PhoneEntry>(true);
lastNames = new MultiDictionary<string, PhoneEntry>(true);
towns = new MultiDictionary<string, PhoneEntry>(true);
foreach (var entry in entries)
{
firstNames.Add(new KeyValuePair<string,
ICollection<PhoneEntry>>(entry.FirstName, new PhoneEntry[] { entry }));
middleNames.Add(new KeyValuePair<string,
ICollection<PhoneEntry>>(entry.MiddleName, new PhoneEntry[] { entry }));
lastNames.Add(new KeyValuePair<string,
ICollection<PhoneEntry>>(entry.LastName, new PhoneEntry[] { entry }));
towns.Add(new KeyValuePair<string,
ICollection<PhoneEntry>>(entry.Town, new PhoneEntry[] { entry }));
}
}
示例15: StepDataRequirements
private StepDataRequirements()
{
requirements = new MultiDictionary<string, string>();
// Get resource file
string path = Application.dataPath + filePath;
XmlDocument doc = new XmlDocument();
doc.Load(path);
XmlNode root = doc.DocumentElement;
foreach(XmlNode current in root.ChildNodes)
{
string key = current.LocalName;
foreach (XmlNode val in current.ChildNodes)
{
requirements.Add(key, val.Value);
}
}
}