Boo vs. PowerShell

Oren (Ayende) wrote a cool little script in Boo showing how to count the number of types and methods in mscorlib. Just for fun, here's an equivalent script in PowerShell that does the same thing:

[System.Object].Assembly.GetTypes() | foreach { 
   $typeCount++ 
   $methodCount += $_.GetMethods().Length
}
"Types $typeCount, Methods $methodCount"

This is, of course, just one possible way to write it.

Technorati tags: ,

Comments (2)

onelinerMay 13th, 2007 at 10:38 am

[System.Object].Assembly.GetTypes() | %{$_.GetMethods().Length} | measure-object -sum

pete wJune 5th, 2007 at 7:23 pm

I just picked up powershell today, I’m hooked!
[System.Object].Assembly.GetTypes() | foreach {
$_.Name; $_.GetMethods() | foreach{"-==-"+$_.Name}
}
"Types $typeCount, Methods $methodCount"

Leave a comment

Your comment