Skip to content

Commit

Permalink
Merge pull request adbertram#24 from daabm/patch-1
Browse files Browse the repository at this point in the history
Update New-DynamicParam.ps1
  • Loading branch information
adbertram authored Apr 26, 2020
2 parents 85694a3 + 8404fa3 commit ce9baf6
Showing 1 changed file with 46 additions and 30 deletions.
76 changes: 46 additions & 30 deletions PowerShell Internals/New-DynamicParam.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,44 @@
DynamicParam {
$ParamOptions = @(
@{
'Name' = 'Right';
'Mandatory' = $true;
'ValidateSetOptions' = ([System.Security.AccessControl.FileSystemRights]).DeclaredMembers | where { $_.IsStatic } | select -ExpandProperty name
Name = 'Right'
ParameterAttributes = @(
@{
Mandatory = $true
# ParameterSetName = 'a'
# Position = 0
# ValueFromPipeline = $true
# ValueFromPipelinyByPropertyName = $true
}
)
ValidateSetOptions = ([System.Security.AccessControl.FileSystemRights]).DeclaredMembers | where { $_.IsStatic } | select -ExpandProperty name
},
@{
'Name' = 'InheritanceFlags';
'Mandatory' = $true;
'ValidateSetOptions' = ([System.Security.AccessControl.InheritanceFlags]).DeclaredMembers | where { $_.IsStatic } | select -ExpandProperty name
Name = 'InheritanceFlags'
ParameterAttributes = @(
@{
Mandatory = $true
}
)
ValidateSetOptions = ([System.Security.AccessControl.InheritanceFlags]).DeclaredMembers | where { $_.IsStatic } | select -ExpandProperty name
},
@{
'Name' = 'PropagationFlags';
'Mandatory' = $true;
'ValidateSetOptions' = ([System.Security.AccessControl.PropagationFlags]).DeclaredMembers | where { $_.IsStatic } | select -ExpandProperty name
Name = 'PropagationFlags'
ParameterAttributes = @(
@{
Mandatory = $true
}
)
ValidateSetOptions = ([System.Security.AccessControl.PropagationFlags]).DeclaredMembers | where { $_.IsStatic } | select -ExpandProperty name
},
@{
'Name' = 'Type';
'Mandatory' = $true;
'ValidateSetOptions' = ([System.Security.AccessControl.AccessControlType]).DeclaredMembers | where { $_.IsStatic } | select -ExpandProperty name
Name = 'Type'
ParameterAttributes = @(
@{
Mandatory = $true
}
)
ValidateSetOptions = ([System.Security.AccessControl.AccessControlType]).DeclaredMembers | where { $_.IsStatic } | select -ExpandProperty name
}
)
$RuntimeParamDic = New-Object System.Management.Automation.RuntimeDefinedParameterDictionary
Expand Down Expand Up @@ -69,8 +89,8 @@ function New-DynamicParameter
[ValidateNotNullOrEmpty()]
[type]$Type = [string],

[ValidateNotNullOrEmpty()]
[Parameter()]
[ValidateNotNullOrEmpty()]
[array]$ValidateSetOptions,

[Parameter()]
Expand All @@ -83,25 +103,21 @@ function New-DynamicParameter
[int[]]$ValidateRange,

[Parameter()]
[switch]$Mandatory = $false,

[Parameter()]
[string]$ParameterSetName = '__AllParameterSets',

[Parameter()]
[switch]$ValueFromPipeline = $false,

[Parameter()]
[switch]$ValueFromPipelineByPropertyName = $false
[Array] $ParameterAttributes
)

$AttribColl = New-Object System.Collections.ObjectModel.Collection[System.Attribute]
$ParamAttrib = New-Object System.Management.Automation.ParameterAttribute
$ParamAttrib.Mandatory = $Mandatory.IsPresent
$ParamAttrib.ParameterSetName = $ParameterSetName
$ParamAttrib.ValueFromPipeline = $ValueFromPipeline.IsPresent
$ParamAttrib.ValueFromPipelineByPropertyName = $ValueFromPipelineByPropertyName.IsPresent
$AttribColl.Add($ParamAttrib)
Foreach ( $ParameterAttribute in $ParameterAttributes ) {
$ParamAttrib = New-Object System.Management.Automation.ParameterAttribute

$ParamAttrib.Mandatory = $ParameterAttribute.Mandatory
If ( $ParameterAttribute.Position ) { $ParamAttrib.Position = $ParameterAttribute.Position }
If ( $ParameterAttribute.ParameterSetName ) { $ParamAttrib.ParameterSetName = $ParameterAttribute.ParameterSetName }
$ParamAttrib.ValueFromPipeline = $ParameterAttribute.ValueFromPipeline
$ParamAttrib.ValueFromPipelineByPropertyName = $ParameterAttribute.ValueFromPipelineByPropertyName

$AttribColl.Add( $ParamAttrib )
}
if ($PSBoundParameters.ContainsKey('ValidateSetOptions'))
{
$AttribColl.Add((New-Object System.Management.Automation.ValidateSetAttribute($ValidateSetOptions)))
Expand All @@ -118,4 +134,4 @@ function New-DynamicParameter
$RuntimeParam = New-Object System.Management.Automation.RuntimeDefinedParameter($Name, $Type, $AttribColl)
$RuntimeParam

}
}

0 comments on commit ce9baf6

Please sign in to comment.