CSharp · Console
using System;
using System.Collections.Generic;
using System.Linq.Dynamic.Core;
using System.Linq.Dynamic.Core.CustomTypeProviders;
using System.Linq.Expressions;
public class Program
{
public static void Main()
{
var config = new ParsingConfig
{
CustomTypeProvider = new CustomTypeProvider(new[]
{
typeof(IS),
typeof(IS.NOT)
})
};
var result = DynamicExpressionParser.ParseLambda(config, false, new ParameterExpression[] { }, typeof(bool), "IS.NOT.NULL(null)");
}
public class CustomTypeProvider : DefaultDynamicLinqCustomTypeProvider
{
private readonly HashSet<Type> _types;
public CustomTypeProvider(Type[] types)
{
_types = new HashSet<Type>(types);
}
public override HashSet<Type> GetCustomTypes()
{
return _types;
}
}
public static class IS
{
public static class NOT
{
public static bool NULL(object value) => value != null;
}
}
}