Beispiel #1
0
        private Collection <AstParameterArgumentPair> BindPositionalParameter(Collection <AstParameterArgumentPair> unboundArguments, int validParameterSetFlags, int defaultParameterSetFlag, bool honorDefaultParameterSet)
        {
            Collection <AstParameterArgumentPair> nonPositionalArguments = new Collection <AstParameterArgumentPair>();

            if (this._bindingEffective && (unboundArguments.Count > 0))
            {
                SortedDictionary <int, Dictionary <MergedCompiledCommandParameter, PositionalCommandParameter> > dictionary;
                List <AstParameterArgumentPair> unboundArgumentsCollection = new List <AstParameterArgumentPair>(unboundArguments);
                try
                {
                    dictionary = ParameterBinderController.EvaluateUnboundPositionalParameters(this._unboundParameters, validParameterSetFlags);
                }
                catch (InvalidOperationException)
                {
                    this._bindingEffective = false;
                    return(nonPositionalArguments);
                }
                if (dictionary.Count == 0)
                {
                    return(unboundArguments);
                }
                int unboundArgumentsIndex = 0;
                foreach (Dictionary <MergedCompiledCommandParameter, PositionalCommandParameter> dictionary2 in dictionary.Values)
                {
                    if (dictionary2.Count != 0)
                    {
                        AstParameterArgumentPair argument = GetNextPositionalArgument(unboundArgumentsCollection, nonPositionalArguments, ref unboundArgumentsIndex);
                        if (argument == null)
                        {
                            break;
                        }
                        bool flag = false;
                        if ((honorDefaultParameterSet && (defaultParameterSetFlag != 0)) && ((validParameterSetFlags & defaultParameterSetFlag) != 0))
                        {
                            flag = this.BindPseudoPositionalParameterInSet(defaultParameterSetFlag, dictionary2, argument, false);
                        }
                        if (!flag)
                        {
                            flag = this.BindPseudoPositionalParameterInSet(validParameterSetFlags, dictionary2, argument, true);
                        }
                        if (!flag)
                        {
                            nonPositionalArguments.Add(argument);
                        }
                        else if (validParameterSetFlags != this._currentParameterSetFlag)
                        {
                            validParameterSetFlags = this._currentParameterSetFlag;
                            ParameterBinderController.UpdatePositionalDictionary(dictionary, validParameterSetFlags);
                        }
                    }
                }
                for (int i = unboundArgumentsIndex; i < unboundArgumentsCollection.Count; i++)
                {
                    nonPositionalArguments.Add(unboundArgumentsCollection[i]);
                }
            }
            return(nonPositionalArguments);
        }
Beispiel #2
0
 private static AstParameterArgumentPair GetNextPositionalArgument(List <AstParameterArgumentPair> unboundArgumentsCollection, Collection <AstParameterArgumentPair> nonPositionalArguments, ref int unboundArgumentsIndex)
 {
     while (unboundArgumentsIndex < unboundArgumentsCollection.Count)
     {
         AstParameterArgumentPair item = unboundArgumentsCollection[unboundArgumentsIndex++];
         if (!item.ParameterSpecified)
         {
             return(item);
         }
         nonPositionalArguments.Add(item);
     }
     return(null);
 }
Beispiel #3
0
        private IEnumerable <PSTypeName> GetInferredTypeFromScriptBlockParameter(AstParameterArgumentPair argument, CompletionContext context)
        {
            AstPair iteratorVariable0 = argument as AstPair;

            if ((iteratorVariable0 != null) && (iteratorVariable0.Argument is ScriptBlockExpressionAst))
            {
                ScriptBlockExpressionAst iteratorVariable1 = (ScriptBlockExpressionAst)iteratorVariable0.Argument;
                foreach (PSTypeName iteratorVariable2 in iteratorVariable1.ScriptBlock.GetInferredType(context))
                {
                    yield return(iteratorVariable2);
                }
            }
        }
