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.

47 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. foreach (char ch in values[0]) {
  16. switch (ch) {
  17. case 'c':
  18. kinds.Add(TypeKind.Class);
  19. break;
  20. case 'i':
  21. kinds.Add(TypeKind.Interface);
  22. break;
  23. case 's':
  24. kinds.Add(TypeKind.Struct);
  25. break;
  26. case 'd':
  27. kinds.Add(TypeKind.Delegate);
  28. break;
  29. case 'e':
  30. kinds.Add(TypeKind.Enum);
  31. break;
  32. }
  33. }
  34. } else {
  35. foreach (var value in values) {
  36. string v = value;
  37. while (v.Length > 0 && !possibleValues.ContainsKey(v))
  38. v = v.Remove(v.Length - 1);
  39. if (possibleValues.TryGetValue(v, out var kind))
  40. kinds.Add(kind);
  41. }
  42. }
  43. return kinds;
  44. }
  45. }
  46. }