PowerShell, Extension Methods, and Monkey Patching
问题 Is it possible to write extension method in PowerShell? or to bolt a new method on top of an existing type like [string] live at runtime? 回答1: I don't know of a way to patch a type with an extension method. But it's certainly possible to patch an object via the add-member cmdlet PS> $a = "foo" PS> $a = add-member -in $a -memberType ScriptMethod -name Bar -value { $this + "bar" } -passthru PS> $a.Foo() foobar EDIT Explain the completely and totally readable PowerShell Syntax :) I love