Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How t list methods and properties after loading DLL

7,989 views
Skip to first unread message

Frank

unread,
Feb 5, 2009, 6:25:00 PM2/5/09
to

Hi,

I have a DLL which is loaded (not in GAC), ie:

[Reflection.Assembly]::LoadFile("D:\test\test.dll")

Is there a way to list the namespace, methods, and properties?

Thanks in advance,


Josh Einstein

unread,
Feb 5, 2009, 6:48:43 PM2/5/09
to
Try this

##############################################################################
# Summary: Gets a loaded assembly that matches the specified filter.
##############################################################################
function Get-Assembly {

param ( [String]$Name='*' )

foreach ($Asm in [AppDomain]::CurrentDomain.GetAssemblies() ) {
$AsmName = $Asm.GetName()
if ( $AsmName.Name -like $Name -or $AsmName.FullName -like $Name ) {
$Asm | Add-Member NoteProperty Name $AsmName.Name -PassThru |
Add-Member NoteProperty Version
$AsmName.Version -PassThru
}
}
}

##############################################################################
# Summary: Gets a loaded type (optionally specifying the assembly) that
# matches the specified filter. By default only public types are
# included unless the $NonPublic switch is set.
##############################################################################
function Get-Type {

param ( [String]$Name='*',
[String]$Assembly='*',
[Switch]$NonPublic )

foreach ( $Asm in $(Get-Assembly $Assembly) ) {
foreach ( $Type in $Asm.GetTypes() ) {
if ( $Type.Name -like $Name -or $Type.FullName -like $Name ) {
if ( $NonPublic -or $Type.IsPublic ) {
$Type | Add-Member NoteProperty AssemblyName $Asm.Name -PassThru |
Add-Member NoteProperty Version
$Asm.Version -PassThru
}
}
}
}

}

"Frank" <Fr...@discussions.microsoft.com> wrote in message
news:82B18CA2-2F91-4241...@microsoft.com...

Keith Hill [MVP]

unread,
Feb 7, 2009, 9:25:07 PM2/7/09
to
You can pretty easily slice and dice the data like this:

$asm = [Reflection.Assembly]::LoadFile("D:\test\test.dll")
$asm.GetTypes() | select Name, Namespace | sort Namespace | ft -groupby
Namespace

and for only public types

$asm.GetTypes() | ?{$_.IsPublic} | select Name, Namespace | sort Namespace |
ft -groupby Namespace

or to count all public instance members of all public types in an assembly:

$asm.GetTypes() | ?{$_.IsPublic} | select
@{n='Members';e={$_.GetMembers('Public,Instance')}} |
select -expand Members -ea 0 | ? {!$_.IsSpecialName} |
measure-object


Count : 23575
Average :
Sum :
Maximum :
Minimum :
Property :

You can get fancier by using the Group-Object cmdlet if you want to measure
certain groups of objects like say all protected vs private vs public
members.

--
Keith

"Frank" <Fr...@discussions.microsoft.com> wrote in message
news:82B18CA2-2F91-4241...@microsoft.com...

0 new messages