private GetParameterByPosition ( int position ) : System.Management.Automation.CommandParameterInfo | ||
position | int | |
Результат | System.Management.Automation.CommandParameterInfo |
/// <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) { // TODO: Bind obj properties to ValueFromPipelinebyPropertyName parameters // TODO: If parameter has ValueFromRemainingArguments any unmatched arguments should be bound to this parameter as an array // TODO: If no parameter has ValueFromRemainingArguments any supplied parameters are unmatched then fail with exception if ((obj == null) && (Parameters.Count == 0)) { return; } // TODO: Perform analysis on passed arguments and obj to identify which parameter set to select for binding CommandParameterSetInfo paramSetInfo = _cmdletInfo.GetDefaultParameterSet(); if (obj != null) { var valueFromPipelineParameter = paramSetInfo.Parameters.Where(paramInfo => paramInfo.ValueFromPipeline).SingleOrDefault(); if (valueFromPipelineParameter != null) { BindArgument(valueFromPipelineParameter.Name, obj, valueFromPipelineParameter.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.LookupParameter(parameter.Name); if (paramInfo != null) { if (parameter.Value == null && paramInfo.ParameterType != typeof(SwitchParameter) && i < Parameters.Count - 1 && Parameters[i + 1].Name == null) { BindArgument(paramInfo.Name, Parameters[i + 1].Value, paramInfo.ParameterType); i++; } else { BindArgument(paramInfo.Name, parameter.Value, paramInfo.ParameterType); } } else { //TODO: Throw ParameterBindingException when implemented throw(new Exception("No parameter found matching '" + parameter.Name + "'")); } } } } }
/// <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); } } } } }