code_junkie

Boolean logic rule evaluator

Nov 12th, 2011
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. true
  2.  
  3. <rule id="1">
  4. <question id="123" answer="true" />
  5. <question id="124" answer="false" />
  6. <choice id="1">
  7. <question id="125" answer='true' />
  8. <choice id="2">
  9. <question id="126" answer='false' />
  10. <question id="127" answer='false' />
  11. </choice>
  12. </choice>
  13. </rule>
  14.  
  15. bool IsRuleSatisfied(XmlElement rule)
  16. {
  17. bool satisfied = true;
  18. foreach (XmlElement child in rule.SelectNodes("*"))
  19. {
  20. if (child.Name == "question")
  21. {
  22. satisfied = satisfied && IsQuestionCorrect(child);
  23. }
  24. if (child.Name == "choice")
  25. {
  26. satisfed = satisfied && IsChoiceCorrect(child);
  27. }
  28. if (!satisfied)
  29. {
  30. return false;
  31. }
  32. }
  33. return true;
  34. }
Add Comment
Please, Sign In to add comment