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