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


C# ArgumentList.TryGetValue方法代码示例

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


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

示例1: GetArgumentValue

	    internal Object GetArgumentValue(ICommandInterpreter interpreter, ArgumentList args, string[] allArguments)
		{
			object value = null;

			if (IsInterpreter)
				return interpreter;

			if (IsAllArguments)
			{
				args.Clear();
				args.Unnamed.Clear();
				return allArguments;
			}

			foreach (string name in AllNames)
			{
				ArgumentList.Item argitem;
				if (args.TryGetValue(name, out argitem))
				{
					if (Parameter.ParameterType == typeof(string[]))
						value = argitem.Values;
					else if (IsFlag)
					{
						bool result;
						value = (String.IsNullOrEmpty(argitem.Value) || (bool.TryParse(argitem.Value, out result) && result));
					}
					else
						value = argitem.Value;
					args.Remove(name);
				}
			}

			return base.ChangeType(value, Parameter.ParameterType, Required, DefaultValue); 
		}
开发者ID:hivie7510,项目名称:csharptest-net,代码行数:34,代码来源:Argument.cs

示例2: Main

		static int Main(string[] raw)
		{
			ArgumentList args = new ArgumentList(raw);
			List<string> input = new List<string>(args.Unnamed);

			if (args.Contains("nologo") == false)
			{
				Console.WriteLine("StampCopyright.exe");
				Console.WriteLine("Copyright 2009-{0:yyyy} by Roger Knapp, Licensed under the Apache License, Version 2.0", DateTime.Now);
				Console.WriteLine("");
			}

			if ((args.Count == 0 && args.Unnamed.Count == 0) || args.Contains("?") || args.Contains("help"))
				return DoHelp();

			try
			{
                args.TryGetValue("svn", out _subversion);

				Log.ConsoleLevel = System.Diagnostics.TraceLevel.Warning;
                _changes = 0;
                _copyText = File.ReadAllText(input[0]).Trim();
                _copyText = _copyText.Replace("YEAR", DateTime.Now.Year.ToString());
                _copyText = _copyText.Replace("yyyy", DateTime.Now.Year.ToString());
				input.RemoveAt(0);
				ProjectVisitor visitor = new ProjectVisitor(false, input.ToArray());
				visitor.VisitProjectItems(VisitProjectItem);
			}
			catch (ApplicationException ae)
			{
				Log.Error(ae);
				Console.Error.WriteLine();
				Console.Error.WriteLine(ae.Message);
				Environment.ExitCode = -1;
			}
			catch (Exception e)
			{
				Log.Error(e);
				Console.Error.WriteLine();
				Console.Error.WriteLine(e.ToString());
				Environment.ExitCode = -1;
			}

			if (args.Contains("wait"))
			{
				Console.WriteLine();
				Console.WriteLine("Press [Enter] to continue...");
				Console.ReadLine();
			}

			return Environment.ExitCode;
		}
开发者ID:modulexcite,项目名称:CSharpTest.Net.Tools,代码行数:52,代码来源:Program.cs

示例3: Test

		public void Test()
		{
			ArgumentList args = new ArgumentList("-test=value", "/Test", "\"/other:value\"");
			Assert.AreEqual(2, args.Count);

			Assert.AreEqual(1, args[0].Count);
			Assert.AreEqual("test", args[0].Name);
			Assert.AreEqual("value", args[1].Value);

			Assert.AreEqual(1, args[1].Count);
			Assert.AreEqual("other", args[1].Name);
			Assert.AreEqual("value", args[1].Value);
			
			string[] keys = args.Keys;
			Assert.AreEqual(2, keys.Length);
			Assert.AreEqual("other", keys[0]);//alpha-sorted
			Assert.AreEqual("test", keys[1]);
			Assert.AreEqual(0, new ArgumentList("unnamed").Keys.Length);
			Assert.AreEqual(0, new ArgumentList(/*empty*/).Keys.Length);

			ArgumentList.DefaultComparison = StringComparer.Ordinal;
			Assert.AreEqual(StringComparer.Ordinal, ArgumentList.DefaultComparison);
			
			ArgumentList.NameDelimeters = new char[] { '=' };
			Assert.AreEqual('=', ArgumentList.NameDelimeters[0]);

			ArgumentList.PrefixChars = new char[] { '/' };
			Assert.AreEqual('/'	, ArgumentList.PrefixChars[0]);

			args = new ArgumentList("-test=value", "/Test", "\"/other:value\"");
			Assert.AreEqual(2, args.Count);
			Assert.AreEqual(0, args[0].Count);
			Assert.AreEqual("Test", args[0].Name);
			Assert.AreEqual(null, args[1].Value);

			Assert.AreEqual(1, args.Unnamed.Count);
			foreach(string sval in args.Unnamed)
				Assert.AreEqual("-test=value", sval);

			Assert.AreEqual(0, args[1].Count);
			Assert.AreEqual("other:value", args[1].Name);
			Assert.AreEqual(null, args[1].Value);

			args.Unnamed = new string[0];
			Assert.AreEqual(0, args.Unnamed.Count);

			args.Add("other", "value");
			Assert.AreEqual(null, (string)args["Test"]);
			Assert.AreEqual("value", (string)args["other"]);
			Assert.AreEqual("value", (string)args.SafeGet("other"));
			Assert.IsNotNull(args.SafeGet("other-not-existing"));
			Assert.AreEqual(null, (string)args.SafeGet("other-not-existing"));

			string test;
			ArgumentList.Item item;

			args = new ArgumentList();
			Assert.AreEqual(0, args.Count);
			Assert.IsFalse(args.TryGetValue(String.Empty, out item));
			args.Add(String.Empty, null);
			Assert.IsTrue(args.TryGetValue(String.Empty, out item));

			args = new ArgumentList();
			Assert.AreEqual(0, args.Count);
			Assert.IsFalse(args.TryGetValue(String.Empty, out test));
			args.Add(String.Empty, null);
			Assert.IsTrue(args.TryGetValue(String.Empty, out test));

			test = item;
			Assert.IsNull(test);

			string[] testarry = item;
			Assert.IsNotNull(testarry);
			Assert.AreEqual(0, testarry.Length);

			item.Value = "roger";
			Assert.AreEqual("roger", item.Value);
			Assert.AreEqual(1, item.Values.Length);
			Assert.AreEqual("roger", item.Values[0]);

			Assert.Contains("roger", item.ToArray());
			Assert.AreEqual(1, item.ToArray().Length);

			item.AddRange(new string[] { "wuz", "here" });
			Assert.AreEqual(3, item.Values.Length);
			Assert.AreEqual("roger wuz here", String.Join(" ", item));

			item.Values = new string[] { "roger", "was", "here" };
			Assert.AreEqual("roger was here", String.Join(" ", item));

			KeyValuePair<string, string[]> testkv = item;
			Assert.AreEqual(String.Empty, testkv.Key);
			Assert.AreEqual(3, testkv.Value.Length);
			Assert.AreEqual("roger was here", String.Join(" ", testkv.Value));
		}
开发者ID:hivie7510,项目名称:csharptest-net,代码行数:95,代码来源:TestArgumentList.cs


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