-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathInstanceData.cs
101 lines (85 loc) · 2.46 KB
/
InstanceData.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
using System.Collections.Generic;
namespace UnityHeapDumper
{
public class InstanceData : IInstanceData
{
private static readonly IFieldData[] emptyFields = new IFieldData[0];
private object obj;
private int id;
private int typeSize;
private ITypeData typeData;
private IList<IFieldData> fields;
private HashSet<int> seenInstances;
void IInstanceData.Init(IDumpContext dumpContext, object obj, int id)
{
seenInstances = new HashSet<int>();
this.obj = obj;
this.id = id;
var type = obj.GetType();
var typeDataFactory = dumpContext.TypeDataFactory;
typeData = typeDataFactory.Create(type);
typeSize = typeData.Size;
if (typeData.IsPureValueType)
{
fields = emptyFields;
return;
}
var fieldDataFactory = dumpContext.FieldDataFactory;
var instanceFields = typeData.InstanceFields;
fields = new List<IFieldData>(instanceFields.Count);
foreach (var fieldInfo in instanceFields)
{
var fieldData = fieldDataFactory.Create(fieldInfo, obj);
fields.Add(fieldData);
}
}
int IInstanceData.Id
{
get
{
return id;
}
}
int IInstanceData.GetSize(ICollection<int> seenInstances)
{
this.seenInstances.Clear();
if (seenInstances != null)
{
if (seenInstances.Contains(id))
{
return 0;
}
this.seenInstances.UnionWith(seenInstances);
}
this.seenInstances.Add(id);
var size = typeSize;
foreach (var field in fields)
{
var fieldInstanceData = field.InstanceData;
size += fieldInstanceData.GetSize(this.seenInstances);
}
return size;
}
ITypeData IInstanceData.TypeData
{
get
{
return typeData;
}
}
IList<IFieldData> IInstanceData.Fields
{
get
{
return fields;
}
}
object IInstanceData.Object
{
get
{
return obj;
}
}
}
}