views:

1137

answers:

2

I am trying to declare List in PowerShell, where the Person is defined using Add-Type:

add-type -Language CSharpVersion3 -TypeDefinition @"
    public class Person
    {
        public Person() {}

        public string First { get; set; }
        public string Last { get; set; }
    }
"@

This works fine:

New-Object Person
New-Object System.Collections.Generic.List``1[System.Object]

But this line fails:

New-Object System.Collections.Generic.List``1[Person]

What is wrong here?

A: 

I am also curious how to do this in powershell 2.0...anyone know?

The same was as described in Lee's blog post above.
Steven Murawski
+5  A: 

This is a bug in New-Object. This will help you create them more easily: http://www.leeholmes.com/blog/CreatingGenericTypesInPowerShell.aspx

LeeHolmes
Welcome to StackOverflow Lee!
Steven Murawski