diff --git a/Formatting/Reflection/System.Type.format.ps1 b/Formatting/Reflection/System.Type.format.ps1 new file mode 100644 index 0000000..c7e3160 --- /dev/null +++ b/Formatting/Reflection/System.Type.format.ps1 @@ -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 \ No newline at end of file diff --git a/Formatting/Reflection/TypeBaseControl.format.ps1 b/Formatting/Reflection/TypeBaseControl.format.ps1 new file mode 100644 index 0000000..bcd0f35 --- /dev/null +++ b/Formatting/Reflection/TypeBaseControl.format.ps1 @@ -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 diff --git a/Formatting/Reflection/TypeEventControl.format.ps1 b/Formatting/Reflection/TypeEventControl.format.ps1 new file mode 100644 index 0000000..0e32e91 --- /dev/null +++ b/Formatting/Reflection/TypeEventControl.format.ps1 @@ -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 \ No newline at end of file diff --git a/Formatting/Reflection/TypeFieldControl.format.ps1 b/Formatting/Reflection/TypeFieldControl.format.ps1 new file mode 100644 index 0000000..ada85f0 --- /dev/null +++ b/Formatting/Reflection/TypeFieldControl.format.ps1 @@ -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' +} \ No newline at end of file diff --git a/Formatting/Reflection/TypeMemberControl.format.ps1 b/Formatting/Reflection/TypeMemberControl.format.ps1 new file mode 100644 index 0000000..a22f2b9 --- /dev/null +++ b/Formatting/Reflection/TypeMemberControl.format.ps1 @@ -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 +} + diff --git a/Formatting/Reflection/TypeMethodControl.format.ps1 b/Formatting/Reflection/TypeMethodControl.format.ps1 new file mode 100644 index 0000000..c813027 --- /dev/null +++ b/Formatting/Reflection/TypeMethodControl.format.ps1 @@ -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 \ No newline at end of file diff --git a/Formatting/Reflection/TypeMethodParameterControl.format.ps1 b/Formatting/Reflection/TypeMethodParameterControl.format.ps1 new file mode 100644 index 0000000..0930a99 --- /dev/null +++ b/Formatting/Reflection/TypeMethodParameterControl.format.ps1 @@ -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 diff --git a/Formatting/Reflection/TypeNameControl.format.ps1 b/Formatting/Reflection/TypeNameControl.format.ps1 new file mode 100644 index 0000000..41ff058 --- /dev/null +++ b/Formatting/Reflection/TypeNameControl.format.ps1 @@ -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 \ No newline at end of file diff --git a/Formatting/Reflection/TypePropertyControl.format.ps1 b/Formatting/Reflection/TypePropertyControl.format.ps1 new file mode 100644 index 0000000..0bf4544 --- /dev/null +++ b/Formatting/Reflection/TypePropertyControl.format.ps1 @@ -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