Being one who likes to document thoroughly, I was glad to discover the SupportsWildcards
attribute, among others, added in PowerShell V3. I have decorated parameters in my library with that attribute as appropriate. In the long run there is no issue, but in the short term there are still plenty of folks using V2 for various reasons (including me in one environment).
It seems silly that just because of one attribute some of my functions can no longer run in PowerShell V2. So I am looking for a way to mock the attribute in V2 to essentially turn it into a "no-op".
The solution, as I see it, needs two parts:
I am looking for guidance on both parts, having not played with custom attributes before.
Perhaps you can try this.
Add-Type @" public class CustomAttribute : System.Attribute { public bool SupportSomething { get; set; } } "@ function Do-Something { param( [CustomAttribute(SupportSomething=$true)] $Command ) } $parameters = Get-Command -Name Do-Something | Select-Object -ExpandProperty Parameters $parameters["Command"].Attributes
Then the output:
SupportSomething : True TypeId : CustomAttribute
We first define the attribute in C#, which you can also do in PowerShell. Add the attribute to the parameter. Then get the list of attributes. See here for more attribute examples
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With