Beispiel #1
0
 // try get variable from build context
 // Note:
 //   The snippet object must be handled on different root (ParamRoot) than the procedure
 //   since the params are not declared on the snippet's root but rather on the master proc's root.
 internal Variable TryGetVariable(
     string variableName,
     out QueryTalkException exception,
     Variable.SearchType searchType = Variable.SearchType.Any)
 {
     if (Root.CompilableType.IsViewOrSnippet())
     {
         return(ParamRoot.TryGetVariable(variableName, out exception, searchType));
     }
     else
     {
         return(Root.TryGetVariable(variableName, out exception, searchType));
     }
 }
Beispiel #2
0
        // attention:
        //   If root object is accessed through the BuildContext object, use buildContext.TryGetVariable method instead.
        internal Variable TryGetVariable(
            string variableName,
            out QueryTalkException exception,
            Variable.SearchType searchType = Variable.SearchType.Any)
        {
            exception = null;

            if (variableName == null)
            {
                exception = Variable.InvalidVariableException(variableName,
                                                              QueryTalkExceptionType.ArgumentNull);
                return(null);
            }

            Variable param;
            Variable variable;

            // try get param
            param = AllParams.Where(p => p.Name.EqualsCS(variableName))
                    .FirstOrDefault();

            // try get non-param
            variable = _variables.Where(v => v.Name.EqualsCS(variableName))
                       .FirstOrDefault();

            if (searchType == Variable.SearchType.Any)
            {
                return(param ?? variable);
            }

            if (searchType == Variable.SearchType.Inliner &&
                (param == null || param.DT.IsNotInliner()))
            {
                exception = Variable.InvalidVariableException(variableName,
                                                              QueryTalkExceptionType.InlinerNotFound);
                return(null);
            }

            // param/variable should exists
            if (searchType != Variable.SearchType.Any && (param == null && variable == null))
            {
                exception = Variable.InvalidVariableException(variableName,
                                                              QueryTalkExceptionType.ParamOrVariableNotDeclared);
                return(null);
            }

            return(param ?? variable);
        }