internal CommandMetadata(ScriptBlock scriptblock, string commandName, ExecutionContext context) { this._commandName = string.Empty; this._defaultParameterSetName = "__AllParameterSets"; this._positionalBinding = true; this._helpUri = string.Empty; this._remotingCapability = System.Management.Automation.RemotingCapability.PowerShell; this._confirmImpact = System.Management.Automation.ConfirmImpact.Medium; this._otherAttributes = new Collection <Attribute>(); if (scriptblock == null) { throw PSTraceSource.NewArgumentException("scriptblock"); } CmdletBindingAttribute cmdletBindingAttribute = scriptblock.CmdletBindingAttribute; if (cmdletBindingAttribute != null) { this.ProcessCmdletAttribute(cmdletBindingAttribute); } else { this._defaultParameterSetName = null; } this._commandName = commandName; this.CommandType = typeof(PSScriptCmdlet); if (scriptblock.HasDynamicParameters) { this._implementsDynamicParameters = true; } InternalParameterMetadata parameterMetadata = InternalParameterMetadata.Get(scriptblock.RuntimeDefinedParameters, false, scriptblock.UsesCmdletBinding); this.staticCommandParameterMetadata = this.MergeParameterMetadata(context, parameterMetadata, scriptblock.UsesCmdletBinding); this._defaultParameterSetFlag = this.staticCommandParameterMetadata.GenerateParameterSetMappingFromMetadata(this._defaultParameterSetName); this.staticCommandParameterMetadata.MakeReadOnly(); }
private MergedCommandParameterMetadata MergeParameterMetadata(ExecutionContext context, InternalParameterMetadata parameterMetadata, bool shouldGenerateCommonParameters) { MergedCommandParameterMetadata metadata = new MergedCommandParameterMetadata(); metadata.AddMetadataForBinder(parameterMetadata, ParameterBinderAssociation.DeclaredFormalParameters); if (shouldGenerateCommonParameters) { InternalParameterMetadata metadata2 = InternalParameterMetadata.Get(typeof(CommonParameters), context, false); metadata.AddMetadataForBinder(metadata2, ParameterBinderAssociation.CommonParameters); if (this.SupportsShouldProcess) { InternalParameterMetadata metadata3 = InternalParameterMetadata.Get(typeof(ShouldProcessParameters), context, false); metadata.AddMetadataForBinder(metadata3, ParameterBinderAssociation.ShouldProcessParameters); } if (this.SupportsPaging) { InternalParameterMetadata metadata4 = InternalParameterMetadata.Get(typeof(PagingParameters), context, false); metadata.AddMetadataForBinder(metadata4, ParameterBinderAssociation.PagingParameters); } if (this.SupportsTransactions) { InternalParameterMetadata metadata5 = InternalParameterMetadata.Get(typeof(TransactionParameters), context, false); metadata.AddMetadataForBinder(metadata5, ParameterBinderAssociation.TransactionParameters); } } return(metadata); }
private void Init(Type commandType, bool shouldGenerateCommonParameters) { this.type = commandType != null ? commandType : throw CommandMetadata.tracer.NewArgumentNullException("cmdletType"); InternalParameterMetadata parameterMetadata = InternalParameterMetadata.Get(commandType, (ExecutionContext)null, false); this.ConstructCmdletMetadataUsingReflection(); this.externalParameterMetadata = ParameterMetadata.GetParameterMetadata(this.MergeParameterMetadata((ExecutionContext)null, parameterMetadata, shouldGenerateCommonParameters)); this.wrappedCommand = this.commandName; this.wrappedCommandType = CommandTypes.Cmdlet; this.wrappedAnyCmdlet = true; }
internal CommandMetadata(string commandName, Type cmdletType, ExecutionContext context) { if (string.IsNullOrEmpty(commandName)) { throw CommandMetadata.tracer.NewArgumentException(nameof(commandName)); } if (cmdletType == null) { throw CommandMetadata.tracer.NewArgumentNullException(nameof(cmdletType)); } this.commandName = commandName; this.type = cmdletType; InternalParameterMetadata parameterMetadata = InternalParameterMetadata.Get(cmdletType, context, false); this.ConstructCmdletMetadataUsingReflection(); this.staticCommandParameterMetadata = this.MergeParameterMetadata(context, parameterMetadata, true); this.defaultParameterSetFlag = this.staticCommandParameterMetadata.GenerateParameterSetMappingFromMetadata(this.defaultParameterSetName); }
internal CommandMetadata(ScriptBlock scriptblock, string commandName, ExecutionContext context) { CmdletBindingAttribute bindingAttribute = scriptblock != null ? scriptblock.CmdletBindingAttribute : throw CommandMetadata.tracer.NewArgumentException(nameof(scriptblock)); if (bindingAttribute != null) { this.ProcessCmdletAttribute((CmdletCommonMetadataAttribute)bindingAttribute); } else { this.defaultParameterSetName = (string)null; } this.commandName = commandName; this.type = typeof(PSScriptCmdlet); if (scriptblock.DynamicParams != null) { this.implementsDynamicParameters = true; } InternalParameterMetadata parameterMetadata = InternalParameterMetadata.Get(scriptblock.RuntimeDefinedParameters, false, scriptblock.UsesCmdletBinding); this.staticCommandParameterMetadata = this.MergeParameterMetadata(context, parameterMetadata, scriptblock.UsesCmdletBinding); this.defaultParameterSetFlag = this.staticCommandParameterMetadata.GenerateParameterSetMappingFromMetadata(this.defaultParameterSetName); }
internal CommandMetadata(string commandName, Type cmdletType, ExecutionContext context) { this._commandName = string.Empty; this._defaultParameterSetName = "__AllParameterSets"; this._positionalBinding = true; this._helpUri = string.Empty; this._remotingCapability = System.Management.Automation.RemotingCapability.PowerShell; this._confirmImpact = System.Management.Automation.ConfirmImpact.Medium; this._otherAttributes = new Collection <Attribute>(); if (string.IsNullOrEmpty(commandName)) { throw PSTraceSource.NewArgumentException("commandName"); } this._commandName = commandName; this.CommandType = cmdletType; if (cmdletType != null) { InternalParameterMetadata parameterMetadata = InternalParameterMetadata.Get(cmdletType, context, false); this.ConstructCmdletMetadataUsingReflection(); this.staticCommandParameterMetadata = this.MergeParameterMetadata(context, parameterMetadata, true); this._defaultParameterSetFlag = this.staticCommandParameterMetadata.GenerateParameterSetMappingFromMetadata(this._defaultParameterSetName); this.staticCommandParameterMetadata.MakeReadOnly(); } }
private void Init(ScriptBlock scriptBlock, string name, bool shouldGenerateCommonParameters) { if (scriptBlock.UsesCmdletBinding) { this.wrappedAnyCmdlet = true; } else { shouldGenerateCommonParameters = false; } CmdletBindingAttribute bindingAttribute = scriptBlock.CmdletBindingAttribute; if (bindingAttribute != null) { this.ProcessCmdletAttribute((CmdletCommonMetadataAttribute)bindingAttribute); } else if (scriptBlock.UsesCmdletBinding) { this.defaultParameterSetName = (string)null; } this.externalParameterMetadata = ParameterMetadata.GetParameterMetadata(this.MergeParameterMetadata((ExecutionContext)null, InternalParameterMetadata.Get(scriptBlock.RuntimeDefinedParameters, false, scriptBlock.UsesCmdletBinding), shouldGenerateCommonParameters)); this.wrappedCommand = this.commandName = name; }