c# - Logical Evaluator -
i have programme needs back upwards "user options" determine how overwrite files, user can take "options" can result several combinations making hard code possible "if... else statements", complex result evaluation hard code , getting long , driving me nuts!
i'm looking solve sort of "parsing" evaluate possible results in faster , more organic way without long chains of if...else blocks
here have in programme options:
for example: user has selected overwrite files , picked alternative "file size" , selected ">=" criteria option, , selected "file date" plus "<=", , picked "or", options select result in "file >= x" or "file date <= x".
given options above on screen shot, user can create sorts of possible logical options , combine them using "or" , "and", , pick ">, <, >=, <=, =, <>".
the complexity behind little screen huge , i've been researching how tackle downwards , heard things called lambda expressions , binary trees have no clue if apply problem, @ to the lowest degree have point me right direction, don't know how correctly classify "issue" when googling around answers :)
thanks in advance all!
i don't think issue solved using expression trees. look trees functional expressions can analyzed, improved or evaluated before they're compiled. it's solution when want create fluent configuration should provide properties provide configuration decided developer (there're other utilize cases goes beyond question):
config.enablewhatever(x => x.haswhatever)
your selection should around enumerations [flagsattribute]
:
[flags] public enum filesizeoptions { none = 0, iffilesizeisgreaterthan = 1, iffilesizeislowerthan = 2, otheroption = 4, = iffilesizeisgreaterthan | iffilesizeislowerthan | otheroptions } filesizeoptions options = filesizeoptions.iffilesizeisgreaterthan | filesizeoptions.otheroption; if(options.hasflag(filesizeoptions.all)) { // stuff } else if(options.hasflag(filesizeoptions.iffilesizeisgreaterthan)) { // stuff } // , on...
i mean, should utilize masks instead of booleans , .net has enums recommended way implement masks or flags.
that is, can evaluate if enumeration value has 1 or n possible flags defined in whole enumeration.
c# .net binary-tree logical-operators expression-evaluation
No comments:
Post a Comment