暂无描述
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

CommandLineArguments.cs 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System;
  2. using System.Collections.Generic;
  3. namespace Unity.PlasticSCM.Editor.Hub
  4. {
  5. internal class CommandLineArguments
  6. {
  7. internal static Dictionary<string, string> Build(string[] args)
  8. {
  9. Dictionary<string, string> result = new Dictionary<string, string>(
  10. StringComparer.OrdinalIgnoreCase);
  11. if (args == null)
  12. return result;
  13. List<string> trimmedArguments = TrimArgs(args);
  14. int index = 1;
  15. while (true)
  16. {
  17. if (index > trimmedArguments.Count - 1)
  18. break;
  19. if (IsKeyValueArgumentAtIndex(trimmedArguments, index))
  20. {
  21. result[trimmedArguments[index]] = trimmedArguments[index + 1];
  22. index += 2;
  23. continue;
  24. }
  25. result[trimmedArguments[index]] = null;
  26. index += 1;
  27. }
  28. return result;
  29. }
  30. static List<string> TrimArgs(string[] args)
  31. {
  32. List<string> trimmedArguments = new List<string>();
  33. foreach (string argument in args)
  34. trimmedArguments.Add(argument.Trim());
  35. return trimmedArguments;
  36. }
  37. static bool IsKeyValueArgumentAtIndex(
  38. List<string> trimmedArguments,
  39. int index)
  40. {
  41. if (index + 1 > trimmedArguments.Count -1)
  42. return false;
  43. return !trimmedArguments[index + 1].StartsWith("-");
  44. }
  45. }
  46. }