/// <summary>
        /// Initializes a new instance of the <see cref="ShowCommandParameterSetInfo"/> class
        /// with the specified <see cref="PSObject"/>.
        /// </summary>
        /// <param name="other">
        /// The object to wrap.
        /// </param>
        public ShowCommandParameterSetInfo(PSObject other)
        {
            if (other == null)
            {
                throw new ArgumentNullException(nameof(other));
            }

            this.Name      = other.Members["Name"].Value as string;
            this.IsDefault = (bool)(other.Members["IsDefault"].Value);
            var parameters = (other.Members["Parameters"].Value as PSObject).BaseObject as System.Collections.ArrayList;

            this.Parameters = ShowCommandCommandInfo.GetObjectEnumerable(parameters).Cast <PSObject>().Select(x => new ShowCommandParameterInfo(x)).ToArray();
        }
Exemple #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ShowCommandParameterInfo"/> class.
        /// Creates an instance of the ShowCommandParameterInfo class based on a PSObject object.
        /// </summary>
        /// <param name="other">
        /// The object to wrap.
        /// </param>
        public ShowCommandParameterInfo(PSObject other)
        {
            if (other == null)
            {
                throw new ArgumentNullException(nameof(other));
            }

            this.Name              = other.Members["Name"].Value as string;
            this.IsMandatory       = (bool)(other.Members["IsMandatory"].Value);
            this.ValueFromPipeline = (bool)(other.Members["ValueFromPipeline"].Value);
            this.HasParameterSet   = (bool)(other.Members["HasParameterSet"].Value);
            this.ParameterType     = new ShowCommandParameterType(other.Members["ParameterType"].Value as PSObject);
            this.Position          = (int)(other.Members["Position"].Value);
            if (this.HasParameterSet)
            {
                this.ValidParamSetValues = ShowCommandCommandInfo.GetObjectEnumerable((other.Members["ValidParamSetValues"].Value as PSObject).BaseObject as System.Collections.ArrayList).Cast <string>().ToList();
            }
        }
 internal object GetCommandViewModel(ShowCommandCommandInfo command, bool noCommonParameter, Dictionary <string, ShowCommandModuleInfo> importedModules, bool moduleQualify)
 {
     return(_graphicalHostReflectionWrapper.CallStaticMethod("GetCommandViewModel", command, noCommonParameter, importedModules, moduleQualify));
 }
        /// <summary>
        /// Creates a new CommandViewModel out the <paramref name="commandInfo"/>.
        /// </summary>
        /// <param name="module">Module to which the CommandViewModel will belong to.</param>
        /// <param name="commandInfo">Will showing command.</param>
        /// <param name="noCommonParameters">True to ommit displaying common parameter.</param>
        /// <exception cref="ArgumentNullException">If commandInfo is null</exception>
        /// <exception cref="RuntimeException">
        /// If could not create the CommandViewModel. For instance the ShowCommandCommandInfo corresponding to
        /// the following function will throw a RuntimeException when the ShowCommandCommandInfo Parameters
        /// are retrieved:
        /// function CrashMe ([I.Am.A.Type.That.Does.Not.Exist]$name) {}
        /// </exception>
        /// <returns>The CommandViewModel corresponding to commandInfo.</returns>
        internal static CommandViewModel GetCommandViewModel(ModuleViewModel module, ShowCommandCommandInfo commandInfo, bool noCommonParameters)
        {
            if (commandInfo == null)
            {
                throw new ArgumentNullException("commandInfo");
            }

            CommandViewModel returnValue = new CommandViewModel();

            returnValue.commandInfo        = commandInfo;
            returnValue.noCommonParameters = noCommonParameters;
            returnValue.parentModule       = module;

            Dictionary <string, ParameterViewModel> commonParametersTable = new Dictionary <string, ParameterViewModel>();

            foreach (ShowCommandParameterSetInfo parameterSetInfo in commandInfo.ParameterSets)
            {
                if (parameterSetInfo.IsDefault)
                {
                    returnValue.defaultParameterSetName = parameterSetInfo.Name;
                }

                List <ParameterViewModel> parametersForParameterSet = new List <ParameterViewModel>();
                foreach (ShowCommandParameterInfo parameterInfo in parameterSetInfo.Parameters)
                {
                    bool isCommon = Cmdlet.CommonParameters.Contains(parameterInfo.Name);

                    if (isCommon)
                    {
                        if (!commonParametersTable.ContainsKey(parameterInfo.Name))
                        {
                            commonParametersTable.Add(parameterInfo.Name, new ParameterViewModel(parameterInfo, parameterSetInfo.Name));
                        }

                        continue;
                    }

                    parametersForParameterSet.Add(new ParameterViewModel(parameterInfo, parameterSetInfo.Name));
                }

                if (parametersForParameterSet.Count != 0)
                {
                    returnValue.ParameterSets.Add(new ParameterSetViewModel(parameterSetInfo.Name, parametersForParameterSet));
                }
            }

            List <ParameterViewModel> commonParametersList = commonParametersTable.Values.ToList <ParameterViewModel>();

            returnValue.comonParameters = new ParameterSetViewModel(string.Empty, commonParametersList);

            returnValue.parameterSets.Sort(returnValue.Compare);

            if (returnValue.parameterSets.Count > 0)
            {
                // Setting SelectedParameterSet will also set SelectedParameterSetAllMandatoryParametersHaveValues
                returnValue.SelectedParameterSet = returnValue.ParameterSets[0];
            }
            else
            {
                returnValue.SelectedParameterSetAllMandatoryParametersHaveValues = true;
            }

            returnValue.SetCommonParametersHeight();

            return(returnValue);
        }