Skip to content

Commit 4446f3f

Browse files
committed
remove PlainTextFormatter.MaxProperties
1 parent 00a468b commit 4446f3f

File tree

4 files changed

+4
-56
lines changed

4 files changed

+4
-56
lines changed

docs/formatting.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,6 @@ The following global settings can be set to change formatting behaviors:
116116

117117
An optional type-specific list expansion limit
118118

119-
* `PlainTextFormatter.MaxProperties` = 20
120-
121-
Indicates the maximum number of properties to show in the default plaintext display of arbitrary objects. If set to zero no properties are shown.
122-
123-
* `HtmlFormatter.MaxProperties` = 20
124-
125-
Indicates the maximum number of properties to show in HTML table displays of arbitrary objects. If set to zero no properties are shown.
126-
127119
## HTML Formatting
128120

129121
### The `CSS` function

src/Microsoft.DotNet.Interactive.ApiCompatibility.Tests/ApiCompatibilityTests.Formatting_api_is_not_changed.approved.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ Microsoft.DotNet.Interactive.Formatting
151151
public class JsonString : Microsoft.AspNetCore.Html.HtmlString, Microsoft.AspNetCore.Html.IHtmlContent
152152
.ctor(System.String json)
153153
public static class PlainTextFormatter
154-
public static System.Int32 MaxProperties { get; set;}
155154
public static ITypeFormatter GetPreferredFormatterFor(System.Type type)
156155
public static ITypeFormatter GetPreferredFormatterFor<T>()
157156
public static System.Void WriteStartProperty(FormatContext context)

src/Microsoft.DotNet.Interactive.Formatting.Tests/PlainTextFormatterTests.Objects.cs

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -85,32 +85,6 @@ public void It_emits_a_default_maximum_number_of_properties()
8585
...".ReplaceLineEndings());
8686
}
8787

88-
[Fact]
89-
public void It_emits_a_configurable_maximum_number_of_properties()
90-
{
91-
var formatter = PlainTextFormatter.GetPreferredFormatterFor<ClassWithManyProperties>();
92-
PlainTextFormatter.MaxProperties = 1;
93-
94-
var writer = new StringWriter();
95-
formatter.Format(new ClassWithManyProperties(), writer);
96-
97-
var s = writer.ToString();
98-
s.Should().Be($"ClassWithManyProperties{Environment.NewLine} X1: 1{Environment.NewLine} ...");
99-
}
100-
101-
[Fact]
102-
public void When_Zero_properties_chosen_just_ToString_is_used()
103-
{
104-
var formatter = PlainTextFormatter.GetPreferredFormatterFor<ClassWithManyPropertiesAndCustomToString>();
105-
PlainTextFormatter.MaxProperties = 0;
106-
107-
var writer = new StringWriter();
108-
formatter.Format(new ClassWithManyPropertiesAndCustomToString(), writer);
109-
110-
var s = writer.ToString();
111-
s.Should().Be($"{typeof(ClassWithManyPropertiesAndCustomToString)} custom ToString value");
112-
}
113-
11488
[Fact]
11589
public void When_Zero_properties_available_to_choose_just_ToString_is_used()
11690
{

src/Microsoft.DotNet.Interactive.Formatting/PlainTextFormatter.cs

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,6 @@ namespace Microsoft.DotNet.Interactive.Formatting;
2121

2222
public static class PlainTextFormatter
2323
{
24-
static PlainTextFormatter()
25-
{
26-
Formatter.Clearing += Initialize;
27-
28-
void Initialize() => MaxProperties = DefaultMaxProperties;
29-
}
30-
3124
public const string MimeType = "text/plain";
3225

3326
public static ITypeFormatter GetPreferredFormatterFor(Type type) =>
@@ -36,14 +29,6 @@ public static ITypeFormatter GetPreferredFormatterFor(Type type) =>
3629
public static ITypeFormatter GetPreferredFormatterFor<T>() =>
3730
GetPreferredFormatterFor(typeof(T));
3831

39-
/// <summary>
40-
/// Indicates the maximum number of properties to show in the default plaintext display of arbitrary objects.
41-
/// If set to zero no properties are shown.
42-
/// </summary>
43-
public static int MaxProperties { get; set; } = DefaultMaxProperties;
44-
45-
private const int DefaultMaxProperties = 20;
46-
4732
private const int NumberOfSpacesToIndent = 2;
4833

4934
internal static ITypeFormatter GetDefaultFormatterForAnyObject(Type type, bool includeInternals = false) =>
@@ -72,10 +57,8 @@ internal static FormatDelegate<T> CreateFormatDelegate<T>(MemberInfo[] forMember
7257

7358
bool FormatObject(T target, FormatContext context)
7459
{
75-
var reducedAccessors = accessors.Take(Math.Max(0, MaxProperties)).ToArray();
76-
7760
// If we haven't got any members to show, just resort to ToString()
78-
if (reducedAccessors.Length == 0)
61+
if (accessors.Length == 0)
7962
{
8063
context.Writer.Write(target.ToString());
8164
return true;
@@ -90,9 +73,9 @@ bool FormatObject(T target, FormatContext context)
9073
context.Writer.WriteLine();
9174
}
9275

93-
for (var i = 0; i < reducedAccessors.Length; i++)
76+
for (var i = 0; i < accessors.Length; i++)
9477
{
95-
var accessor = reducedAccessors[i];
78+
var accessor = accessors[i];
9679

9780
object value = accessor.GetValueOrException(target);
9881

@@ -107,7 +90,7 @@ bool FormatObject(T target, FormatContext context)
10790
}
10891
}
10992

110-
if (reducedAccessors.Length < accessors.Length)
93+
if (accessors.Length < accessors.Length)
11194
{
11295
WriteIndent(context);
11396
context.Writer.Write("...");

0 commit comments

Comments
 (0)