MegaBites-AI/Windows-powershell
0372
1// Copyright (c) Microsoft Corporation.2// Licensed under the MIT License.3 4using System.Collections.ObjectModel;5using System.Management.Automation.Runspaces;6 7namespace System.Management.Automation8{9 /// <summary>10 /// The command information for scripts that are directly executable by PowerShell.11 /// </summary>12 public class ScriptInfo : CommandInfo, IScriptCommandInfo13 {14 #region ctor15 16 /// <summary>17 /// Creates an instance of the ScriptInfo class with the specified name, and script.18 /// </summary>19 /// <param name="name">20 /// The name of the script.21 /// </param>22 /// <param name="script">23 /// The script definition24 /// </param>25 /// <param name="context">26 /// The execution context for the script.27 /// </param>28 /// <exception cref="ArgumentNullException">29 /// If <paramref name="script"/> is null.30 /// </exception>31 internal ScriptInfo(string name, ScriptBlock script, ExecutionContext context)32 : base(name, CommandTypes.Script, context)33 {34 if (script == null)35 {36 throw PSTraceSource.NewArgumentException(nameof(script));37 }38 39 this.ScriptBlock = script;40 }41 42 /// <summary>43 /// This is a copy constructor, used primarily for get-command.44 /// </summary>45 internal ScriptInfo(ScriptInfo other)46 : base(other)47 {48 this.ScriptBlock = other.ScriptBlock;49 }50 51 /// <summary>52 /// Create a copy of commandInfo for GetCommandCommand so that we can generate parameter53 /// sets based on an argument list (so we can get the dynamic parameters.)54 /// </summary>55 internal override CommandInfo CreateGetCommandCopy(object[] argumentList)56 {57 ScriptInfo copy = new ScriptInfo(this) { IsGetCommandCopy = true, Arguments = argumentList };58 return copy;59 }60 61 #endregion ctor62 63 internal override HelpCategory HelpCategory64 {65 get { return HelpCategory.ScriptCommand; }66 }67 68 /// <summary>69 /// Gets the ScriptBlock that represents the implementation of the script.70 /// </summary>71 public ScriptBlock ScriptBlock { get; }72 73 // Path74 75 /// <summary>76 /// Gets the definition of the ScriptBlock for the script. This is the ToString() of77 /// the ScriptBlock.78 /// </summary>79 public override string Definition80 {81 get82 {83 return ScriptBlock.ToString();84 }85 }86 87 /// <summary>88 /// The output type(s) is specified in the script block.89 /// </summary>90 public override ReadOnlyCollection<PSTypeName> OutputType91 {92 get { return ScriptBlock.OutputType; }93 }94 95 /// <summary>96 /// For diagnostic purposes.97 /// </summary>98 /// <returns></returns>99 public override string ToString()100 {101 return ScriptBlock.ToString();102 }103 104 /// <summary>105 /// True if the command has dynamic parameters, false otherwise.106 /// </summary>107 internal override bool ImplementsDynamicParameters108 {109 get { return ScriptBlock.HasDynamicParameters; }110 }111 112 /// <summary>113 /// The command metadata for the script.114 /// </summary>115 internal override CommandMetadata CommandMetadata116 {117 get118 {119 return _commandMetadata ??=120 new CommandMetadata(this.ScriptBlock, this.Name, LocalPipeline.GetExecutionContextFromTLS());121 }122 }123 124 private CommandMetadata _commandMetadata;125 }126}127 