我正在使用Windows 7和PowerGUI脚本编辑器来编写ps1.这是我的代码的一部分:
#In global scope
$Type_Trans = "System.Collections.Generic.Dictionary[System.String,PSObject]"
$Type_Farms = "System.Collections.Generic.Dictionary[System.Int32,$Type_Trans]"
$Dic_Counts = New-Object $Type_Farms
#...puts some data in $Dic_Counts here...
#It is no problem with printing out it in console
#Now call the function below
Write-Data $Dic_Counts
Function Write-Data
{
param(
$Dic_Counts
)
Foreach($Dic_CountsSingle in $Dic_Counts)
{
Write-DataSingle $Dic_CountsSingle #THIS LINE!
}
}
Run Code Online (Sandbox Code Playgroud)
这里很奇怪:为什么Dic_CountsSingle不是KeyValuePair,但是和Dic_Counts?? 一样?
非常感谢你!
我这里有一个愚蠢的问题.我定义了一个包含许多数据成员的类,如下所示:
public class A
{
public string Name { get; set; }
public double Score { get; set; }
//...many members
public C Direction { get; set; }
public List<B> NameValue1 { get; set; }
public List<string> NameValue2 { get; set; }
//...many members
}
Run Code Online (Sandbox Code Playgroud)
现在,我正在编写单元测试代码,并希望比较A类的两个实例.但我发现这不起作用:
Assert.AreEquals(a1, a2);
Run Code Online (Sandbox Code Playgroud)
我必须覆盖Equals方法来做到这一点?默认情况下C#无法解决这个问题?或者我可以序列化这两个人并比较文件流?
谢谢.
我正在使用Microsoft Moles来模拟一个方法.
此方法调用另一个调用PowerShell脚本并返回的方法
采集
<PSObject>
所以我想模仿它来返回一个自定义的PSObject.它将具有两个属性,ID和Name.
但是当我尝试使用时
PSObject obj = new PSObject();
obj.Members.Add(new PSMemberInfo(
Run Code Online (Sandbox Code Playgroud)
我发现构造函数受到保护.
我该如何添加属性?
谢谢.