Пример #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
 public CommandMetadata(Type commandType)
 {
     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>();
     this.Init(null, commandType, false);
 }
Пример #3
0
        public CommandMetadata(string path)
        {
            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>();
            ExternalScriptInfo info = new ExternalScriptInfo(Path.GetFileName(path), path);

            this.Init(info.ScriptBlock, path, false);
            this._wrappedCommandType = CommandTypes.ExternalScript;
        }
Пример #4
0
 public CommandMetadata(CommandMetadata other)
 {
     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 (other == null)
     {
         throw PSTraceSource.NewArgumentNullException("other");
     }
     this._commandName                 = other._commandName;
     this._confirmImpact               = other._confirmImpact;
     this._defaultParameterSetFlag     = other._defaultParameterSetFlag;
     this._defaultParameterSetName     = other._defaultParameterSetName;
     this._implementsDynamicParameters = other._implementsDynamicParameters;
     this._supportsShouldProcess       = other._supportsShouldProcess;
     this._supportsPaging              = other._supportsPaging;
     this._supportsTransactions        = other._supportsTransactions;
     this.CommandType         = other.CommandType;
     this._wrappedAnyCmdlet   = other._wrappedAnyCmdlet;
     this._wrappedCommand     = other._wrappedCommand;
     this._wrappedCommandType = other._wrappedCommandType;
     this._parameters         = new Dictionary <string, ParameterMetadata>(other.Parameters.Count, StringComparer.OrdinalIgnoreCase);
     if (other.Parameters != null)
     {
         foreach (KeyValuePair <string, ParameterMetadata> pair in other.Parameters)
         {
             this._parameters.Add(pair.Key, new ParameterMetadata(pair.Value));
         }
     }
     if (other._otherAttributes == null)
     {
         this._otherAttributes = null;
     }
     else
     {
         this._otherAttributes = new Collection <Attribute>(new List <Attribute>(other._otherAttributes.Count));
         foreach (Attribute attribute in other._otherAttributes)
         {
             this._otherAttributes.Add(attribute);
         }
     }
     this.staticCommandParameterMetadata = null;
 }
Пример #5
0
        public CommandMetadata(CommandInfo commandInfo, bool shouldGenerateCommonParameters)
        {
            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 (commandInfo == null)
            {
                throw PSTraceSource.NewArgumentNullException("commandInfo");
            }
            while (commandInfo is AliasInfo)
            {
                commandInfo = ((AliasInfo)commandInfo).ResolvedCommand;
                if (commandInfo == null)
                {
                    throw PSTraceSource.NewNotSupportedException();
                }
            }
            CmdletInfo info = commandInfo as CmdletInfo;

            if (info != null)
            {
                this.Init(commandInfo.Name, info.ImplementingType, shouldGenerateCommonParameters);
            }
            else
            {
                ExternalScriptInfo info2 = commandInfo as ExternalScriptInfo;
                if (info2 != null)
                {
                    this.Init(info2.ScriptBlock, info2.Path, shouldGenerateCommonParameters);
                    this._wrappedCommandType = CommandTypes.ExternalScript;
                }
                else
                {
                    FunctionInfo info3 = commandInfo as FunctionInfo;
                    if (info3 == null)
                    {
                        throw PSTraceSource.NewNotSupportedException();
                    }
                    this.Init(info3.ScriptBlock, info3.Name, shouldGenerateCommonParameters);
                    this._wrappedCommandType = commandInfo.CommandType;
                }
            }
        }
Пример #6
0
 public CommandMetadata(CommandMetadata other)
 {
     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 (other == null)
     {
         throw PSTraceSource.NewArgumentNullException("other");
     }
     this._commandName = other._commandName;
     this._confirmImpact = other._confirmImpact;
     this._defaultParameterSetFlag = other._defaultParameterSetFlag;
     this._defaultParameterSetName = other._defaultParameterSetName;
     this._implementsDynamicParameters = other._implementsDynamicParameters;
     this._supportsShouldProcess = other._supportsShouldProcess;
     this._supportsPaging = other._supportsPaging;
     this._supportsTransactions = other._supportsTransactions;
     this.CommandType = other.CommandType;
     this._wrappedAnyCmdlet = other._wrappedAnyCmdlet;
     this._wrappedCommand = other._wrappedCommand;
     this._wrappedCommandType = other._wrappedCommandType;
     this._parameters = new Dictionary<string, ParameterMetadata>(other.Parameters.Count, StringComparer.OrdinalIgnoreCase);
     if (other.Parameters != null)
     {
         foreach (KeyValuePair<string, ParameterMetadata> pair in other.Parameters)
         {
             this._parameters.Add(pair.Key, new ParameterMetadata(pair.Value));
         }
     }
     if (other._otherAttributes == null)
     {
         this._otherAttributes = null;
     }
     else
     {
         this._otherAttributes = new Collection<Attribute>(new List<Attribute>(other._otherAttributes.Count));
         foreach (Attribute attribute in other._otherAttributes)
         {
             this._otherAttributes.Add(attribute);
         }
     }
     this.staticCommandParameterMetadata = null;
 }
