protected static bool AddDynamicParameter(Type type, string name, ref RuntimeDefinedParameterDictionary dic, bool valueFromPipeline) { bool paramAdded = false; if (dic == null || !dic.ContainsKey(name)) { var attrib = new ParameterAttribute { Mandatory = false, ValueFromPipeline = valueFromPipeline, }; var param = new RuntimeDefinedParameter { IsSet = false, Name = name, ParameterType = type }; param.Attributes.Add(attrib); if (dic == null) { dic = new RuntimeDefinedParameterDictionary(); } dic.Add(name, param); paramAdded = true; } return paramAdded; }
protected object CreateExtensionImageRegisterDynamicParameters() { dynamicParameters = new RuntimeDefinedParameterDictionary(); var pParameters = new RuntimeDefinedParameter(); pParameters.Name = "ExtensionImageRegisterParameters"; pParameters.ParameterType = typeof(Microsoft.WindowsAzure.Management.Compute.Models.ExtensionImageRegisterParameters); pParameters.Attributes.Add(new ParameterAttribute { ParameterSetName = "InvokeByDynamicParameters", Position = 1, Mandatory = true }); pParameters.Attributes.Add(new AllowNullAttribute()); dynamicParameters.Add("ExtensionImageRegisterParameters", pParameters); var pArgumentList = new RuntimeDefinedParameter(); pArgumentList.Name = "ArgumentList"; pArgumentList.ParameterType = typeof(object[]); pArgumentList.Attributes.Add(new ParameterAttribute { ParameterSetName = "InvokeByStaticParameters", Position = 2, Mandatory = true }); pArgumentList.Attributes.Add(new AllowNullAttribute()); dynamicParameters.Add("ArgumentList", pArgumentList); return dynamicParameters; }
protected object CreateHostedServiceListExtensionsDynamicParameters() { dynamicParameters = new RuntimeDefinedParameterDictionary(); var pServiceName = new RuntimeDefinedParameter(); pServiceName.Name = "ServiceName"; pServiceName.ParameterType = typeof(System.String); pServiceName.Attributes.Add(new ParameterAttribute { ParameterSetName = "InvokeByDynamicParameters", Position = 1, Mandatory = true }); pServiceName.Attributes.Add(new AllowNullAttribute()); dynamicParameters.Add("ServiceName", pServiceName); var pArgumentList = new RuntimeDefinedParameter(); pArgumentList.Name = "ArgumentList"; pArgumentList.ParameterType = typeof(object[]); pArgumentList.Attributes.Add(new ParameterAttribute { ParameterSetName = "InvokeByStaticParameters", Position = 2, Mandatory = true }); pArgumentList.Attributes.Add(new AllowNullAttribute()); dynamicParameters.Add("ArgumentList", pArgumentList); return dynamicParameters; }
protected object CreateVirtualMachineScaleSetListDynamicParameters() { dynamicParameters = new RuntimeDefinedParameterDictionary(); var pResourceGroupName = new RuntimeDefinedParameter(); pResourceGroupName.Name = "ResourceGroupName"; pResourceGroupName.ParameterType = typeof(string); pResourceGroupName.Attributes.Add(new ParameterAttribute { ParameterSetName = "InvokeByDynamicParameters", Position = 1, Mandatory = true }); pResourceGroupName.Attributes.Add(new AllowNullAttribute()); dynamicParameters.Add("ResourceGroupName", pResourceGroupName); var pArgumentList = new RuntimeDefinedParameter(); pArgumentList.Name = "ArgumentList"; pArgumentList.ParameterType = typeof(object[]); pArgumentList.Attributes.Add(new ParameterAttribute { ParameterSetName = "InvokeByStaticParameters", Position = 2, Mandatory = true }); pArgumentList.Attributes.Add(new AllowNullAttribute()); dynamicParameters.Add("ArgumentList", pArgumentList); return dynamicParameters; }
protected object CreateVirtualMachineOSImageGetDetailsDynamicParameters() { dynamicParameters = new RuntimeDefinedParameterDictionary(); var pImageName = new RuntimeDefinedParameter(); pImageName.Name = "ImageName"; pImageName.ParameterType = typeof(System.String); pImageName.Attributes.Add(new ParameterAttribute { ParameterSetName = "InvokeByDynamicParameters", Position = 1, Mandatory = true }); pImageName.Attributes.Add(new AllowNullAttribute()); dynamicParameters.Add("ImageName", pImageName); var pArgumentList = new RuntimeDefinedParameter(); pArgumentList.Name = "ArgumentList"; pArgumentList.ParameterType = typeof(object[]); pArgumentList.Attributes.Add(new ParameterAttribute { ParameterSetName = "InvokeByStaticParameters", Position = 2, Mandatory = true }); pArgumentList.Attributes.Add(new AllowNullAttribute()); dynamicParameters.Add("ArgumentList", pArgumentList); return dynamicParameters; }
protected object CreateVirtualMachineScaleSetVMListNextDynamicParameters() { dynamicParameters = new RuntimeDefinedParameterDictionary(); var pNextPageLink = new RuntimeDefinedParameter(); pNextPageLink.Name = "NextPageLink"; pNextPageLink.ParameterType = typeof(string); pNextPageLink.Attributes.Add(new ParameterAttribute { ParameterSetName = "InvokeByDynamicParameters", Position = 1, Mandatory = true }); pNextPageLink.Attributes.Add(new AllowNullAttribute()); dynamicParameters.Add("NextPageLink", pNextPageLink); var pArgumentList = new RuntimeDefinedParameter(); pArgumentList.Name = "ArgumentList"; pArgumentList.ParameterType = typeof(object[]); pArgumentList.Attributes.Add(new ParameterAttribute { ParameterSetName = "InvokeByStaticParameters", Position = 2, Mandatory = true }); pArgumentList.Attributes.Add(new AllowNullAttribute()); dynamicParameters.Add("ArgumentList", pArgumentList); return dynamicParameters; }
internal object GetDefaultScriptParameterValue(RuntimeDefinedParameter parameter, IList implicitUsingParameters = null) { object obj2 = parameter.Value; Compiler.DefaultValueExpressionWrapper wrapper = obj2 as Compiler.DefaultValueExpressionWrapper; if (wrapper != null) { obj2 = wrapper.GetValue(base.Context, this.Script.SessionStateInternal, implicitUsingParameters); } return obj2; }
protected object CreateVirtualMachineRestartDynamicParameters() { dynamicParameters = new RuntimeDefinedParameterDictionary(); var pServiceName = new RuntimeDefinedParameter(); pServiceName.Name = "ServiceName"; pServiceName.ParameterType = typeof(System.String); pServiceName.Attributes.Add(new ParameterAttribute { ParameterSetName = "InvokeByDynamicParameters", Position = 1, Mandatory = true }); pServiceName.Attributes.Add(new AllowNullAttribute()); dynamicParameters.Add("ServiceName", pServiceName); var pDeploymentName = new RuntimeDefinedParameter(); pDeploymentName.Name = "DeploymentName"; pDeploymentName.ParameterType = typeof(System.String); pDeploymentName.Attributes.Add(new ParameterAttribute { ParameterSetName = "InvokeByDynamicParameters", Position = 2, Mandatory = true }); pDeploymentName.Attributes.Add(new AllowNullAttribute()); dynamicParameters.Add("DeploymentName", pDeploymentName); var pVirtualMachineName = new RuntimeDefinedParameter(); pVirtualMachineName.Name = "VirtualMachineName"; pVirtualMachineName.ParameterType = typeof(System.String); pVirtualMachineName.Attributes.Add(new ParameterAttribute { ParameterSetName = "InvokeByDynamicParameters", Position = 3, Mandatory = true }); pVirtualMachineName.Attributes.Add(new AllowNullAttribute()); dynamicParameters.Add("VirtualMachineName", pVirtualMachineName); var pArgumentList = new RuntimeDefinedParameter(); pArgumentList.Name = "ArgumentList"; pArgumentList.ParameterType = typeof(object[]); pArgumentList.Attributes.Add(new ParameterAttribute { ParameterSetName = "InvokeByStaticParameters", Position = 4, Mandatory = true }); pArgumentList.Attributes.Add(new AllowNullAttribute()); dynamicParameters.Add("ArgumentList", pArgumentList); return dynamicParameters; }
protected object CreateVirtualMachineStartRolesDynamicParameters() { dynamicParameters = new RuntimeDefinedParameterDictionary(); var pServiceName = new RuntimeDefinedParameter(); pServiceName.Name = "ServiceName"; pServiceName.ParameterType = typeof(System.String); pServiceName.Attributes.Add(new ParameterAttribute { ParameterSetName = "InvokeByDynamicParameters", Position = 1, Mandatory = true }); pServiceName.Attributes.Add(new AllowNullAttribute()); dynamicParameters.Add("ServiceName", pServiceName); var pDeploymentName = new RuntimeDefinedParameter(); pDeploymentName.Name = "DeploymentName"; pDeploymentName.ParameterType = typeof(System.String); pDeploymentName.Attributes.Add(new ParameterAttribute { ParameterSetName = "InvokeByDynamicParameters", Position = 2, Mandatory = true }); pDeploymentName.Attributes.Add(new AllowNullAttribute()); dynamicParameters.Add("DeploymentName", pDeploymentName); var pParameters = new RuntimeDefinedParameter(); pParameters.Name = "VirtualMachineStartRolesParameters"; pParameters.ParameterType = typeof(Microsoft.WindowsAzure.Management.Compute.Models.VirtualMachineStartRolesParameters); pParameters.Attributes.Add(new ParameterAttribute { ParameterSetName = "InvokeByDynamicParameters", Position = 3, Mandatory = true }); pParameters.Attributes.Add(new AllowNullAttribute()); dynamicParameters.Add("VirtualMachineStartRolesParameters", pParameters); var pArgumentList = new RuntimeDefinedParameter(); pArgumentList.Name = "ArgumentList"; pArgumentList.ParameterType = typeof(object[]); pArgumentList.Attributes.Add(new ParameterAttribute { ParameterSetName = "InvokeByStaticParameters", Position = 4, Mandatory = true }); pArgumentList.Attributes.Add(new AllowNullAttribute()); dynamicParameters.Add("ArgumentList", pArgumentList); return dynamicParameters; }
/// <summary> /// Constructs an instance of the CompiledCommandAttribute using the specified /// runtime-defined parameter /// </summary> /// /// <param name="runtimeDefinedParameter"> /// A runtime defined parameter that contains the definition of the parameter and its /// metadata. /// </param> /// /// <param name="processingDynamicParameters"> /// True if dynamic parameters are being processed, or false otherwise. /// </param> /// /// <exception cref="ArgumentNullException"> /// If <paramref name="runtimeDefinedParameter"/> is null. /// </exception> /// /// <exception cref="MetadataException"> /// If the parameter has more than one <see cref="ParameterAttribute">ParameterAttribute</see> /// that defines the same parameter-set name. /// </exception> /// internal CompiledCommandParameter(RuntimeDefinedParameter runtimeDefinedParameter, bool processingDynamicParameters) { if (runtimeDefinedParameter == null) { throw PSTraceSource.NewArgumentNullException("runtimeDefinedParameter"); } this.Name = runtimeDefinedParameter.Name; this.Type = runtimeDefinedParameter.ParameterType; this.IsDynamic = processingDynamicParameters; this.CollectionTypeInformation = new ParameterCollectionTypeInformation(runtimeDefinedParameter.ParameterType); this.CompiledAttributes = new Collection<Attribute>(); this.ParameterSetData = new Dictionary<string, ParameterSetSpecificMetadata>(StringComparer.OrdinalIgnoreCase); Collection<ValidateArgumentsAttribute> validationAttributes = null; Collection<ArgumentTransformationAttribute> argTransformationAttributes = null; string[] aliases = null; // First, process attributes that aren't type conversions foreach (Attribute attribute in runtimeDefinedParameter.Attributes) { if (!(attribute is ArgumentTypeConverterAttribute)) { ProcessAttribute(runtimeDefinedParameter.Name, attribute, ref validationAttributes, ref argTransformationAttributes, ref aliases); } } // If this is a PSCredential type and they haven't added any argument transformation attributes, // add one for credential transformation if ((this.Type == typeof(PSCredential)) && argTransformationAttributes == null) { ProcessAttribute(runtimeDefinedParameter.Name, new CredentialAttribute(), ref validationAttributes, ref argTransformationAttributes, ref aliases); } // Now process type converters foreach (ArgumentTypeConverterAttribute attribute in runtimeDefinedParameter.Attributes.OfType<ArgumentTypeConverterAttribute>()) { ProcessAttribute(runtimeDefinedParameter.Name, attribute, ref validationAttributes, ref argTransformationAttributes, ref aliases); } this.ValidationAttributes = validationAttributes == null ? Utils.EmptyArray<ValidateArgumentsAttribute>() : validationAttributes.ToArray(); this.ArgumentTransformationAttributes = argTransformationAttributes == null ? Utils.EmptyArray<ArgumentTransformationAttribute>() : argTransformationAttributes.ToArray(); this.Aliases = aliases == null ? Utils.EmptyArray<string>() : aliases.ToArray(); }
protected object CreateContainerServiceCreateOrUpdateDynamicParameters() { dynamicParameters = new RuntimeDefinedParameterDictionary(); var pResourceGroupName = new RuntimeDefinedParameter(); pResourceGroupName.Name = "ResourceGroupName"; pResourceGroupName.ParameterType = typeof(string); pResourceGroupName.Attributes.Add(new ParameterAttribute { ParameterSetName = "InvokeByDynamicParameters", Position = 1, Mandatory = true }); pResourceGroupName.Attributes.Add(new AllowNullAttribute()); dynamicParameters.Add("ResourceGroupName", pResourceGroupName); var pContainerServiceName = new RuntimeDefinedParameter(); pContainerServiceName.Name = "Name"; pContainerServiceName.ParameterType = typeof(string); pContainerServiceName.Attributes.Add(new ParameterAttribute { ParameterSetName = "InvokeByDynamicParameters", Position = 2, Mandatory = true }); pContainerServiceName.Attributes.Add(new AllowNullAttribute()); dynamicParameters.Add("Name", pContainerServiceName); var pParameters = new RuntimeDefinedParameter(); pParameters.Name = "ContainerService"; pParameters.ParameterType = typeof(ContainerService); pParameters.Attributes.Add(new ParameterAttribute { ParameterSetName = "InvokeByDynamicParameters", Position = 3, Mandatory = true }); pParameters.Attributes.Add(new AllowNullAttribute()); dynamicParameters.Add("ContainerService", pParameters); var pArgumentList = new RuntimeDefinedParameter(); pArgumentList.Name = "ArgumentList"; pArgumentList.ParameterType = typeof(object[]); pArgumentList.Attributes.Add(new ParameterAttribute { ParameterSetName = "InvokeByStaticParameters", Position = 4, Mandatory = true }); pArgumentList.Attributes.Add(new AllowNullAttribute()); dynamicParameters.Add("ArgumentList", pArgumentList); return dynamicParameters; }
protected object CreateExtensionImageUnregisterDynamicParameters() { dynamicParameters = new RuntimeDefinedParameterDictionary(); var pProviderNamespace = new RuntimeDefinedParameter(); pProviderNamespace.Name = "ProviderNamespace"; pProviderNamespace.ParameterType = typeof(System.String); pProviderNamespace.Attributes.Add(new ParameterAttribute { ParameterSetName = "InvokeByDynamicParameters", Position = 1, Mandatory = true }); pProviderNamespace.Attributes.Add(new AllowNullAttribute()); dynamicParameters.Add("ProviderNamespace", pProviderNamespace); var pType = new RuntimeDefinedParameter(); pType.Name = "Type"; pType.ParameterType = typeof(System.String); pType.Attributes.Add(new ParameterAttribute { ParameterSetName = "InvokeByDynamicParameters", Position = 2, Mandatory = true }); pType.Attributes.Add(new AllowNullAttribute()); dynamicParameters.Add("Type", pType); var pVersion = new RuntimeDefinedParameter(); pVersion.Name = "Version"; pVersion.ParameterType = typeof(System.String); pVersion.Attributes.Add(new ParameterAttribute { ParameterSetName = "InvokeByDynamicParameters", Position = 3, Mandatory = true }); pVersion.Attributes.Add(new AllowNullAttribute()); dynamicParameters.Add("Version", pVersion); var pArgumentList = new RuntimeDefinedParameter(); pArgumentList.Name = "ArgumentList"; pArgumentList.ParameterType = typeof(object[]); pArgumentList.Attributes.Add(new ParameterAttribute { ParameterSetName = "InvokeByStaticParameters", Position = 4, Mandatory = true }); pArgumentList.Attributes.Add(new AllowNullAttribute()); dynamicParameters.Add("ArgumentList", pArgumentList); return dynamicParameters; }
protected object CreateOperatingSystemListDynamicParameters() { dynamicParameters = new RuntimeDefinedParameterDictionary(); var pArgumentList = new RuntimeDefinedParameter(); pArgumentList.Name = "ArgumentList"; pArgumentList.ParameterType = typeof(object[]); pArgumentList.Attributes.Add(new ParameterAttribute { ParameterSetName = "InvokeByStaticParameters", Position = 1, Mandatory = true }); pArgumentList.Attributes.Add(new AllowNullAttribute()); dynamicParameters.Add("ArgumentList", pArgumentList); return dynamicParameters; }
internal CompiledCommandParameter(RuntimeDefinedParameter runtimeDefinedParameter, bool processingDynamicParameters) { this.name = string.Empty; this.typeName = string.Empty; this.argumentTransformationAttributes = new Collection<ArgumentTransformationAttribute>(); this.validationAttributes = new Collection<ValidateArgumentsAttribute>(); this.aliases = new Collection<string>(); if (runtimeDefinedParameter == null) { throw PSTraceSource.NewArgumentNullException("runtimeDefinedParameter"); } this.name = runtimeDefinedParameter.Name; this.type = runtimeDefinedParameter.ParameterType; this.isDynamic = processingDynamicParameters; this.collectionTypeInformation = new ParameterCollectionTypeInformation(runtimeDefinedParameter.ParameterType); this.ConstructCompiledAttributesUsingRuntimeDefinedParameter(runtimeDefinedParameter); }
protected object CreateVirtualMachineExtensionListVersionsDynamicParameters() { dynamicParameters = new RuntimeDefinedParameterDictionary(); var pPublisherName = new RuntimeDefinedParameter(); pPublisherName.Name = "PublisherName"; pPublisherName.ParameterType = typeof(System.String); pPublisherName.Attributes.Add(new ParameterAttribute { ParameterSetName = "InvokeByDynamicParameters", Position = 1, Mandatory = true }); pPublisherName.Attributes.Add(new AllowNullAttribute()); dynamicParameters.Add("PublisherName", pPublisherName); var pExtensionName = new RuntimeDefinedParameter(); pExtensionName.Name = "ExtensionName"; pExtensionName.ParameterType = typeof(System.String); pExtensionName.Attributes.Add(new ParameterAttribute { ParameterSetName = "InvokeByDynamicParameters", Position = 2, Mandatory = true }); pExtensionName.Attributes.Add(new AllowNullAttribute()); dynamicParameters.Add("ExtensionName", pExtensionName); var pArgumentList = new RuntimeDefinedParameter(); pArgumentList.Name = "ArgumentList"; pArgumentList.ParameterType = typeof(object[]); pArgumentList.Attributes.Add(new ParameterAttribute { ParameterSetName = "InvokeByStaticParameters", Position = 3, Mandatory = true }); pArgumentList.Attributes.Add(new AllowNullAttribute()); dynamicParameters.Add("ArgumentList", pArgumentList); return dynamicParameters; }
protected object CreateVirtualMachineVMImageDeleteDynamicParameters() { dynamicParameters = new RuntimeDefinedParameterDictionary(); var pVMImageName = new RuntimeDefinedParameter(); pVMImageName.Name = "VMImageName"; pVMImageName.ParameterType = typeof(System.String); pVMImageName.Attributes.Add(new ParameterAttribute { ParameterSetName = "InvokeByDynamicParameters", Position = 1, Mandatory = true }); pVMImageName.Attributes.Add(new AllowNullAttribute()); dynamicParameters.Add("VMImageName", pVMImageName); var pDeleteFromStorage = new RuntimeDefinedParameter(); pDeleteFromStorage.Name = "DeleteFromStorage"; pDeleteFromStorage.ParameterType = typeof(System.Boolean); pDeleteFromStorage.Attributes.Add(new ParameterAttribute { ParameterSetName = "InvokeByDynamicParameters", Position = 2, Mandatory = true }); pDeleteFromStorage.Attributes.Add(new AllowNullAttribute()); dynamicParameters.Add("DeleteFromStorage", pDeleteFromStorage); var pArgumentList = new RuntimeDefinedParameter(); pArgumentList.Name = "ArgumentList"; pArgumentList.ParameterType = typeof(object[]); pArgumentList.Attributes.Add(new ParameterAttribute { ParameterSetName = "InvokeByStaticParameters", Position = 3, Mandatory = true }); pArgumentList.Attributes.Add(new AllowNullAttribute()); dynamicParameters.Add("ArgumentList", pArgumentList); return dynamicParameters; }
public object GetDynamicParameters() { if (_runtimeParamsDict == null) { ParameterAttribute paramAttribute = new ParameterAttribute(); paramAttribute.Mandatory = true; string[] validNames = IndicatorAndStrategyContainer.Instance.Indicators.Select(indicator => indicator.Name).ToArray(); Collection<Attribute> nameAttributes = new Collection<Attribute>(new Attribute[] { new ValidateSetAttribute(validNames), new ValidateNotNullOrEmptyAttribute(), paramAttribute }); var nameParam = new RuntimeDefinedParameter("Name", typeof(string), nameAttributes); _runtimeParamsDict = new RuntimeDefinedParameterDictionary(); _runtimeParamsDict.Add("Name", nameParam); } return _runtimeParamsDict; }
private RuntimeDefinedParameter CreateCacheMemoryDynamicParameter(CacheServiceSkuType sku) { var parameter = new RuntimeDefinedParameter { Name = MemoryParameterName, ParameterType = typeof(string), }; // add the [parameter] attribute var parameterAttribute = new ParameterAttribute { Mandatory = false, }; parameter.Attributes.Add(parameterAttribute); string[] values = (new CacheSkuCountConvert(sku)).GetValueList(); parameter.Attributes.Add(new ValidateSetAttribute(values) { IgnoreCase = true }); return parameter; }
internal void InitializeRuntimeDefinedParameters(ref bool useCmdletBinding) { if (this._runtimeDefinedParameters != null) { return; } this._runtimeDefinedParameters = new RuntimeDefinedParameterDictionary(); this._runtimeDefinedParameterList = new List <RuntimeDefinedParameter>(); bool flag = false; if (!useCmdletBinding) { for (int index = 0; index < this._parameters.Count; ++index) { if (this._parameters[index].HasParameterAttribute()) { useCmdletBinding = true; break; } } } int num1 = 0; for (int index = 0; index < this._parameters.Count; ++index) { RuntimeDefinedParameter definedParameter = this._parameters[index].GetRuntimeDefinedParameter(useCmdletBinding); if (!useCmdletBinding) { ParameterAttribute parameterAttribute = new ParameterAttribute(); if (!this._parameters[index].IsSwitchParameter()) { parameterAttribute.Position = num1++; } definedParameter.Attributes.Add((Attribute)parameterAttribute); } else { foreach (Attribute attribute in definedParameter.Attributes) { if (attribute is ParameterAttribute parameterAttribute && (parameterAttribute.Position != int.MinValue || !parameterAttribute.ParameterSetName.Equals("__AllParameterSets", StringComparison.OrdinalIgnoreCase))) { flag = true; break; } } } try { this._runtimeDefinedParameters.Add(definedParameter.Name, definedParameter); this._runtimeDefinedParameterList.Add(definedParameter); } catch (ArgumentException ex) { throw InterpreterError.NewInterpreterException((object)null, typeof(RuntimeException), this._parameters[index].NodeToken, "DuplicateFormalParameter", (object)this._parameters[index].NodeToken.TokenText); } } if (!useCmdletBinding || flag) { return; } for (int index = 0; index < this._runtimeDefinedParameterList.Count; ++index) { foreach (Attribute attribute in this._runtimeDefinedParameterList[index].Attributes) { if (attribute is ParameterAttribute parameterAttribute && !this._parameters[index].IsSwitchParameter()) { int num2 = num1++; parameterAttribute.Position = num2; break; } } } }
/// <summary> /// Generate dynamic parameters based on the connection strings in the Web.config. /// It will look at 2 Web.config files: /// 1. Web.config /// 2. Web.<configuration>.config (like Web.Release.config) /// This only works when -ProjectFile is used and -ConnectionString is not used. /// </summary> /// <returns>The dynamic parameters.</returns> public object GetDynamicParameters() { if (!string.IsNullOrEmpty(ProjectFile) && ConnectionString == null) { // Get the 2 Web.config files. PrepareFileFullPaths(); dynamicParameters = new RuntimeDefinedParameterDictionary(); if (string.Compare("ProjectFile", ParameterSetName) == 0) { // Parse the connection strings from the Web.config files. var names = WebsitesClient.ParseConnectionStringNamesFromWebConfig(fullWebConfigFile, fullWebConfigFileWithConfiguration); // Create a dynmaic parameter for each connection string using the same name. foreach (var name in names) { var parameter = new RuntimeDefinedParameter(); parameter.Name = name; parameter.ParameterType = typeof(string); parameter.Attributes.Add(new ParameterAttribute() { ParameterSetName = "ProjectFile", Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "Connection string from Web.config." } ); dynamicParameters.Add(name, parameter); } } } return dynamicParameters; }
/// <summary> /// Adds http error action parameters to PowerShell. /// </summary> /// <param name="create">true if parameters added for create scenario and false for update scenario.</param> /// <returns>PowerShell parameters.</returns> internal RuntimeDefinedParameterDictionary AddHttpErrorActionParameters(bool create = true) { var errorActionMethodAttributes = new Collection<Attribute> { new ParameterAttribute { Mandatory = create ? true : false, HelpMessage = "The Method for Http and Https Action types (GET, PUT, POST, HEAD or DELETE).", }, new ValidateSetAttribute(Constants.HttpMethodGET, Constants.HttpMethodPUT, Constants.HttpMethodPOST, Constants.HttpMethodDELETE) { IgnoreCase = true, } }; var errorActionUriAttributes = new Collection<Attribute> { new ParameterAttribute { Mandatory = create ? true : false, HelpMessage = "The Uri for error job action.", }, new ValidateNotNullOrEmptyAttribute() }; var errorActionRequestBodyAttributes = new Collection<Attribute> { new ParameterAttribute { Mandatory = false, HelpMessage = "The Body for PUT and POST job actions.", }, new ValidateNotNullOrEmptyAttribute() }; var errorActionHeadersAttributes = new Collection<Attribute> { new ParameterAttribute { Mandatory = false, HelpMessage = "The header collection." }, new ValidateNotNullOrEmptyAttribute() }; var errorActionHttpAuthenticationTypeAttributes = new Collection<Attribute> { new ParameterAttribute { Mandatory = false, HelpMessage = "The Http Authentication type." }, new ValidateSetAttribute(Constants.HttpAuthenticationNone, Constants.HttpAuthenticationClientCertificate, Constants.HttpAuthenticationActiveDirectoryOAuth, Constants.HttpAuthenticationBasic) { IgnoreCase = true } }; this._errorActionMethod = new RuntimeDefinedParameter("ErrorActionMethod", typeof(string), errorActionMethodAttributes); this._errorActionUri = new RuntimeDefinedParameter("ErrorActionUri", typeof(Uri), errorActionUriAttributes); this._errorActionRequestBody = new RuntimeDefinedParameter("ErrorActionRequestBody", typeof(string), errorActionRequestBodyAttributes); this._errorActionHeaders = new RuntimeDefinedParameter("ErrorActionHeaders", typeof(Hashtable), errorActionHeadersAttributes); this._errorActionHttpAuthenticationType = new RuntimeDefinedParameter("ErrorActionHttpAuthenticationType", typeof(string), errorActionHttpAuthenticationTypeAttributes); var runtimeDefinedParameterDictionary = new RuntimeDefinedParameterDictionary(); runtimeDefinedParameterDictionary.Add("ErrorActionMethod", this._errorActionMethod); runtimeDefinedParameterDictionary.Add("ErrorActionUri", this._errorActionUri); runtimeDefinedParameterDictionary.Add("ErrorActionRequestBody", this._errorActionRequestBody); runtimeDefinedParameterDictionary.Add("ErrorActionHeaders", this._errorActionHeaders); runtimeDefinedParameterDictionary.Add("ErrorActionHttpAuthenticationType", this._errorActionHttpAuthenticationType); runtimeDefinedParameterDictionary.AddRange(this.AddHttpErrorActionClientCertificateAuthenticationTypeParameters()); runtimeDefinedParameterDictionary.AddRange(this.AddHttpErrorActionBasicAuthenticationTypeParameters()); runtimeDefinedParameterDictionary.AddRange(this.AddHttpErrorActionActiveDirectoryOAuthAuthenticationTypeParameters()); return runtimeDefinedParameterDictionary; }
public override object GetDynamicParameters() { dynamicParameters = new RuntimeDefinedParameterDictionary(); var pResourceGroupName = new RuntimeDefinedParameter(); pResourceGroupName.Name = "ResourceGroupName"; pResourceGroupName.ParameterType = typeof(string); pResourceGroupName.Attributes.Add(new ParameterAttribute { ParameterSetName = "InvokeByDynamicParameters", Position = 1, Mandatory = false, ValueFromPipeline = false }); pResourceGroupName.Attributes.Add(new ParameterAttribute { ParameterSetName = "InvokeByDynamicParametersForFriendMethod", Position = 1, Mandatory = false, ValueFromPipeline = false }); pResourceGroupName.Attributes.Add(new AllowNullAttribute()); dynamicParameters.Add("ResourceGroupName", pResourceGroupName); var pVMScaleSetName = new RuntimeDefinedParameter(); pVMScaleSetName.Name = "VMScaleSetName"; pVMScaleSetName.ParameterType = typeof(string); pVMScaleSetName.Attributes.Add(new ParameterAttribute { ParameterSetName = "InvokeByDynamicParameters", Position = 2, Mandatory = false, ValueFromPipeline = false }); pVMScaleSetName.Attributes.Add(new ParameterAttribute { ParameterSetName = "InvokeByDynamicParametersForFriendMethod", Position = 2, Mandatory = false, ValueFromPipeline = false }); pVMScaleSetName.Attributes.Add(new AllowNullAttribute()); dynamicParameters.Add("VMScaleSetName", pVMScaleSetName); var pInstanceId = new RuntimeDefinedParameter(); pInstanceId.Name = "InstanceId"; pInstanceId.ParameterType = typeof(string); pInstanceId.Attributes.Add(new ParameterAttribute { ParameterSetName = "InvokeByDynamicParameters", Position = 3, Mandatory = false, ValueFromPipeline = false }); pInstanceId.Attributes.Add(new ParameterAttribute { ParameterSetName = "InvokeByDynamicParametersForFriendMethod", Position = 3, Mandatory = false, ValueFromPipeline = false }); pInstanceId.Attributes.Add(new AllowNullAttribute()); dynamicParameters.Add("InstanceId", pInstanceId); var pInstanceView = new RuntimeDefinedParameter(); pInstanceView.Name = "InstanceView"; pInstanceView.ParameterType = typeof(SwitchParameter); pInstanceView.Attributes.Add(new ParameterAttribute { ParameterSetName = "InvokeByDynamicParametersForFriendMethod", Position = 4, Mandatory = true }); pInstanceView.Attributes.Add(new ParameterAttribute { ParameterSetName = "InvokeByStaticParametersForFriendMethod", Position = 5, Mandatory = true }); pInstanceView.Attributes.Add(new AllowNullAttribute()); dynamicParameters.Add("InstanceView", pInstanceView); return dynamicParameters; }
/// <summary> /// Constructs an instance of the CompiledCommandAttribute using the specified /// runtime-defined parameter. /// </summary> /// <param name="runtimeDefinedParameter"> /// A runtime defined parameter that contains the definition of the parameter and its metadata. /// </param> /// <param name="processingDynamicParameters"> /// True if dynamic parameters are being processed, or false otherwise. /// </param> /// <exception cref="ArgumentNullException"> /// If <paramref name="runtimeDefinedParameter"/> is null. /// </exception> /// <exception cref="MetadataException"> /// If the parameter has more than one <see cref="ParameterAttribute">ParameterAttribute</see> /// that defines the same parameter-set name. /// </exception> internal CompiledCommandParameter(RuntimeDefinedParameter runtimeDefinedParameter, bool processingDynamicParameters) { if (runtimeDefinedParameter == null) { throw PSTraceSource.NewArgumentNullException(nameof(runtimeDefinedParameter)); } this.Name = runtimeDefinedParameter.Name; this.Type = runtimeDefinedParameter.ParameterType; this.IsDynamic = processingDynamicParameters; this.CollectionTypeInformation = new ParameterCollectionTypeInformation(runtimeDefinedParameter.ParameterType); this.CompiledAttributes = new Collection <Attribute>(); this.ParameterSetData = new Dictionary <string, ParameterSetSpecificMetadata>(StringComparer.OrdinalIgnoreCase); Collection <ValidateArgumentsAttribute> validationAttributes = null; Collection <ArgumentTransformationAttribute> argTransformationAttributes = null; string[] aliases = null; // First, process attributes that aren't type conversions foreach (Attribute attribute in runtimeDefinedParameter.Attributes) { if (processingDynamicParameters) { // When processing dynamic parameters, the attribute list may contain experimental attributes // and disabled parameter attributes. We should ignore those attributes. // When processing non-dynamic parameters, the experimental attributes and disabled parameter // attributes have already been filtered out when constructing the RuntimeDefinedParameter. if (attribute is ExperimentalAttribute || attribute is ParameterAttribute param && param.ToHide) { continue; } } if (attribute is not ArgumentTypeConverterAttribute) { ProcessAttribute(runtimeDefinedParameter.Name, attribute, ref validationAttributes, ref argTransformationAttributes, ref aliases); } } // If this is a PSCredential type and they haven't added any argument transformation attributes, // add one for credential transformation if ((this.Type == typeof(PSCredential)) && argTransformationAttributes == null) { ProcessAttribute(runtimeDefinedParameter.Name, new CredentialAttribute(), ref validationAttributes, ref argTransformationAttributes, ref aliases); } // Now process type converters foreach (var attribute in runtimeDefinedParameter.Attributes.OfType <ArgumentTypeConverterAttribute>()) { ProcessAttribute(runtimeDefinedParameter.Name, attribute, ref validationAttributes, ref argTransformationAttributes, ref aliases); } this.ValidationAttributes = validationAttributes == null ? Array.Empty <ValidateArgumentsAttribute>() : validationAttributes.ToArray(); this.ArgumentTransformationAttributes = argTransformationAttributes == null ? Array.Empty <ArgumentTransformationAttribute>() : argTransformationAttributes.ToArray(); this.Aliases = aliases == null ? Array.Empty <string>() : aliases.ToArray(); }
/// <summary> /// Adds client certificate authentication parameters for http error action. /// </summary> /// <returns>PowerShell parameters.</returns> internal RuntimeDefinedParameterDictionary AddHttpErrorActionClientCertificateAuthenticationTypeParameters() { var errorActionClientCertificatePfxAttributes = new Collection<Attribute> { new ParameterAttribute { Mandatory = false, HelpMessage = "The file name of client certificate.", }, new ValidateNotNullOrEmptyAttribute() }; var errorActionClientCertificatePasswordAttributes = new Collection<Attribute> { new ParameterAttribute { Mandatory = false, HelpMessage = "The password for the pfx.", }, new ValidateNotNullOrEmptyAttribute() }; this._errorActionClientCertificatePfx = new RuntimeDefinedParameter("ErrorActionClientCertificatePfx", typeof(object), errorActionClientCertificatePfxAttributes); this._errorActionClientCertificatePassword = new RuntimeDefinedParameter("ErrorActionClientCertificatePassword", typeof(string), errorActionClientCertificatePasswordAttributes); var runtimeDefinedParameterDictionary = new RuntimeDefinedParameterDictionary(); runtimeDefinedParameterDictionary.Add("ErrorActionClientCertificatePfx", this._errorActionClientCertificatePfx); runtimeDefinedParameterDictionary.Add("ErrorActionClientCertificatePassword", this._errorActionClientCertificatePassword); return runtimeDefinedParameterDictionary; }
internal static object[] BindArgumentsForScripblockInvoke(RuntimeDefinedParameter[] parameters, object[] args, ExecutionContext context, bool dotting, Dictionary<string, PSVariable> backupWhenDotting, MutableTuple locals) { object value; CommandLineParameters commandLineParameter = new CommandLineParameters(); if ((int)parameters.Length != 0) { for (int i = 0; i < (int)parameters.Length; i++) { RuntimeDefinedParameter variableAtScope = parameters[i]; bool flag = false; if (i < (int)args.Length) { value = args[i]; } else { value = variableAtScope.Value; if (value as Compiler.DefaultValueExpressionWrapper != null) { value = ((Compiler.DefaultValueExpressionWrapper)value).GetValue(context, null, null); } flag = true; } bool flag1 = false; if (!dotting || backupWhenDotting == null) { flag1 = locals.TrySetParameter(variableAtScope.Name, value); } else { backupWhenDotting[variableAtScope.Name] = context.EngineSessionState.GetVariableAtScope(variableAtScope.Name, "local"); } if (!flag1) { PSVariable pSVariable = new PSVariable(variableAtScope.Name, value, ScopedItemOptions.None, variableAtScope.Attributes); context.EngineSessionState.SetVariable(pSVariable, false, CommandOrigin.Internal); } if (!flag) { commandLineParameter.Add(variableAtScope.Name, value); commandLineParameter.MarkAsBoundPositionally(variableAtScope.Name); } } locals.SetAutomaticVariable(AutomaticVariable.PSBoundParameters, commandLineParameter.GetValueToBindToPSBoundParameters(), context); int length = (int)args.Length - (int)parameters.Length; if (length > 0) { object[] objArray = new object[length]; Array.Copy(args, (int)parameters.Length, objArray, 0, (int)objArray.Length); return objArray; } else { return ScriptBlock.EmptyArray; } } else { return args; } }
/// <summary> /// Adds Storage queue error action parameters. /// </summary> /// <param name="create">true if parameters added for create scenario and false for update scenario.</param> /// <returns>PowerShell parameters.</returns> internal RuntimeDefinedParameterDictionary AddStorageQueueErrorActionParameters(bool create = true) { var errorActionStorageAccountAttributes = new Collection<Attribute> { new ParameterAttribute { Mandatory = create ? true : false, HelpMessage = "The Storage account name.", }, new ValidateNotNullOrEmptyAttribute() }; var errorActionStorageQueueAttributes = new Collection<Attribute> { new ParameterAttribute { Mandatory = create ? true : false, HelpMessage = "The Storage Queue name.", }, new ValidateNotNullOrEmptyAttribute() }; var errorActionStorageSASTokenAttributes = new Collection<Attribute> { new ParameterAttribute { Mandatory = create ? true : false, HelpMessage = "The SAS token for storage queue.", }, new ValidateNotNullOrEmptyAttribute() }; var errorActionStorageQueueMessageBodyAttributes = new Collection<Attribute> { new ParameterAttribute { Mandatory = create ? true : false, HelpMessage = "The Body for Storage job actions." }, new ValidateNotNullOrEmptyAttribute() }; this._errorActionStorageAccount = new RuntimeDefinedParameter("ErrorActionStorageAccount", typeof(string), errorActionStorageAccountAttributes); this._errorActionStorageQueue = new RuntimeDefinedParameter("ErrorActionStorageQueue", typeof(string), errorActionStorageQueueAttributes); this._errorActionStorageSASToken = new RuntimeDefinedParameter("ErrorActionStorageSASToken", typeof(string), errorActionStorageSASTokenAttributes); this._errorActionStorageQueueMessageBody = new RuntimeDefinedParameter("ErrorActionStorageQueueMessageBody", typeof(string), errorActionStorageQueueMessageBodyAttributes); var runtimeDefinedParameterDictionary = new RuntimeDefinedParameterDictionary(); runtimeDefinedParameterDictionary.Add("ErrorActionStorageAccount", this._errorActionStorageAccount); runtimeDefinedParameterDictionary.Add("ErrorActionStorageQueue", this._errorActionStorageQueue); runtimeDefinedParameterDictionary.Add("ErrorActionStorageSASToken", this._errorActionStorageSASToken); runtimeDefinedParameterDictionary.Add("ErrorActionStorageQueueMessageBody", this._errorActionStorageQueueMessageBody); return runtimeDefinedParameterDictionary; }
public override object GetDynamicParameters() { dynamicParameters = new RuntimeDefinedParameterDictionary(); var pResourceGroupName = new RuntimeDefinedParameter(); pResourceGroupName.Name = "ResourceGroupName"; pResourceGroupName.ParameterType = typeof(string); pResourceGroupName.Attributes.Add(new ParameterAttribute { ParameterSetName = "InvokeByDynamicParameters", Position = 1, Mandatory = true, ValueFromPipeline = false }); pResourceGroupName.Attributes.Add(new AllowNullAttribute()); dynamicParameters.Add("ResourceGroupName", pResourceGroupName); var pName = new RuntimeDefinedParameter(); pName.Name = "Name"; pName.ParameterType = typeof(string); pName.Attributes.Add(new ParameterAttribute { ParameterSetName = "InvokeByDynamicParameters", Position = 2, Mandatory = true, ValueFromPipeline = false }); pName.Attributes.Add(new AllowNullAttribute()); dynamicParameters.Add("Name", pName); var pParameters = new RuntimeDefinedParameter(); pParameters.Name = "VirtualMachineScaleSet"; pParameters.ParameterType = typeof(VirtualMachineScaleSet); pParameters.Attributes.Add(new ParameterAttribute { ParameterSetName = "InvokeByDynamicParameters", Position = 3, Mandatory = true, ValueFromPipeline = true }); pParameters.Attributes.Add(new AllowNullAttribute()); dynamicParameters.Add("VirtualMachineScaleSet", pParameters); return dynamicParameters; }
/// <summary> /// Adds basic authentication parameters for http error action. /// </summary> /// <returns>PowerShell parameters.</returns> internal RuntimeDefinedParameterDictionary AddHttpErrorActionBasicAuthenticationTypeParameters() { var errorActionBasicUsernameAttributes = new Collection<Attribute> { new ParameterAttribute { Mandatory = false, HelpMessage = "The user name.", }, new ValidateNotNullOrEmptyAttribute() }; var errorActionBasicPasswordAttributes = new Collection<Attribute> { new ParameterAttribute { Mandatory = false, HelpMessage = "The password.", }, new ValidateNotNullOrEmptyAttribute() }; this._errorActionBasicUsername = new RuntimeDefinedParameter("ErrorActionUsername", typeof(string), errorActionBasicUsernameAttributes); this._errorActionBasicPassword = new RuntimeDefinedParameter("ErrorActionPassword", typeof(string), errorActionBasicPasswordAttributes); var runtimeDefinedParameterDictionary = new RuntimeDefinedParameterDictionary(); runtimeDefinedParameterDictionary.Add("ErrorActionUsername", this._errorActionBasicUsername); runtimeDefinedParameterDictionary.Add("ErrorActionPassword", this._errorActionBasicPassword); return runtimeDefinedParameterDictionary; }
internal static object[] BindArgumentsForScriptblockInvoke( RuntimeDefinedParameter[] parameters, object[] args, ExecutionContext context, bool dotting, Dictionary<string, PSVariable> backupWhenDotting, MutableTuple locals) { var boundParameters = new CommandLineParameters(); if (parameters.Length == 0) { return args; } for (int i = 0; i < parameters.Length; i++) { var parameter = parameters[i]; object valueToBind; bool wasDefaulted = false; if (i >= args.Length) { valueToBind = parameter.Value; if (valueToBind is Compiler.DefaultValueExpressionWrapper) { // We pass in a null SessionStateInternal because the current scope is already set correctly. valueToBind = ((Compiler.DefaultValueExpressionWrapper)valueToBind).GetValue(context, null); } wasDefaulted = true; } else { valueToBind = args[i]; } bool valueSet = false; if (dotting && backupWhenDotting != null) { backupWhenDotting[parameter.Name] = context.EngineSessionState.GetVariableAtScope(parameter.Name, "local"); } else { valueSet = locals.TrySetParameter(parameter.Name, valueToBind); } if (!valueSet) { var variable = new PSVariable(parameter.Name, valueToBind, ScopedItemOptions.None, parameter.Attributes); context.EngineSessionState.SetVariable(variable, false, CommandOrigin.Internal); } if (!wasDefaulted) { boundParameters.Add(parameter.Name, valueToBind); boundParameters.MarkAsBoundPositionally(parameter.Name); } } locals.SetAutomaticVariable(AutomaticVariable.PSBoundParameters, boundParameters.GetValueToBindToPSBoundParameters(), context); var leftOverArgs = args.Length - parameters.Length; if (leftOverArgs <= 0) { return Utils.EmptyArray<object>(); } object[] result = new object[leftOverArgs]; Array.Copy(args, parameters.Length, result, 0, result.Length); return result; }
/// <summary> /// Adds OAuth authentication parameters for http error action. /// </summary> /// <returns>PowerShell parameters.</returns> internal RuntimeDefinedParameterDictionary AddHttpErrorActionActiveDirectoryOAuthAuthenticationTypeParameters() { var errorActionOAuthTenantAttributes = new Collection<Attribute> { new ParameterAttribute { Mandatory = false, HelpMessage = "The tenant Id.", }, new ValidateNotNullOrEmptyAttribute() }; var errorActionOAuthAudienceAttributes = new Collection<Attribute> { new ParameterAttribute { Mandatory = false, HelpMessage = "The audience.", }, new ValidateNotNullOrEmptyAttribute() }; var errorActionOAuthClientIdAttributes = new Collection<Attribute> { new ParameterAttribute { Mandatory = false, HelpMessage = "The client id.", }, new ValidateNotNullOrEmptyAttribute() }; var errorActionOAuthSecretAttributes = new Collection<Attribute> { new ParameterAttribute { Mandatory = false, HelpMessage = "The secret.", }, new ValidateNotNullOrEmptyAttribute() }; this._errorActionOAuthTenant = new RuntimeDefinedParameter("ErrorActionTenant", typeof(string), errorActionOAuthTenantAttributes); this._errorActionOAuthAudience = new RuntimeDefinedParameter("ErrorActionAudience", typeof(string), errorActionOAuthAudienceAttributes); this._errorActionOAuthClientId = new RuntimeDefinedParameter("ErrorActionClientId", typeof(string), errorActionOAuthClientIdAttributes); this._errorActionOAuthSecret = new RuntimeDefinedParameter("ErrorActionSecret", typeof(string), errorActionOAuthSecretAttributes); var runtimeDefinedParameterDictionary = new RuntimeDefinedParameterDictionary(); runtimeDefinedParameterDictionary.Add("ErrorActionTenant", this._errorActionOAuthTenant); runtimeDefinedParameterDictionary.Add("ErrorActionAudience", this._errorActionOAuthAudience); runtimeDefinedParameterDictionary.Add("ErrorActionClientId", this._errorActionOAuthClientId); runtimeDefinedParameterDictionary.Add("ErrorActionSecret", this._errorActionOAuthSecret); return runtimeDefinedParameterDictionary; }
public override object GetDynamicParameters() { dynamicParameters = new RuntimeDefinedParameterDictionary(); var pResourceGroupName = new RuntimeDefinedParameter(); pResourceGroupName.Name = "ResourceGroupName"; pResourceGroupName.ParameterType = typeof(string); pResourceGroupName.Attributes.Add(new ParameterAttribute { ParameterSetName = "InvokeByDynamicParameters", Position = 1, Mandatory = true, ValueFromPipelineByPropertyName = true, ValueFromPipeline = false }); pResourceGroupName.Attributes.Add(new AllowNullAttribute()); dynamicParameters.Add("ResourceGroupName", pResourceGroupName); var pVMScaleSetName = new RuntimeDefinedParameter(); pVMScaleSetName.Name = "VMScaleSetName"; pVMScaleSetName.ParameterType = typeof(string); pVMScaleSetName.Attributes.Add(new ParameterAttribute { ParameterSetName = "InvokeByDynamicParameters", Position = 2, Mandatory = true, ValueFromPipelineByPropertyName = true, ValueFromPipeline = false }); pVMScaleSetName.Attributes.Add(new AliasAttribute("Name")); pVMScaleSetName.Attributes.Add(new AllowNullAttribute()); dynamicParameters.Add("VMScaleSetName", pVMScaleSetName); var pInstanceIds = new RuntimeDefinedParameter(); pInstanceIds.Name = "InstanceId"; pInstanceIds.ParameterType = typeof(string[]); pInstanceIds.Attributes.Add(new ParameterAttribute { ParameterSetName = "InvokeByDynamicParameters", Position = 3, Mandatory = true, ValueFromPipelineByPropertyName = true, ValueFromPipeline = false }); pInstanceIds.Attributes.Add(new AllowNullAttribute()); dynamicParameters.Add("InstanceId", pInstanceIds); return dynamicParameters; }
private static RuntimeDefinedParameterDictionary CreateDynamicParametersResult() { var bindableFunctions = (typeof(PSConsoleReadLine).GetMethods(BindingFlags.Public | BindingFlags.Static)) .Where(method => { var parameters = method.GetParameters(); return parameters.Length == 2 && parameters[0].ParameterType == typeof(ConsoleKeyInfo?) && parameters[1].ParameterType == typeof(object); }) .Select(method => method.Name) .OrderBy(name => name); var attributes = new Collection<Attribute> { new ParameterAttribute { Position = 1, Mandatory = true, ParameterSetName = FunctionParameterSet }, new ValidateSetAttribute(bindableFunctions.ToArray()) }; var parameter = new RuntimeDefinedParameter(FunctionParameter, typeof(string), attributes); var result = new RuntimeDefinedParameterDictionary {{FunctionParameter, parameter}}; return result; }