@@ -230,6 +230,10 @@ function Invoke-DscCacheRefresh {
230
230
if ($classBased -and ($classBased.CustomAttributes.AttributeType.Name -eq ' DscResourceAttribute' )) {
231
231
" Detected class-based resource: $ ( $dscResource.Name ) => Type: $ ( $classBased.BaseType.FullName ) " | Write-DscTrace
232
232
$dscResourceInfo.ImplementationDetail = ' ClassBased'
233
+ $properties = GetClassBasedProperties - filePath $dscResource.Path - className $dscResource.Name
234
+ if ($null -ne $properties ) {
235
+ $DscResourceInfo.Properties = $properties
236
+ }
233
237
}
234
238
235
239
# fill in resource files (and their last-write-times) that will be used for up-do-date checks
@@ -239,10 +243,10 @@ function Invoke-DscCacheRefresh {
239
243
}
240
244
241
245
$dscResourceCacheEntries.Add ([dscResourceCacheEntry ]@ {
242
- Type = " $moduleName /$ ( $dscResource.Name ) "
243
- DscResourceInfo = $DscResourceInfo
244
- LastWriteTimes = $lastWriteTimes
245
- })
246
+ Type = " $moduleName /$ ( $dscResource.Name ) "
247
+ DscResourceInfo = $DscResourceInfo
248
+ LastWriteTimes = $lastWriteTimes
249
+ })
246
250
}
247
251
248
252
if ($namedModules.Count -gt 0 ) {
@@ -584,6 +588,72 @@ function ValidateMethod {
584
588
return $method
585
589
}
586
590
591
+ function GetClassBasedProperties {
592
+ param (
593
+ [Parameter (Mandatory = $true )]
594
+ [string ] $filePath ,
595
+
596
+ [Parameter (Mandatory = $true )]
597
+ [string ] $className
598
+ )
599
+
600
+ if (" .psd1" -notcontains ([System.IO.Path ]::GetExtension($filePath ))) {
601
+ return @ (' get' , ' set' , ' test' )
602
+ }
603
+
604
+ $module = $filePath.Replace (' .psd1' , ' .psm1' )
605
+
606
+ $properties = [System.Collections.Generic.List [DscResourcePropertyInfo ]]::new()
607
+
608
+ if (Test-Path $module - ErrorAction Ignore) {
609
+ [System.Management.Automation.Language.Token []] $tokens = $null
610
+ [System.Management.Automation.Language.ParseError []] $errors = $null
611
+ $ast = [System.Management.Automation.Language.Parser ]::ParseFile($module , [ref ]$tokens , [ref ]$errors )
612
+ foreach ($e in $errors ) {
613
+ $e | Out-String | Write-DscTrace - Operation Error
614
+ }
615
+
616
+ $typeDefinitions = $ast.FindAll (
617
+ {
618
+ $typeAst = $args [0 ] -as [System.Management.Automation.Language.TypeDefinitionAst ]
619
+ return $null -ne $typeAst ;
620
+ },
621
+ $false );
622
+
623
+ $typeDefinition = $typeDefinitions | Where-Object - Property Name -EQ $className
624
+
625
+ foreach ($member in $typeDefinition.Members ) {
626
+ $property = $member -as [System.Management.Automation.Language.PropertyMemberAst ]
627
+ if (($null -eq $property ) -or ($property.IsStatic )) {
628
+ continue ;
629
+ }
630
+ $skipProperty = $true
631
+ $isKeyProperty = $false
632
+ foreach ($attr in $property.Attributes ) {
633
+ if ($attr.TypeName.Name -eq ' DscProperty' ) {
634
+ $skipProperty = $false
635
+ foreach ($attrArg in $attr.NamedArguments ) {
636
+ if ($attrArg.ArgumentName -eq ' Key' ) {
637
+ $isKeyProperty = $true
638
+ break
639
+ }
640
+ }
641
+ }
642
+ }
643
+ if ($skipProperty ) {
644
+ continue ;
645
+ }
646
+
647
+ [DscResourcePropertyInfo ]$prop = [DscResourcePropertyInfo ]::new()
648
+ $prop.Name = $property.Name
649
+ $prop.PropertyType = $property.PropertyType.TypeName.Name
650
+ $prop.IsMandatory = $isKeyProperty
651
+ $properties.Add ($prop )
652
+ }
653
+ return $properties
654
+ }
655
+ }
656
+
587
657
# cached resource
588
658
class dscResourceCacheEntry {
589
659
[string ] $Type
@@ -612,6 +682,13 @@ enum dscResourceType {
612
682
Composite
613
683
}
614
684
685
+ class DscResourcePropertyInfo {
686
+ [string ] $Name
687
+ [string ] $PropertyType
688
+ [bool ] $IsMandatory
689
+ [System.Collections.Generic.List [string ]] $Values
690
+ }
691
+
615
692
# dsc resource type (settable clone)
616
693
class DscResourceInfo {
617
694
[dscResourceType ] $ImplementationDetail
0 commit comments