/// <summary> /// Creates an instance of the ShowCommandParameterSetInfo class based on a PSObject object /// </summary> /// /// <param name="other"> /// The object to wrap. /// </param> public ShowCommandParameterSetInfo(PSObject other) { if (null == other) { throw new ArgumentNullException("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(); }
/// <summary> /// 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 (null == other) { throw new ArgumentNullException("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); }
private static object GetCommandViewModel(ShowCommandCommandInfo command, bool noCommonParameter, Dictionary<string, ShowCommandModuleInfo> importedModules, bool moduleQualify) { CommandViewModel returnValue = CommandViewModel.GetCommandViewModel(new ModuleViewModel(command.ModuleName, importedModules), command, noCommonParameter); returnValue.ModuleQualifyCommandName = moduleQualify; return returnValue; }
/// <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 omit 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>(); bool isWorkflow = (commandInfo.CommandType & CommandTypes.Workflow) != 0; 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); bool isCommonWorkflow = isWorkflow && SMAI.CommonParameters.CommonWorkflowParameters.Contains(parameterInfo.Name, StringComparer.OrdinalIgnoreCase); if (isCommon || isCommonWorkflow) { 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; }