Skip to content

Commit

Permalink
Merge pull request #584 from 0xced/DateTime-key
Browse files Browse the repository at this point in the history
Convert DateTimeOffset to DateTime when necessary
  • Loading branch information
robertmclaws committed Dec 20, 2018
2 parents 9a0a1c1 + 05052b7 commit af7ad3f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Microsoft.Restier.AspNet/Query/RestierQueryBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public IQueryable BuildQuery()
{
var property = Expression.Property(parameterExpression, propertyName);
var constant = Expression.Constant(
Convert.ChangeType(propertyValue, property.Type, CultureInfo.InvariantCulture));
TypeConverter.ChangeType(propertyValue, property.Type, CultureInfo.InvariantCulture));
return Expression.Equal(property, constant);
}

Expand Down
12 changes: 12 additions & 0 deletions src/Microsoft.Restier.Core/Extensions/TypeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,16 @@ public static bool IsDateTimeOffset(Type type)
return underlyingTypeOrSelf == typeof(DateTimeOffset);
}
}

internal static class TypeConverter
{
public static object ChangeType(object value, Type conversionType, IFormatProvider provider)
{
if (conversionType == typeof(DateTime) && value is DateTimeOffset)
{
return ((DateTimeOffset)value).DateTime;
}
return Convert.ChangeType(value, conversionType, provider);
}
}
}
2 changes: 1 addition & 1 deletion src/Microsoft.Restier.Core/Submit/ChangeSetItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ private static Expression ApplyPredicate(ParameterExpression param, Expression w

if (itemValue.GetType() != property.Type)
{
itemValue = Convert.ChangeType(itemValue, property.Type, CultureInfo.InvariantCulture);
itemValue = TypeConverter.ChangeType(itemValue, property.Type, CultureInfo.InvariantCulture);
}

// TODO GitHubIssue#31 : Check if LinqParameterContainer is necessary
Expand Down

0 comments on commit af7ad3f

Please sign in to comment.