Skip to content

Commit

Permalink
feat: adding support for frameworks greater than and equal to NET6 (#…
Browse files Browse the repository at this point in the history
…1296)

* feat: adding support for frameworks greater than and equal to NET6

* remove all `#if NET6_0_OR_GREATER` - they are unnecessary
  • Loading branch information
andygjp authored Aug 14, 2024
1 parent d7ae43a commit 0785691
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 88 deletions.
2 changes: 0 additions & 2 deletions src/Microsoft.AspNetCore.OData/Common/TypeHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ public static bool IsDateTime(Type clrType)
return Type.GetTypeCode(underlyingTypeOrSelf) == TypeCode.DateTime;
}

#if NET6_0
/// <summary>
/// Determine if a type is a <see cref="DateOnly"/>.
/// </summary>
Expand All @@ -115,7 +114,6 @@ public static bool IsTimeOnly(this Type clrType)
Type underlyingTypeOrSelf = GetUnderlyingTypeOrSelf(clrType);
return underlyingTypeOrSelf == typeof(TimeOnly);
}
#endif

/// <summary>
/// Determine if a type is a TimeSpan.
Expand Down
3 changes: 0 additions & 3 deletions src/Microsoft.AspNetCore.OData/Edm/DefaultODataTypeMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,8 @@ static DefaultODataTypeMapper()
BuildReferenceTypeMapping<char[]>(EdmPrimitiveTypeKind.String, isStandard: false);
BuildValueTypeMapping<char>(EdmPrimitiveTypeKind.String, isStandard: false);
BuildValueTypeMapping<DateTime>(EdmPrimitiveTypeKind.DateTimeOffset, isStandard: false);

#if NET6_0
BuildValueTypeMapping<DateOnly>(EdmPrimitiveTypeKind.Date, isStandard: false);
BuildValueTypeMapping<TimeOnly>(EdmPrimitiveTypeKind.TimeOfDay, isStandard: false);
#endif
}
#endregion

