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

loresoft / FluentCommand / 6499663996

12 Oct 2023 06:38PM UTC coverage: 51.489% (+0.03%) from 51.463%
6499663996

push

github

pwelter34
logging and documentation updates

981 of 2450 branches covered (0.0%)

Branch coverage included in aggregate %.

3 of 3 new or added lines in 1 file covered. (100.0%)

2892 of 5072 relevant lines covered (57.02%)

156.13 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
    public static implicit operator byte[](ConcurrencyToken token) => token.Value;
×
74

75
    public static implicit operator string(ConcurrencyToken token) => token.ToString();
×
76

77
    public static implicit operator ConcurrencyToken(byte[] token) => new(token);
51✔
78

79
    public static implicit operator ConcurrencyToken(string token) => new(token);
×
80

81

82
#if NETSTANDARD2_0
83
    private static string ToHexString(byte[] bytes)
84
    {
85
        var hex = StringBuilderCache.Acquire(bytes.Length * 2);
86

87
        foreach (var b in bytes)
88
            hex.Append(b.ToString("X2"));
89

90
        return StringBuilderCache.ToString(hex);
91
    }
92

93
    private static byte[] FromHexString(string hexString)
94
    {
95
        var hexLength = hexString.Length;
96
        var bytes = new byte[hexLength / 2];
97

98
        for (var i = 0; i < hexLength; i += 2)
99
            bytes[i / 2] = Convert.ToByte(hexString.Substring(i, 2), 16);
100

101
        return bytes;
102
    }
103
#endif
104
}
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