如何在C#中向PSObject添加成员?
我用微软的Moles来模拟一个方法 此方法调用调用PowerShell脚本并返回的另一个方法 收藏如何在C#中向PSObject添加成员?,c#,.net,powershell,mocking,moles,C#,.net,Powershell,Mocking,Moles,我用微软的Moles来模拟一个方法 此方法调用调用PowerShell脚本并返回的另一个方法 收藏 所以我想模拟它来返回一个定制的PSObject。 它将有两个属性,ID和Name 但是当我尝试使用 PSObject obj = new PSObject(); obj.Members.Add(new PSMemberInfo( 我发现构造函数是受保护的 如何添加属性 谢谢。PSMemberInfo是一个抽象类,因此您不能直接创建实例,而是选择其子类 在页面中:您可以找到以下内容: System
所以我想模拟它来返回一个定制的PSObject。
它将有两个属性,ID和Name
但是当我尝试使用
PSObject obj = new PSObject();
obj.Members.Add(new PSMemberInfo(
我发现构造函数是受保护的
如何添加属性
谢谢。
PSMemberInfo
是一个抽象类,因此您不能直接创建实例,而是选择其子类
在页面中:您可以找到以下内容:
System.Object
System.Management.Automation.PSMemberInfo
System.Management.Automation.PSPropertyInfo
System.Management.Automation.PSAliasProperty
System.Management.Automation.PSCodeProperty
System.Management.Automation.PSNoteProperty
System.Management.Automation.PSProperty
System.Management.Automation.PSScriptProperty
选择您的类,并初始化它。尝试PSNoteProperty,这是我在模拟中使用的。