-
Notifications
You must be signed in to change notification settings - Fork 874
Expand file tree
/
Copy pathLoggingEnumerable.cs
More file actions
36 lines (26 loc) · 929 Bytes
/
LoggingEnumerable.cs
File metadata and controls
36 lines (26 loc) · 929 Bytes
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
using System.Collections;
using System.Collections.Generic;
using System.Text;
namespace Npgsql.Util;
// For logging batches we have to use a wrapper for parameters, otherwise they're logged as object[]. See https://github.com/npgsql/npgsql/issues/6078.
sealed class LoggingEnumerable<T>(IEnumerable<T> wrappedEnumerable) : IEnumerable<T>
{
public IEnumerator<T> GetEnumerator() => wrappedEnumerable.GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() => ((IEnumerable)wrappedEnumerable).GetEnumerator();
public override string ToString()
{
var sb = new StringBuilder();
sb.Append('[');
var appended = false;
foreach (var o in wrappedEnumerable)
{
if (appended)
sb.Append(", ");
else
appended = true;
sb.Append(o);
}
sb.Append(']');
return sb.ToString();
}
}