When learning a strongly-typed, object oriented language one of the first concepts you learn is polymorphism. Polymorphic members accept object types that define a particular contract. Class instances that meet this contract, even if they extend from it, can be provided to these members. In PowerShell, this can be true when dealing with .NET classes. For example, our good friend WebClient exposes some polymorphic methods. When you invoke GetWebRequest, it returns a WebRequest class instance. What you’ll notice, via MSDN, is that there are actually more specific versions of a WebRequest. For example, the HttpRequest that is returned when using the WebClient and the HTTP protocol.
↧