/********************************************************************++
Copyright (c) Microsoft Corporation. All rights reserved.
--********************************************************************/
using System;
using System.Management.Automation.Runspaces;
using System.Collections.ObjectModel;
namespace System.Management.Automation
{
///
/// The command information for MSH scripts that are directly executable by MSH
///
public class ScriptInfo : CommandInfo, IScriptCommandInfo
{
#region ctor
///
/// Creates an instance of the ScriptInfo class with the specified name, and script.
///
///
///
/// The name of the script.
///
///
///
/// The script definition
///
///
///
/// The execution context for the script.
///
///
///
/// If is null.
///
///
internal ScriptInfo(string name, ScriptBlock script, ExecutionContext context)
: base(name, CommandTypes.Script, context)
{
if (script == null)
{
throw PSTraceSource.NewArgumentException("script");
}
this.ScriptBlock = script;
} // ScriptInfo ctor
///
/// This is a copy constructor, used primarily for get-command.
///
internal ScriptInfo(ScriptInfo other)
: base(other)
{
this.ScriptBlock = other.ScriptBlock;
}
///
/// Create a copy of commandInfo for GetCommandCommand so that we can generate parameter
/// sets based on an argument list (so we can get the dynamic parameters.)
///
internal override CommandInfo CreateGetCommandCopy(object[] argumentList)
{
ScriptInfo copy = new ScriptInfo(this) {IsGetCommandCopy = true, Arguments = argumentList};
return copy;
}
#endregion ctor
internal override HelpCategory HelpCategory
{
get { return HelpCategory.ScriptCommand; }
}
///
/// Gets the ScriptBlock that represents the implementation of the script.
///
public ScriptBlock ScriptBlock { get; private set; }
// Path
///
/// Gets the definition of the ScriptBlock for the script. This is the ToString() of
/// the ScriptBlock.
///
public override string Definition
{
get
{
return ScriptBlock.ToString();
}
}
///
/// The output type(s) is specified in the script block
///
public override ReadOnlyCollection OutputType
{
get { return ScriptBlock.OutputType; }
}
///
/// for diagnostic purposes
///
///
public override string ToString()
{
return ScriptBlock.ToString();
}
///
/// True if the command has dynamic parameters, false otherwise.
///
internal override bool ImplementsDynamicParameters
{
get { return ScriptBlock.HasDynamicParameters; }
}
///
/// The command metadata for the script.
///
override internal CommandMetadata CommandMetadata
{
get
{
return _commandMetadata ??
(_commandMetadata =
new CommandMetadata(this.ScriptBlock, this.Name, LocalPipeline.GetExecutionContextFromTLS()));
}
}
CommandMetadata _commandMetadata;
} // ScriptInfo
} // namespace System.Management.Automation