Skip to content

Commit 57f4127

Browse files
author
Friedrich Weinmann
committed
Added parameters
Can now filter by Attribute on properties and fields
1 parent 486a42c commit 57f4127

File tree

4 files changed

+34
-5
lines changed

4 files changed

+34
-5
lines changed

PSModuleDevelopment/PSModuleDevelopment.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
RootModule = 'PSModuleDevelopment.psm1'
55

66
# Version number of this module.
7-
ModuleVersion = '2.2.3.17'
7+
ModuleVersion = '2.2.4.18'
88

99
# ID used to uniquely identify this module
1010
GUID = '37dd5fce-e7b5-4d57-ac37-832055ce49d6'

PSModuleDevelopment/PSModuleDevelopment.psm1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
$script:PSModuleRoot = $PSScriptRoot
2-
$script:PSModuleVersion = "2.2.3.17"
2+
$script:PSModuleVersion = "2.2.4.18"
33

44
$script:doDotSource = $false
55
if (Get-PSFConfigValue -FullName PSModuleDevelopment.Import.DoDotSource) { $script:doDotSource = $true }

PSModuleDevelopment/changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
# Changelog
2+
## 2.2.4.18 (May 04rd, 2018)
3+
- Upd: New-PSMDFormatTableDefinition - Update to add parameters `-IncludePropertyAttribute` and `-ExcludePropertyAttribute`
4+
25
## 2.2.3.17 (May 04rd, 2018)
36
- Upd: New-PSMDFormatTableDefinition - Major redesign, extensive additional functionality (#29)
47
- Upd: Find-PSMDType - add `-Attribute` parameter to filter by class attributes (#27)

PSModuleDevelopment/functions/format/New-PSMDFormatTableDefinition.ps1

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
Note:
1212
Loading format files has a measureable impact on module import PER FILE.
1313
For the sake of performance, you should only generate a single file for an entire module.
14-
14+
1515
You can generate all items in a single call (which will probably be messy on many types at a time)
1616
Or you can use the -Fragment parameter to create individual fragments, and combine them by passing
1717
those items again to this command (the final time without the -Fragment parameter).
@@ -27,6 +27,12 @@
2727
.PARAMETER ExcludeProperty
2828
Only properties not in this list will be included.
2929
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+
3036
.PARAMETER Fragment
3137
The function will only return a partial Format-XML object (an individual table definition per type).
3238
@@ -67,12 +73,12 @@
6773
Label | string | L / Label
6874
Width | int | W / Width
6975
Alignment | string | Align / Alignment
70-
76+
7177
Notes:
7278
- Append needs to be specified if a new column should be added if no property to override was found.
7379
Use this to add a completely new column with a ScriptBlock.
7480
- Alignment: Expects a string, can be any choice of "Left", "Center", "Right"
75-
81+
7682
Example:
7783
$transform = @{
7884
Type = "System.IO.FileInfo"
@@ -106,6 +112,12 @@
106112
[string[]]
107113
$ExcludeProperty,
108114

115+
[string]
116+
$IncludePropertyAttribute,
117+
118+
[string]
119+
$ExcludePropertyAttribute,
120+
109121
[Parameter(ParameterSetName = "fragment")]
110122
[switch]
111123
$Fragment,
@@ -170,6 +182,20 @@
170182
{
171183
$propertyNames = $propertyNames | Where-Object { $_ -notin $ExcludeProperty }
172184
}
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+
}
173199

174200
$table = New-Object PSModuleDevelopment.Format.TableDefinition
175201
$table.Name = $typeName

0 commit comments

Comments
 (0)