-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Start using parameter defined for ToString #118306
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
base: main
Are you sure you want to change the base?
Start using parameter defined for ToString #118306
Conversation
…in existing behavior.
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.
Pull Request Overview
This PR fixes an issue where a ToString(IFormatProvider)
method in the DateTimeOffsetAdapter
struct was accepting but ignoring its format provider parameter, causing compiler warnings. The fix implements proper usage of the format provider parameter while maintaining existing behavior by passing null
at the call site.
Key Changes
- Updates the
ToString(IFormatProvider?)
method to actually use the format provider when formatting theUtcDateTime
- Changes the call site to pass
null
instead ofCultureInfo.InvariantCulture
to preserve existing behavior - Removes compiler warning suppressions that are no longer needed
....Private.DataContractSerialization/src/System/Runtime/Serialization/DateTimeOffsetAdapter.cs
Outdated
Show resolved
Hide resolved
....Private.DataContractSerialization/src/System/Runtime/Serialization/DateTimeOffsetAdapter.cs
Outdated
Show resolved
Hide resolved
....Private.DataContractSerialization/src/System/Runtime/Serialization/DateTimeOffsetAdapter.cs
Outdated
Show resolved
Hide resolved
....Private.DataContractSerialization/src/System/Runtime/Serialization/DateTimeOffsetAdapter.cs
Outdated
Show resolved
Hide resolved
…tem/Runtime/Serialization/DateTimeOffsetAdapter.cs
Historically, this adapter struct took an
IFormatProvider
agrument for it'sToString()
method... and never used it. This makes the compiler unhappy now. So to keep the API (partly for binary compat, and partly to not bump heads with Object.ToString()), lets start using the format provider as one might expect. And then pass a null value in the one place that we call this ToString overload so the existing behavior is maintained.Fixes #76012