Skip to content
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

Warn against TimeSpan.Milliseconds #73

Open
bretehlert opened this issue Feb 26, 2019 · 2 comments
Open

Warn against TimeSpan.Milliseconds #73

bretehlert opened this issue Feb 26, 2019 · 2 comments

Comments

@bretehlert
Copy link

I have never seen a valid use for TimeSpan.Milliseconds, but I have seen developers mistakenly use this where they really mean TimeSpan.TotalMilliseconds.

Can we add a rule against using TimesSpan.Days, TimeSpan.Hours, TimeSpan.Minutes, TimeSpan.Seconds, and TimeSpan.Milliseconds, suggesting instead to use the equivalent Total value?

We might also consider a rule against passing the result of TimeSpan.TotalMilliseconds into a method that has a TimeSpan parameter override.

@brian-reichle
Copy link
Contributor

I have seen valid usages of TimeSpan.Milliseconds but always in conjunction with other "non-total" properties, not in isolation. Maybe we should warn when:

a) accessing a single non-total property without accessing other non-total properties,
b) accessing a mixture of total and non-total properties in the same method and
c) accessing multiple distinct "total" properties in the same method.

For the second rule, maybe it would be better to warn against using a method that takes an int if there is another overload that takes a TimeSpan for the same argument (and all other arguments are the same).

@bretehlert
Copy link
Author

Sounds fine to me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants