SoFunction
Updated on 2025-03-01

c# Reflection Expression Tree Fuzzy Search Example


public static Expression<Func<T, bool>> GetSearchExpression<T>(string SearchString)
        {
            Expression<Func<T, bool>> filter = null;

            if ((SearchString)) return null;
            var left = (typeof(T), "m");

            Expression expression = (false);
            T obj = default(T);
            var type = typeof(T);
            obj = (T)(type);
           var propertyInfos = ();

            foreach (var propertyInfo in propertyInfos)
            {

                if (() == "id" || == typeof(DateTime)) continue;
                Expression tostring =
         (
            (left, typeof(T).GetProperty().Name),

           typeof(object).GetMethod("ToString", new Type[] { })

         );
                Expression right =

                      (

                          tostring,

                        typeof(string).GetMethod("Contains", new Type[] { typeof(string) }),

                        (SearchString)

                      );
                expression = (right, expression);
            }

            filter = <Func<T, bool>>(expression, new[] { left });

            return filter;

        }