• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

loresoft / FluentCommand / 6648415992

26 Oct 2023 01:49AM UTC coverage: 51.645% (+0.1%) from 51.515%
6648415992

push

github

pwelter34
Update InsertBuilder.cs

981 of 2442 branches covered (0.0%)

Branch coverage included in aggregate %.

2896 of 5065 relevant lines covered (57.18%)

156.37 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

19.05
/src/FluentCommand/ConcurrencyToken.cs
1
using FluentCommand.Internal;
2

3
namespace FluentCommand;
4

5
/// <summary>
6
/// A structure to hold concurrency token
7
/// </summary>
8
public readonly struct ConcurrencyToken : IEquatable<ConcurrencyToken>
9
{
10
    /// <summary>
11
    /// The default empty token
12
    /// </summary>
13
    public static readonly ConcurrencyToken None = new(Array.Empty<byte>());
×
14

15
    /// <summary>
16
    /// Gets the underlying value of the token.
17
    /// </summary>
18
    /// <value>
19
    /// The underlying value of the token.
20
    /// </value>
21
    public byte[] Value { get; }
22

23
    /// <summary>
24
    /// Initializes a new instance of the <see cref="ConcurrencyToken"/> struct.
25
    /// </summary>
26
    /// <param name="value">The value.</param>
27
    public ConcurrencyToken(byte[] value)
28
    {
29
        Value = value ?? Array.Empty<byte>();
1,233!
30
    }
1,233✔
31

32
    /// <summary>
33
    /// Initializes a new instance of the <see cref="ConcurrencyToken"/> struct.
34
    /// </summary>
35
    /// <param name="value">The value.</param>
36
    public ConcurrencyToken(string value)
37
    {
38
#if NET5_0_OR_GREATER
39
        Value = string.IsNullOrEmpty(value) ? Array.Empty<byte>() : Convert.FromHexString(value);
×
40
#else
41
        Value = string.IsNullOrEmpty(value) ? Array.Empty<byte>() : FromHexString(value);
42
#endif
43
    }
×
44

45
    /// <inheritdoc />
46
    public override string ToString()
47
    {
48
#if NET5_0_OR_GREATER
49
        return Value != null ? Convert.ToHexString(Value) : null;
×
50
#else
51
        return Value != null ? ToHexString(Value) : null;
52
#endif
53
    }
54

55
    /// <inheritdoc />
56
    public override bool Equals(object obj)
57
    {
58
        return obj is ConcurrencyToken token && Equals(token);
×
59
    }
60

61
    /// <inheritdoc />
62
    public bool Equals(ConcurrencyToken other)
63
    {
64
        return EqualityComparer<byte[]>.Default.Equals(Value, other.Value);
×
65
    }
66

67
    /// <inheritdoc />
68
    public override int GetHashCode()
69
    {
70
        return Value.GetHashCode();
×
71
    }
72

73
    /// <summary>
74
    /// Performs an implicit conversion from <see cref="ConcurrencyToken"/> to byte array.
75
    /// </summary>
76
    /// <param name="token">The concurrency token.</param>
77
    /// <returns>
78
    /// The result of the conversion.
79
    /// </returns>
80
    public static implicit operator byte[](ConcurrencyToken token) => token.Value;
×
81

82
    /// <summary>
83
    /// Performs an implicit conversion from <see cref="ConcurrencyToken"/> to <see cref="System.String"/>.
84
    /// </summary>
85
    /// <param name="token">The concurrency token.</param>
86
    /// <returns>
87
    /// The result of the conversion.
88
    /// </returns>
89
    public static implicit operator string(ConcurrencyToken token) => token.ToString();
×
90

91
    /// <summary>
92
    /// Performs an implicit conversion from byte array to <see cref="ConcurrencyToken"/>.
93
    /// </summary>
94
    /// <param name="token">The concurrency token.</param>
95
    /// <returns>
96
    /// The result of the conversion.
97
    /// </returns>
98
    public static implicit operator ConcurrencyToken(byte[] token) => new(token);
51✔
99

100
    /// <summary>
101
    /// Performs an implicit conversion from <see cref="System.String"/> to <see cref="ConcurrencyToken"/>.
102
    /// </summary>
103
    /// <param name="token">The concurrency token.</param>
104
    /// <returns>
105
    /// The result of the conversion.
106
    /// </returns>
107
    public static implicit operator ConcurrencyToken(string token) => new(token);
×
108

109

110
#if NETSTANDARD2_0
111
    private static string ToHexString(byte[] bytes)
112
    {
113
        var hex = StringBuilderCache.Acquire(bytes.Length * 2);
114

115
        foreach (var b in bytes)
116
            hex.Append(b.ToString("X2"));
117

118
        return StringBuilderCache.ToString(hex);
119
    }
120

121
    private static byte[] FromHexString(string hexString)
122
    {
123
        var hexLength = hexString.Length;
124
        var bytes = new byte[hexLength / 2];
125

126
        for (var i = 0; i < hexLength; i += 2)
127
            bytes[i / 2] = Convert.ToByte(hexString.Substring(i, 2), 16);
128

129
        return bytes;
130
    }
131
#endif
132
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc