-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding Reflection Formatter (Fixes #15)
- Loading branch information
James Brundage
committed
Jul 20, 2023
1 parent
23807ca
commit 6ae0841
Showing
9 changed files
with
156 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
Write-FormatView -TypeName System.Type -Property FullName, BaseType, IsPublic, IsSerializable -AutoSize | ||
|
||
Write-FormatView -TypeName System.Type -Action { | ||
Write-FormatViewExpression -Newline | ||
Write-FormatViewExpression -ScriptBlock { '-' * ($Host.UI.RawUI.BufferSize.Width - 1) } | ||
Write-FormatViewExpression -ScriptBlock { ' ' * 1 } | ||
Write-FormatViewExpression -ForegroundColor 'Verbose' -ScriptBlock { $_ } -ControlName TypeNameControl | ||
Write-FormatViewExpression -ScriptBlock { ' ' * 1 } | ||
Write-FormatViewExpression -If { $_.BaseType -and -not $_.IsValueType } -ScriptBlock { | ||
':' | ||
} | ||
Write-FormatViewExpression -If { $_.BaseType -and -not $_.IsValueType -and $_.BaseType -ne [Object] } -Property BaseType -ControlName TypeBase | ||
Write-FormatViewExpression -If { $_.GetInterfaces() } -ScriptBlock { $_.GetInterfaces() | Sort-Object Name} -Enumerate -ControlName TypeBase | ||
} -GroupLabel 'Type Summary' -GroupByScript { '| Format-Custom -View System.Type.Full for more'} -Name System.Type.Summary | ||
|
||
Write-FormatView -TypeName System.Type -Action { | ||
Write-FormatViewExpression -Newline | ||
Write-FormatViewExpression -ScriptBlock { '-' * ($Host.UI.RawUI.BufferSize.Width - 1) } | ||
Write-FormatViewExpression -ScriptBlock { ' ' * 1 } | ||
Write-FormatViewExpression -ForegroundColor 'Verbose' -ScriptBlock { $_ } -ControlName TypeNameControl | ||
Write-FormatViewExpression -ScriptBlock { ' ' * 1 } | ||
Write-FormatViewExpression -If { $_.BaseType -and -not $_.IsValueType -and $_.BaseType -ne [Object] } -ScriptBlock { | ||
':' | ||
} | ||
Write-FormatViewExpression -If { $_.BaseType -and -not $_.IsValueType -and $_.BaseType -ne [Object] } -Property BaseType -ControlName TypeBase | ||
Write-FormatViewExpression -If { $_.GetInterfaces() } -ScriptBlock { $_.GetInterfaces() | Sort-Object Name} -Enumerate -ControlName TypeBase | ||
|
||
Write-FormatViewExpression -If { $_.GetConstructors('Instance,Public') } -ScriptBlock { | ||
[Environment]::NewLine + ('#' * 3) + ' Constructors:' | ||
} | ||
Write-FormatViewExpression -If { $_.GetConstructors('Instance,Public') } -ScriptBlock { | ||
$_.GetConstructors('Instance,Public') | ||
} -Enumerate -ControlName TypeMethodControl | ||
Write-FormatViewExpression -If { $_.GetEvents('Instance,Public') } -ScriptBlock { | ||
[Environment]::NewLine + ('#' * 3) + ' Events:' | ||
} | ||
Write-FormatViewExpression -If { $_.GetEvents('Instance,Public') } -ScriptBlock { | ||
$_.GetEvents('Instance,Public') | Sort-Object Name | ||
} -Enumerate -ControlName TypeEventControl | ||
Write-FormatViewExpression -If { $_.GetProperties('Static,Public') } -ScriptBlock { | ||
[Environment]::NewLine + ('#' * 3) + ' Static Properties:' | ||
} | ||
Write-FormatViewExpression -If { $_.GetProperties('Static,Public')} -ScriptBlock { | ||
$_.GetProperties('Static,Public') | Sort-Object Name | ||
} -Enumerate -ControlName TypePropertyControl | ||
Write-FormatViewExpression -If { $_.GetProperties('Instance,Public') } -ScriptBlock { | ||
[Environment]::NewLine + ('#' * 3) + ' Properties:' | ||
} | ||
Write-FormatViewExpression -If { $_.GetProperties('Instance,Public')} -ScriptBlock { | ||
$_.GetProperties('Instance,Public') | Sort-Object Name | ||
} -Enumerate -ControlName TypePropertyControl | ||
Write-FormatViewExpression -If { $_.GetMethods('Static,Public') } -ScriptBlock { | ||
[Environment]::NewLine + ('#' * 3) + ' Static Methods:' | ||
} | ||
Write-FormatViewExpression -If { $_.GetMethods('Static,Public') } -ScriptBlock { | ||
$_.GetMethods('Static,Public') | Sort-Object Name | Where-Object { -not $_.IsSpecialName } | ||
} -Enumerate -ControlName TypeMethodControl | ||
Write-FormatViewExpression -If { $_.GetMethods('Instance,Public') } -ScriptBlock { | ||
[Environment]::NewLine + ('#' * 3) + ' Methods:' | ||
} | ||
Write-FormatViewExpression -If { $_.GetMethods('Instance,Public') } -ScriptBlock { | ||
$_.GetMethods('Instance,Public') | Sort-Object Name | Where-Object { -not $_.IsSpecialName } | ||
} -Enumerate -ControlName TypeMethodControl | ||
} -Name System.Type.Full |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Write-FormatView -Action { | ||
Write-FormatViewExpression -Newline | ||
Write-FormatViewExpression -ScriptBlock { ' *' } | ||
Write-FormatViewExpression -ControlName TypeNameControl -ScriptBlock {$_ } -Style 'Foreground.Cyan', 'Bold' | ||
} -TypeName TypeBase -Name TypeBase -AsControl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
Write-FormatView -Action { | ||
Write-FormatViewExpression -If { -not $script:DisplayingMember } -ScriptBlock { [Environment]::NewLine } | ||
Write-FormatViewExpression -ScriptBlock { ' * ' } | ||
Write-FormatViewExpression -Property Name -Style 'Formatting.Warning' | ||
Write-FormatViewExpression -Text '(' | ||
Write-FormatViewExpression -If { $_.EventHandlerType.GetMethod('Invoke') } -ScriptBlock { | ||
$MethodParameters = @($_.EventHandlerType.GetMethod('Invoke').GetParameters()) | ||
foreach ($n in 0..($MethodParameters.Count - 1)) { | ||
$o =[PSObject]::new($MethodParameters[$n]) | ||
$o.psobject.properties.add([PSNoteProperty]::new('N', $N)) | ||
$o | ||
} | ||
} -ControlName TypeMethodParameterControl -Enumerate | ||
Write-FormatViewExpression -Text ')' | ||
} -TypeName TypeEventControl -Name TypeEventControl -AsControl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Write-FormatControl -Name TypeFieldControl -Action { | ||
Write-FormatViewExpression -If { -not $script:DisplayingMember } -ScriptBlock { [Environment]::NewLine } | ||
Write-FormatViewExpression -ScriptBlock { ' * '} | ||
Write-FormatViewExpression -Property FieldType -ControlName TypeNameControl -Style 'Foreground.Cyan', 'Bold' | ||
Write-FormatViewExpression -Property Name -Style 'Formatting.Warning' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
Write-FormatControl -Name TypeMemberControl -Action { | ||
Write-FormatViewExpression -If { | ||
'RuntimeMethodInfo', 'RuntimeConstructorInfo' -contains $_.GetType().Name | ||
} -ScriptBlock {$_ } -ControlName TypeMethodControl | ||
Write-FormatViewExpression -If { $_.GetType().Name -eq 'RuntimePropertyInfo' } -ScriptBlock {$_ } -ControlName TypePropertyControl | ||
Write-FormatViewExpression -If { | ||
|
||
'MdFieldInfo', 'RtFieldInfo' -contains $_.GetType().Name | ||
} -ScriptBlock {$_ } -ControlName TypeFieldControl | ||
Write-FormatViewExpression -If { $_.GetType().Name -eq 'RuntimeEventInfo' } -ScriptBlock {$_ } -ControlName TypeEventControl | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Write-FormatView -Action { | ||
Write-FormatViewExpression -If { -not $script:DisplayingMember } -ScriptBlock { [Environment]::NewLine } | ||
Write-FormatViewExpression -ScriptBlock { ' *' } | ||
Write-FormatViewExpression -If { $_.IsStatic } -ScriptBlock { ' static ' } | ||
Write-FormatViewExpression -If {$_.IsConstructor } -ScriptBlock { $_.DeclaringType } -ControlName TypeNameControl -Style 'Foreground.Cyan','Bold' | ||
Write-FormatViewExpression -If { -not $_.IsConstructor -and $_.ReturnType } -ScriptBlock { $_.ReturnType } -ControlName TypeNameControl -Style 'Foreground.Cyan','Bold' | ||
Write-FormatViewExpression -If { -not $_.IsConstructor } -ScriptBlock { ' ' + $_.Name } -Style 'Formatting.Warning' | ||
Write-FormatViewExpression -ScriptBlock { ' (' } | ||
Write-FormatViewExpression -ScriptBlock { | ||
$MethodParameters = @($_.GetParameters()) | ||
foreach ($n in 0..($MethodParameters.Count - 1)) { | ||
$o =[PSObject]::new($MethodParameters[$n]) | ||
$o.psobject.properties.add([PSNoteProperty]::new('N', $N)) | ||
$o | ||
} | ||
} -ControlName TypeMethodParameterControl -Enumerate | ||
Write-FormatViewExpression -ScriptBlock { ')' } | ||
|
||
} -TypeName TypeMethodControl -Name TypeMethodControl -AsControl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Write-FormatView -Action { | ||
Write-FormatViewExpression -If { $_.N -gt 0} -ScriptBlock { ', ' } | ||
Write-FormatViewExpression -Property ParameterType -ControlName TypeNameControl -Style 'Formatting.Verbose' | ||
Write-FormatViewExpression -ScriptBlock { '$' + $_.Name } -Style 'Formatting.Warning' | ||
Write-FormatViewExpression -ScriptBlock { ' ' } | ||
} -TypeName TypeMethodParameterControl -Name TypeMethodParameterControl -AsControl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
Write-FormatView -AsControl -Name TypeNameControl -Action { | ||
Write-FormatViewExpression -Text ' [' | ||
Write-FormatViewExpression -ScriptBlock { | ||
if ($_.FullName) { | ||
$_.Fullname -replace '`.+', '' -replace '^System\.', '' | ||
} else { | ||
$_.Name -replace '`.+', '' -replace '^System\.', '' | ||
} | ||
} | ||
|
||
Write-FormatViewExpression -If { | ||
$_.IsGenericType | ||
} -ControlName TypeNameControl -ScriptBlock { | ||
$_.GenericTypeArguments | ||
} -Enumerate | ||
Write-FormatViewExpression -Text ']' | ||
} -TypeName TypeNameControl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
Write-FormatView -Action { | ||
Write-FormatViewExpression -If { -not $script:DisplayingMember } -ScriptBlock { [Environment]::NewLine } | ||
Write-FormatViewExpression -ScriptBlock { ' * '} | ||
Write-FormatViewExpression -Property PropertyType -ControlName TypeNameControl -Style 'Foreground.Cyan','Bold' | ||
Write-FormatViewExpression -Property Name -Style 'Formatting.Warning' | ||
Write-FormatViewExpression -ScriptBlock { | ||
' {' + | ||
$(if ($_.CanRead) {'get;'}) + | ||
$(if ($_.CanWrite) {'set;'})+ | ||
'}' | ||
} | ||
} -TypeName TypePropertyControl -Name TypePropertyControl -AsControl |