4
可以說,我定義了一個PowerShell腳本中使用C#以下類別的屬性:使用新物體,物業設置嵌套類
Add-Type -TypeDefinition @"
public class InnerClass {
int a, b;
public int A { get { return a; } set { a = value; } }
public int B { get { return b; } set { b = value; } }
}
public class SomeClass {
string name;
public string Name { get { return name; } set { name= value; } }
InnerClass numbers;
public InnerClass Numbers { get { return numbers; } set { numbers = value; } }
}
"@
我可以像這樣實例的InnerClass
一個實例:
New-Object InnerClass -Property @{
'A' = 1;
'B' = 2;
}
但是,如果我想以類似的方式實例化SomeClass
並設置InnerClass
的屬性,則會失敗。
New-Object SomeClass -Property @{
'Name' = "Justin Dearing";
Numbers = @{
'A' = 1;
'B' = 2;
};
} ;
New-Object : The value supplied is not valid, or the property is read-only. Cha
nge the value, and then try again.
At line:20 char:11
+ New-Object <<<< SomeClass -Property @{
+ CategoryInfo : InvalidData: (:) [New-Object], Exception
+ FullyQualifiedErrorId : InvalidValue,Microsoft.PowerShell.Commands.NewOb
jectCommand
Name : Justin Dearing
Numbers :
反正是有設定SomeClass
,包括Numbers
在一個新Statement對象的屬性?