-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConstraintBase.cs
More file actions
67 lines (57 loc) · 2.13 KB
/
ConstraintBase.cs
File metadata and controls
67 lines (57 loc) · 2.13 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
namespace NetEvolve.FluentValue.Constraints;
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Text;
using NetEvolve.FluentValue;
[SuppressMessage("Info Code Smell", "S1133:Deprecated code should be removed", Justification = "As designed.")]
[SuppressMessage(
"Blocker Code Smell",
"S3877:Exceptions should not be thrown from unexpected methods",
Justification = "As designed."
)]
internal abstract class ConstraintBase : IConstraint
{
[ThreadStatic]
private static StringBuilder? _builder;
private const int DefaultCapacity = 1024;
/// <inheritdoc />
public abstract bool IsSatisfiedBy(object? value);
/// <inheritdoc />
public abstract void SetDescription(StringBuilder builder);
/// <inhertdoc />
[Obsolete("This is base `object` method that should not be called.", true)]
[EditorBrowsable(EditorBrowsableState.Never)]
[DebuggerHidden]
public new bool Equals(object? obj) =>
throw new NotSupportedException("This is base `object` method that should not be called.");
/// <inheritdoc/>
[Obsolete("This is base `object` method that should not be called.", true)]
[EditorBrowsable(EditorBrowsableState.Never)]
[DebuggerHidden]
public new int GetHashCode() =>
throw new NotSupportedException("This is base `object` method that should not be called.");
public override string ToString()
{
var builder = _builder ?? new StringBuilder(capacity: DefaultCapacity);
#pragma warning disable S2696 // Instance members should not write to "static" fields
_builder = null;
#pragma warning restore S2696 // Instance members should not write to "static" fields
try
{
_ = builder.Append('"').Append("{Value}");
SetDescription(builder);
return builder.Append('.').Append('"').ToString();
}
finally
{
_ = builder.Clear();
if (builder.Capacity > DefaultCapacity)
{
builder.Capacity = DefaultCapacity;
}
_builder = builder;
}
}
}