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.

41 lines
1.3 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Management.Automation;
  6. using System.Text;
  7. using ICSharpCode.Decompiler.CSharp;
  8. using ICSharpCode.Decompiler.TypeSystem;
  9. namespace ICSharpCode.Decompiler.PowerShell
  10. {
  11. [Cmdlet(VerbsCommon.Get, "DecompiledTypes")]
  12. [OutputType(typeof(ITypeDefinition[]))]
  13. public class GetDecompiledTypesCmdlet : PSCmdlet
  14. {
  15. [Parameter(Position = 0, Mandatory = true)]
  16. public CSharpDecompiler Decompiler { get; set; }
  17. [Parameter(Mandatory = true)]
  18. public string[] Types { get; set; }
  19. protected override void ProcessRecord()
  20. {
  21. HashSet<TypeKind> kinds = TypesParser.ParseSelection(Types);
  22. try {
  23. List<ITypeDefinition> output = new List<ITypeDefinition>();
  24. foreach (var type in Decompiler.TypeSystem.Compilation.MainAssembly.GetAllTypeDefinitions()) {
  25. if (!kinds.Contains(type.Kind))
  26. continue;
  27. output.Add(type);
  28. }
  29. WriteObject(output.ToArray());
  30. } catch (Exception e) {
  31. WriteVerbose(e.ToString());
  32. WriteError(new ErrorRecord(e, ErrorIds.DecompilationFailed, ErrorCategory.OperationStopped, null));
  33. }
  34. }
  35. }
  36. }