Пример #7
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;
            }
        }
Пример #8
0
 internal CommandMetadata(string name, CommandTypes commandType, bool isProxyForCmdlet, string defaultParameterSetName, bool supportsShouldProcess, System.Management.Automation.ConfirmImpact confirmImpact, bool supportsPaging, bool supportsTransactions, bool positionalBinding, Dictionary <string, ParameterMetadata> parameters)
 {
     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>();
     this._commandName             = this._wrappedCommand = name;
     this._wrappedCommandType      = commandType;
     this._wrappedAnyCmdlet        = isProxyForCmdlet;
     this._defaultParameterSetName = defaultParameterSetName;
     this._supportsShouldProcess   = supportsShouldProcess;
     this._supportsPaging          = supportsPaging;
     this._confirmImpact           = confirmImpact;
     this._supportsTransactions    = supportsTransactions;
     this._positionalBinding       = positionalBinding;
     this.Parameters               = parameters;
 }
Пример #9
0
 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();
     }
 }
Пример #10
0
 public CommandMetadata(string path)
 {
     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>();
     ExternalScriptInfo info = new ExternalScriptInfo(Path.GetFileName(path), path);
     this.Init(info.ScriptBlock, path, false);
     this._wrappedCommandType = CommandTypes.ExternalScript;
 }
Пример #11
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;
     }
 }
Пример #12
0
 internal CommandMetadata(string name, CommandTypes commandType, bool isProxyForCmdlet, string defaultParameterSetName, bool supportsShouldProcess, System.Management.Automation.ConfirmImpact confirmImpact, bool supportsPaging, bool supportsTransactions, bool positionalBinding, Dictionary<string, ParameterMetadata> parameters)
 {
     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>();
     this._commandName = this._wrappedCommand = name;
     this._wrappedCommandType = commandType;
     this._wrappedAnyCmdlet = isProxyForCmdlet;
     this._defaultParameterSetName = defaultParameterSetName;
     this._supportsShouldProcess = supportsShouldProcess;
     this._supportsPaging = supportsPaging;
     this._confirmImpact = confirmImpact;
     this._supportsTransactions = supportsTransactions;
     this._positionalBinding = positionalBinding;
     this.Parameters = parameters;
 }
Пример #13
0
 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();
     }
 }
Пример #14
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();
 }
Пример #15
0
 public CommandMetadata(CommandInfo commandInfo, bool shouldGenerateCommonParameters)
 {
     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 (commandInfo == null)
     {
         throw PSTraceSource.NewArgumentNullException("commandInfo");
     }
     while (commandInfo is AliasInfo)
     {
         commandInfo = ((AliasInfo) commandInfo).ResolvedCommand;
         if (commandInfo == null)
         {
             throw PSTraceSource.NewNotSupportedException();
         }
     }
     CmdletInfo info = commandInfo as CmdletInfo;
     if (info != null)
     {
         this.Init(commandInfo.Name, info.ImplementingType, shouldGenerateCommonParameters);
     }
     else
     {
         ExternalScriptInfo info2 = commandInfo as ExternalScriptInfo;
         if (info2 != null)
         {
             this.Init(info2.ScriptBlock, info2.Path, shouldGenerateCommonParameters);
             this._wrappedCommandType = CommandTypes.ExternalScript;
         }
         else
         {
             FunctionInfo info3 = commandInfo as FunctionInfo;
             if (info3 == null)
             {
                 throw PSTraceSource.NewNotSupportedException();
             }
             this.Init(info3.ScriptBlock, info3.Name, shouldGenerateCommonParameters);
             this._wrappedCommandType = commandInfo.CommandType;
         }
     }
 }
Пример #16
0
 public CommandMetadata(Type commandType)
 {
     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>();
     this.Init(null, commandType, false);
 }