One of the most important properties of LINQ: its flexibility
I am looking at extending LINQ for a current project. I Googled for custom linq and found resources like Charlie Calvert’s Links to LINQ then Introducing Linq to Amazon and then LINQ in Action. Other resources, Bart De Smet’s many detailed posts on LINQ that included LINQ through PowerShell.
Reading LINQ in Action, the authors start with Extension Methods. Which got me thinking about extension methods in PowerShell. Experimenting a while back I created a static class, added a method, used the this syntactical sugar but loading it up PowerShell and trying it did not work.
Continuing research on customization of LINQ led me to Bart’s post Extension Methods in Windows PowerShell. He used PowerShell’s feature called the Extended Type System. With this approach you to create Xml and use the cmdlet Update-TypeData.
You can view the extend types shipped with PowerShell like this
notepad %windir%\system32\WindowsPowerShell\v1.0\types.ps1xml
Here is Bart’s illustration of what you can find in this file and its use.
<Type>
<Name>System.Array</Name>
<Members>
<AliasProperty>
<Name>Count</Name>
<ReferencedMemberName>Length</ReferencedMemberName>
</AliasProperty>
</Members>
</Type>
PS > $a = "Jimmy", "John"
PS > $a.Count
2
Take a look at Jeffery Snover’s post Hate Add-Member? (PowerShell’s Adaptive Type System to the Rescue). He calls this feature the Adaptive Type System and shows how to extend every object so it can dynamically add Methods and Properties to itself.
Back to LINQ
Bart has a new post outlining one of the most important properties of LINQ: its flexibility.
The potential of LINQ is infinity², the reason for it being the infinite fan-in (LINQ though C#, VB, F#, PowerShell, various transport mechanisms, etc) multiplied by the infinite fan-out (LINQ to SQL, Entities, XML, Objects, DataSets, SharePoint, Active Directory, Amazon, etc).
Bart’s full post Who ever said LINQ predicates need to be Boolean-valued?

