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


C# StringDictionary.GetEnumerator方法代码示例

本文整理汇总了C#中System.Collections.Specialized.StringDictionary.GetEnumerator方法的典型用法代码示例。如果您正苦于以下问题:C# StringDictionary.GetEnumerator方法的具体用法?C# StringDictionary.GetEnumerator怎么用?C# StringDictionary.GetEnumerator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Collections.Specialized.StringDictionary的用法示例。


在下文中一共展示了StringDictionary.GetEnumerator方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CLAParser

        /// <summary>
        /// <para>Class CLAParser provides everything for easy and fast handling of commandline arguments.</para>
        /// <para>Usage:</para>
        /// <para>1) Create an instance of CLAParser by calling this constructor.</para>
        /// <para>2) Define parameters by calling Parameter() as often as needed.</para>
        /// <para>3) Optionally: Set variables such as AllowAdditionalParameters and ParameterPrefix.</para>
        /// <para>4) Call Parse(), catch all CmdLineArgumentExceptions, and show those to user.</para>
        /// <para>5) Call GetUsage() and GetParameterInfo() to create information about using commandline arguments.</para>
        /// </summary>
        /// <param name="NamespaceOfResX">Pass the name of the default namespace (usually the namespace of main code file Program.cs)<para>[This is necessary so that CLAParser can find its resource files (CmdLineArgumentParserRes.resx, CmdLineArgumentParserRes.de-DE.resx, ...)]</para></param>
        public CLAParser(string NamespaceOfResX)
        {
            CmdLineArgResourceManager = new ResourceManager(NamespaceOfResX + ".CmdLineArgumentParserRes", this.GetType().Assembly);

            FoundParameters = new StringDictionary();
            WantedParameters = new SortedDictionary<string, ParameterDefintion>(StringComparer.InvariantCultureIgnoreCase);
            Enumerator = FoundParameters.GetEnumerator();

            ParameterPrefix = "/";
            AllowAdditionalParameters = false;
        }
开发者ID:VivianMC,项目名称:CLAParser,代码行数:21,代码来源:CLAParser.cs

示例2: PrintKeysAndValues2

 // Uses the enumerator.
 // NOTE: The foreach statement is the preferred way of enumerating the contents of a collection.
 public static void PrintKeysAndValues2(StringDictionary myCol)
 {
     IEnumerator myEnumerator = myCol.GetEnumerator();
     DictionaryEntry de;
     Console.WriteLine("   KEY                       VALUE");
     while (myEnumerator.MoveNext())
     {
         de = (DictionaryEntry)myEnumerator.Current;
         Console.WriteLine("   {0,-25} {1}", de.Key, de.Value);
     }
     Console.WriteLine();
 }
开发者ID:BigBearGCU,项目名称:FNDEVModule2ExampleCode,代码行数:14,代码来源:Program.cs

示例3: Empty

		public void Empty ()
		{
			StringDictionary sd = new StringDictionary ();
			Assert.AreEqual (0, sd.Count, "Count");
			Assert.IsFalse (sd.IsSynchronized, "IsSynchronized");
			Assert.AreEqual (0, sd.Keys.Count, "Keys");
			Assert.AreEqual (0, sd.Values.Count, "Values");
			Assert.IsNotNull (sd.SyncRoot, "SyncRoot");
			Assert.IsFalse (sd.ContainsKey ("a"), "ContainsKey");
			Assert.IsFalse (sd.ContainsValue ("1"), "ContainsValue");
			sd.CopyTo (new DictionaryEntry[0], 0);
			Assert.IsNotNull (sd.GetEnumerator (), "GetEnumerator");
			sd.Remove ("a"); // doesn't exists
			sd.Clear ();
		}
开发者ID:nlhepler,项目名称:mono,代码行数:15,代码来源:StringDictionaryTest.cs

