Skip to content

Commit ee617bc

Browse files
Merge pull request #30 from PowershellFrameworkCollective/find-psmdtype
Find-PSMDType Attribute parameter
2 parents b3bbbcd + b4f4219 commit ee617bc

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

PSModuleDevelopment/changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
# Changelog
2+
## 2.2.2.14 (May 03rd, 2018)
3+
- Upd: Find-PSMDType - add `-Attribute` parameter to filter by class attributes (#27)
4+
- Fix: Find-PSMDType - suppress error that gets thrown on empty assemblies.
5+
26
## 2.2.1.12 (March 08th, 2018)
37
- Added out-of-the box templates
48
- fix: Verious bugfixes around the template system

PSModuleDevelopment/functions/assembly/Find-PSMDType.ps1

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@
3737
The type must directly inherit from this type.
3838
Accepts wildcards.
3939
40+
.PARAMETER Attribute
41+
The type must have this attribute assigned.
42+
Accepts wildcards.
43+
4044
.EXAMPLE
4145
Find-PSMDType -Name "*String*"
4246
@@ -70,7 +74,10 @@
7074
$Implements,
7175

7276
[string]
73-
$InheritsFrom
77+
$InheritsFrom,
78+
79+
[string]
80+
$Attribute
7481
)
7582

7683
begin
@@ -85,11 +92,18 @@
8592
if ($boundPublic)
8693
{
8794
if ($Public) { $types = $item.ExportedTypes }
88-
else { $types = $item.GetTypes() | Where-Object IsPublic -EQ $false }
95+
else
96+
{
97+
# Empty Assemblies will error on this, which is not really an issue and can be safely ignored
98+
try { $types = $item.GetTypes() | Where-Object IsPublic -EQ $false }
99+
catch { Write-PSFMessage -Message "Failed to enumerate types on $item" -Level InternalComment -Tag 'fail','assembly','type','enumerate' -ErrorRecord $_ }
100+
}
89101
}
90102
else
91103
{
92-
$types = $item.GetTypes()
104+
# Empty Assemblies will error on this, which is not really an issue and can be safely ignored
105+
try { $types = $item.GetTypes() }
106+
catch { Write-PSFMessage -Message "Failed to enumerate types on $item" -Level InternalComment -Tag 'fail', 'assembly', 'type', 'enumerate' -ErrorRecord $_ }
93107
}
94108

95109
foreach ($type in $types)
@@ -99,6 +113,7 @@
99113
if ($Implements -and ($type.ImplementedInterfaces.Name -notcontains $Implements)) { continue }
100114
if ($boundEnum -and ($Enum -ne $type.IsEnum)) { continue }
101115
if ($InheritsFrom -and ($type.BaseType.FullName -notlike $InheritsFrom)) { continue }
116+
if ($Attribute -and ($type.CustomAttributes.AttributeType.Name -notlike $Attribute)) { continue }
102117

103118
$type
104119
}

0 commit comments

Comments
 (0)