PowerShell Cmdlet Parameters and Inheritance

Posted by Adam Driscoll on Stack Overflow See other posts from Stack Overflow or by Adam Driscoll
Published on 2010-03-12T17:14:44Z Indexed on 2010/03/12 17:17 UTC
Read the original article Hit count: 360

Filed under:
|
|

I have an interface:

public interface X 
{}

I have a class:

public class Y : X
{}

I have one cmdlet:

[Cmdlet("Get", "Y")]
public class GetYCmdlet : PSCmdlet
{
    protected override void ProcessRecord()
    {
        WriteObject(new Y());
    }
}

I have another cmdlet:

[Cmdlet("Set", "X")]
public class SetYCmdlet : PSCmdlet
{
    [Parameter]
    public X SomeObj {get;set;}
}

When I do this:

$y = Get-Y
Set-X -SomeObj $y

I get this:

Could not convert "Y" to "X". Method not supported.

Any ideas?

© Stack Overflow or respective owner

Related posts about powershell-sdk

Related posts about .NET