-
Notifications
You must be signed in to change notification settings - Fork 1
/
ExtendedClrObject.cs
83 lines (74 loc) · 3.12 KB
/
ExtendedClrObject.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
using System.Management.Automation;
using Microsoft.Diagnostics.Runtime;
namespace RuntimeDiagnostics
{
public class ExtendedClrObject : PSObject
{
public ExtendedClrObject(ClrObject baseObject) : base(baseObject)
{
if (baseObject.Type?.Name == "System.String")
{
Properties.Add(new PSNoteProperty("Value", baseObject.AsString()));
}
else if (baseObject.Type?.IsArray == true)
{
var array = baseObject.AsArray();
Properties.Add(new PSNoteProperty("Value", array));
for (var i = 0; i < array.Length; i++)
{
var index = i;
try
{
if (array.Type.ComponentType?.ElementType == ClrElementType.Object)
{
Properties.Add(new PSNoteProperty($"[{index}]", new Lazy<ExtendedClrObject>(() => new ExtendedClrObject(array.GetObjectValue(index)))));
}
else if (array.Type.ComponentType?.ElementType == ClrElementType.Struct)
{
Properties.Add(new PSNoteProperty($"[{index}]", new Lazy<ExtendedClrObject>(() => new ExtendedClrObject(array.GetStructValue(index)))));
}
else
{
}
}
catch
{
}
}
}
baseObject.Type?.Fields.ToList().ForEach(field =>
{
if (field.Name == null) return;
if (Properties.Any(m => m.Name == field.Name)) return;
if (field.Type?.Name == "System.String")
{
var value = baseObject.ReadStringField(field.Name);
Properties.Add(new PSNoteProperty(field.Name, value));
}
else if (field.Type?.Name == "System.Int32")
{
var value = baseObject.ReadField<int>(field.Name);
Properties.Add(new PSNoteProperty(field.Name, value));
}
else if (field.Type?.Name == "System.Boolean")
{
var value = baseObject.ReadField<bool>(field.Name);
Properties.Add(new PSNoteProperty(field.Name, value));
}
else if (field.IsValueType)
{
var value = baseObject.ReadValueTypeField(field.Name);
Properties.Add(new PSNoteProperty(field.Name, new Lazy<ExtendedClrObject>(() => new ExtendedClrObject(value))));
}
else
{
var value = baseObject.ReadObjectField(field.Name);
Properties.Add(new PSNoteProperty(field.Name, new Lazy<ExtendedClrObject>(() => new ExtendedClrObject(value))));
}
});
}
public ExtendedClrObject(ClrValueType baseObject) : base(baseObject)
{
}
}
}