//powershell code
$quiotent = divRemainderQuiotent ($a) ($b) ([ref] $remainder) # I need to pass this $remainder as reference
Для этого мне нужно передать его как PSReference
//csharp code
private PSReference remainder= null;
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1044:PropertiesShouldNotBeWriteOnly"),
Parameter(
Position = 2,
Mandatory = true,
ValueFromPipeline = true)]
[ValidateNotNullOrEmpty]
public PSReference Remainder // if I don’t use this and use a value type and later change it to ref (inside C#) the result won’t bubble up, which I think is bad.
{
set { remainder = value; }
}
Но теперь возникает проблема, функция, которая принимает этот параметр в качестве целочисленного значения.
protected override void ProcessRecord()
{
//main method, this is executed when cmdlet is run
int r = remainder ; //this is the problem I cannot convert PSReference to other object type (integer here).
int q = _csharpDivideRemainderQuiotent(a,b, ref r); // if I change this function to take PSReference type, I will have to make changes down the line for every function.
WriteObject(q);
} // method ProcessRecord