Пример #1
0
        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();
        }
Пример #2
0
        private void ProcessCmdletAttribute(CmdletCommonMetadataAttribute attribute)
        {
            if (attribute == null)
            {
                throw PSTraceSource.NewArgumentNullException("attribute");
            }
            this._defaultParameterSetName = attribute.DefaultParameterSetName;
            this._supportsShouldProcess   = attribute.SupportsShouldProcess;
            this._confirmImpact           = attribute.ConfirmImpact;
            this._supportsPaging          = attribute.SupportsPaging;
            this._supportsTransactions    = attribute.SupportsTransactions;
            this._helpUri            = attribute.HelpUri;
            this._remotingCapability = attribute.RemotingCapability;
            CmdletBindingAttribute attribute2 = attribute as CmdletBindingAttribute;

            if (attribute2 != null)
            {
                this.PositionalBinding = attribute2.PositionalBinding;
            }
        }
Пример #3
0
        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);
        }
Пример #4
0
        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;
        }
Пример #5
0
        private void Init(ScriptBlock scriptBlock, string name, bool shouldGenerateCommonParameters)
        {
            if (scriptBlock.UsesCmdletBinding)
            {
                this._wrappedAnyCmdlet = true;
            }
            else
            {
                shouldGenerateCommonParameters = false;
            }
            CmdletBindingAttribute cmdletBindingAttribute = scriptBlock.CmdletBindingAttribute;

            if (cmdletBindingAttribute != null)
            {
                this.ProcessCmdletAttribute(cmdletBindingAttribute);
            }
            else if (scriptBlock.UsesCmdletBinding)
            {
                this._defaultParameterSetName = null;
            }
            this._scriptBlock    = scriptBlock;
            this._wrappedCommand = this._commandName = name;
            this._shouldGenerateCommonParameters = shouldGenerateCommonParameters;
        }