-
Notifications
You must be signed in to change notification settings - Fork 463
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
CA1806 should analyze calls to date and time methods #6489
Comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Analyzer
Diagnostic ID: CA1806: Do not ignore method results
Describe the improvement
DateTime
is similar toString
insofar as it's immutable and has methods for changing the value which return a new instance.CA1806 currently checks that the return value from certain
String
methods are not ignored. This analyzer could also check that the return value from certainDateTime
methods are not ignored.DateTimeOffset
,DateOnly
,TimeOnly
andTimeSpan
could also be supported.Describe suggestions on how to achieve the rule
On
DateTime
andDateTimeOffset
, the return value of these methods should not be ignored:Add(TimeSpan)
AddDays(Double)
AddHours(Double)
AddMicroseconds(Double)
AddMilliseconds(Double)
AddMinutes(Double)
AddMonths(Int32)
AddSeconds(Double)
AddTicks(Int64)
AddYears(Int32)
Subtract(DateTime)
Subtract(TimeSpan)
ToLocalTime()
ToUniversalTime()
On
DateOnly
, the return value of these methods should not be ignored:AddDays(Int32)
AddMonths(Int32)
AddYears(Int32)
On
TimeOnly
, the return value of these methods should not be ignored:Add(TimeSpan)
Add(TimeSpan, Int32)
AddHours(Double)
AddHours(Double, Int32)
AddMinutes(Double)
AddMinutes(Double, Int32)
On
TimeSpan
, the return value of these methods should not be ignored:Add(TimeSpan)
Divide(Double)
Divide(TimeSpan)
Multiply(Double)
Multiply(TimeSpan)
Negate(Double)
Subtract(TimeSpan)
The text was updated successfully, but these errors were encountered: