private bool BindUnboundParametersForBindingStateInParameterSet( PSObject inputToOperateOn, CurrentlyBinding currentlyBinding, uint validParameterSets) { bool aParameterWasBound = false; // For all unbound parameters in the parameter set, see if we can bind // from the input object directly from pipeline without type coercion. // // We loop the unbound parameters in reversed order, so that we can move // items from the unboundParameters collection to the boundParameters // collection as we process, without the need to make a copy of the // unboundParameters collection. // // We used to make a copy of UnboundParameters and loop from the head of the // list. Now we are processing the unbound parameters from the end of the list. // This change should NOT be a breaking change. The 'validParameterSets' in // this method never changes, so no matter we start from the head or the end of // the list, every unbound parameter in the list that takes pipeline input and // satisfy the 'validParameterSets' will be bound. If parameters from more than // one sets got bound, then "parameter set cannot be resolved" error will be thrown, // which is expected. for (int i = UnboundParameters.Count - 1; i >= 0; i--) { var parameter = UnboundParameters[i]; // if the parameter is never a pipeline parameter, don't consider it if (!parameter.Parameter.IsPipelineParameterInSomeParameterSet) continue; // if the parameter is not in the specified parameter set, don't consider it if ((validParameterSets & parameter.Parameter.ParameterSetFlags) == 0 && !parameter.Parameter.IsInAllSets) { continue; } // Get the appropriate parameter set data var parameterSetData = parameter.Parameter.GetMatchingParameterSetData(validParameterSets); bool bindResult = false; foreach (ParameterSetSpecificMetadata parameterSetMetadata in parameterSetData) { // In the first phase we try to bind the value from the pipeline without // type coercion if (currentlyBinding == CurrentlyBinding.ValueFromPipelineNoCoercion && parameterSetMetadata.ValueFromPipeline) { bindResult = BindValueFromPipeline(inputToOperateOn, parameter, ParameterBindingFlags.None); } // In the next phase we try binding the value from the pipeline by matching // the property name else if (currentlyBinding == CurrentlyBinding.ValueFromPipelineByPropertyNameNoCoercion && parameterSetMetadata.ValueFromPipelineByPropertyName && inputToOperateOn != null) { bindResult = BindValueFromPipelineByPropertyName(inputToOperateOn, parameter, ParameterBindingFlags.None); } // The third step is to attempt to bind the value from the pipeline with // type coercion. else if (currentlyBinding == CurrentlyBinding.ValueFromPipelineWithCoercion && parameterSetMetadata.ValueFromPipeline) { bindResult = BindValueFromPipeline(inputToOperateOn, parameter, ParameterBindingFlags.ShouldCoerceType); } // The final step is to attempt to bind the value from the pipeline by matching // the property name else if (currentlyBinding == CurrentlyBinding.ValueFromPipelineByPropertyNameWithCoercion && parameterSetMetadata.ValueFromPipelineByPropertyName && inputToOperateOn != null) { bindResult = BindValueFromPipelineByPropertyName(inputToOperateOn, parameter, ParameterBindingFlags.ShouldCoerceType); } if (bindResult) { aParameterWasBound = true; break; } } } return aParameterWasBound; }
private bool BindUnboundParametersForBindingStateInParameterSet(PSObject inputToOperateOn, CurrentlyBinding currentlyBinding, ref int validParameterSets) { bool flag = false; List<MergedCompiledCommandParameter> list = new List<MergedCompiledCommandParameter>(base.UnboundParameters); foreach (MergedCompiledCommandParameter parameter in list) { if (parameter.Parameter.IsPipelineParameterInSomeParameterSet && (((validParameterSets & parameter.Parameter.ParameterSetFlags) != 0) || parameter.Parameter.IsInAllSets)) { IEnumerable<ParameterSetSpecificMetadata> matchingParameterSetData = parameter.Parameter.GetMatchingParameterSetData(validParameterSets); bool flag2 = false; foreach (ParameterSetSpecificMetadata metadata in matchingParameterSetData) { if ((currentlyBinding == CurrentlyBinding.ValueFromPipelineNoCoercion) && metadata.ValueFromPipeline) { flag2 = this.BindValueFromPipeline(inputToOperateOn, parameter, ParameterBindingFlags.None); } else if (((currentlyBinding == CurrentlyBinding.ValueFromPipelineByPropertyNameNoCoercion) && metadata.ValueFromPipelineByPropertyName) && (inputToOperateOn != null)) { flag2 = this.BindValueFromPipelineByPropertyName(inputToOperateOn, parameter, ParameterBindingFlags.None); } else if ((currentlyBinding == CurrentlyBinding.ValueFromPipelineWithCoercion) && metadata.ValueFromPipeline) { flag2 = this.BindValueFromPipeline(inputToOperateOn, parameter, ParameterBindingFlags.ShouldCoerceType); } else if (((currentlyBinding == CurrentlyBinding.ValueFromPipelineByPropertyNameWithCoercion) && metadata.ValueFromPipelineByPropertyName) && (inputToOperateOn != null)) { flag2 = this.BindValueFromPipelineByPropertyName(inputToOperateOn, parameter, ParameterBindingFlags.ShouldCoerceType); } if (flag2) { flag = true; break; } } } } return flag; }
private bool BindUnboundParametersForBindingState( PSObject inputToOperateOn, CurrentlyBinding currentlyBinding, uint validParameterSets) { bool aParameterWasBound = false; // First check to see if the default parameter set has been defined and if it // is still valid. uint defaultParameterSetFlag = _commandMetadata.DefaultParameterSetFlag; if (defaultParameterSetFlag != 0 && (validParameterSets & defaultParameterSetFlag) != 0) { // Since we have a default parameter set and it is still valid, give preference to the // parameters in the default set. aParameterWasBound = BindUnboundParametersForBindingStateInParameterSet( inputToOperateOn, currentlyBinding, defaultParameterSetFlag); if (!aParameterWasBound) { validParameterSets &= ~(defaultParameterSetFlag); } } if (!aParameterWasBound) { // Since nothing was bound for the default parameter set, try all // the other parameter sets that are still valid. aParameterWasBound = BindUnboundParametersForBindingStateInParameterSet( inputToOperateOn, currentlyBinding, validParameterSets); } s_tracer.WriteLine("aParameterWasBound = {0}", aParameterWasBound); return aParameterWasBound; }
private bool BindUnboundParametersForBindingState(PSObject inputToOperateOn, CurrentlyBinding currentlyBinding, ref int validParameterSets) { bool flag = false; int num = validParameterSets; int defaultParameterSetFlag = this._commandMetadata.DefaultParameterSetFlag; if ((defaultParameterSetFlag != 0) && ((validParameterSets & defaultParameterSetFlag) != 0)) { int num3 = defaultParameterSetFlag; flag = this.BindUnboundParametersForBindingStateInParameterSet(inputToOperateOn, currentlyBinding, ref num3); if (!flag) { num &= ~defaultParameterSetFlag; } else { num = defaultParameterSetFlag; } } if (!flag) { flag = this.BindUnboundParametersForBindingStateInParameterSet(inputToOperateOn, currentlyBinding, ref num); if (flag) { validParameterSets = num; } } _tracer.WriteLine("aParameterWasBound = {0}", new object[] { flag }); return flag; }