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.

34 lines
1.1 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Management.Automation;
  4. using System.Text;
  5. using ICSharpCode.Decompiler.CSharp;
  6. namespace ICSharpCode.Decompiler.PowerShell
  7. {
  8. [Cmdlet(VerbsCommon.Get, "Decompiler")]
  9. [OutputType(typeof(CSharpDecompiler))]
  10. public class GetDecompilerCmdlet : PSCmdlet
  11. {
  12. [Parameter(Position = 0, Mandatory = true, HelpMessage = "Path to the assembly you want to decompile")]
  13. [Alias("PSPath")]
  14. [ValidateNotNullOrEmpty]
  15. public string LiteralPath { get; set; }
  16. protected override void ProcessRecord()
  17. {
  18. string path = GetUnresolvedProviderPathFromPSPath(LiteralPath);
  19. try {
  20. var decompiler = new CSharpDecompiler(path, new DecompilerSettings() {
  21. ThrowOnAssemblyResolveErrors = false
  22. });
  23. WriteObject(decompiler);
  24. } catch (Exception e) {
  25. WriteVerbose(e.ToString());
  26. WriteError(new ErrorRecord(e, ErrorIds.AssemblyLoadFailed, ErrorCategory.OperationStopped, null));
  27. }
  28. }
  29. }
  30. }