Beispiel #4
0
        private bool ParseParameterArguments(CommandParameterAst paramAstAtCursor)
        {
            if (!this._bindingEffective)
            {
                return(this._bindingEffective);
            }
            Collection <AstParameterArgumentPair> collection = new Collection <AstParameterArgumentPair>();

            for (int i = 0; i < this._arguments.Count; i++)
            {
                AstParameterArgumentPair item = this._arguments[i];
                if (!item.ParameterSpecified || item.ArgumentSpecified)
                {
                    collection.Add(item);
                }
                else
                {
                    string parameterName = item.ParameterName;
                    MergedCompiledCommandParameter parameter = null;
                    try
                    {
                        bool tryExactMatching = item.Parameter != paramAstAtCursor;
                        parameter = this._bindableParameters.GetMatchingParameter(parameterName, false, tryExactMatching, null);
                    }
                    catch (ParameterBindingException)
                    {
                        this._ambiguousParameters.Add(item.Parameter);
                        goto Label_01F1;
                    }
                    if (parameter == null)
                    {
                        if (i < (this._arguments.Count - 1))
                        {
                            AstParameterArgumentPair pair2 = this._arguments[i + 1];
                            if (!pair2.ParameterSpecified && pair2.ArgumentSpecified)
                            {
                                this._arguments = null;
                                return(false);
                            }
                        }
                        this._parametersNotFound.Add(item.Parameter);
                    }
                    else if (parameter.Parameter.Type == typeof(SwitchParameter))
                    {
                        SwitchPair pair3 = new SwitchPair(item.Parameter);
                        collection.Add(pair3);
                    }
                    else if (i < (this._arguments.Count - 1))
                    {
                        AstParameterArgumentPair pair4 = this._arguments[i + 1];
                        if (pair4.ParameterSpecified)
                        {
                            try
                            {
                                if (this._bindableParameters.GetMatchingParameter(pair4.ParameterName, false, true, null) == null)
                                {
                                    AstPair pair5 = new AstPair(item.Parameter, pair4.Parameter);
                                    collection.Add(pair5);
                                    i++;
                                }
                                else
                                {
                                    FakePair pair6 = new FakePair(item.Parameter);
                                    collection.Add(pair6);
                                }
                                goto Label_01F1;
                            }
                            catch (ParameterBindingException)
                            {
                                FakePair pair7 = new FakePair(item.Parameter);
                                collection.Add(pair7);
                                goto Label_01F1;
                            }
                        }
                        AstPair pair8 = pair4 as AstPair;
                        AstPair pair9 = new AstPair(item.Parameter, (ExpressionAst)pair8.Argument);
                        collection.Add(pair9);
                        i++;
                    }
                    else
                    {
                        FakePair pair10 = new FakePair(item.Parameter);
                        collection.Add(pair10);
                    }
                    Label_01F1 :;
                }
            }
            this._arguments = collection;
            return(true);
        }
Beispiel #5
0
        private bool BindPseudoPositionalParameterInSet(int validParameterSetFlag, Dictionary <MergedCompiledCommandParameter, PositionalCommandParameter> nextPositionalParameters, AstParameterArgumentPair argument, bool typeConversion)
        {
            bool flag = false;
            int  num  = 0;

            foreach (PositionalCommandParameter parameter in nextPositionalParameters.Values)
            {
                foreach (ParameterSetSpecificMetadata metadata in parameter.ParameterSetData)
                {
                    if (((validParameterSetFlag & metadata.ParameterSetFlag) != 0) || metadata.IsInAllSets)
                    {
                        bool   flag2        = false;
                        string name         = parameter.Parameter.Parameter.Name;
                        Type   paramType    = parameter.Parameter.Parameter.Type;
                        Type   argumentType = argument.ArgumentType;
                        if (argumentType.Equals(typeof(object)))
                        {
                            flag = flag2 = true;
                        }
                        else if (IsTypeEquivalent(argumentType, paramType))
                        {
                            flag = flag2 = true;
                        }
                        else if (typeConversion)
                        {
                            flag = flag2 = true;
                        }
                        if (flag2)
                        {
                            num |= parameter.Parameter.Parameter.ParameterSetFlags;
                            this._unboundParameters.Remove(parameter.Parameter);
                            if (!this._boundParameters.ContainsKey(name))
                            {
                                this._boundParameters.Add(name, parameter.Parameter);
                                this._boundPositionalParameter.Add(name);
                            }
                            if (!this._boundArguments.ContainsKey(name))
                            {
                                this._boundArguments.Add(name, argument);
                            }
                            break;
                        }
                    }
                }
            }
            if (flag && (num != 0))
            {
                this._currentParameterSetFlag &= num;
            }
            return(flag);
        }