示例4: Test01

        public void Test01()
        {
            StringDictionary sd;
            IEnumerator en;
            DictionaryEntry curr;        // Enumerator.Current value
            // simple string values
            string[] values =
            {
                "a",
                "aa",
                "",
                " ",
                "text",
                "     spaces",
                "1",
                "$%^#",
                "2222222222222222222222222",
                System.DateTime.Today.ToString(),
                Int32.MaxValue.ToString()
            };

            // keys for simple string values
            string[] keys =
            {
                "zero",
                "one",
                " ",
                "",
                "aa",
                "1",
                System.DateTime.Today.ToString(),
                "$%^#",
                Int32.MaxValue.ToString(),
                "     spaces",
                "2222222222222222222222222"
            };

            // [] StringDictionary GetEnumerator()
            //-----------------------------------------------------------------

            sd = new StringDictionary();

            // [] Enumerator for empty dictionary
            //
            en = sd.GetEnumerator();
            string type = en.GetType().ToString();
            if (type.IndexOf("Enumerator", 0) == 0)
            {
                Assert.False(true, string.Format("Error, type is not Enumerator"));
            }

            //
            //  MoveNext should return false
            //
            bool res = en.MoveNext();
            if (res)
            {
                Assert.False(true, string.Format("Error, MoveNext returned true"));
            }

            //
            //  Attempt to get Current should result in exception
            //
            Assert.Throws<InvalidOperationException>(() => { curr = (DictionaryEntry)en.Current; });

            //
            //   Filled collection
            // [] Enumerator for filled dictionary
            //
            for (int i = 0; i < values.Length; i++)
            {
                sd.Add(keys[i], values[i]);
            }

            en = sd.GetEnumerator();
            type = en.GetType().ToString();
            if (type.IndexOf("Enumerator", 0) == 0)
            {
                Assert.False(true, string.Format("Error, type is not Enumerator"));
            }

            //
            //  MoveNext should return true
            //

            for (int i = 0; i < sd.Count; i++)
            {
                res = en.MoveNext();
                if (!res)
                {
                    Assert.False(true, string.Format("Error, MoveNext returned false", i));
                }

                curr = (DictionaryEntry)en.Current;
                //
                //enumerator enumerates in different than added order
                // so we'll check Contains
                //
                if (!sd.ContainsValue(curr.Value.ToString()))
                {
//.........这里部分代码省略.........
开发者ID:er0dr1guez,项目名称:corefx,代码行数:101,代码来源:GetEnumeratorTests.cs

示例5: Parse

        /// <summary>
        /// <para>Starts the parsing process. Throws CmdLineArgumentExceptions in case of errors.</para>
        /// <para>Afterwards use the enumerator or the dictionary interface to access the found paramters and their values.</para>
        /// </summary>
        /// <param name="ArgumentLine">Argument line passed via command line to the program.</param>        
        public void Parse(string ArgumentLine)
        {
            FoundParameters = new StringDictionary();
            Enumerator = FoundParameters.GetEnumerator();

            //pure: ^[\s]*((?<unknownvalues>("[^"]*")|('[^']*')|([^ "'/-]*)?)[\s]*)*([\s]*[/-](?<name>[^\s-/:=]+)([:=]?)([\s]*)(?<value>("[^"]*")|('[^']*')|([\s]*[^/-][^\s]+[\s]*)|([^/-]+)|)?([\s]*))*$
            string CorrectCmdLineRegEx = "^[\\s]*((?<unknownvalues>(\"[^\"]*\")|('[^']*')|([^ \"'/-]*)?)[\\s]*)*([\\s]*[/-](?<name>[^\\s-/:=]+)([:=]?)([\\s]*)(?<value>(\"[^\"]*\")|('[^']*')|([\\s]*[^/-][^\\s]+[\\s]*)|([^/-]+)|)?([\\s]*))*$";
            string ParamValuePairRegEx = "^(([\\s]*[/-])(?<name>[^\\s-/:=]+)([:=]?)([\\s]*)(?<value>(\"[^\"]*\")|('[^']*')|([\\s]*[^/-][^\\s]+[\\s]*)|([^/-]+)|)?([\\s]*))*$";

            //start from beginning (^) and go to very end ($)
            //first optionally remove spaces [\s]* (this might not be necessary)
            //find optionally values without parameter. one of following:
            //  1) anything enclosed by double quotes ("[^"]*")
            //  2) anything enclosed by single quotes ('[^']*')
            //  3) anything that is not double or single quote nor slash nor minus [^"'/-]*
            //  4) or anything that contains no space [^ ]*?
            //find each parameter-value pair which seems to be okay. however, there might be unwanted some / or - signs in between.
            //each pair must start with a space followed by / or - ([\s]+[/-])
            //next is the parameter name which can be anything but spaces, -, /, or : ([^\\s-/:=])
            //next is the value which can either be one of following: (note: order matters!)
            //  -anything except " enclosed by " or anything except ' enclosed by ' ((\"[^\"]*\")|('[^']*'))
            //  -anything but spaces not starting with / nor -  optionally enclosed by spaces (([\\s]*[^/-][^\\s]+[\\s]*))
            //  -anything but / or - ([^/-]+).
            //the argument may end with spaces (([\\s]*))

            RegexOptions ro = new RegexOptions();
            ro = ro | RegexOptions.IgnoreCase;
            ro = ro | RegexOptions.Multiline;
            Regex ParseCmdLine = new Regex(CorrectCmdLineRegEx, ro);

            ///For test and debug purposes function Matches() is used which returns
            ///a MatchCollection. However, there should never be more than one entry.
            /*MatchCollection mc = ParseCmdLine.Matches(ArgumentLine.ToString());
            if (mc.Count > 1)
                throw new Exception("Internal Exception: MatchCollection contains more than 1 entry!");
            foreach (Match m in mc)*/

            ///By default use Match() because in case of no match raising ExceptionSyntaxError would be skipped by Matches() and foreach.
            Match m = ParseCmdLine.Match(ArgumentLine.ToString());
            {

                if (m.Success == false)
                {
                    ///Regular expression did not match ArgumentLine. There might be two / or -.
                    ///Find out up to where ArgumentLine seems to be okay and raise an exception reporting the rest.
                    int LastCorrectPosition = FindMismatchReasonInRegex(CorrectCmdLineRegEx, ArgumentLine);
                    string ProbableErrorCause = ArgumentLine.Substring(LastCorrectPosition);
                    throw new ExceptionSyntaxError(String("Exception") + String("ExceptionSyntaxError") + ArgumentLine +
                                                  String("ExceptionSyntaxError2") + ProbableErrorCause + String("ExceptionSyntaxError3"));
                }
                else
                {
                    //RegEx match ArgumentLine, thus syntax is ok.

                    ///try to add values without parameters to FoundParameter using function
                    ///AddNewFoundParameter(). Before adding move quotes if any.
                    ///If those arguments are not allowed AddNewFoundParameter() raises an exception.
                    Group u_grp = m.Groups["unknownvalues"];
                    String unknownValues = null;
                    if (u_grp != null && u_grp.Value == string.Empty && u_grp.Captures != null && u_grp.Captures.Count > 0)
                    {
                        String g = "";
                        foreach (Capture f in u_grp.Captures)
                        {
                            g += f + " ";
                        }
                        unknownValues = g.TrimEnd();

                    }
                    else
                    {
                        unknownValues = u_grp.Value;
                    }

                    if (unknownValues != null && unknownValues != string.Empty)
                    {
                        string unknown = unknownValues.Trim();
                        Regex Enclosed = new Regex("^(\".*\")|('.*')$");
                        Match e = Enclosed.Match(unknown);
                        if (e.Length != 0)
                            unknown = unknown.Substring(1, unknown.Length - 2);

                        //check whether this first (unknown) value is actually a boolean parameter. (e.g. /help)
                        //if it is a boolean parameter (or switch) add if as such.
                        bool unknownParameterHandled = false;
                        if (WantedParameters.ContainsKey(unknown))
                        {
                            if (WantedParameters[unknown].ValueType == ValueType.Bool || WantedParameters[unknown].ValueType == ValueType.MultipleBool)
                            {
                                AddNewFoundParameter(unknown, "");
                                unknownParameterHandled = true;
                            }
                        }
                        else if ((unknown[0] == '/' || unknown[0] == '-') && WantedParameters.ContainsKey(unknown.Substring(1)))
                        {
//.........这里部分代码省略.........
开发者ID:VivianMC,项目名称:CLAParser,代码行数:101,代码来源:CLAParser.cs

示例6: Test01

        public void Test01()
        {
            IntlStrings intl;
            StringDictionary sd;
            // simple string values
            string[] values =
            {
                "",
                " ",
                "a",
                "aa",
                "text",
                "     spaces",
                "1",
                "$%^#",
                "2222222222222222222222222",
                System.DateTime.Today.ToString(),
                Int32.MaxValue.ToString()
            };

            // keys for simple string values
            string[] keys =
            {
                "zero",
                "one",
                " ",
                "",
                "aa",
                "1",
                System.DateTime.Today.ToString(),
                "$%^#",
                Int32.MaxValue.ToString(),
                "     spaces",
                "2222222222222222222222222"
            };

            Array destination;
            int cnt = 0;            // Count
            // initialize IntStrings
            intl = new IntlStrings();


            // [] StringDictionary is constructed as expected
            //-----------------------------------------------------------------

            sd = new StringDictionary();

            // [] Copy empty dictionary into empty array
            //
            destination = Array.CreateInstance(typeof(Object), sd.Count);
            Assert.Throws<ArgumentOutOfRangeException>(() => { sd.CopyTo(destination, -1); });
            sd.CopyTo(destination, 0);
            Assert.Throws<ArgumentException>(() => { sd.CopyTo(destination, 1); });

            // [] Copy empty dictionary into non-empty array
            //
            destination = Array.CreateInstance(typeof(Object), values.Length);
            for (int i = 0; i < values.Length; i++)
            {
                destination.SetValue(values[i], i);
            }
            sd.CopyTo(destination, 0);
            if (destination.Length != values.Length)
            {
                Assert.False(true, string.Format("Error, altered array after copying empty collection"));
            }
            if (destination.Length == values.Length)
            {
                for (int i = 0; i < values.Length; i++)
                {
                    if (String.Compare(destination.GetValue(i).ToString(), values[i]) != 0)
                    {
                        Assert.False(true, string.Format("Error, altered item {0} after copying empty collection", i));
                    }
                }
            }


            // [] add simple strings and CopyTo(Array, 0)
            //

            cnt = sd.Count;
            int len = values.Length;
            for (int i = 0; i < len; i++)
            {
                sd.Add(keys[i], values[i]);
            }
            if (sd.Count != len)
            {
                Assert.False(true, string.Format("Error, count is {0} instead of {1}", sd.Count, values.Length));
            }

            destination = Array.CreateInstance(typeof(Object), len);
            sd.CopyTo(destination, 0);

            IEnumerator en = sd.GetEnumerator();
            //
            // order of items is the same as order of enumerator
            //
            for (int i = 0; i < len; i++)
//.........这里部分代码省略.........
开发者ID:noahfalk,项目名称:corefx,代码行数:101,代码来源:CopyToArrayIntTests.cs


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