Desidero utilizzare l'espressione Linq per alcune funzioni dinamiche. Ho bisogno di E, O e Non espressioni .. Non ho potuto ottenere molto ..Espressione C# che utilizza E e Nessuna espressione insieme in base a AST
Vogliamo verificare se alcune funzionalità sono state abilitate o meno nel nostro sistema e in base a questo decideremo se mostrare la voce di menu o no. abbiamo formato le regole in formato XML, so di convertire la regola in AST ma non so mappare all'espressione di Linq.
regole sono come: Feature1Enabled E Feature2Eenabled o (Feature3Disabled E non Feature5Enabled)
Qui "Feature1Enabled", "Feature2Eenabled" ecc sono il nome della funzione. Passeremo questa stringa alla funzione IsFeatureEnabled per verificare se una funzionalità è stata abilitata o meno.
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")
}
Voglio l'equivalente al risultato bool = IsFeatureEnabled ("MV", "") & & IsFeatureEnabled ("GAS", "G") || ! IsFEatureEnabled ("GAS", "F")
in LINQ espressione formato .. Comunque io possa convertire in modo dinamico in base alle mie notazioni AST ..
Grazie mille .. Se avete bisogno di più informazioni , dimmi nei commenti ..
(ad esempio rivisto per mostrare edificio featureEnabledExpTree in fase di esecuzione sulla base dei dati) –