@@ -70,6 +70,10 @@ $Override,
70
70
[switch ]
71
71
$Dynamic ,
72
72
73
+ # If set, will not generate a dynamic parameter block. This is primarily present so Abstract inheritance has a small change footprint.
74
+ [switch ]
75
+ $NoDynamic ,
76
+
73
77
# If set, will always inherit commands as proxy commands.
74
78
# This is implied by -Dynamic.
75
79
[switch ]
@@ -163,6 +167,20 @@ process {
163
167
return
164
168
}
165
169
170
+ $InheritTemplate =
171
+ if ($resolvedCommand.Inherit ) {
172
+ $resolvedCommand.Inherit
173
+ } elseif ($resolvedCommand.Module.Inherit ) {
174
+ $resolvedCommand.Module.Inherit
175
+ }
176
+
177
+ if ($InheritTemplate -is [Management.Automation.PSMethodInfo ]) {
178
+ return $InheritTemplate.Invoke (@ ([Ordered ]@ {} + $PSBoundParameters ))
179
+ }
180
+ elseif ($InheritTemplate -is [scriptblock ]) {
181
+ return (& $InheritTemplate @ ([Ordered ]@ {} + $PSBoundParameters ) )
182
+ }
183
+
166
184
# Prepare parameters for Join-ScriptBlock
167
185
$joinSplat = @ {}
168
186
foreach ($key in ' IncludeBlockType' , ' ExcludeBlockType' ) {
263
281
# If we do not have a resolved command,
264
282
if (-not $resolvedCommand ) {
265
283
{} # the first script block is empty.
266
- } else {
284
+ }
285
+ else {
267
286
# If we have a resolvedCommand, fully qualify it.
268
287
$fullyQualifiedCommand =
269
288
if ($resolvedCommand.Module ) {
273
292
}
274
293
275
294
# Then create a dynamicParam block that will set `$baseCommand,
276
- # as well as a `$script: scoped variable for the command name.
277
-
278
- [scriptblock ]::create(@"
295
+ # as well as a `$script: scoped variable for the command name.
296
+ if ($NotDynamic ) # unless, of course -NotDynamic is passed
297
+ {
298
+ {}
299
+ } else
300
+ {
301
+ [scriptblock ]::create(@"
279
302
dynamicParam {
280
303
`$ baseCommand =
281
304
if (-not `$ script:$commandVariable ) {
@@ -302,6 +325,7 @@ dynamicParam {
302
325
})
303
326
}
304
327
"@ )
328
+ }
305
329
}
306
330
),
307
331
# Next is our [ScriptBlock]. This will come before almost everything else.
0 commit comments