/
QueryTraceOptions.cs
82 lines (70 loc) · 2 KB
/
QueryTraceOptions.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
using System;
using System.Diagnostics;
namespace LinqToDB.Data
{
using Common;
using Common.Internal;
/// <param name="TraceLevel">
/// Gets custom trace level to use with <see cref="DataConnection"/> instance.
/// </param>
/// <param name="OnTrace">
/// Gets custom trace method to use with <see cref="DataConnection"/> instance.
/// </param>
/// <param name="WriteTrace">
/// Gets custom trace writer to use with <see cref="DataConnection"/> instance.
/// </param>
public sealed record QueryTraceOptions
(
TraceLevel? TraceLevel = default,
Action<TraceInfo>? OnTrace = default,
Action<string?,string?,TraceLevel>? WriteTrace = default
// If you add another parameter here, don't forget to update
// QueryTraceOptions copy constructor and IConfigurationID.ConfigurationID.
)
: IOptionSet, IApplicable<DataConnection>
{
public QueryTraceOptions() : this((TraceLevel?)null)
{
}
QueryTraceOptions(QueryTraceOptions original)
{
TraceLevel = original.TraceLevel;
OnTrace = original.OnTrace;
WriteTrace = original.WriteTrace;
}
int? _configurationID;
int IConfigurationID.ConfigurationID
{
get
{
if (_configurationID == null)
{
using var idBuilder = new IdentifierBuilder();
_configurationID = idBuilder
.Add(TraceLevel)
.Add(OnTrace)
.Add(WriteTrace)
.CreateID();
}
return _configurationID.Value;
}
}
public static readonly QueryTraceOptions Empty = new();
void IApplicable<DataConnection>.Apply(DataConnection obj)
{
DataConnection.ConfigurationApplier.Apply(obj, this);
}
#region IEquatable implementation
public bool Equals(QueryTraceOptions? other)
{
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
return ((IOptionSet)this).ConfigurationID == ((IOptionSet)other).ConfigurationID;
}
public override int GetHashCode()
{
return ((IOptionSet)this).ConfigurationID;
}
#endregion
}
}