public static CommandParameterSet Create(CommandParameterSetInfo paramSet) { return(new CommandParameterSet { Name = paramSet.Name, Parameters = paramSet.Parameters.Select(CommandParameter.Create).ToArray() }); }
/// <summary> /// Initializes a new instance of the <see cref="ShowCommandParameterSetInfo"/> class /// with the specified <see cref="CommandParameterSetInfo"/>. /// </summary> /// <param name="other"> /// The object to wrap. /// </param> public ShowCommandParameterSetInfo(CommandParameterSetInfo other) { if (other == null) { throw new ArgumentNullException(nameof(other)); } this.Name = other.Name; this.IsDefault = other.IsDefault; this.Parameters = other.Parameters.Select(static x => new ShowCommandParameterInfo(x)).ToArray();
/// <summary> /// Creates an instance of the ShowCommandParameterSetInfo class based on a CommandParameterSetInfo object /// </summary> /// /// <param name="other"> /// The object to wrap. /// </param> public ShowCommandParameterSetInfo(CommandParameterSetInfo other) { if (null == other) { throw new ArgumentNullException("other"); } this.Name = other.Name; this.IsDefault = other.IsDefault; this.Parameters = other.Parameters.Select(x => new ShowCommandParameterInfo(x)).ToArray(); }
public void VerboseCommonParameterAvailableFromGetCommandCmdlet() { CmdletInfo info = ReferenceHost.RawExecute("Get-Command") .Select(psObject => psObject.BaseObject as CmdletInfo) .FirstOrDefault(cmdletInfo => (cmdletInfo != null) && (cmdletInfo.Name == "Get-Command")); CommandParameterSetInfo parameterSetInfo = info.ParameterSets[0]; CommandParameterInfo verboseParameter = parameterSetInfo.Parameters.FirstOrDefault(parameter => parameter.Name == "Verbose"); Assert.IsNotNull(verboseParameter); Assert.IsTrue(verboseParameter.Aliases.Contains("vb")); }
private static void AddParameterTypeProperties(PSObject obj, Type parameterType, IEnumerable <Attribute> attributes) { PSObject obj2 = new PSObject(); obj2.TypeNames.Clear(); obj2.TypeNames.Add(string.Format(CultureInfo.InvariantCulture, "{0}#type", new object[] { TypeNameForDefaultHelp })); string parameterTypeString = CommandParameterSetInfo.GetParameterTypeString(parameterType, attributes); obj2.Properties.Add(new PSNoteProperty("name", parameterTypeString)); obj.Properties.Add(new PSNoteProperty("type", obj2)); }
/// <summary> /// Adds the parameterType properties. /// </summary> /// <param name="obj">HelpInfo object.</param> /// <param name="parameterType">The type of a parameter.</param> /// <param name="attributes">The attributes of the parameter (needed to look for PSTypeName).</param> private static void AddParameterTypeProperties(PSObject obj, Type parameterType, IEnumerable <Attribute> attributes) { PSObject mshObject = new PSObject(); mshObject.TypeNames.Clear(); mshObject.TypeNames.Add(string.Format(CultureInfo.InvariantCulture, "{0}#type", DefaultCommandHelpObjectBuilder.TypeNameForDefaultHelp)); var parameterTypeString = CommandParameterSetInfo.GetParameterTypeString(parameterType, attributes); mshObject.Properties.Add(new PSNoteProperty("name", parameterTypeString)); obj.Properties.Add(new PSNoteProperty("type", mshObject)); }
public void ReflectionAttributes() { CommandParameterSetInfo allSet = info.GetParameterSetByName(ParameterAttribute.AllParameterSets); Assert.IsNotNull(allSet); var nameParam = allSet.GetParameterByName("Name"); Assert.IsNotNull(nameParam); Assert.AreEqual(2, nameParam.Attributes.Count); Assert.AreEqual(1, nameParam.Attributes.Where(a => a is AliasAttribute).Count()); Assert.AreEqual(1, nameParam.Attributes.Where(a => a is ParameterAttribute).Count()); }
/// <summary> /// Constructs an instance of a ParameterSetSignature /// </summary> /// <param name="commandParamInfoSet">Collection of parameter info</param> public ParameterSetSignature(CommandParameterSetInfo commandParamInfoSet) { List <ParameterInfo> parameterInfo = new List <ParameterInfo>(); foreach (CommandParameterInfo commandParameterInfo in commandParamInfoSet.Parameters) { if (!commonParameterNames.ContainsKey(commandParameterInfo.Name)) { parameterInfo.Add(new ParameterInfo(commandParameterInfo)); } } SignatureText = commandParamInfoSet.ToString(); Parameters = parameterInfo.ToArray(); }
public void ReflectionAliases() { CommandParameterSetInfo allSet = info.GetParameterSetByName(ParameterAttribute.AllParameterSets); Assert.IsNotNull(allSet); var nameParam = allSet.GetParameterByName("Name"); Assert.IsNotNull(nameParam); Assert.AreEqual(3, nameParam.Aliases.Count); Assert.Contains("FullName", nameParam.Aliases); Assert.Contains("fn", nameParam.Aliases); Assert.Contains("identity", nameParam.Aliases); }
public void ReflectionParameters() { var numCommon = CommonCmdletParameters.ParameterDiscovery.AllParameters.Count; CommandParameterSetInfo allSet = info.GetParameterSetByName(ParameterAttribute.AllParameterSets); CommandParameterSetInfo fileSet = info.GetParameterSetByName("File"); CommandParameterSetInfo variableSet = info.GetParameterSetByName("Variable"); Assert.AreEqual(3 + numCommon, allSet.Parameters.Count); Assert.AreEqual(4 + numCommon, fileSet.Parameters.Count); Assert.AreEqual(5 + numCommon, variableSet.Parameters.Count); Assert.IsNotNull(allSet); Assert.IsNotNull(fileSet); Assert.IsNotNull(variableSet); Assert.IsNull(info.GetParameterSetByName("TheseShouldBeSkipped")); CheckForAllSetsParameters(allSet); CheckForAllSetsParameters(fileSet); CheckForAllSetsParameters(variableSet); CommandParameterInfo filePathParam = fileSet.GetParameterByName("FilePath"); Assert.IsNotNull(filePathParam); Assert.AreEqual("FilePath", filePathParam.Name); Assert.AreEqual(3, filePathParam.Position); Assert.AreEqual(true, filePathParam.IsMandatory); CommandParameterInfo variableParam = variableSet.GetParameterByName("Variable"); Assert.IsNotNull(variableParam); Assert.AreEqual("Variable", variableParam.Name); Assert.AreEqual(0, variableParam.Position); Assert.AreEqual(true, variableParam.IsMandatory); CommandParameterInfo constVarParam = variableSet.GetParameterByName("ConstVar"); Assert.IsNotNull(constVarParam); Assert.AreEqual("ConstVar", constVarParam.Name); Assert.AreEqual(-1, constVarParam.Position); Assert.AreEqual(false, constVarParam.IsMandatory); CommandParameterInfo ageParam = fileSet.GetParameterByName("Age"); Assert.IsNull(ageParam); }
private static void AddParameterValueProperties(PSObject obj, Type parameterType, IEnumerable <Attribute> attributes) { PSObject obj2; if (parameterType != null) { Nullable.GetUnderlyingType(parameterType); obj2 = new PSObject(string.Copy(CommandParameterSetInfo.GetParameterTypeString(parameterType, attributes))); obj2.Properties.Add(new PSNoteProperty("variableLength", parameterType.IsArray)); } else { obj2 = new PSObject("System.Object"); obj2.Properties.Add(new PSNoteProperty("variableLength", StringUtil.Format(HelpDisplayStrings.FalseShort, new object[0]))); } obj2.Properties.Add(new PSNoteProperty("required", "true")); obj.Properties.Add(new PSNoteProperty("parameterValue", obj2)); }
/// <summary> /// Adds the parameterValue properties. /// </summary> /// <param name="obj">HelpInfo object.</param> /// <param name="parameterType">The type of a parameter.</param> /// <param name="attributes">The attributes of the parameter (needed to look for PSTypeName).</param> private static void AddParameterValueProperties(PSObject obj, Type parameterType, IEnumerable <Attribute> attributes) { PSObject mshObject; if (parameterType != null) { Type type = Nullable.GetUnderlyingType(parameterType) ?? parameterType; var parameterTypeString = CommandParameterSetInfo.GetParameterTypeString(parameterType, attributes); mshObject = new PSObject(parameterTypeString); mshObject.Properties.Add(new PSNoteProperty("variableLength", parameterType.IsArray)); } else { mshObject = new PSObject("System.Object"); mshObject.Properties.Add(new PSNoteProperty("variableLength", StringUtil.Format(HelpDisplayStrings.FalseShort))); } mshObject.Properties.Add(new PSNoteProperty("required", "true")); obj.Properties.Add(new PSNoteProperty("parameterValue", mshObject)); }
private void CheckForAllSetsParameters(CommandParameterSetInfo set) { CommandParameterInfo inputObjectParam = set.GetParameterByName("InputObject"); Assert.IsNotNull(inputObjectParam); Assert.AreEqual("InputObject", inputObjectParam.Name); Assert.AreEqual(-1, inputObjectParam.Position); Assert.AreEqual(false, inputObjectParam.IsMandatory); CommandParameterInfo nameParam = set.GetParameterByName("Name"); Assert.IsNotNull(nameParam); Assert.AreEqual("Name", nameParam.Name); Assert.AreEqual(1, nameParam.Position); Assert.AreEqual(false, nameParam.IsMandatory); CommandParameterInfo recurseParam = set.GetParameterByName("Recurse"); Assert.IsNotNull(recurseParam); Assert.AreEqual("Recurse", recurseParam.Name); Assert.AreEqual(-1, recurseParam.Position); Assert.AreEqual(false, recurseParam.IsMandatory); }
public void ReflectionParameters() { CommandParameterSetInfo allSet = info.GetParameterSetByName(ParameterAttribute.AllParameterSets); CommandParameterSetInfo fileSet = info.GetParameterSetByName("File"); CommandParameterSetInfo variableSet = info.GetParameterSetByName("Variable"); Assert.AreEqual(3, allSet.Parameters.Count); Assert.AreEqual(4, fileSet.Parameters.Count); Assert.AreEqual(4, variableSet.Parameters.Count); Assert.IsNotNull(allSet); Assert.IsNotNull(fileSet); Assert.IsNotNull(variableSet); Assert.IsNull(info.GetParameterSetByName("TheseShouldBeSkipped")); CheckForAllSetsParameters(allSet); CheckForAllSetsParameters(fileSet); CheckForAllSetsParameters(variableSet); CommandParameterInfo filePathParam = fileSet.GetParameterByName("FilePath"); Assert.IsNotNull(filePathParam); Assert.AreEqual("FilePath", filePathParam.Name); Assert.AreEqual(0, filePathParam.Position); Assert.AreEqual(true, filePathParam.IsMandatory); CommandParameterInfo variableParam = variableSet.GetParameterByName("Variable"); Assert.IsNotNull(variableParam); Assert.AreEqual("Variable", variableParam.Name); Assert.AreEqual(-1, variableParam.Position); Assert.AreEqual(true, variableParam.IsMandatory); CommandParameterInfo ageParam = fileSet.GetParameterByName("Age"); Assert.IsNull(ageParam); }