Skip to content

Commit 7556548

Browse files
Merge pull request #34 from PowershellFrameworkCollective/development
2.2.4.18
2 parents 9a6df1b + 4e5e837 commit 7556548

File tree

4 files changed

+35
-5
lines changed

4 files changed

+35
-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: 30 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"
@@ -93,6 +99,7 @@
9399
Creates a format xml that only includes the columns LastWriteTime, FullName
94100
#>
95101
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "")]
102+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseDeclaredVarsMoreThanAssignments", "")]
96103
[OutputType([PSModuleDevelopment.Format.Document], ParameterSetName = "default")]
97104
[OutputType([PSModuleDevelopment.Format.TableDefinition], ParameterSetName = "fragment")]
98105
[CmdletBinding(DefaultParameterSetName = "default")]
@@ -106,6 +113,12 @@
106113
[string[]]
107114
$ExcludeProperty,
108115

116+
[string]
117+
$IncludePropertyAttribute,
118+
119+
[string]
120+
$ExcludePropertyAttribute,
121+
109122
[Parameter(ParameterSetName = "fragment")]
110123
[switch]
111124
$Fragment,
@@ -170,6 +183,20 @@
170183
{
171184
$propertyNames = $propertyNames | Where-Object { $_ -notin $ExcludeProperty }
172185
}
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+
}
173200

174201
$table = New-Object PSModuleDevelopment.Format.TableDefinition
175202
$table.Name = $typeName

0 commit comments

Comments
 (0)