fluentassertions
fluentassertions copied to clipboard
DateBuilder that allows DateOnly building too
As illustration of the discussion in #2234
Qodana for .NET
4 new problems were found
Inspection name | Severity | Problems |
---|---|---|
Convert local variable or field into constant (private accessibility) |
◽️ Notice | 4 |
💡 Qodana analysis was run in the pull request mode: only the changed files were checked ☁️ View the detailed Qodana report
Contact Qodana team
Contact us at [email protected]
- Or via our issue tracker: https://jb.gg/qodana-issue
- Or share your feedback: https://jb.gg/qodana-discussions
@Corniel I like this :)
Although I would suggest to drop the AsOffset()
and WithOffset()
methods inside the DateBuilder
struct, and only use extension methods for this, like:
public static DateTimeOffset WithOffset(this DateTime self, TimeSpan offset) => new(self, offset);
public static DateTimeOffset WithOffset(this DateBuilder self, TimeSpan offset) => new(self, offset);
public static DateTimeOffset AsOffset(this DateTime self) => new(self, 0.Hours());
public static DateTimeOffset AsOffset(this DateBuilder self) => new(self, 0.Hours());
This will address https://github.com/fluentassertions/fluentassertions/issues/2234#issuecomment-1694726115
@Corniel I like this :)
Although I would suggest to drop the
AsOffset()
andWithOffset()
methods inside theDateBuilder
struct, and only use extension methods for this, like:
Why define the offset methods as extensions on the date builder? It's only purpose is just to do things like that?!
Why define the offset methods as extensions on the date builder?
Because it shouldn't matter if you call AsOffset()
/WithOffset()
after the date "thing" like 10.May(2023).AsOffset()
or after the time "thing" like 10.May(2023).At(...).AsOffset()
.
Now this is not possible, because AsOffset()
is not recognized when chaining after At(...)
.
And if you introduce AsOffset()
as an extension method, the AsOffset()
in the DateBuilder
becomes useless.
Do you see my point?
@IT-VBFK: I ment, that AsOffset
should not be an extension for the DateBuilder
. For DateTime
it should.