Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues resolution #109

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions Code/Classes/06_CUClass.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,34 @@ Class CUClass {

}

[string]Sirene(){
$string = $null

$properties =''
$this.property.foreach({
if($_.visibility -eq 'public' ) {
$properties = $properties + "`n+" + $_.Type + " " + $_.Name
} else {
$properties = $properties + "`n-" + $_.Type + " " + $_.Name
}
})

$methods = ''
$this.method.foreach({
if(-not $_.static ) { $methods = $methods + "`n+" + $_.Name + "(" + ($_.Parameter.Name -join ',') + ") " + $_.ReturnType } else { "prout "}
})

$Composition = ''


$string =
"class $($this.name){
$properties
$methods
}
$composition
"
return $string
}

}
51 changes: 51 additions & 0 deletions Code/Classes/09_CUHelper.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using namespace System.Management.Automation.Language

class CUHelper {

[CUClass[]] static FindClass() {
## sera retourner
$x = @()

$name = "*"

[Array]$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 '^\\', ''}}
}

Foreach ( $Class in ($LoadedClasses | Select-Object -Property Path -Unique) ) {
# Get-CUAst -Path $Class.Path
## On parse le fichier
$ParsedFile = [Parser]::ParseFile($Class.Path, [ref]$null, [ref]$Null)
## un script commence toujours par un nameblockast, on recherche donc ce type d'AST
$NamedBlock = $ParsedFile.find({$args[0] -is [namedblockast]},$false)

## On parcour toutes les AST
foreach ( $node in $NamedBlock.FindAll({$args[0] -is [TypeDefinitionAst]},$false) ) {
$x += [CUClass]::new($node)
}
}
return $x
}

