Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert to enum automatically #24

Open
luizfbicalho opened this issue Aug 3, 2016 · 0 comments
Open

Convert to enum automatically #24

luizfbicalho opened this issue Aug 3, 2016 · 0 comments

Comments

@luizfbicalho
Copy link

If one field of the grid is an enum, if you filter you get an error,

I added this code to change the enums to their correct values, i could be done inside the library

private static void UpdateFilter(Filter filter)
{
if(filter==null)
{
return;
}
if (filter.Field != null)
{
var campo = filter.Field.Split('.');
var val = filter.Value;
var type = typeof(T);
foreach (var c in campo)
{
type = type.GetProperty(c).PropertyType;
}
if (type.IsEnum)
{
val = val ?? "0";
try
{
var enumVal = Enum.Parse(type, val.ToString());
filter.Value = enumVal;
}
catch { }

        }
    }
    if(filter.Filters ==null)
    {
        return;
    }
    foreach (var item in filter.Filters)
    {
        UpdateFilter<T>(item);
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant