Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Sieve/Models/SieveOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ public class SieveOptions
public int MaxPageSize { get; set; } = 0;

public bool ThrowExceptions { get; set; } = false;

public string CultureNameOfTypeConversion { get; set; } = "en";
}
}
}
5 changes: 4 additions & 1 deletion Sieve/Services/SieveProcessor.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
Expand Down Expand Up @@ -169,6 +170,8 @@ private IQueryable<TEntity> ApplyFiltering<TEntity>(
return result;
}

var cultureInfoToUseForTypeConversion = new CultureInfo(_options.Value.CultureNameOfTypeConversion ?? "en");

Expression outerExpression = null;
var parameterExpression = Expression.Parameter(typeof(TEntity), "e");
foreach (var filterTerm in model.GetFiltersParsed())
Expand All @@ -193,7 +196,7 @@ private IQueryable<TEntity> ApplyFiltering<TEntity>(
{

dynamic constantVal = converter.CanConvertFrom(typeof(string))
? converter.ConvertFrom(filterTermValue)
? converter.ConvertFrom(null, cultureInfoToUseForTypeConversion, filterTermValue)
: Convert.ChangeType(filterTermValue, property.PropertyType);

Expression filterValue = GetClosureOverConstant(constantVal, property.PropertyType);
Expand Down