.net - C# boolean logic with dynamic LINQ? -


i've struggle following task:

assuming have list names , values (like dictionary). need provide user of web interface field can write query, checking existence of specific names , values on list.

for example, i've got following list:

a = 2, b = 4, d = 0 

users want query list (don't mind syntax, it's pseudocode)

  • a == 2 && d => returns true, a exists , it's value 2 , d exists.
  • (a && b) || c => returns true, both a , b exists on list.
  • a && !b => returns false, a exists on list b (but b shouldn't)

i've been looking on dynamic linq, seems can evaluate 1 object @ time (can't check if object exists on list , ask if 1 doesn't). knows materials or links useful? thanks

not sure whether have understood requirement...

is asking for?

dictionary<string, int> namevaluepairs = new dictionary<string, int>();         namevaluepairs.add("a", 2);         namevaluepairs.add("b", 4);         namevaluepairs.add("d", 0);           //a == 2 && d => returns true, exists , it's value 2 , d exists         int d = 0;         if (namevaluepairs.containskey("a") && namevaluepairs.trygetvalue("d", out d) && namevaluepairs.containskey("d"))         {             console.writeline("test 1: true");         }         else         {             console.writeline("test 1: false");         }          //(a && b) or c => returns true, both , b exists on list         if ((namevaluepairs.containskey("a") && namevaluepairs.containskey("b")) || namevaluepairs.containskey("c"))         {             console.writeline("test 2: true");         }         else         {             console.writeline("test 2: false");         }          //a && !b => returns false, exists on list b (but b shouldn't)         if (namevaluepairs.containskey("a") && !namevaluepairs.containskey("b"))          {             console.writeline("test 3: true");         }         else         {             console.writeline("test 3: false");         } 

Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -