|
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" |
|
106 | 112 | [string[]] |
107 | 113 | $ExcludeProperty, |
108 | 114 |
|
| 115 | + [string] |
| 116 | + $IncludePropertyAttribute, |
| 117 | + |
| 118 | + [string] |
| 119 | + $ExcludePropertyAttribute, |
| 120 | + |
109 | 121 | [Parameter(ParameterSetName = "fragment")] |
110 | 122 | [switch] |
111 | 123 | $Fragment, |
|
170 | 182 | { |
171 | 183 | $propertyNames = $propertyNames | Where-Object { $_ -notin $ExcludeProperty } |
172 | 184 | } |
| 185 | + if ($IncludePropertyAttribute) |
| 186 | + { |
| 187 | + $listToInclude = @() |
| 188 | + $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 } |
| 189 | + |
| 190 | + $propertyNames = $propertyNames | Where-Object { $_ -in $listToInclude } |
| 191 | + } |
| 192 | + if ($ExcludePropertyAttribute) |
| 193 | + { |
| 194 | + $listToExclude = @() |
| 195 | + $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 } |
| 196 | + |
| 197 | + $propertyNames = $propertyNames | Where-Object { $_ -notin $listToExclude } |
| 198 | + } |
173 | 199 |
|
174 | 200 | $table = New-Object PSModuleDevelopment.Format.TableDefinition |
175 | 201 | $table.Name = $typeName |
|
0 commit comments