-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Makes Format-Custom treat DateTime as a scalar unless Expaned #18293
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
966e189
to
9666006
Compare
@@ -418,6 +418,8 @@ internal TraversalInfo NextLevel | |||
/// </summary> | |||
internal sealed class ComplexViewObjectBrowser | |||
{ | |||
private static readonly HashSet<string> s_defaultLeafTypes = new() { "System.DateTime" }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DateTimeOffset
is good candidate in the list.
Should the HashSet be OrdinalIgnorecase?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm uncertain about casing - This seemed like the safest choice, but we could also ensure that we never have types that only differ by case in the set of types.
private static bool TreatAsScalarType(Collection<string> typeNames) | ||
private static bool TreatAsScalarType(Collection<string> typeNames, string[] scalarTypesToExpand) | ||
{ | ||
return TypeIsScalarForComplexView(typeNames, scalarTypesToExpand) || DefaultScalarTypes.IsTypeInList(typeNames); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- I'd swap the condition since it makes no sense to change the behavior by user input.
- And at first look it makes sense to put "Datetime" in DefaultScalarTypes (and enhance it with exclusion list). Perhaps it is useful for other code paths too.
- Perhaps it makes sense to use the s_defaultLeafTypes list in ExpandType parameter for IntelliSense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding #2: It was not obvious to me that that behavior was desired. With Format-List, for example, a user may reasonably want to see all the properties of the type.
97f5dbe
to
fc901d8
Compare
fc901d8
to
dc89342
Compare
This PR has Quantification details
Why proper sizing of changes matters
Optimal pull request sizes drive a better predictable PR flow as they strike a
What can I do to optimize my changes
How to interpret the change counts in git diff output
Was this comment helpful? 👍 :ok_hand: :thumbsdown: (Email) |
This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days. |
src/System.Management.Automation/FormatAndOutput/common/FormatViewGenerator_Complex.cs
Show resolved
Hide resolved
This pull request has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 15 days. It will be closed if no further activity occurs within 10 days of this comment. |
PR Summary
The default behavior of Format-Custom with datetime Properties becomes very spammy. This PR makes the formatting system treat System.DateTime as a scalar, unless included in the new
ExpandType
parameter.PR Context
As discussed in issue #18142, and easily verified by typing
the default handling of datetime is spammy.
This PR changes the default treatment of DateTime in Format-Custom, but adds a parameter
-ExpandType
that allows the user to opt-in to the old behavior.PR Checklist
.h
,.cpp
,.cs
,.ps1
and.psm1
files have the correct copyright headerWIP:
or[ WIP ]
to the beginning of the title (theWIP
bot will keep its status check atPending
while the prefix is present) and remove the prefix when the PR is ready.(which runs in a different PS Host).