Expand Down
2 changes: 0 additions & 2 deletions src/Microsoft.AspNetCore.OData/Edm/EdmPrimitiveHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ public static object ConvertPrimitiveValue(object value, Type type, TimeZoneInfo

throw new ValidationException(Error.Format(SRResources.PropertyMustBeBoolean));
}
#if NET6_0
else if (type == typeof(DateOnly))
{
if (value is Date dt)
Expand All @@ -156,7 +155,6 @@ public static object ConvertPrimitiveValue(object value, Type type, TimeZoneInfo

throw new ValidationException(Error.Format(SRResources.PropertyMustBeTimeOfDay));
}
#endif
else
{
if (TypeHelper.TryGetInstance(type, value, out var result))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ internal static object ConvertPrimitiveValue(object value, IEdmPrimitiveTypeRefe
return tod;
}

#if NET6_0
// Since ODL doesn't support "DateOnly", we have to use Date defined in ODL.
if (primitiveType != null && primitiveType.IsDate() && TypeHelper.IsDateOnly(type))
{
Expand All @@ -171,7 +170,6 @@ internal static object ConvertPrimitiveValue(object value, IEdmPrimitiveTypeRefe
TimeOnly timeOnly = (TimeOnly)value;
return new TimeOfDay(timeOnly.Hour, timeOnly.Minute, timeOnly.Second, timeOnly.Millisecond);
}
#endif

return ConvertUnsupportedPrimitives(value, timeZoneInfo);
}
Expand Down
106 changes: 60 additions & 46 deletions src/Microsoft.AspNetCore.OData/Microsoft.AspNetCore.OData.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1079,6 +1079,20 @@
<param name="clrType">The type to test.</param>
<returns>True if the type is a DateTime; false otherwise.</returns>
</member>
<member name="M:Microsoft.AspNetCore.OData.Common.TypeHelper.IsDateOnly(System.Type)">
<summary>
Determine if a type is a <see cref="T:System.DateOnly"/>.
</summary>
<param name="clrType">The type to test.</param>
<returns>True if the type is a DateOnly; false otherwise.</returns>
</member>
<member name="M:Microsoft.AspNetCore.OData.Common.TypeHelper.IsTimeOnly(System.Type)">
<summary>
Determine if a type is a <see cref="T:System.TimeOnly"/>.
</summary>
<param name="clrType">The type to test.</param>
<returns>True if the type is a TimeOnly; false otherwise.</returns>
</member>
<member name="M:Microsoft.AspNetCore.OData.Common.TypeHelper.IsTimeSpan(System.Type)">
<summary>
Determine if a type is a TimeSpan.
Expand Down Expand Up @@ -10942,52 +10956,6 @@
<param name="nodeIn">The node to be translated.</param>
<returns>The translated node.</returns>
</member>
<member name="T:Microsoft.AspNetCore.OData.Query.QueryFilterProvider">
<summary>
An implementation of <see cref="T:Microsoft.AspNetCore.Mvc.Filters.IFilterProvider" /> that applies an action filter to
any action with an <see cref="T:System.Linq.IQueryable" /> or <see cref="T:System.Linq.IQueryable`1" /> return type
that doesn't bind a parameter of type <see cref="T:Microsoft.AspNetCore.OData.Query.ODataQueryOptions" />.
</summary>
</member>
<member name="M:Microsoft.AspNetCore.OData.Query.QueryFilterProvider.#ctor(Microsoft.AspNetCore.Mvc.Filters.IActionFilter)">
<summary>
Initializes a new instance of the <see cref="T:Microsoft.AspNetCore.OData.Query.QueryFilterProvider" /> class.
</summary>
<param name="queryFilter">The action filter that executes the query.</param>
</member>
<member name="P:Microsoft.AspNetCore.OData.Query.QueryFilterProvider.QueryFilter">
<summary>
Gets the action filter that executes the query.
</summary>
</member>
<member name="P:Microsoft.AspNetCore.OData.Query.QueryFilterProvider.Order">
<summary>
Gets the order value for determining the order of execution of providers. Providers
execute in ascending numeric value of the Microsoft.AspNetCore.Mvc.Filters.IFilterProvider.Order
property.
</summary>
</member>
<member name="M:Microsoft.AspNetCore.OData.Query.QueryFilterProvider.OnProvidersExecuting(Microsoft.AspNetCore.Mvc.Filters.FilterProviderContext)">
<summary>
Provides filters to apply to the specified action.
</summary>
<param name="context">The filter context.</param>
</member>
<member name="M:Microsoft.AspNetCore.OData.Query.QueryFilterProvider.OnProvidersExecuted(Microsoft.AspNetCore.Mvc.Filters.FilterProviderContext)">
<summary>
Summary:
Called in decreasing Microsoft.AspNetCore.Mvc.Filters.IFilterProvider.Order,
after all Microsoft.AspNetCore.Mvc.Filters.IFilterProviders have executed once.
</summary>
<param name="context">The Microsoft.AspNetCore.Mvc.Filters.FilterProviderContext.</param>
</member>
<member name="M:Microsoft.AspNetCore.OData.Query.QueryFilterProvider.IsIQueryable(System.Type)">
<summary>
Determines whether the given type is IQueryable.
</summary>
<param name="type">The type</param>
<returns><c>true</c> if the type is IQueryable.</returns>
</member>
<member name="T:Microsoft.AspNetCore.OData.Query.ApplyQueryOption">
<summary>
This defines a $apply OData query option for querying.
Expand Down Expand Up @@ -11739,6 +11707,52 @@
</summary>
<param name="validationSettings">The <see cref="T:Microsoft.AspNetCore.OData.Query.Validator.ODataValidationSettings"/> instance which contains all the validation settings.</param>
</member>
<member name="T:Microsoft.AspNetCore.OData.Query.QueryFilterProvider">
<summary>
An implementation of <see cref="T:Microsoft.AspNetCore.Mvc.Filters.IFilterProvider" /> that applies an action filter to
any action with an <see cref="T:System.Linq.IQueryable" /> or <see cref="T:System.Linq.IQueryable`1" /> return type
that doesn't bind a parameter of type <see cref="T:Microsoft.AspNetCore.OData.Query.ODataQueryOptions" />.
</summary>
</member>
<member name="M:Microsoft.AspNetCore.OData.Query.QueryFilterProvider.#ctor(Microsoft.AspNetCore.Mvc.Filters.IActionFilter)">
<summary>
Initializes a new instance of the <see cref="T:Microsoft.AspNetCore.OData.Query.QueryFilterProvider" /> class.
</summary>
<param name="queryFilter">The action filter that executes the query.</param>
</member>
<member name="P:Microsoft.AspNetCore.OData.Query.QueryFilterProvider.QueryFilter">
<summary>
Gets the action filter that executes the query.
</summary>
</member>
<member name="P:Microsoft.AspNetCore.OData.Query.QueryFilterProvider.Order">
<summary>
Gets the order value for determining the order of execution of providers. Providers
execute in ascending numeric value of the Microsoft.AspNetCore.Mvc.Filters.IFilterProvider.Order
property.
</summary>
</member>
<member name="M:Microsoft.AspNetCore.OData.Query.QueryFilterProvider.OnProvidersExecuting(Microsoft.AspNetCore.Mvc.Filters.FilterProviderContext)">
<summary>
Provides filters to apply to the specified action.
</summary>
<param name="context">The filter context.</param>
</member>
<member name="M:Microsoft.AspNetCore.OData.Query.QueryFilterProvider.OnProvidersExecuted(Microsoft.AspNetCore.Mvc.Filters.FilterProviderContext)">
<summary>
Summary:
Called in decreasing Microsoft.AspNetCore.Mvc.Filters.IFilterProvider.Order,
after all Microsoft.AspNetCore.Mvc.Filters.IFilterProviders have executed once.
</summary>
<param name="context">The Microsoft.AspNetCore.Mvc.Filters.FilterProviderContext.</param>
</member>
<member name="M:Microsoft.AspNetCore.OData.Query.QueryFilterProvider.IsIQueryable(System.Type)">
<summary>
Determines whether the given type is IQueryable.
</summary>
<param name="type">The type</param>
<returns><c>true</c> if the type is IQueryable.</returns>
</member>
<member name="F:Microsoft.AspNetCore.OData.Query.SelectExpandIncludedProperty._propertySegment">
<summary>
the corresponding property segment.
Expand Down
2 changes: 0 additions & 2 deletions src/Microsoft.AspNetCore.OData/Query/ClrCanonicalFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ internal class ClrCanonicalFunctions
new KeyValuePair<string, PropertyInfo>(MillisecondFunctionName, typeof(TimeOfDay).GetProperty("Milliseconds")),
}.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);

