Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export multi methods #579

Merged
merged 14 commits into from
Nov 12, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,30 @@ class TestClassResource : BaseTestClass

return $resultList.ToArray()
}

static [TestClassResource[]] Export([bool]$UseExport)
{
if ($UseExport)
{
return [TestClassResource]::Export()
}
else
{
$resultList = [List[TestClassResource]]::new()
$resultCount = 5
if ($env:TestClassResourceResultCount) {
$resultCount = $env:TestClassResourceResultCount
}
1..$resultCount | %{
$obj = New-Object TestClassResource
$obj.Name = "Object$_"
$obj.Prop1 = "Property of object$_"
$resultList.Add($obj)
}
}

return $resultList.ToArray()
}
}

[DscResource()]
Expand Down
9 changes: 8 additions & 1 deletion powershell-adapter/psDscAdapter/psDscAdapter.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,14 @@ function Invoke-DscOperation {
}
'Export' {
$t = $dscResourceInstance.GetType()
anmenaga marked this conversation as resolved.
Show resolved Hide resolved
$method = $t.GetMethod('Export')
$methods = $t.GetMethods() | Where-Object { $_.Name -eq 'Export' }
$method = foreach ($mt in $methods) {
if ($mt.GetParameters().Count -eq 0) {
$mt
break
}
}

if ($null -eq $method) {
"Export method not implemented by resource '$($DesiredState.Type)'" | Write-DscTrace -Operation Error
exit 1
Expand Down
Loading