I have a C# function (MyFunction(List<SafeInfo> securitySchema)). I'm trying to write a powershell script that will create the List<SafeInfo> object and pass it into MyFunction(List<SafeInfo>) via reflection. Reflection's all good in PowerShell, but I'm trying to figure out the correct way to transpose the creation of the argument object into PowerShell.
Here's asample C# object that can be used:
List<SafeInfo> schema = new List<SafeInfo>() {
new SafeInfo("mySafe1", new SecurityInfo("key1", SecurityType.Key, "some description")),
new SafeInfo("mySafe2", new SecurityInfo("key2", SecurityType.Combination, "another description")),
new SafeInfo("mySafe3", SecurityInfo.Unsecured)
};
My PowerShell so far:
$schema = New-Object 'Collections.Generic.List[MyNamespace.SafeInfo]'
$schema.Add(New-Object('MyNamespace.SafeInfo', 'mySafe1', New-Object('MyNamespace.SecurityInfo', 'key1', SecurityType.Key, 'some description')))
$schema.Add(New-Object('MyNamespace.SafeInfo', 'mySafe2', New-Object('MyNamespace.SecurityInfo', 'key2', SecurityType.Combination, 'another description')))
$schema.Add(New-Object('MyNamespace.SafeInfo', 'mySafe3', [MyNamespace.SecurityInfo]::Unsecured))
Am I on the right track? What's the best way to create this nested object in PowerShell? Thanks!