Enums filtering support
duhapunk opened this issue · comments
duhapunk commented
Hello again! I noticed that your lib doesn't support enums. I fixed it like this:
- https://github.com/Kusumoto/PrimeNG.TableFilter/blob/master/PrimeNG.TableFilter/Core/LinqOperator.cs line 244
if (propertyType == typeof(bool) || propertyType == typeof(bool?) || propertyType.IsEnum)
- https://github.com/Kusumoto/PrimeNG.TableFilter/blob/master/PrimeNG.TableFilter/Utils/ObjectCasterUtil.cs line 85
if (property.PropertyType.IsEnum)
{
Enum.TryParse(property.PropertyType, value.ToString(), true, out var result);
return result; // additional checks required
}
Nikolay Prohorov commented
Works for me, @Kusumoto Could you release the fix?
Weerayut Hongsa commented
Works for me, @Kusumoto Could you release the fix?
I already try, it work but TryParse
method just work for .NET Standard 2.0 only.
This is the major change because after support this I'll obsolete .NET Framework support.
duhapunk commented
Did you try "manual" TryParse ? Something like this
try
{
var val = Enum.Parse(property.PropertyType, value.ToString(), true);
var result = Convert.ChangeType(val, property.PropertyType);
// additional checks required
return result;
}
catch (Exception ex)
{
// do some stuff
return null;
}
Garry Mitchell commented
Enum filtering would be great, if this could be incorporated :)