예제 #1
0
 private void AddSwitch(string currentParameter, ParameterBindingResult bindingResult)
 {
     bindingResult.ConstantValue = true;
     AddBoundParameter(null, currentParameter, bindingResult);
 }
예제 #2
0
 private void AddBoundParameter(CommandParameterAst parameter, string parameterName, ParameterBindingResult bindingResult)
 {
     if (BoundParameters.ContainsKey(parameterName))
     {
         AddDuplicateParameterBindingException(parameter);
     }
     else
     {
         BoundParameters.Add(parameterName, bindingResult);
     }
 }
예제 #3
0
 private static void ResetCurrentParameter(ref CommandParameterAst currentParameter, ref ParameterBindingResult bindingResult)
 {
     currentParameter = null;
     bindingResult = new ParameterBindingResult();
 }
예제 #4
0
        private void CreateBindingResultForSyntacticBind(CommandAst commandAst)
        {
            bool foundCommand = false;

            CommandParameterAst currentParameter = null;
            int position = 0;
            ParameterBindingResult bindingResult = new ParameterBindingResult();

            foreach (CommandElementAst commandElement in commandAst.CommandElements)
            {
                // Skip the command name
                if (!foundCommand)
                {
                    foundCommand = true;
                    continue;
                }

                CommandParameterAst parameter = commandElement as CommandParameterAst;
                if (parameter != null)
                {
                    if (currentParameter != null)
                    {
                        // Assume it was a switch
                        AddSwitch(currentParameter.ParameterName, bindingResult);
                        ResetCurrentParameter(ref currentParameter, ref bindingResult);
                    }

                    // If this is an actual parameter, get its name.
                    string parameterName = parameter.ParameterName;
                    bindingResult.Value = parameter;

                    // If it's a parameter with argument, add them both to the dictionary
                    if (parameter.Argument != null)
                    {
                        bindingResult.Value = parameter.Argument;

                        AddBoundParameter(parameter, parameterName, bindingResult);
                        ResetCurrentParameter(ref currentParameter, ref bindingResult);
                    }
                    // Otherwise, it's just a parameter and the argument is to follow.
                    else
                    {
                        // Store our current parameter
                        currentParameter = parameter;
                    }
                }
                else
                {
                    // This isn't a parameter, it's a value for the previous parameter
                    if (currentParameter != null)
                    {
                        bindingResult.Value = commandElement;
                        AddBoundParameter(currentParameter, currentParameter.ParameterName, bindingResult);
                    }
                    else
                    {
                        // Assume positional
                        bindingResult.Value = commandElement;
                        AddBoundParameter(null, position.ToString(CultureInfo.InvariantCulture), bindingResult);
                        position++;
                    }

                    ResetCurrentParameter(ref currentParameter, ref bindingResult);
                }
            }

            // Catch any hanging parameters at the end of the command
            if (currentParameter != null)
            {
                // Assume it was a switch
                AddSwitch(currentParameter.ParameterName, bindingResult);
            }
        }