示例#1
0
        private void AddNewArraySlotIfNeeded()
        {
            if (IsArray && (CurrentArrayIDEdited == -1 ||
                            CurrentArrayIDEdited >= CurrentArrayTextEntered.Count))
            {
                if (CurrentArrayIDEdited == -1)
                {
                    currentArrayIDEdited = 0;
                }

                CurrentArrayTextEntered.Add("");
                CurrentArrayValuesParsed.Add(null);
            }
        }
示例#2
0
        private void ComputeCurrentParameterValue(CommandConsoleWindow window)
        {
            if (CurrentParameterID == -1)
            {
                return;
            }

            LastParameterCompleted = CurrentParameterID;

            if (!IsArray)
            {
                TextEntered[CurrentParameterID] = CurrentTextEntered;

                object parsedObject = null;


                if (!CurrentParameterInfo.PreventDefaultValueUsage &&
                    CurrentTextEntered.IsNullOrEmpty())
                {
                    parsedObject = CurrentParameterInfo.DefaultValue;
                    if (CurrentAutoComplete != null)
                    {
                        if (CurrentAutoCompleteID == -1 || CurrentAutoCompleteID >= CurrentAutoComplete.Count)
                        {
                            for (int i = 0; i < CurrentAutoComplete.Count; i++)
                            {
                                if (CurrentAutoComplete.GetValue(i) != null &&
                                    CurrentAutoComplete.GetValue(i).ToString() == parsedObject.ToString())
                                {
                                    CurrentAutoCompleteID = i;
                                    break;
                                }
                            }
                        }
                        if (CurrentAutoCompleteID != -1 && CurrentAutoCompleteID < CurrentAutoComplete.Count)
                        {
                            parsedObject = CurrentAutoComplete.GetValue(CurrentAutoCompleteID);
                        }
                    }
                }
                else
                {
                    if (!Info.CommandParameterInfo[CurrentParameterID].ForceAutoCompleteUsage &&
                        CurrentAutoCompleteID == -1)
                    {
                        currentInterpreter.TryParse(CurrentTextEntered, out parsedObject);
                    }

                    if (IsAutoCompleteSuggestions &&
                        parsedObject == null &&
                        (Info.CommandParameterInfo[CurrentParameterID].ForceAutoCompleteUsage ||
                         CurrentAutoCompleteID != -1))
                    {
                        if (CurrentAutoCompleteID == -1)
                        {
                            CurrentAutoCompleteID = 0;
                        }

                        if (CurrentAutoComplete != null)
                        {
                            if (CurrentAutoComplete.Count <= CurrentAutoCompleteID)
                            {
                                CurrentAutoComplete.GenerateAndSortAutoComplete(CurrentTextEntered);
                            }

                            parsedObject = CurrentAutoComplete.GetValue(CurrentAutoCompleteID);
                            TextEntered[CurrentParameterID] =
                                CurrentAutoComplete.GetStringValue(CurrentAutoCompleteID);
                        }
                        else
                        {
                            parsedObject = CurrentParameterInfo.DefaultValue;
                        }
                    }
                }



                if (parsedObject == null)
                {
                    valuesParsed[CurrentParameterID] = TextEntered[CurrentParameterID]
                                                       .IsNullOrEmpty() && !CurrentParameterInfo.PreventDefaultValueUsage
                        ? Info.CommandParameterInfo[CurrentParameterID].DefaultValue
                        : null;
                }
                else
                {
                    valuesParsed[CurrentParameterID] = parsedObject;
                }
            }
            else
            {
                ComputeCurrentArrayVariable(window);
                if (CurrentArrayValuesParsed != null && CurrentArrayValuesParsed.Count > 0)
                {
                    if (!CurrentArrayValuesParsed.Contains(null))
                    {
                        Type elemType = CurrentParameterInfo.ParameterType.GetElementType();
                        if (elemType != null)
                        {
                            var obj = Array.CreateInstance(elemType,
                                                           CurrentArrayValuesParsed.Count);
                            for (int i = 0; i < CurrentArrayValuesParsed.Count; i++)
                            {
                                obj.SetValue(CurrentArrayValuesParsed[i], i);
                            }
                            valuesParsed[CurrentParameterID] = obj;
                        }
                        else
                        {
                            valuesParsed[CurrentParameterID] = null;
                        }
                    }
                    else
                    {
                        valuesParsed[CurrentParameterID] = null;
                    }
                    arrayValuesParsed[CurrentParameterID] = CurrentArrayValuesParsed;
                }
                else if (!CurrentParameterInfo.PreventDefaultValueUsage &&
                         CurrentParameterInfo.DefaultValue != null)
                {
                    valuesParsed[CurrentParameterID] = CurrentParameterInfo.DefaultValue;
                    Array ar = (Array)
                               CurrentParameterInfo.DefaultValue;

                    if (ar != null)
                    {
                        List <object> list = new List <object>();

                        foreach (object o in ar)
                        {
                            list.Add(o);
                        }

                        arrayValuesParsed[CurrentParameterID] = list;
                    }
                }
                else
                {
                    valuesParsed[CurrentParameterID]      = null;
                    arrayValuesParsed[CurrentParameterID] = CurrentArrayValuesParsed;
                }
            }
        }