#if NET6_0
// DateOnly properties
public static readonly Dictionary<string, PropertyInfo> DateOnlyProperties = new Dictionary<string, PropertyInfo>
{
Expand All @@ -141,7 +140,6 @@ internal class ClrCanonicalFunctions
{ SecondFunctionName, typeof(TimeOnly).GetProperty(nameof(TimeOnly.Second)) },
{ MillisecondFunctionName, typeof(TimeOnly).GetProperty(nameof(TimeOnly.Millisecond)) }
};
#endif

// TimeSpan properties
public static readonly Dictionary<string, PropertyInfo> TimeSpanProperties = new[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ public static Expression CreateBinaryExpression(BinaryOperatorKind binaryOperato
right = CreateTimeBinaryExpression(right, querySettings);
}

#if NET6_0
if ((IsType<DateOnly>(leftUnderlyingType) && IsDate(rightUnderlyingType)) ||
(IsDate(leftUnderlyingType) && IsType<DateOnly>(rightUnderlyingType)))
{
Expand All @@ -109,7 +108,6 @@ public static Expression CreateBinaryExpression(BinaryOperatorKind binaryOperato
left = CreateTimeBinaryExpression(left, querySettings);
right = CreateTimeBinaryExpression(right, querySettings);
}
#endif

if (left.Type != right.Type)
{
Expand Down Expand Up @@ -396,7 +394,6 @@ private static Expression GetProperty(Expression source, string propertyName, OD
{
return MakePropertyAccess(ClrCanonicalFunctions.TimeSpanProperties[propertyName], source, querySettings);
}
#if NET6_0
else if (IsType<DateOnly>(source.Type))
{
return MakePropertyAccess(ClrCanonicalFunctions.DateOnlyProperties[propertyName], source, querySettings);
Expand All @@ -405,7 +402,6 @@ private static Expression GetProperty(Expression source, string propertyName, OD
{
return MakePropertyAccess(ClrCanonicalFunctions.TimeOnlyProperties[propertyName], source, querySettings);
}
#endif

return source;
}
Expand Down Expand Up @@ -477,7 +473,6 @@ private static Expression ConvertToDateTimeRelatedConstExpression(Expression sou
return Expression.Constant(timeOfDay.Value, typeof(TimeOfDay));
}

#if NET6_0
if (parameterizedConstantValue is DateOnly dateOnly)
{
return Expression.Constant(dateOnly, typeof(DateOnly));
Expand All @@ -487,7 +482,6 @@ private static Expression ConvertToDateTimeRelatedConstExpression(Expression sou
{
return Expression.Constant(timeOnly, typeof(TimeOnly));
}
#endif
}

return source;
Expand All @@ -510,29 +504,19 @@ public static bool IsDateAndTimeRelated(Type type)
|| IsType<DateTimeOffset>(type)
|| IsType<TimeOfDay>(type)
|| IsType<TimeSpan>(type)
#if NET6_0
|| IsType<DateOnly>(type)
|| IsType<TimeOnly>(type)
#endif
;
}

public static bool IsDateRelated(Type type)
{
#if NET6_0
return IsType<Date>(type) || IsType<DateTime>(type) || IsType<DateTimeOffset>(type) || IsType<DateOnly>(type);
#else
return IsType<Date>(type) || IsType<DateTime>(type) || IsType<DateTimeOffset>(type);
#endif
}

public static bool IsTimeRelated(Type type)
{
#if NET6_0
return IsType<TimeOfDay>(type) || IsType<DateTime>(type) || IsType<DateTimeOffset>(type) || IsType<TimeSpan>(type) || IsType<TimeOnly>(type);
#else
return IsType<TimeOfDay>(type) || IsType<DateTime>(type) || IsType<DateTimeOffset>(type) || IsType<TimeSpan>(type);
#endif
}

public static bool IsDateOrOffset(Type type)
Expand Down Expand Up @@ -560,7 +544,6 @@ public static bool IsDate(Type type)
return IsType<Date>(type);
}

#if NET6_0
public static bool IsDateOnly(this Type type)
{
return IsType<DateOnly>(type);
Expand All @@ -570,7 +553,6 @@ public static bool IsTimeOnly(this Type type)
{
return IsType<TimeOnly>(type);
}
#endif

public static bool IsInteger(Type type)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,13 +384,11 @@ protected virtual Expression BindDateRelatedProperty(SingleValueFunctionCallNode
Contract.Assert(ClrCanonicalFunctions.DateProperties.ContainsKey(node.Name));
property = ClrCanonicalFunctions.DateProperties[node.Name];
}
#if NET6_0
else if (parameter.Type.IsDateOnly())
{
Contract.Assert(ClrCanonicalFunctions.DateOnlyProperties.ContainsKey(node.Name));
property = ClrCanonicalFunctions.DateOnlyProperties[node.Name];
}
#endif
else if (ExpressionBinderHelper.IsDateTime(parameter.Type))
{
Contract.Assert(ClrCanonicalFunctions.DateTimeProperties.ContainsKey(node.Name));
Expand Down Expand Up @@ -428,13 +426,11 @@ protected virtual Expression BindTimeRelatedProperty(SingleValueFunctionCallNode
Contract.Assert(ClrCanonicalFunctions.TimeOfDayProperties.ContainsKey(node.Name));
property = ClrCanonicalFunctions.TimeOfDayProperties[node.Name];
}
#if NET6_0
else if (parameter.Type.IsTimeOnly())
{
Contract.Assert(ClrCanonicalFunctions.TimeOnlyProperties.ContainsKey(node.Name));
property = ClrCanonicalFunctions.TimeOnlyProperties[node.Name];
}
#endif
else if (ExpressionBinderHelper.IsDateTime(parameter.Type))
{
Contract.Assert(ClrCanonicalFunctions.DateTimeProperties.ContainsKey(node.Name));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1147,12 +1147,10 @@ internal static Expression ConvertNonStandardPrimitives(Expression source, Query
// we handle enum conversions ourselves
convertedExpression = source;
}
#if NET6_0
else if (TypeHelper.IsDateOnly(sourceType) || TypeHelper.IsTimeOnly(sourceType))
{
convertedExpression = source;
}
#endif
else
{
switch (Type.GetTypeCode(sourceType))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
// </copyright>
//------------------------------------------------------------------------------

#if NET6_0
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -395,5 +394,4 @@ public class DateOnyTimeOnlyModel

public TimeOnly ResumeTime { get; set; }
}
}
#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,6 @@ public async Task MultipleAggregationOnEntitySetWorks(string queryString)
Assert.Equal(1 + 2 + 3 + 4 + 5 + 6, totalId);
}

#if NET6_0_OR_GREATER

[Fact]
public async Task GroupByWithAggregationAndOrderByWorks()
{
Expand Down Expand Up @@ -208,8 +206,6 @@ public async Task GroupByWithAggregationAndFilterByWorks()
Assert.Equal(expectedResult, stringObject.ToString());
}

#endif

[Fact(Skip = "See the comments above")]
public async Task AggregationOnEntitySetWorksWithPropertyAggregation()
{
Expand Down

0 comments on commit 0785691

Please sign in to comment.