Skip to content

Commit

Permalink
Merge pull request #579 from Gijsreyn/export-multi-methods
Browse files Browse the repository at this point in the history
Export multi methods
  • Loading branch information
anmenaga authored Nov 12, 2024
2 parents 71fac96 + 242a1a0 commit 22dbb57
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
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()
$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

0 comments on commit 22dbb57

Please sign in to comment.