Closed Stephanevg closed 5 years ago
Hello @Stephanevg as discussed on the chat, maybe the path parameter of the cmdlet shoud only be a fileinfo type. With the correct alias for Path (example fullname), and the following properties in your parameter: acceptvaluefrompipelinebypropertyname this could do the trick
I agree, I think it is quite elegant actually. I'll update the first comment I made to take this into consideration. (See edits parts above)
I rewrote the Get-CUClass and the return is an ASTDocument type. You can review the code is you like it in my dev_branch: Get-CUClass
PS C:\Users\Lxlechat\GitPerso\PSClassUtils\PsClassUtils> Get-CUClass
Classes Enums Source
------- ----- ------
{ClassProperty} C:\Users\Lxlechat\GitPerso\PSClassUtils\PsClassUtils\Classes\Private\01_ClassProperty.ps1
{ClassMethod} C:\Users\Lxlechat\GitPerso\PSClassUtils\PsClassUtils\Classes\Private\02_ClassMethod.ps1
{ClassConstructor} C:\Users\Lxlechat\GitPerso\PSClassUtils\PsClassUtils\Classes\Private\03_ClassConstructor.ps1
{ASTDocument} C:\Users\Lxlechat\GitPerso\PSClassUtils\PsClassUtils\Classes\Private\04_ASTDocument.ps1
{ClassEnum} C:\Users\Lxlechat\GitPerso\PSClassUtils\PsClassUtils\Classes\Private\05_ClassEnum.ps1
With Path parameter
PS C:\Users\Lxlechat\GitPerso\PSClassUtils\PsClassUtils\Classes\Private> Get-CUClass -Path .\01_ClassProperty.ps1
Classes Enums Source
------- ----- ------
{ClassProperty} C:\Users\Lxlechat\GitPerso\PSClassUtils\PsClassUtils\Classes\Private\01_ClassProperty.ps1
From the pipeline
PS C:\Users\Lxlechat\GitPerso\PSClassUtils\PsClassUtils\Classes> gci -Recurse | Get-CUClass
Classes Enums Source
------- ----- ------
{ClassProperty} C:\Users\Lxlechat\GitPerso\PSClassUtils\PsClassUtils\Classes\Private\01_ClassProperty.ps1
{ClassMethod} C:\Users\Lxlechat\GitPerso\PSClassUtils\PsClassUtils\Classes\Private\02_ClassMethod.ps1
{ClassConstructor} C:\Users\Lxlechat\GitPerso\PSClassUtils\PsClassUtils\Classes\Private\03_ClassConstructor.ps1
{ASTDocument} C:\Users\Lxlechat\GitPerso\PSClassUtils\PsClassUtils\Classes\Private\04_ASTDocument.ps1
{ClassEnum} C:\Users\Lxlechat\GitPerso\PSClassUtils\PsClassUtils\Classes\Private\05_ClassEnum.ps1
With an array of paths
PS C:\Users\Lxlechat\GitPerso\PSClassUtils\PsClassUtils> Get-CUClass -Path ".\Classes\Private\01_ClassProperty.ps1","C:\Users\Lxlechat\GitPerso\HostsFileManagement\HostsFileManagement\Classes\Public\HostsEntry.ps1"
Classes Enums Source
------- ----- ------
{ClassProperty} C:\Users\Lxlechat\GitPerso\PSClassUtils\PsClassUtils\Classes\Private\01_ClassProperty.ps1
{HostsEntry} C:\Users\Lxlechat\GitPerso\HostsFileManagement\HostsFileManagement\Classes\Public\HostsEntry.ps1
The main change i did was modyfying the default behavior where i replace the name property that was firest return, to a path
$LoadedClasses = [AppDomain]::CurrentDomain.GetAssemblies() |
Where-Object { $_.GetCustomAttributes($false) |
Where-Object { $_ -is [System.Management.Automation.DynamicClassImplementationAssemblyAttribute]} } |
ForEach-Object { $_.GetTypes() |
Where-Object IsPublic |
Where-Object { $_.Name -like $Name } |
Select-Object @{l='Path';e={($_.Module.ScopeName.Replace([char]0x29F9,'\').replace([char]0x589,':')) -replace '^\\',''}}
}
Thanks to @NicolasBn for helping me resolve the conversion of the strange ScopeName encoding! and his help for the DefaultParameterSetName !! Team Work !
Closing as this has been merged.
I would like to add the possiblity to get class information of classes located in files. For this, adding -Path parameter seems to be the best solution.
The parameter should be added to the following functions:
The -Path parameter should be allowed to receive
only
either.ps1
or.psm1
files, any other types should be ignored.edits after discussions
As suggested by @LxLeChat we could make -Path accept pipelineinput, and set an alias on it. It will allow us to avoid an extra complicated design choise, and handle folder input. It will also make the cmdlet more user friendly, as one could use it like this:
Also, what should not be forgoten, is that currently, the
Get-CUXXX
cmdlets have only one parameter-ClassName
and it should be kept.When no -Path is passed, the -ClassName should look into the current loaded classes (current existing code). When
-ClassName
&-Path
are together,-ClassName
should filter the file out, that has a class having the name$ClassName
end of edits