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

loresoft / FluentCommand / 8727898407

17 Apr 2024 07:50PM UTC coverage: 51.881% (-0.3%) from 52.205%
8727898407

push

github

pwelter34
improve query logging

1022 of 2496 branches covered (40.95%)

Branch coverage included in aggregate %.

49 of 67 new or added lines in 2 files covered. (73.13%)

43 existing lines in 1 file now uncovered.

2978 of 5214 relevant lines covered (57.12%)

747.29 hits per line

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

37.25
/src/FluentCommand/Extensions/StringBuilderExtensions.cs
1
using System.Text;
2

3
namespace FluentCommand.Extensions;
4

5
/// <summary>
6
/// <see cref="StringBuilder"/> extension methods
7
/// </summary>
8
public static class StringBuilderExtensions
9
{
10
    /// <summary>
11
    /// Appends a copy of the specified string followed by the default line terminator to the end of the StringBuilder object.
12
    /// </summary>
13
    /// <param name="sb">The StringBuilder instance to append to.</param>
14
    /// <param name="format">A composite format string.</param>
15
    /// <param name="args">An object array that contains zero or more objects to format.</param>
16
    public static StringBuilder AppendLine(this StringBuilder sb, string format, params object[] args)
17
    {
NEW
18
        sb.AppendFormat(format, args);
×
NEW
19
        sb.AppendLine();
×
NEW
20
        return sb;
×
21
    }
22

23
    /// <summary>
24
    /// Appends a copy of the specified string if <paramref name="condition"/> is met.
25
    /// </summary>
26
    /// <param name="sb">The StringBuilder instance to append to.</param>
27
    /// <param name="text">The string to append.</param>
28
    /// <param name="condition">The condition delegate to evaluate. If condition is null, String.IsNullOrWhiteSpace method will be used.</param>
29
    public static StringBuilder AppendIf(this StringBuilder sb, string text, Func<string, bool> condition = null)
30
    {
31
        var c = condition ?? (s => !string.IsNullOrEmpty(s));
7,446!
32

33
        if (c(text))
7,446✔
34
            sb.Append(text);
6,225✔
35

36
        return sb;
7,446✔
37
    }
38

39
    /// <summary>
40
    /// Appends a copy of the specified string if <paramref name="condition"/> is met.
41
    /// </summary>
42
    /// <param name="sb">The StringBuilder instance to append to.</param>
43
    /// <param name="text">The string to append.</param>
44
    /// <param name="condition">The condition delegate to evaluate. If condition is null, String.IsNullOrWhiteSpace method will be used.</param>
45
    public static StringBuilder AppendIf(this StringBuilder sb, string text, bool condition)
46
    {
NEW
47
        if (condition)
×
NEW
48
            sb.Append(text);
×
49

NEW
50
        return sb;
×
51
    }
52

53
    /// <summary>
54
    /// Appends a copy of the specified string followed by the default line terminator if <paramref name="condition"/> is met.
55
    /// </summary>
56
    /// <param name="sb">The StringBuilder instance to append to.</param>
57
    /// <param name="text">The string to append.</param>
58
    /// <param name="condition">The condition delegate to evaluate. If condition is null, String.IsNullOrWhiteSpace method will be used.</param>
59
    public static StringBuilder AppendLineIf(this StringBuilder sb, string text, Func<string, bool> condition = null)
60
    {
61
        var c = condition ?? (s => !string.IsNullOrEmpty(s));
2,061!
62

63
        if (c(text))
2,061✔
64
            sb.AppendLine(text);
1,887✔
65

66
        return sb;
2,061✔
67
    }
68

69
    /// <summary>
70
    /// Appends a copy of the specified string followed by the default line terminator if <paramref name="condition"/> is met.
71
    /// </summary>
72
    /// <param name="sb">The StringBuilder instance to append to.</param>
73
    /// <param name="condition">The condition delegate to evaluate. If condition is null, String.IsNullOrWhiteSpace method will be used.</param>
74
    public static StringBuilder AppendLineIf(this StringBuilder sb, Func<bool> condition)
75
    {
76
        if (condition())
912✔
77
            sb.AppendLine();
531✔
78

79
        return sb;
912✔
80
    }
81

82
    /// <summary>
83
    /// Concatenates and appends the members of a collection, using the specified separator between each member.
84
    /// </summary>
85
    /// <typeparam name="T">The type of the members of values.</typeparam>
86
    /// <param name="sb">A reference to this instance after the append operation has completed.</param>
87
    /// <param name="separator">The string to use as a separator. separator is included in the concatenated and appended strings only if values has more than one element.</param>
88
    /// <param name="values">A collection that contains the objects to concatenate and append to the current instance of the string builder.</param>
89
    /// <returns>A reference to this instance after the append operation has completed.</returns>
90
    public static StringBuilder AppendJoin<T>(this StringBuilder sb, string separator, IEnumerable<T> values)
91
    {
NEW
92
        if (sb is null)
×
NEW
93
            throw new ArgumentNullException(nameof(sb));
×
NEW
94
        if (values is null)
×
NEW
95
            throw new ArgumentNullException(nameof(values));
×
96

NEW
97
        separator ??= string.Empty;
×
98

NEW
99
        var wroteValue = false;
×
100

NEW
101
        foreach (var value in values)
×
102
        {
NEW
103
            if (wroteValue)
×
NEW
104
                sb.Append(separator);
×
105

NEW
106
            sb.Append(value);
×
NEW
107
            wroteValue = true;
×
108
        }
109

NEW
110
        return sb;
×
111
    }
112

113
}
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