You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.4 KiB

8 years ago
8 years ago
8 years ago
8 years ago
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using ICSharpCode.Decompiler.TypeSystem;
  5. namespace ICSharpCode.Decompiler.Console
  6. {
  7. public static class TypesParser
  8. {
  9. public static HashSet<TypeKind> ParseSelection(string[] values)
  10. {
  11. var possibleValues = new Dictionary<string, TypeKind>(StringComparer.OrdinalIgnoreCase) { ["class"] = TypeKind.Class, ["struct"] = TypeKind.Struct, ["interface"] = TypeKind.Interface, ["enum"] = TypeKind.Enum, ["delegate"] = TypeKind.Delegate };
  12. HashSet<TypeKind> kinds = new HashSet<TypeKind>();
  13. if (values.Length == 1 && !possibleValues.Keys.Any(v => values[0].StartsWith(v, StringComparison.OrdinalIgnoreCase)))
  14. {
  15. foreach (char ch in values[0])
  16. {
  17. switch (ch)
  18. {
  19. case 'c':
  20. kinds.Add(TypeKind.Class);
  21. break;
  22. case 'i':
  23. kinds.Add(TypeKind.Interface);
  24. break;
  25. case 's':
  26. kinds.Add(TypeKind.Struct);
  27. break;
  28. case 'd':
  29. kinds.Add(TypeKind.Delegate);
  30. break;
  31. case 'e':
  32. kinds.Add(TypeKind.Enum);
  33. break;
  34. }
  35. }
  36. }
  37. else
  38. {
  39. foreach (var value in values)
  40. {
  41. string v = value;
  42. while (v.Length > 0 && !possibleValues.ContainsKey(v))
  43. v = v.Remove(v.Length - 1);
  44. if (possibleValues.TryGetValue(v, out var kind))
  45. kinds.Add(kind);
  46. }
  47. }
  48. return kinds;
  49. }
  50. }
  51. }