I know I can add an instance method to a built-in .net class in PowerShell like this.
PS C:\Users\a> [string] | Add-Member -MemberType ScriptMethod -Name test -Value {
>> param(
>> $name
>> )
>> Write-Host $name
>> }
>>
PS C:\Users\a> [string].test("Joe")
Joe
PS C:\Users\a>
I want to know if it's possible to add a class method that I can call it like [string]::test("blah").
Thanks.
Edit:
The reason I want to do this is because I have written a PowerShell script against .net 4.5 and I used the method [string]::isnullorwhitespace which is a .net 4 and .net 4.5 method. When I run the on a machine that only have .net 3.0 installed, I got errors. I don't want to modify all the place that used that method, instead I want to just add that method if it does not exist.
Thanks.