-
-
Notifications
You must be signed in to change notification settings - Fork 231
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for DateOnly and TimeOnly (#671)
* DateOnly * TimeOnly * fix
- Loading branch information
Showing
16 changed files
with
437 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/System.Linq.Dynamic.Core/Parser/SupportedOperands/IAddAndSubtractSignatures.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
namespace System.Linq.Dynamic.Core.Parser.SupportedOperands; | ||
|
||
internal interface IAddAndSubtractSignatures : IArithmeticSignatures | ||
{ | ||
void F(TimeSpan x, TimeSpan y); | ||
|
||
void F(TimeSpan x, TimeSpan? y); | ||
|
||
void F(TimeSpan? x, TimeSpan y); | ||
|
||
void F(TimeSpan? x, TimeSpan? y); | ||
|
||
void F(DateTime x, DateTime y); | ||
|
||
void F(DateTime x, DateTime? y); | ||
|
||
void F(DateTime? x, DateTime y); | ||
|
||
void F(DateTime? x, DateTime? y); | ||
|
||
#if NET6_0_OR_GREATER | ||
void F(DateOnly x, DateOnly y); | ||
|
||
void F(DateOnly x, DateOnly? y); | ||
|
||
void F(DateOnly? x, DateOnly y); | ||
|
||
void F(DateOnly? x, DateOnly? y); | ||
|
||
void F(TimeOnly x, TimeOnly y); | ||
|
||
void F(TimeOnly x, TimeOnly? y); | ||
|
||
void F(TimeOnly? x, TimeOnly y); | ||
|
||
void F(TimeOnly? x, TimeOnly? y); | ||
#endif | ||
} |
10 changes: 0 additions & 10 deletions
10
src/System.Linq.Dynamic.Core/Parser/SupportedOperands/IAddSignatures.cs
This file was deleted.
Oops, something went wrong.
37 changes: 18 additions & 19 deletions
37
src/System.Linq.Dynamic.Core/Parser/SupportedOperands/IArithmeticSignatures.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,19 @@ | ||
namespace System.Linq.Dynamic.Core.Parser.SupportedOperands | ||
namespace System.Linq.Dynamic.Core.Parser.SupportedOperands; | ||
|
||
internal interface IArithmeticSignatures | ||
{ | ||
internal interface IArithmeticSignatures | ||
{ | ||
void F(int x, int y); | ||
void F(uint x, uint y); | ||
void F(long x, long y); | ||
void F(ulong x, ulong y); | ||
void F(float x, float y); | ||
void F(double x, double y); | ||
void F(decimal x, decimal y); | ||
void F(int? x, int? y); | ||
void F(uint? x, uint? y); | ||
void F(long? x, long? y); | ||
void F(ulong? x, ulong? y); | ||
void F(float? x, float? y); | ||
void F(double? x, double? y); | ||
void F(decimal? x, decimal? y); | ||
} | ||
} | ||
void F(int x, int y); | ||
void F(uint x, uint y); | ||
void F(long x, long y); | ||
void F(ulong x, ulong y); | ||
void F(float x, float y); | ||
void F(double x, double y); | ||
void F(decimal x, decimal y); | ||
void F(int? x, int? y); | ||
void F(uint? x, uint? y); | ||
void F(long? x, long? y); | ||
void F(ulong? x, ulong? y); | ||
void F(float? x, float? y); | ||
void F(double? x, double? y); | ||
void F(decimal? x, decimal? y); | ||
} |
45 changes: 31 additions & 14 deletions
45
src/System.Linq.Dynamic.Core/Parser/SupportedOperands/IRelationalSignatures.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,32 @@ | ||
namespace System.Linq.Dynamic.Core.Parser.SupportedOperands | ||
namespace System.Linq.Dynamic.Core.Parser.SupportedOperands; | ||
|
||
internal interface IRelationalSignatures : IArithmeticSignatures | ||
{ | ||
internal interface IRelationalSignatures : IArithmeticSignatures | ||
{ | ||
void F(string x, string y); | ||
void F(char x, char y); | ||
void F(DateTime x, DateTime y); | ||
void F(DateTimeOffset x, DateTimeOffset y); | ||
void F(TimeSpan x, TimeSpan y); | ||
void F(char? x, char? y); | ||
void F(DateTime? x, DateTime? y); | ||
void F(DateTimeOffset? x, DateTimeOffset? y); | ||
void F(TimeSpan? x, TimeSpan? y); | ||
} | ||
} | ||
void F(string x, string y); | ||
|
||
void F(char x, char y); | ||
|
||
void F(DateTime x, DateTime y); | ||
|
||
void F(DateTimeOffset x, DateTimeOffset y); | ||
|
||
void F(TimeSpan x, TimeSpan y); | ||
|
||
void F(char? x, char? y); | ||
|
||
void F(DateTime? x, DateTime? y); | ||
|
||
void F(DateTimeOffset? x, DateTimeOffset? y); | ||
|
||
void F(TimeSpan? x, TimeSpan? y); | ||
|
||
#if NET6_0_OR_GREATER | ||
void F(DateOnly x, DateOnly y); | ||
|
||
void F(DateOnly? x, DateOnly? y); | ||
|
||
void F(TimeOnly x, TimeOnly y); | ||
|
||
void F(TimeOnly? x, TimeOnly? y); | ||
#endif | ||
} |
8 changes: 0 additions & 8 deletions
8
src/System.Linq.Dynamic.Core/Parser/SupportedOperands/ISubtractSignatures.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/System.Linq.Dynamic.Core/TypeConverters/DateOnlyConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#if NET6_0 | ||
using System.ComponentModel; | ||
using System.Globalization; | ||
|
||
namespace System.Linq.Dynamic.Core.TypeConverters; | ||
|
||
/// <summary> | ||
/// Based on https://github.com/dotnet/runtime/issues/68743 | ||
/// </summary> | ||
internal class DateOnlyConverter : TypeConverter | ||
{ | ||
public override bool CanConvertFrom(ITypeDescriptorContext? context, Type sourceType) | ||
{ | ||
return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); | ||
} | ||
|
||
public override bool CanConvertTo(ITypeDescriptorContext? context, Type? destinationType) | ||
{ | ||
return destinationType == typeof(string) || base.CanConvertTo(context, destinationType); | ||
} | ||
|
||
public override object? ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object value) | ||
{ | ||
if (value is string s) | ||
{ | ||
return DateOnly.Parse(s, culture); | ||
} | ||
|
||
return base.ConvertFrom(context, culture, value); | ||
} | ||
|
||
public override object? ConvertTo(ITypeDescriptorContext? context, CultureInfo? culture, object? value, Type destinationType) | ||
{ | ||
if (destinationType == typeof(string)) | ||
{ | ||
return ((DateOnly?)value)?.ToString(culture); | ||
} | ||
|
||
return base.ConvertTo(context, culture, value, destinationType); | ||
} | ||
|
||
public override bool IsValid(ITypeDescriptorContext? context, object? value) | ||
{ | ||
return value is DateOnly || base.IsValid(context, value); | ||
} | ||
} | ||
#endif |
Oops, something went wrong.