[CUClass[]] static FindClass([string]$File) {
## sera retourner
$x = @()

## On parse le fichier
$ParsedFile = [Parser]::ParseFile($file, [ref]$null, [ref]$Null)

## un script commence toujours par un nameblockast, on recherche donc ce type d'AST
$NamedBlock = $ParsedFile.find({$args[0] -is [namedblockast]},$false)

## On parcour toutes les AST
foreach ( $node in $NamedBlock.FindAll({$args[0] -is [TypeDefinitionAst]},$false) ) {
$x += [CUClass]::new($node)
}
return $x
}
}
20 changes: 10 additions & 10 deletions Code/Functions/Public/Get-CUClass.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -103,23 +103,23 @@ function Get-CUClass {
} Else {

Foreach ( $x in (Get-CULoadedClass @ClassParams ) ) {

If ( $PSBoundParameters['ClassName'] ) {
If ( $x.name -eq $PSBoundParameters['ClassName'] ) {
If ( !$x.IsEnum ){
If ( $PSBoundParameters['ClassName'] ) {
If ( $x.name -eq $PSBoundParameters['ClassName'] ) {
If ( $PSBoundParameters['Raw'] ) {
([CUClass]::New($x)).Raw
} Else {
[CUClass]::New($x)
}
}
} Else {
If ( $PSBoundParameters['Raw'] ) {
([CUClass]::New($x)).Raw
} Else {
[CUClass]::New($x)
}
}
} Else {
If ( $PSBoundParameters['Raw'] ) {
([CUClass]::New($x)).Raw
} Else {
[CUClass]::New($x)
}
}

}
}
}
Expand Down
118 changes: 75 additions & 43 deletions Code/Functions/Public/Get-CUClassProperty.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,21 @@ Function Get-CUClassProperty {
.NOTES
General notes
#>
[cmdletBinding()]
[cmdletBinding(DefaultParameterSetName="All")]
[OutputType([CUClassMethod[]])]
Param(
[Alias("FullName")]
[Parameter(ParameterSetName = "Path", Position = 1, Mandatory = $False, ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True)]
[System.IO.FileInfo[]]$Path,

[Parameter(Mandatory=$False, ValueFromPipeline=$False)]
[String[]]$ClassName,

[Parameter(ValueFromPipeline=$True)]
[ValidateScript({
If ( !($_.GetType().Name -eq "CUClass" ) ) { Throw "InputObect Must be of type CUClass.."} Else { $True }
})]
[Object[]]$InputObject,
[Parameter(ValueFromPipeline=$True,ParameterSetName="Set1")]
[CUClass[]]$InputObject,

[Alias("FullName")]
[Parameter(ValueFromPipeline=$True,ParameterSetName="Set2",ValueFromPipelineByPropertyName=$True)]
[System.IO.FileInfo[]]$Path,

[Switch]$Raw

)

BEGIN {}
Expand All @@ -42,50 +41,83 @@ Function Get-CUClassProperty {
$ClassParams.ClassName = $ClassName
}

If ($Path -or $PSBoundParameters['Path'] ) {
$ClassParams.Path = $Path.FullName
}
Switch ( $PSCmdlet.ParameterSetName ) {

If ($InputObject) {
$ClassParams.ClassName = $ClassName
}
## CUClass as input
Set1 {
Write-Verbose '[Get-CUClassProperty][CUClassInput]'
Foreach ( $Class in $InputObject ) {
Write-Verbose "[Get-CUClassProperty][CUClass Class Name is: $($Class.Name) ]"
If ( $ClassParams.ClassName ) {
If ( $Class.Name -eq $ClassParams.ClassName ) {
If ( $PSBoundParameters['Raw'] ) {
($Class.GetCuClassProperty()).Raw
} Else {
$Class.GetCuClassProperty()
}
}
} Else {
If ( $PSBoundParameters['Raw'] ) {
($Class.GetCuClassProperty()).Raw
} Else {
$Class.GetCuClassProperty()
}
}
}

}


$Class = Get-CuClass @ClassParams
If ($Class) {
## File as Input
Set2 {
Write-Verbose '[Get-CUClassProperty][FileInput]'
Foreach ( $P in $Path ) {
Write-Verbose "[Get-CUClassProperty][FileInput Path is: $($p.fullname) ]"
If ( $P.extension -in ".ps1",".psm1" ) {

If($Raw){
$Class.GetCuClassProperty().Raw
}else{
If ($PSCmdlet.MyInvocation.ExpectingInput) {
$ClassParams.Path = $P.FullName
} Else {
$ClassParams.Path = (Get-Item (Resolve-Path $P).Path).FullName
}

$x=Get-CuClass @ClassParams
If ( $null -ne $x.Property ) {
If ( $PSBoundParameters['Raw'] ) {

($x.GetCuClassProperty()).Raw
} Else {
$x.GetCuClassProperty()
}

}
}
}

$Class.GetCuClassProperty()
}
}

<# If ( $MyInvocation.PipelinePosition -eq 1 ) {
## Not from the Pipeline
If ( $Null -eq $PSBoundParameters['InputObject'] ) {
Throw "Please Specify an InputObject of type CUClass"
}
If ( $Null -eq $PSBoundParameters['ClassName'] ) {
$InputObject.GetCuClassProperty()
} Else {
Foreach ( $C in $ClassName ){
($InputObject | where Name -eq $c).GetCuClassProperty()
Default {
$ClassParams = @{}

If ( $null -ne $PSBoundParameters['ClassName'] ) {
$ClassParams.ClassName = $PSBoundParameters['ClassName']
}
}

} Else {
## From the Pipeline
If ( $Null -eq $PSBoundParameters['ClassName'] ) {
$InputObject.GetCuClassProperty()
} Else {
Throw "-ClassName parameter must be specified on the left side of the pipeline"
Foreach($Class in (Get-CuClass @ClassParams)) {
If ( $Class.Constructor.count -ne 0 ) {
If ( $Raw ) {
$Class.GetCuClassProperty().Raw
} Else {

$Class.GetCuClassProperty()
}

}
}
}
}
#>

}

END {}

}
}
36 changes: 21 additions & 15 deletions Code/Functions/Public/Get-CUEnum.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,38 @@ Function Get-CUEnum{
#>
[cmdletBinding()]
Param(

[Parameter(Mandatory=$false,ValueFromPipeline=$true)]
[String[]]
$Path = (throw "Please provide a path")
[Alias("FullName")]
[Parameter(ValueFromPipeline=$True,ValueFromPipelineByPropertyName=$True)]
[string[]]$Path
)

begin{

}
Process{

foreach($p in $Path){
Process{
ForEach( $p in $Path) {

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

foreach($enum in $AST){
[ClassEnum]::New($enum.Name,$enum.members.Name)
$item = get-item (resolve-path -path $p).path
If ( $item -is [system.io.FileInfo] -and $item.Extension -in @('.ps1','.psm1') ) {
Write-Verbose "[Get-CUEnum][Path] $($item.FullName)"
$AST = Get-cuast -Path $item.FullName | Where-Object IsEnum

foreach($enum in $AST){
[ClassEnum]::New($enum.Name,$enum.members.Name)
}
}
}


If ( $null -eq $PSBoundParameters['Path']) {
Foreach ( $Enum in (Get-CULoadedClass ) ) {
If($Enum.IsEnum){
[ClassEnum]::New($Enum.Name,$Enum.members.Name)
}
}
}
}
End{

}
}



}
Loading