I want to use Linq expression for some dynamic features. I need And, Or and Not expressions.. I couldn't get much..
We want to check whether certain feature has been enabled or not in our system and based on that we will decide whether to show the menu item or not. we have formed rules in XML format, I know to convert the rule to AST but I don't know to map to Linq expression.
Rules Are like : Feature1Enabled And Feature2Eenabled or (Feature3Disabled And Not Feature5Enabled)
Here "Feature1Enabled", "Feature2Eenabled" etc are name of the feature. We will pass this string to IsFeatureEnabled function to check whether a feature has been enabled or not.
public delegate bool IsEnabledDelegate(string name, string value);
public static bool IsFeatureEnabled(string name, string value)
{
if (name == "MV")
return true;
if (name == "GAS" && value == "G")
return true;
//More conditions goes here
return false;
}
static void Main(string[] args)
{
Expression<Func<string, string, bool>> featureEnabledExpTree =
(name, value) => IsFeatureEnabled(name, value);
//I want the equal of the following statement in C# Linq Expression
bool result = IsFeatureEnabled("MV", "") && IsFeatureEnabled("GAS", "G") || !IsFEatureEnabled("GAS", "F")
}
I want the equivalent to the bool result = IsFeatureEnabled("MV", "") && IsFeatureEnabled("GAS", "G") || !IsFEatureEnabled("GAS", "F")
in Linq expression Format.. However I can convert them to dynamically based on my AST notations..
Thank you so much.. If you need more info, tell me in comments..