@@ -49,6 +49,57 @@ function Get-DSCResourceModules
49
49
return $dscModulePsd1List
50
50
}
51
51
52
+ function Add-AstMembers {
53
+ param (
54
+ $AllTypeDefinitions ,
55
+ $TypeAst ,
56
+ $Properties
57
+ )
58
+
59
+ foreach ($TypeConstraint in $TypeAst.BaseTypes ) {
60
+ $t = $AllTypeDefinitions | Where-Object {$_.Name -eq $TypeConstraint.TypeName.Name }
61
+ if ($t ) {
62
+ Add-AstMembers $AllTypeDefinitions $t $Properties
63
+ }
64
+ }
65
+
66
+ foreach ($member in $TypeAst.Members )
67
+ {
68
+ $property = $member -as [System.Management.Automation.Language.PropertyMemberAst ]
69
+ if (($property -eq $null ) -or ($property.IsStatic ))
70
+ {
71
+ continue ;
72
+ }
73
+ $skipProperty = $true
74
+ $isKeyProperty = $false
75
+ foreach ($attr in $property.Attributes )
76
+ {
77
+ if ($attr.TypeName.Name -eq ' DscProperty' )
78
+ {
79
+ $skipProperty = $false
80
+ foreach ($attrArg in $attr.NamedArguments )
81
+ {
82
+ if ($attrArg.ArgumentName -eq ' Key' )
83
+ {
84
+ $isKeyProperty = $true
85
+ break
86
+ }
87
+ }
88
+ }
89
+ }
90
+ if ($skipProperty )
91
+ {
92
+ continue ;
93
+ }
94
+
95
+ [DscResourcePropertyInfo ]$prop = [DscResourcePropertyInfo ]::new()
96
+ $prop.Name = $property.Name
97
+ $prop.PropertyType = $property.PropertyType.TypeName.Name
98
+ $prop.IsMandatory = $isKeyProperty
99
+ $Properties.Add ($prop )
100
+ }
101
+ }
102
+
52
103
function FindAndParseResourceDefinitions
53
104
{
54
105
[CmdletBinding (HelpUri = ' ' )]
@@ -68,7 +119,6 @@ function FindAndParseResourceDefinitions
68
119
}
69
120
70
121
" Loading resources from file '$filePath '" | Write-DscTrace - Operation Trace
71
- # TODO: Handle class inheritance
72
122
# TODO: Ensure embedded instances in properties are working correctly
73
123
[System.Management.Automation.Language.Token []] $tokens = $null
74
124
[System.Management.Automation.Language.ParseError []] $errors = $null
@@ -78,76 +128,38 @@ function FindAndParseResourceDefinitions
78
128
$e | Out-String | Write-DscTrace - Operation Error
79
129
}
80
130
81
- $resourceDefinitions = $ast.FindAll (
131
+ $typeDefinitions = $ast.FindAll (
82
132
{
83
133
$typeAst = $args [0 ] -as [System.Management.Automation.Language.TypeDefinitionAst ]
84
- if ($typeAst )
85
- {
86
- foreach ($a in $typeAst.Attributes )
87
- {
88
- if ($a.TypeName.Name -eq ' DscResource' )
89
- {
90
- return $true ;
91
- }
92
- }
93
- }
94
-
95
- return $false ;
134
+ return $typeAst -ne $null ;
96
135
},
97
136
$false );
98
137
99
138
$resourceList = [System.Collections.Generic.List [DscResourceInfo ]]::new()
100
139
101
- foreach ($typeDefinitionAst in $resourceDefinitions )
140
+ foreach ($typeDefinitionAst in $typeDefinitions )
102
141
{
103
- $DscResourceInfo = [DscResourceInfo ]::new()
104
- $DscResourceInfo.Name = $typeDefinitionAst.Name
105
- $DscResourceInfo.ResourceType = $typeDefinitionAst.Name
106
- $DscResourceInfo.FriendlyName = $typeDefinitionAst.Name
107
- $DscResourceInfo.ImplementationDetail = ' ClassBased'
108
- $DscResourceInfo.Module = $filePath
109
- $DscResourceInfo.Path = $filePath
110
- # TODO: ModuleName, Version and ParentPath should be taken from psd1 contents
111
- $DscResourceInfo.ModuleName = [System.IO.Path ]::GetFileNameWithoutExtension($filePath )
112
- $DscResourceInfo.ParentPath = [System.IO.Path ]::GetDirectoryName($filePath )
113
-
114
- $DscResourceInfo.Properties = [System.Collections.Generic.List [DscResourcePropertyInfo ]]::new()
115
- foreach ($member in $typeDefinitionAst.Members )
142
+ foreach ($a in $typeDefinitionAst.Attributes )
116
143
{
117
- $property = $member -as [System.Management.Automation.Language.PropertyMemberAst ]
118
- if (($property -eq $null ) -or ($property.IsStatic ))
144
+ if ($a.TypeName.Name -eq ' DscResource' )
119
145
{
120
- continue ;
121
- }
122
- $skipProperty = $true
123
- $isKeyProperty = $false
124
- foreach ($attr in $property.Attributes )
125
- {
126
- if ($attr.TypeName.Name -eq ' DscProperty' )
127
- {
128
- $skipProperty = $false
129
- foreach ($attrArg in $attr.NamedArguments )
130
- {
131
- if ($attrArg.ArgumentName -eq ' Key' )
132
- {
133
- $isKeyProperty = $true
134
- }
135
- }
136
- }
137
- }
138
- if ($skipProperty )
139
- {
140
- continue ;
146
+ $DscResourceInfo = [DscResourceInfo ]::new()
147
+ $DscResourceInfo.Name = $typeDefinitionAst.Name
148
+ $DscResourceInfo.ResourceType = $typeDefinitionAst.Name
149
+ $DscResourceInfo.FriendlyName = $typeDefinitionAst.Name
150
+ $DscResourceInfo.ImplementationDetail = ' ClassBased'
151
+ $DscResourceInfo.Module = $filePath
152
+ $DscResourceInfo.Path = $filePath
153
+ # TODO: ModuleName, Version and ParentPath should be taken from psd1 contents
154
+ $DscResourceInfo.ModuleName = [System.IO.Path ]::GetFileNameWithoutExtension($filePath )
155
+ $DscResourceInfo.ParentPath = [System.IO.Path ]::GetDirectoryName($filePath )
156
+
157
+ $DscResourceInfo.Properties = [System.Collections.Generic.List [DscResourcePropertyInfo ]]::new()
158
+ Add-AstMembers $typeDefinitions $typeDefinitionAst $DscResourceInfo.Properties
159
+
160
+ $resourceList.Add ($DscResourceInfo )
141
161
}
142
-
143
- [DscResourcePropertyInfo ]$prop = [DscResourcePropertyInfo ]::new()
144
- $prop.Name = $property.Name
145
- $prop.PropertyType = $property.PropertyType.TypeName.Name
146
- $prop.IsMandatory = $isKeyProperty
147
- $DscResourceInfo.Properties.Add ($prop )
148
162
}
149
-
150
- $resourceList.Add ($DscResourceInfo )
151
163
}
152
164
153
165
return $resourceList
0 commit comments