当前位置: 首页>>代码示例>>C#>>正文


C# MultiDictionary.Add方法代码示例

本文整理汇总了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);
        }
开发者ID:cameron314,项目名称:msbuild,代码行数:31,代码来源:MultiDictionary_Tests.cs

示例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);
        }
开发者ID:ruibm,项目名称:Danio,代码行数:53,代码来源:ConsoleParser.cs

示例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);
                }
            }
        }
开发者ID:ruibm,项目名称:Danio,代码行数:26,代码来源:IndexedArgInstances.cs

示例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);
 }
开发者ID:Alex-Bubblemaster,项目名称:HighQualityCode,代码行数:7,代码来源:EventHandlingProgramme.cs

示例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();
                }
            }
        }
开发者ID:huuuskyyy,项目名称:CSharp-Homeworks,代码行数:27,代码来源:Program.cs

示例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;
        }
开发者ID:afrog33k,项目名称:csnative,代码行数:26,代码来源:WithPrimaryConstructorParametersBinder.cs

示例7: FastInvokerBase

        protected FastInvokerBase(Type type)
        {
            ObjectType = type;

            MethodNameCache = new MultiDictionary<string, MethodInfo>(false);

            type.GetMethods(_methodBindingFlags).Each(method => MethodNameCache.Add(method.Name, method));
        }
开发者ID:xliang,项目名称:Magnum,代码行数:8,代码来源:FastInvokerBase.cs

示例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());
 }
开发者ID:ruibm,项目名称:Danio,代码行数:9,代码来源:ArgAssignerTest.cs

示例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);
     }
 }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:10,代码来源:Binder.WithQueryLambdaParametersBinder.cs

示例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();
 }
开发者ID:tjakopovic,项目名称:Rhetos,代码行数:10,代码来源:MockWindowsSecurity.cs

示例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;
        }
开发者ID:druzil,项目名称:nggp-base,代码行数:28,代码来源:SentenceFormModelFactory.cs

示例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;
            }
        }
开发者ID:jesusico83,项目名称:Telerik,代码行数:46,代码来源:PhonesAndCommands.cs

示例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);
                    }
                }

            }
        }
开发者ID:bonchovylkov,项目名称:DictionaryHomework,代码行数:44,代码来源:PhoneFile.cs

示例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 }));
            }
        }
开发者ID:ekostadinov,项目名称:CoursesProjects,代码行数:19,代码来源:PhoneBook.cs

示例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);
          }
        }
    }
开发者ID:shawnmiller,项目名称:RoomWithTheMoose,代码行数:20,代码来源:StepDataRequirements.cs


注:本文中的MultiDictionary.Add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。