functions/get-d365dotnetmethod.ps1

<#
.SYNOPSIS
Get a .NET method from the Dynamics 365 for Finance and Operations installation
 
.DESCRIPTION
Get a .NET method from an assembly file (dll) from the package directory
 
.PARAMETER Assembly
Name of the assembly file that you want to search for the .NET method
 
Provide the full path for the assembly file you want to work against
 
.PARAMETER Name
Name of the .NET method that you are looking for
 
Accepts wildcards for searching. E.g. -Name "parmER*Excel*"
 
Default value is "*" which will search for all methods
 
.PARAMETER TypeName
Name of the .NET class that you want to work against
 
Accepts wildcards for searching. E.g. -Name "*ER*Excel*"
 
Default value is "*" which will work against all classes
 
.EXAMPLE
Get-D365DotNetMethod -Assembly "C:\AOSService\PackagesLocalDirectory\ElectronicReporting\bin\Microsoft.Dynamics365.LocalizationFrameworkForAx.dll"
 
Will get all methods, across all classes, from the assembly file
 
.EXAMPLE
Get-D365DotNetMethod -Assembly "C:\AOSService\PackagesLocalDirectory\ElectronicReporting\bin\Microsoft.Dynamics365.LocalizationFrameworkForAx.dll" -TypeName "ERTextFormatExcelFileComponent"
 
Will get all methods, from the "ERTextFormatExcelFileComponent" class, from the assembly file
 
.EXAMPLE
Get-D365DotNetMethod -Assembly "C:\AOSService\PackagesLocalDirectory\ElectronicReporting\bin\Microsoft.Dynamics365.LocalizationFrameworkForAx.dll" -TypeName "ERTextFormatExcelFileComponent" -Name "*parm*"
 
Will get all methods that fits the search "*parm*", from the "ERTextFormatExcelFileComponent" class, from the assembly file
 
.EXAMPLE
Get-D365DotNetClass -Name "ERTextFormatExcelFileComponent" -Assembly "*LocalizationFrameworkForAx.dll*" | Get-D365DotNetMethod
 
Will get all methods, from the "ERTextFormatExcelFileComponent" class, from any assembly file that fits the search "*LocalizationFrameworkForAx.dll*"
 
.NOTES
The cmdlet supports piping and can be used in advanced scenarios. See more on github and the wiki pages.
 
#>

function Get-D365DotNetMethod {
    [CmdletBinding(DefaultParameterSetName = 'Default')]
    param (
        [Parameter(Mandatory = $true, ParameterSetName = 'Default', ValueFromPipelineByPropertyName = $true, Position = 1 )]
        [Alias('File')]
        [string] $Assembly,

        [Parameter(Mandatory = $false, ParameterSetName = 'Default', Position = 2 )]
        [Alias('MethodName')]
        [string] $Name = "*",

        [Parameter(Mandatory = $false, ParameterSetName = 'Default', Position = 3 )]
        [Alias('ClassName')]
        [string] $TypeName = "*"

    )
    
    begin {
    }
    
    process {
        $StartTime = Get-Date

        try {
            Write-Verbose "Loading the file"
            [Reflection.Assembly]$ass = [Reflection.Assembly]::LoadFile($Assembly)

            Write-Verbose "Getting all the types"
            $types = $ass.GetTypes()

            Write-Verbose "Looping all the types"
            foreach ($obj in $types) {
                Write-Verbose "$($obj.Name)"

                if ($obj.Name -NotLike $TypeName) {continue}

                $members = $obj.GetMethods()

                foreach ($objI in $members) {
                    if ($objI.Name -NotLike $Name) { continue }
                    [PSCustomObject]@{
                        TypeName     = $obj.Name
                        TypeIsPublic = $obj.IsPublic
                        MethodName   = $objI.Name
                    }

                }
            }
        }
        catch {
            # write-Error $_.Exception.Message
            # Write-Error $_.Exception

            Write-Verbose "Failed to load: $path"
        } 

        $EndTime = Get-Date
        $TimeSpan = New-TimeSpan -End $EndTime -Start $StartTime
        
        if ($PSCmdlet.MyInvocation.BoundParameters["Verbose"].IsPresent) {
            Write-Host "Time Taken inside: Get-D365DotNetMethod" -ForegroundColor Green
            Write-Host "$TimeSpan" -ForegroundColor Green
        }
    }

    end {
    }

}