-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCountedInstance.cs
More file actions
71 lines (62 loc) · 1.57 KB
/
CountedInstance.cs
File metadata and controls
71 lines (62 loc) · 1.57 KB
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
namespace Pluton.Core
{
using System;
using System.Collections.Generic;
[Serializable]
public class CountedInstance
{
[NonSerialized]
public static Dictionary<Type, CountedInstance.Counts> InstanceTypes = new Dictionary<Type, CountedInstance.Counts>();
~CountedInstance()
{
CountedInstance.RemoveCount(base.GetType());
}
public CountedInstance()
{
CountedInstance.AddCount(base.GetType());
}
static CountedInstance()
{
CountedInstance.InstanceTypes = new Dictionary<Type, CountedInstance.Counts>();
}
internal static void AddCount(Type type)
{
CountedInstance.Counts counts;
if (CountedInstance.InstanceTypes.TryGetValue(type, out counts)) {
counts.Created++;
return;
}
CountedInstance.InstanceTypes.Add(type, new CountedInstance.Counts());
}
internal static void RemoveCount(Type type)
{
CountedInstance.Counts counts;
if (CountedInstance.InstanceTypes.TryGetValue(type, out counts)) {
counts.Destroyed++;
}
}
public static string InstanceReportText()
{
string text = "";
foreach (KeyValuePair<Type, CountedInstance.Counts> current in CountedInstance.InstanceTypes) {
object obj = text;
text = String.Concat(new object[] {
obj,
current.Key.FullName,
Environment.NewLine + "\tCurrently:\t",
current.Value.Created - current.Value.Destroyed,
Environment.NewLine + "\tCreated: \t",
current.Value.Created,
Environment.NewLine
});
}
return text;
}
[Serializable]
public class Counts
{
public int Created = 1;
public int Destroyed;
}
}
}