/
EventOpcode.cs
90 lines (81 loc) · 2.38 KB
/
EventOpcode.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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
namespace System.Diagnostics.Eventing.Reader
{
/// <summary>
/// The metadata for a specific Opcode defined by a Provider.
/// An instance of this class is obtained from a ProviderMetadata object.
/// </summary>
public sealed class EventOpcode
{
private readonly int _value;
private string _name;
private string _displayName;
private bool _dataReady;
private readonly ProviderMetadata _pmReference;
private readonly object _syncObject;
internal EventOpcode(int value, ProviderMetadata pmReference)
{
_value = value;
_pmReference = pmReference;
_syncObject = new object();
}
internal EventOpcode(string name, int value, string displayName)
{
_value = value;
_name = name;
_displayName = displayName;
_dataReady = true;
_syncObject = new object();
}
internal void PrepareData()
{
lock (_syncObject)
{
if (_dataReady)
return;
// Get the data
IEnumerable<EventOpcode> result = _pmReference.Opcodes;
// Set the names and display names to null
_name = null;
_displayName = null;
_dataReady = true;
foreach (EventOpcode op in result)
{
if (op.Value == _value)
{
_name = op.Name;
_displayName = op.DisplayName;
_dataReady = true;
break;
}
}
}
} // End Prepare Data
public string Name
{
get
{
PrepareData();
return _name;
}
}
public int Value
{
get
{
return _value;
}
}
public string DisplayName
{
get
{
PrepareData();
return _displayName;
}
}
}
}