private GetParameterByName ( string name ) : System.Management.Automation.CommandParameterInfo | ||
name | string | |
Результат | System.Management.Automation.CommandParameterInfo |
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); }
/// <summary> /// /// </summary> /// <param name="obj"></param> /// <remarks> /// All abount Cmdlet parameters: http://msdn2.microsoft.com/en-us/library/ms714433(VS.85).aspx /// </remarks> internal override void BindArguments(PSObject obj) { if ((obj == null) && (Parameters.Count == 0)) { return; } // TODO: bind the arguments to the parameters CommandParameterSetInfo paramSetInfo = _cmdletInfo.GetDefaultParameterSet(); // TODO: refer to the Command._ParameterSetName for a param set name if (obj != null) { foreach (CommandParameterInfo paramInfo in paramSetInfo.Parameters) { if (paramInfo.ValueFromPipeline) { BindArgument(paramInfo.Name, obj, paramInfo.ParameterType); } } } if (Parameters.Count > 0) { // bind by position location for (int i = 0; i < Parameters.Count; i++) { CommandParameterInfo paramInfo = null; CommandParameter parameter = Parameters[i]; if (string.IsNullOrEmpty(parameter.Name)) { paramInfo = paramSetInfo.GetParameterByPosition(i); if (paramInfo != null) { BindArgument(paramInfo.Name, parameter.Value, paramInfo.ParameterType); } } else { paramInfo = paramSetInfo.GetParameterByName(parameter.Name); if (paramInfo != null) { BindArgument(paramInfo.Name, parameter.Value, paramInfo.ParameterType); } } } } }
/// <summary> /// /// </summary> /// <param name="obj"></param> /// <remarks> /// All abount Cmdlet parameters: http://msdn2.microsoft.com/en-us/library/ms714433(VS.85).aspx /// </remarks> internal override void BindArguments(PSObject obj) { if ((obj == null) && (Parameters.Count == 0)) { return; } // TODO: bind the arguments to the parameters CommandParameterSetInfo paramSetInfo = _cmdletInfo.GetDefaultParameterSet(); // TODO: refer to the Command._ParameterSetName for a param set name if (obj != null) { foreach (CommandParameterInfo paramInfo in paramSetInfo.Parameters) { if (paramInfo.ValueFromPipeline) { // TODO: extract this into a method PropertyInfo pi = Command.GetType().GetProperty(paramInfo.Name, paramInfo.ParameterType); pi.SetValue(Command, obj, null); } } } if (Parameters.Count > 0) { // bind by position location for (int i = 0; i < Parameters.Count; i++) { CommandParameterInfo paramInfo = null; CommandParameter parameter = Parameters[i]; if (string.IsNullOrEmpty(parameter.Name)) { paramInfo = paramSetInfo.GetParameterByPosition(i); if (paramInfo != null) { // TODO: extract this into a method PropertyInfo pi = Command.GetType().GetProperty(paramInfo.Name, paramInfo.ParameterType); // TODO: make this generic if (pi.PropertyType == typeof(PSObject[])) { PSObject[] arr = new PSObject[] { PSObject.AsPSObject(Parameters[i].Value) }; pi.SetValue(Command, arr, null); } else if (pi.PropertyType == typeof(String[])) { String[] arr = new String[] { Parameters[i].Value.ToString() }; pi.SetValue(Command, arr, null); } else { pi.SetValue(Command, Parameters[i].Value, null); } } } else { paramInfo = paramSetInfo.GetParameterByName(parameter.Name); if (paramInfo != null) { // TODO: extract this into a method PropertyInfo pi = Command.GetType().GetProperty(paramInfo.Name, paramInfo.ParameterType); pi.SetValue(Command, Parameters[i].Value, null); } } } } }