Beispiel #6
0
 private IEnumerable<PSTypeName> GetInferredTypeFromScriptBlockParameter(AstParameterArgumentPair argument, CompletionContext context)
 {
     AstPair iteratorVariable0 = argument as AstPair;
     if ((iteratorVariable0 != null) && (iteratorVariable0.Argument is ScriptBlockExpressionAst))
     {
         ScriptBlockExpressionAst iteratorVariable1 = (ScriptBlockExpressionAst) iteratorVariable0.Argument;
         foreach (PSTypeName iteratorVariable2 in iteratorVariable1.ScriptBlock.GetInferredType(context))
         {
             yield return iteratorVariable2;
         }
     }
 }
        private bool BindPseudoPositionalParameterInSet(
            uint validParameterSetFlag,
            Dictionary<MergedCompiledCommandParameter, PositionalCommandParameter> nextPositionalParameters,
            AstParameterArgumentPair argument,
            bool typeConversion)
        {
            bool bindingSuccessful = false;
            uint localParameterSetFlag = 0;
            foreach (PositionalCommandParameter parameter in nextPositionalParameters.Values)
            {
                foreach (ParameterSetSpecificMetadata parameterSetData in parameter.ParameterSetData)
                {
                    // Skip it if it's not in the specified parameter set
                    if ((validParameterSetFlag & parameterSetData.ParameterSetFlag) == 0 &&
                        !parameterSetData.IsInAllSets)
                    {
                        continue;
                    }

                    bool result = false;
                    string parameterName = parameter.Parameter.Parameter.Name;
                    Type parameterType = parameter.Parameter.Parameter.Type;
                    Type argumentType = argument.ArgumentType;

                    // 1. the argument type is not known(typeof(object)). we assume the binding always succeeds
                    // 2. the argument type is the same as parameter type, we assume the binding succeeds
                    // 3. the types are not the same, but we allow conversion, we assume the binding succeeds
                    // 4. the types are not the same, and conversion is not allowed, we assume the binding fails
                    if (argumentType == typeof(object))
                        bindingSuccessful = result = true;
                    else if (IsTypeEquivalent(argumentType, parameterType))
                        bindingSuccessful = result = true;
                    else if (typeConversion)
                        bindingSuccessful = result = true;

                    if (result)
                    {
                        localParameterSetFlag |= parameter.Parameter.Parameter.ParameterSetFlags;
                        _unboundParameters.Remove(parameter.Parameter);

                        if (!_boundParameters.ContainsKey(parameterName))
                        {
                            _boundParameters.Add(parameterName, parameter.Parameter);
                            _boundPositionalParameter.Add(parameterName);
                        }

                        if (!_boundArguments.ContainsKey(parameterName))
                        {
                            _boundArguments.Add(parameterName, argument);
                        }

                        break;
                    }
                }
            }

            // We preserve all posibilities
            if (bindingSuccessful && localParameterSetFlag != 0)
                _currentParameterSetFlag &= localParameterSetFlag;
            return bindingSuccessful;
        }
Beispiel #8
0
 private bool BindPseudoPositionalParameterInSet(int validParameterSetFlag, Dictionary<MergedCompiledCommandParameter, PositionalCommandParameter> nextPositionalParameters, AstParameterArgumentPair argument, bool typeConversion)
 {
     bool flag = false;
     int num = 0;
     foreach (PositionalCommandParameter parameter in nextPositionalParameters.Values)
     {
         foreach (ParameterSetSpecificMetadata metadata in parameter.ParameterSetData)
         {
             if (((validParameterSetFlag & metadata.ParameterSetFlag) != 0) || metadata.IsInAllSets)
             {
                 bool flag2 = false;
                 string name = parameter.Parameter.Parameter.Name;
                 Type paramType = parameter.Parameter.Parameter.Type;
                 Type argumentType = argument.ArgumentType;
                 if (argumentType.Equals(typeof(object)))
                 {
                     flag = flag2 = true;
                 }
                 else if (IsTypeEquivalent(argumentType, paramType))
                 {
                     flag = flag2 = true;
                 }
                 else if (typeConversion)
                 {
                     flag = flag2 = true;
                 }
                 if (flag2)
                 {
                     num |= parameter.Parameter.Parameter.ParameterSetFlags;
                     this._unboundParameters.Remove(parameter.Parameter);
                     if (!this._boundParameters.ContainsKey(name))
                     {
                         this._boundParameters.Add(name, parameter.Parameter);
                         this._boundPositionalParameter.Add(name);
                     }
                     if (!this._boundArguments.ContainsKey(name))
                     {
                         this._boundArguments.Add(name, argument);
                     }
                     break;
                 }
             }
         }
     }
     if (flag && (num != 0))
     {
         this._currentParameterSetFlag &= num;
     }
     return flag;
 }