Exemplo n.º 1
0
        private bool invokeEvaluator(NetSiteState netState, Evaluator evaluator)
        {
            if (netState == null)
            {
                return(false);
            }

            string evaluated = string.Empty;

            lock (netState.m_Variables)
            {
                evaluated = evaluator.Evaluate(
                    (varName) =>
                {
                    if (varName.StartsWith(VAR_EXPRESSION_PREFIX) && varName.Length > VAR_EXPRESSION_PREFIX.Length)
                    {
                        NetSiteState._value lookedUp;
                        varName = varName.Substring(VAR_EXPRESSION_PREFIX.Length);
                        if (netState.m_Variables.TryGetValue(varName, out lookedUp))
                        {
                            return(lookedUp.Value.ToString());
                        }
                        //is it important to return "0" so all expressions keep working even if the variable does not exist
                        return("0");
                    }
                    return(varName);
                });
            }
            if (evaluated == "1" || //this check for speed as AsBool() does extra conv and parses as int
                evaluated.AsBool())
            {
                return(true);
            }

            return(false);
        }
Exemplo n.º 2
0
    private bool invokeEvaluator(NetSiteState netState, Evaluator evaluator)
    {
        if (netState==null) return false;

        string evaluated = string.Empty;

        lock(netState.m_Variables)
        {
          evaluated = evaluator.Evaluate(
                         (varName)=>
                         {
                            if (varName.StartsWith(VAR_EXPRESSION_PREFIX)&&varName.Length>VAR_EXPRESSION_PREFIX.Length)
                            {
                               NetSiteState._value lookedUp;
                               varName = varName.Substring(VAR_EXPRESSION_PREFIX.Length);
                               if (netState.m_Variables.TryGetValue(varName, out lookedUp)) return lookedUp.Value.ToString();
                               //is it important to return "0" so all expressions keep working even if the variable does not exist
                               return "0";
                            }
                            return varName;
                         });
        }
        if (evaluated=="1" ||  //this check for speed as AsBool() does extra conv and parses as int
            evaluated.AsBool()) return true;

        return false;
    }