mardi 8 novembre 2016

Get propertyinfo from lambda expression, but fails with int

Hi Wat is the best way to get to all the propertyinfo of items in a lamba expression.

i want to set a filter on a xml field in a sql database.

        var FilterBase = new FilterBase<SimpleItemSubObject>()
            .SetSimpleFilter(x => x.ID, 123)
            .SetSimpleFilter(x => x.Test.Name, "demo3");

in de analyser, i'm able to get the propertyinfo for the Name property.

   internal IEnumerable<PropertyInfo> GetExpressionList()
    {
        return GetPropertyListfor(lambda.Body as MemberExpression);
    }

    private IEnumerable<PropertyInfo> GetPropertyListfor(MemberExpression body)
    {
        var result = new List<PropertyInfo>();
        if (body != null && body.Expression != null)
        {
            result.AddRange(GetPropertyListfor(body.Expression as MemberExpression));
            result.Add((body as MemberExpression).Member as PropertyInfo);
        }

        return result;
    }

this will return the propertyinfo if it's a string property. but in case of a int the analyser fails becous lambda has added a convert function.

{x => Convert(x.ID)}

It added a convert function.

so what is the best method of geting the propertyinfo in this for the x.ID

thanks





Aucun commentaire:

Enregistrer un commentaire