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.

40 lines
1.1 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Management.Automation;
  5. using System.Text;
  6. using ICSharpCode.Decompiler.CSharp;
  7. using ICSharpCode.Decompiler.TypeSystem;
  8. namespace ICSharpCode.Decompiler.PowerShell
  9. {
  10. [Cmdlet(VerbsCommon.Get, "DecompiledSource")]
  11. [OutputType(typeof(string))]
  12. public class GetDecompiledSourceCmdlet : PSCmdlet
  13. {
  14. [Parameter(Position = 0, Mandatory = true)]
  15. public CSharpDecompiler Decompiler { get; set; }
  16. [Parameter]
  17. public string TypeName { get; set; } = string.Empty;
  18. protected override void ProcessRecord()
  19. {
  20. try
  21. {
  22. StringWriter output = new StringWriter();
  23. if (TypeName == null) {
  24. output.Write(Decompiler.DecompileWholeModuleAsString());
  25. } else {
  26. var name = new FullTypeName(TypeName);
  27. output.Write(Decompiler.DecompileTypeAsString(name));
  28. }
  29. WriteObject(output.ToString());
  30. } catch (Exception e) {
  31. WriteVerbose(e.ToString());
  32. WriteError(new ErrorRecord(e, ErrorIds.DecompilationFailed, ErrorCategory.OperationStopped, null));
  33. }
  34. }
  35. }
  36. }