Skip to content

Commit c30d4b5

Browse files
Mpdreamzrusscam
authored andcommitted
make sure types that implement DebuggerDisplay override ToString since these are likely to get logged (#4002)
(cherry picked from commit 901e60d)
1 parent fc83b6d commit c30d4b5

File tree

12 files changed

+21
-7
lines changed

12 files changed

+21
-7
lines changed

src/Nest/CommonAbstractions/Infer/Field/Field.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ public Field(PropertyInfo property, double? boost, string format = null)
8787
+ $"{(!string.IsNullOrEmpty(Format) ? " format: " + Format : string.Empty)}"
8888
+ $"{(_type == null ? string.Empty : " typeof: " + _type.Name)}";
8989

90+
public override string ToString() => DebugDisplay;
91+
9092
private string PropertyDebug => Property == null ? null : $"PropertyInfo: {Property.Name}";
9193

9294
public bool Equals(Field other) => _type != null

src/Nest/CommonAbstractions/Infer/Fields/Fields.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ public class Fields : IUrlParameter, IEnumerable<Field>, IEquatable<Fields>
2222

2323
private string DebugDisplay =>
2424
$"Count: {ListOfFields.Count} [" + string.Join(",", ListOfFields.Select((t, i) => $"({i + 1}: {t?.DebugDisplay ?? "NULL"})")) + "]";
25+
26+
public override string ToString() => DebugDisplay;
2527

2628
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
2729

src/Nest/CommonAbstractions/Infer/Id/Id.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ string IUrlParameter.GetString(IConnectionConfigurationValues settings)
6868

6969
public static Id From<T>(T document) where T : class => new Id(document);
7070

71-
public override string ToString() => StringOrLongValue;
71+
public override string ToString() => DebugDisplay;
7272

7373
public override bool Equals(object obj)
7474
{

src/Nest/CommonAbstractions/Infer/IndexName/IndexName.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ private IndexName(string index, Type type, string cluster = null)
3434
public Type Type { get; }
3535

3636
internal string DebugDisplay => Type == null ? Name : $"{nameof(IndexName)} for typeof: {Type?.Name}";
37-
37+
3838
private static int TypeHashCode { get; } = typeof(IndexName).GetHashCode();
3939

4040
bool IEquatable<IndexName>.Equals(IndexName other) => EqualsMarker(other);

src/Nest/CommonAbstractions/Infer/Indices/Indices.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ internal Indices(IEnumerable<IndexName> indices) : base(new ManyIndices(indices)
2424
types => $"Count: {types.Indices.Count} [" + string.Join(",", types.Indices.Select((t, i) => $"({i + 1}: {t.DebugDisplay})")) + "]"
2525
);
2626

27+
public override string ToString() => DebugDisplay;
28+
2729
string IUrlParameter.GetString(IConnectionConfigurationValues settings) => Match(
2830
all => "_all",
2931
many =>

src/Nest/CommonAbstractions/Infer/JoinFieldRouting/Routing.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ public Routing(object document)
4747

4848
private string DebugDisplay => StringOrLongValue ?? "Routing from instance typeof: " + Document?.GetType().Name;
4949

50+
public override string ToString() => DebugDisplay;
51+
5052
private static int TypeHashCode { get; } = typeof(Routing).GetHashCode();
5153

5254
public bool Equals(Routing other)

src/Nest/CommonAbstractions/Infer/Name/Name.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ public class Name : IEquatable<Name>, IUrlParameter
1313

1414
private string DebugDisplay => Value;
1515

16+
public override string ToString() => DebugDisplay;
17+
1618
private static int TypeHashCode { get; } = typeof(Name).GetHashCode();
1719

1820
public bool Equals(Name other) => EqualsString(other?.Value);

src/Nest/CommonAbstractions/Infer/Name/Names.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ public Names(IEnumerable<Name> names)
2222

2323
private string DebugDisplay => ((IUrlParameter)this).GetString(null);
2424

25+
public override string ToString() => DebugDisplay;
26+
2527
public bool Equals(Names other) => EqualsAllIds(Value, other.Value);
2628

2729
string IUrlParameter.GetString(IConnectionConfigurationValues settings) =>

src/Nest/CommonAbstractions/Infer/NodeId/NodeIds.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ public NodeIds(IEnumerable<string> nodeIds)
2020

2121
private string DebugDisplay => ((IUrlParameter)this).GetString(null);
2222

23+
public override string ToString() => DebugDisplay;
24+
2325
public bool Equals(NodeIds other) => EqualsAllIds(Value, other.Value);
2426

2527
string IUrlParameter.GetString(IConnectionConfigurationValues settings) => string.Join(",", Value);

src/Nest/CommonAbstractions/Infer/PropertyName/PropertyName.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ public PropertyName(PropertyInfo property)
4343
internal string DebugDisplay =>
4444
$"{Expression?.ToString() ?? PropertyDebug ?? Name}{(_type == null ? "" : " typeof: " + _type.Name)}";
4545

46+
public override string ToString() => DebugDisplay;
47+
4648
private string PropertyDebug => Property == null ? null : $"PropertyInfo: {Property.Name}";
4749
private static int TypeHashCode { get; } = typeof(PropertyName).GetHashCode();
4850

0 commit comments

Comments
 (0)