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