@@ -49,6 +49,56 @@ 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
+ }
86
+ }
87
+ }
88
+ }
89
+ if ($skipProperty )
90
+ {
91
+ continue ;
92
+ }
93
+
94
+ [DscResourcePropertyInfo ]$prop = [DscResourcePropertyInfo ]::new()
95
+ $prop.Name = $property.Name
96
+ $prop.PropertyType = $property.PropertyType.TypeName.Name
97
+ $prop.IsMandatory = $isKeyProperty
98
+ $Properties.Add ($prop )
99
+ }
100
+ }
101
+
52
102
function FindAndParseResourceDefinitions
53
103
{
54
104
[CmdletBinding (HelpUri = ' ' )]
@@ -68,7 +118,6 @@ function FindAndParseResourceDefinitions
68
118
}
69
119
70
120
" Loading resources from file '$filePath '" | Write-DscTrace - Operation Trace
71
- # TODO: Handle class inheritance
72
121
# TODO: Ensure embedded instances in properties are working correctly
73
122
[System.Management.Automation.Language.Token []] $tokens = $null
74
123
[System.Management.Automation.Language.ParseError []] $errors = $null
@@ -78,76 +127,38 @@ function FindAndParseResourceDefinitions
78
127
$e | Out-String | Write-DscTrace - Operation Error
79
128
}
80
129
81
- $resourceDefinitions = $ast.FindAll (
130
+ $typeDefinitions = $ast.FindAll (
82
131
{
83
132
$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 ;
133
+ return $typeAst -ne $null ;
96
134
},
97
135
$false );
98
136
99
137
$resourceList = [System.Collections.Generic.List [DscResourceInfo ]]::new()
100
138
101
- foreach ($typeDefinitionAst in $resourceDefinitions )
139
+ foreach ($typeDefinitionAst in $typeDefinitions )
102
140
{
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 )
141
+ foreach ($a in $typeDefinitionAst.Attributes )
116
142
{
117
- $property = $member -as [System.Management.Automation.Language.PropertyMemberAst ]
118
- if (($property -eq $null ) -or ($property.IsStatic ))
119
- {
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 )
143
+ if ($a.TypeName.Name -eq ' DscResource' )
139
144
{
140
- continue ;
145
+ $DscResourceInfo = [DscResourceInfo ]::new()
146
+ $DscResourceInfo.Name = $typeDefinitionAst.Name
147
+ $DscResourceInfo.ResourceType = $typeDefinitionAst.Name
148
+ $DscResourceInfo.FriendlyName = $typeDefinitionAst.Name
149
+ $DscResourceInfo.ImplementationDetail = ' ClassBased'
150
+ $DscResourceInfo.Module = $filePath
151
+ $DscResourceInfo.Path = $filePath
152
+ # TODO: ModuleName, Version and ParentPath should be taken from psd1 contents
153
+ $DscResourceInfo.ModuleName = [System.IO.Path ]::GetFileNameWithoutExtension($filePath )
154
+ $DscResourceInfo.ParentPath = [System.IO.Path ]::GetDirectoryName($filePath )
155
+
156
+ $DscResourceInfo.Properties = [System.Collections.Generic.List [DscResourcePropertyInfo ]]::new()
157
+ Add-AstMembers $typeDefinitions $typeDefinitionAst $DscResourceInfo.Properties
158
+
159
+ $resourceList.Add ($DscResourceInfo )
141
160
}
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
161
}
149
-
150
- $resourceList.Add ($DscResourceInfo )
151
162
}
152
163
153
164
return $resourceList
0 commit comments