8000 Add more methods to directly add a `CommandInfo` to a `PSCommand` · Issue #12295 · PowerShell/PowerShell · GitHub
[go: up one dir, main page]

Skip to content

Add more methods to directly add a CommandInfo to a PSCommand #12295

@SeeminglyScience

Description

@SeeminglyScience

Summary of the new feature/enhancement

Currently PowerShell has a method that allows this, AddCommand(CommandInfo). However, there's no supported way to add a CommandInfo to a PSCommand instance directly. PowerShellEditorServices (and likely other projects) construct a PSCommand instance well before actually getting to the internal PowerShell object, so working with CommandInfo directly can only be done with reflection.

Proposed technical implementation details (optional)

using System.Management.Automation.Runspaces;

namespace System.Management.Automation
{
    public partial sealed class PSCommand
    {
        public PSCommand AddCommand(CommandInfo commandInfo)
        {
            return AddCommand(new Command(commandInfo));
        }
    }
}
namespace System.Management.Automation.Runspaces
{
    public sealed class Command
    {
-       internal Command(CommandInfo commandInfo) : this(commandInfo, false)
+       public Command(CommandInfo commandInfo) : this(commandInfo, false)
        {
        }
    }
}

/cc @TylerLeonhardt @rjmholt

Metadata

Metadata

Assignees

No one assigned

    Labels

    Committee-ReviewedPS-Committee has reviewed this and made a decisionIssue-Enhancementthe issue is more of a feature request than a bugResolution-No ActivityIssue has had no activity for 6 months or moreWG-Enginecore PowerShell engine, interpreter, and runtime

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0