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.

46 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. {
  25. output.Write(Decompiler.DecompileWholeModuleAsString());
  26. }
  27. else
  28. {
  29. var name = new FullTypeName(TypeName);
  30. output.Write(Decompiler.DecompileTypeAsString(name));
  31. }
  32. WriteObject(output.ToString());
  33. }
  34. catch (Exception e)
  35. {
  36. WriteVerbose(e.ToString());
  37. WriteError(new ErrorRecord(e, ErrorIds.DecompilationFailed, ErrorCategory.OperationStopped, null));
  38. }
  39. }
  40. }
  41. }