Please feel free to provide feedback or file bugs here.

Splatting for class method input parameters

Votes from Connect: 23

Original Date Submitted: 5/28/2015 11:09:44 PM

Description:
********Contact Information********
Handle: Trevor Sullivan [MVP]
Site Name: PowerShell
Feedback ID: 1376904
***************************************

Problem Description:
In the spirit of splatting, a cool feature to have for PowerShell v5 or vNext, would be to be ale to splat method parameters on PowerShell classes.

Right now, an error message appears: "The splatting operator '@' cannot be used to reference variables in an expression. '@NewPerson' can be used only as an argument to a command. To reference variables in an expression use '$NewPerson'."

class Person {
[string] $FirstName;
[string] $LastName;

Person ([string] $First, [string] $Last) {
$this.FirstName = $First;
$this.LastName = $Last;
}
}

$NewPerson = @{
FirstName = 'Trevor';
LastName = 'Sullivan';
};
[Person]::new(@NewPerson);

Product Studio item created by Connect Synchronizer due to creation of feedback ID 1376904 (http://connect.microsoft.com/PowerShell/feedback/ViewFeedback.aspx?FeedbackID=1376904).

Repro Steps:

Internal BugId: 14521

14 votes
Sign in
(thinking…)
Password icon
Signed in as (Sign out)

We’ll send you updates on this idea

AdminJoey Aiello [MSFT] (Program Manager, Windows Server) shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

1 comment

Sign in
(thinking…)
Password icon
Signed in as (Sign out)
Submitting...
  • sljd commented  ·   ·  Flag as inappropriate

    I would much more prefer to be able to instantiate the class in the same way as when no constructor parameters are specified:

    [Person]@{FirstName = 'Trevor'; LastName = 'Sullivan'}

Feedback and Knowledge Base