/// <summary> /// This method gets a backup of the default value of a parameter. /// Derived classes may override this method to get the default parameter /// value in a different way. /// </summary> /// /// <param name="name"> /// The name of the parameter to get the default value of. /// </param> /// /// <returns> /// The value of the parameter specified by name. /// </returns> /// /// <exception cref="ParameterBindingParameterDefaultValueException"> /// If the parameter binder encounters an error getting the default value. /// </exception> /// internal object GetDefaultParameterValue(string name) { MergedCompiledCommandParameter matchingParameter = BindableParameters.GetMatchingParameter( name, false, true, null); object result = null; try { switch (matchingParameter.BinderAssociation) { case ParameterBinderAssociation.DeclaredFormalParameters: result = DefaultParameterBinder.GetDefaultParameterValue(name); break; case ParameterBinderAssociation.CommonParameters: result = CommonParametersBinder.GetDefaultParameterValue(name); break; case ParameterBinderAssociation.ShouldProcessParameters: result = ShouldProcessParametersBinder.GetDefaultParameterValue(name); break; case ParameterBinderAssociation.DynamicParameters: if (_dynamicParameterBinder != null) { result = _dynamicParameterBinder.GetDefaultParameterValue(name); } break; } } catch (GetValueException getValueException) { ParameterBindingParameterDefaultValueException bindingError = new ParameterBindingParameterDefaultValueException( getValueException, ErrorCategory.ReadError, this.Command.MyInvocation, null, name, null, null, "ParameterBinderStrings", "GetDefaultValueFailed", getValueException.Message); throw bindingError; } return result; }
internal object GetDefaultParameterValue(string name) { MergedCompiledCommandParameter parameter = base.BindableParameters.GetMatchingParameter(name, false, true, null); object defaultParameterValue = null; try { switch (parameter.BinderAssociation) { case ParameterBinderAssociation.DeclaredFormalParameters: return base.DefaultParameterBinder.GetDefaultParameterValue(name); case ParameterBinderAssociation.DynamicParameters: if (this._dynamicParameterBinder != null) { defaultParameterValue = this._dynamicParameterBinder.GetDefaultParameterValue(name); } return defaultParameterValue; case ParameterBinderAssociation.CommonParameters: return this.CommonParametersBinder.GetDefaultParameterValue(name); case ParameterBinderAssociation.ShouldProcessParameters: return this.ShouldProcessParametersBinder.GetDefaultParameterValue(name); } return defaultParameterValue; } catch (GetValueException exception) { ParameterBindingParameterDefaultValueException exception2 = new ParameterBindingParameterDefaultValueException(exception, ErrorCategory.ReadError, this.Command.MyInvocation, null, name, null, null, "ParameterBinderStrings", "GetDefaultValueFailed", new object[] { exception.Message }); throw exception2; } return defaultParameterValue; }