在powershell中实现out和ref参数

时间:2018-04-09 17:42:49

标签: powershell ref out function-parameter

我有C#类

class ConfigurationPropertyBag : IPropertyBag
{
    internal HybridDictionary properties;
    internal ConfigurationPropertyBag()
    {
        properties = new HybridDictionary();
    }
    public void Read(string propName, out object ptrVar, int errLog)
    {
        ptrVar = properties[propName];
    }
    public void Write(string propName, ref object ptrVar)
    {
        properties.Add(propName, ptrVar);
    }
}

实现接口IPropertyBag。我想在PowerShell中编写这个类,但我不知道如何在函数Read中定义out object ptrVar

class ConfigurationPropertyBag  : Microsoft.BizTalk.SSOClient.Interop.IPropertyBag
{

    [System.Collections.Specialized.HybridDictionary] $properties;
    ConfigurationPropertyBag()
    {
        $this.properties = new-object  System.Collections.Specialized.HybridDictionary
    }

    [void] Read([string]$propName, [out]$ptrVar, [int]$errLog)
    {
        $ptrVar = $this.properties[$propName];
    }

    [void] Write([string]$propName, [ref]$ptrVar)
    {
        $this.properties.Add($propName, $ptrVar);
    }    
}

[out]$ptrVar返回错误。有什么想法吗?

0 个答案:

没有答案