Number of Types/Methods in IronPython

Thomas and Oren recently showed a couple of scripts in PowerShell and Boo respectively that count the number of types and methods in mscorlib.

Here is one possible implementation in IronPython ...

import System
typeCount = methodCount = 0
mscorlib = System.Type.GetType('System.Object').Assembly
for t in mscorlib.GetTypes():
    typeCount += 1
    methodCount += t.GetMethods().Length
print "Types: %s | Methods: %s" % (typeCount, methodCount)

On my system (Vista) this script will output ...

Types: 2318 | Methods: 27677

I wonder, is there a more efficient way to implement this in IronPython?

2 Comments

  • Here is another implementation.

    import System
    mscorlib = System.Type.Assembly.GetValue(System.Object)
    types = mscorlib.GetTypes()
    typecount = len(types)
    methodcount = sum(len(t.GetMethods()) for t in types)
    print 'Types %d, Methods %d' % (typecount, methodcount)

  • @Michael - sure it's OK. I did have a look at posting it myself at ironpython.info, but wasn't sure where it should go.

Comments have been disabled for this content.