|
11 | 11 | Note:
|
12 | 12 | Loading format files has a measureable impact on module import PER FILE.
|
13 | 13 | For the sake of performance, you should only generate a single file for an entire module.
|
14 |
| - |
| 14 | + |
15 | 15 | You can generate all items in a single call (which will probably be messy on many types at a time)
|
16 | 16 | Or you can use the -Fragment parameter to create individual fragments, and combine them by passing
|
17 | 17 | those items again to this command (the final time without the -Fragment parameter).
|
|
27 | 27 | .PARAMETER ExcludeProperty
|
28 | 28 | Only properties not in this list will be included.
|
29 | 29 |
|
| 30 | + .PARAMETER IncludePropertyAttribute |
| 31 | + Only properties that have the specified attribute will be included. |
| 32 | + |
| 33 | + .PARAMETER ExcludePropertyAttribute |
| 34 | + Only properties that do NOT have the specified attribute will be included. |
| 35 | + |
30 | 36 | .PARAMETER Fragment
|
31 | 37 | The function will only return a partial Format-XML object (an individual table definition per type).
|
32 | 38 |
|
|
67 | 73 | Label | string | L / Label
|
68 | 74 | Width | int | W / Width
|
69 | 75 | Alignment | string | Align / Alignment
|
70 |
| - |
| 76 | + |
71 | 77 | Notes:
|
72 | 78 | - Append needs to be specified if a new column should be added if no property to override was found.
|
73 | 79 | Use this to add a completely new column with a ScriptBlock.
|
74 | 80 | - Alignment: Expects a string, can be any choice of "Left", "Center", "Right"
|
75 |
| - |
| 81 | + |
76 | 82 | Example:
|
77 | 83 | $transform = @{
|
78 | 84 | Type = "System.IO.FileInfo"
|
|
93 | 99 | Creates a format xml that only includes the columns LastWriteTime, FullName
|
94 | 100 | #>
|
95 | 101 | [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "")]
|
| 102 | + [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseDeclaredVarsMoreThanAssignments", "")] |
96 | 103 | [OutputType([PSModuleDevelopment.Format.Document], ParameterSetName = "default")]
|
97 | 104 | [OutputType([PSModuleDevelopment.Format.TableDefinition], ParameterSetName = "fragment")]
|
98 | 105 | [CmdletBinding(DefaultParameterSetName = "default")]
|
|
106 | 113 | [string[]]
|
107 | 114 | $ExcludeProperty,
|
108 | 115 |
|
| 116 | + [string] |
| 117 | + $IncludePropertyAttribute, |
| 118 | + |
| 119 | + [string] |
| 120 | + $ExcludePropertyAttribute, |
| 121 | + |
109 | 122 | [Parameter(ParameterSetName = "fragment")]
|
110 | 123 | [switch]
|
111 | 124 | $Fragment,
|
|
170 | 183 | {
|
171 | 184 | $propertyNames = $propertyNames | Where-Object { $_ -notin $ExcludeProperty }
|
172 | 185 | }
|
| 186 | + if ($IncludePropertyAttribute) |
| 187 | + { |
| 188 | + $listToInclude = @() |
| 189 | + $object.GetType().GetMembers([System.Reflection.BindingFlags]("FlattenHierarchy, Public, Instance")) | Where-Object { ($_.MemberType -match "Property|Field") -and ($_.CustomAttributes.AttributeType.Name -like $IncludePropertyAttribute) } | ForEach-Object { $listToInclude += $_.Name } |
| 190 | + |
| 191 | + $propertyNames = $propertyNames | Where-Object { $_ -in $listToInclude } |
| 192 | + } |
| 193 | + if ($ExcludePropertyAttribute) |
| 194 | + { |
| 195 | + $listToExclude = @() |
| 196 | + $object.GetType().GetMembers([System.Reflection.BindingFlags]("FlattenHierarchy, Public, Instance")) | Where-Object { ($_.MemberType -match "Property|Field") -and ($_.CustomAttributes.AttributeType.Name -like $ExcludePropertyAttribute) } | ForEach-Object { $listToExclude += $_.Name } |
| 197 | + |
| 198 | + $propertyNames = $propertyNames | Where-Object { $_ -notin $listToExclude } |
| 199 | + } |
173 | 200 |
|
174 | 201 | $table = New-Object PSModuleDevelopment.Format.TableDefinition
|
175 | 202 | $table.Name = $typeName
|
|
0 commit comments