0

I have the C# class

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);
    }
}

which implements the interface IPropertyBag. I want to write this class in PowerShell but I don't know how to define the out object ptrVar in function Read.

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);
    }    
}

the [out]$ptrVar returns error. Any ideas?

user3417479
  • 1,830
  • 3
  • 18
  • 23
  • 1
    I would suggest just using `Add-Type` and native `C#` code, honestly. – Maximilian Burszley Apr 09 '18 at 17:55
  • 1
    As an aside, `[out]` is not a type in `PowerShell`, but `[ref]` is. Your mistake in `Write` is trying to use `$ptrVar`. Instead, you need to do `$ptrVar.Value` – Maximilian Burszley Apr 09 '18 at 17:58
  • thanks for your suggestions. I tried Add-Type but got some errors with the import assemblies. In the end I made one dll which is called by powershell and now it works. Not the ideal solution but enough for now – user3417479 Apr 10 '18 at 11:52

0 Answers0