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,
##############################################################################
# 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...
$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...