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.

54 lines
1.4 KiB

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