-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIdsContainer.cs
More file actions
63 lines (53 loc) · 1.53 KB
/
IdsContainer.cs
File metadata and controls
63 lines (53 loc) · 1.53 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
using IdCounter = System.Collections.Generic.Dictionary<string, int>;
namespace DataKeeper
{
internal class Ids
{
private static volatile Ids _instance;
private static readonly object syncRoot = new object();
public static Ids Container
{
get
{
if (_instance == null)
{
lock (syncRoot)
{
if (_instance == null)
_instance = new Ids();
}
}
return _instance;
}
}
private readonly IdCounter counter = new IdCounter();
internal string GenerateConstraintId()
{
return GenerateId("constraint");
}
internal string GenerateTriggerId()
{
return GenerateId("trigger");
}
// generating id: prefix_number
internal string GenerateId(string prefix)
{
int count = 0;
counter.TryGetValue(prefix, out count);
counter[prefix] = count + 1;
return prefix + "_" + count;
}
internal string ReturnId(string prefix)
{
int count = 0;
bool idExists = counter.TryGetValue(prefix, out count);
string result = prefix;
if (idExists)
{
result = prefix + "_" + count;
}
counter[prefix] = count + 1;
return result;
}
}
}