Skip to content

Commit

Permalink
Enums
Browse files Browse the repository at this point in the history
Fixing issue Stephanevg#104
  • Loading branch information
LxLeChat committed Apr 19, 2019
1 parent 6616f15 commit d0b68d1
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 29 deletions.
32 changes: 17 additions & 15 deletions Code/Functions/Public/Get-CUEnum.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -28,30 +28,32 @@ Function Get-CUEnum{
Param(

[Parameter(Mandatory=$false,ValueFromPipeline=$true)]
[String[]]
$Path = (throw "Please provide a path")
[System.IO.FileInfo[]]$Path
)

begin{

}
Process{

foreach($p in $Path){

$AST = Get-cuast -Path $p | ? {$_.IsEnum -eq $True}

foreach($enum in $AST){
[ClassEnum]::New($enum.Name,$enum.members.Name)
Process{
If ( $null -ne $PSBoundParameters['Path']) {
foreach($p in $Path){

$AST = Get-cuast -Path $p | ? {$_.IsEnum -eq $True}

foreach($enum in $AST){
[ClassEnum]::New($enum.Name,$enum.members.Name)
}
}
} Else {
Foreach ( $Enum in (Get-CULoadedEnum ) ) {
If($Enum.IsEnum){
[ClassEnum]::New($Enum.Name,$Enum.members.Name)
}
}
}


}
End{

}
}



}
48 changes: 48 additions & 0 deletions Code/Functions/Public/Get-CULoadedEnums.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
function Get-CULoadedEnum {
<#
.SYNOPSIS
Return all loaded classes in the current PSSession
.DESCRIPTION
Return all loaded classes in the current PSSession
.EXAMPLE
PS C:\> <example usage>
Explanation of what the example does
.INPUTS
String
.OUTPUTS
ASTDocument
.NOTES
General notes
#>
[CmdletBinding()]
param (
[String[]]$Enum = '*'
)

BEGIN {
}

PROCESS {

Foreach ( $Name in $Enum ) {

[Array]$LoadedEnums = [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 -and $_.baseType.Name -eq 'Enum' } |
Select-Object name,@{l = 'Path'; e = {($_.Module.ScopeName.Replace([char]0x29F9, '\').replace([char]0x589, ':')) -replace '^\\', ''}}
}

Foreach ( $Enum in ($LoadedEnums | Select-Object -Property Path -Unique) ) {
#Get-CURaw -Path $Class.Path
Get-CUAst -Path $Enum.Path
}

}
}

END {
}
}
2 changes: 1 addition & 1 deletion PSClassUtils/PSClassUtils.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ PowerShellVersion = '5.0'

# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
FunctionsToExport = 'Get-CUClass', 'Get-CUClassConstructor', 'Get-CUClassMethod',
'Get-CUClassProperty', 'Get-CUCommands', 'Get-CUEnum',
'Get-CUClassProperty', 'Get-CUCommands', 'Get-CUEnum','Get-CULoadedEnum',
'Get-CULoadedClass', 'Get-CURaw', 'Install-CUDiagramPrerequisites',
'Test-IsCustomType', 'Write-CUClassDiagram',
'Write-CUInterfaceImplementation', 'Write-CUPesterTest'
Expand Down
86 changes: 73 additions & 13 deletions PSClassUtils/PSClassUtils.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,7 @@ Function Get-CUAst {
}
}


function New-CUGraphExport {
<#
.SYNOPSIS
Expand Down Expand Up @@ -1650,6 +1651,62 @@ function Get-CUCommands {

return Get-Command -Module PSClassUtils
}


function Get-CULoadedEnum {
<#
.SYNOPSIS
Return all loaded classes in the current PSSession
.DESCRIPTION
Return all loaded classes in the current PSSession
.EXAMPLE
PS C:\> <example usage>
Explanation of what the example does
.INPUTS
String
.OUTPUTS
ASTDocument
.NOTES
General notes
#>
[CmdletBinding()]
param (
[String[]]$Enum = '*'
)

BEGIN {
}

PROCESS {

Foreach ( $Name in $Enum ) {

[Array]$LoadedEnums = [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 -and $_.baseType.Name -eq 'Enum' } |
Select-Object name,@{l = 'Path'; e = {($_.Module.ScopeName.Replace([char]0x29F9, '\').replace([char]0x589, ':')) -replace '^\\', ''}}
}

If ( ($LoadedEnums | Select-Object -Property Path -Unique) -is [Array]){
Foreach ( $Enum in $x ) {
Get-CUAst -Path $Enum.Path
}
} Else {
Get-CUAST -Path ($LoadedEnums | Select-Object -Property Path -Unique).Path
}



}
}

END {
}
}

Function Get-CUEnum{
<#
.SYNOPSIS
Expand All @@ -1670,7 +1727,7 @@ Function Get-CUEnum{
.OUTPUTS
Classenum
.NOTES
Author: Stéphane van Gulick
Author: Stéphane van Gulick
Version: 0.2.0
.LINK
Expand All @@ -1680,33 +1737,37 @@ Function Get-CUEnum{
Param(

[Parameter(Mandatory=$false,ValueFromPipeline=$true)]
[String[]]
$Path = (throw "Please provide a path")
[System.IO.FileInfo[]]$Path
)

begin{

}
Process{

foreach($p in $Path){
Process{
If ( $null -ne $PSBoundParameters['Path']) {
foreach($p in $Path){

$AST = Get-cuast -Path $p | ? {$_.IsEnum -eq $True}

foreach($enum in $AST){
[ClassEnum]::New($enum.Name,$enum.members.Name)
$AST = Get-cuast -Path $p | ? {$_.IsEnum -eq $True}

foreach($enum in $AST){
[ClassEnum]::New($enum.Name,$enum.members.Name)
}
}
} Else {
Foreach ( $Enum in (Get-CULoadedEnum ) ) {
If($Enum.IsEnum){
[ClassEnum]::New($Enum.Name,$Enum.members.Name)
}
}
}


}
End{

}
}



function Get-CULoadedClass {
<#
.SYNOPSIS
Expand Down Expand Up @@ -1745,7 +1806,6 @@ function Get-CULoadedClass {
}

Foreach ( $Class in ($LoadedClasses | Select-Object -Property Path -Unique) ) {
#Get-CURaw -Path $Class.Path
Get-CUAst -Path $Class.Path
}

Expand Down

0 comments on commit d0b68d1

Please sign in to comment.