Following Create a wrapper for functions in powershell, I want to add an attribute that changes functions' (more precisely cmdlets) behavior. Add a certain Begin
and DynamicParam
scriptblock.
The attribute could act like a decorator in python. That is replacing the function with a new one that "wraps it" and calls it internally. Or it could just keep the original cmdlet object (that is keep the Process
code , attributes and parameters), but it should add a "constant" begin section to every function(maybe depends on the function's name alone).
Is it possible to do it natively in powershell?
The question can be divided to 2:
- Is it possible to dynamically generate a function?
- Is it possible to do it in an attribute?
An example
function My
{
[WrapperFor(Other)]
[CmdLetBinding()]
Process { Other @newparams }
}
Which causes My
to support all params of Other
and parse them. Practically adds code sections.