Repository navigation
Open
Labels
KeepOpenThe bot will ignore these and not auto-closeUp-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsWG-Enginecore PowerShell engine, interpreter, and runtime
Description
Should be able to add validate attributes to params like:
class NetHelper
{
static [String]ConvertToSubnetMask(
[ValidateRange(0, 32)]
[UInt32]$PrefixLength
)
{
$byteMask = ([Convert]::ToUInt32($(("1" \* $PrefixLength).PadRight(32, "0")), 2))
$bytes = [BitConverter]::GetBytes($byteMask)
[Array]::Reverse($bytes)
$ipAddress = New-Object System.Net.IPAddress -ArgumentList (, $bytes)
return $ipAddress.IPAddressToString
}
}Just to be clear - I understand that we are creating a proper .net class and using real .Net call conventions.
What I'm suggesting is that underneath the covers, we implement something along the lines of:
class NetHelper
{
static [String]ConvertToSubnetMask(
[UInt32]$PrefixLength
)
{
[ValidateRange(0, 32)]$LocalPrefixLength = $PrefixLength
$byteMask = ([Convert]::ToUInt32($(("1" \* $LocalPrefixLength).PadRight(32, "0")), 2))
$bytes = [BitConverter]::GetBytes($byteMask)
[Array]::Reverse($bytes)
$ipAddress = New-Object System.Net.IPAddress -ArgumentList (, $bytes)
return $ipAddress.IPAddressToString
}
}Error message example:
The attribute cannot be added because variable LocalPrefixLength with value 35 would no longer be valid.
At line:8 char:8
- [ValidateRange(0, 32)]$LocalPrefixLength = $PrefixLength
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- CategoryInfo : MetadataError: (:) [], ValidationMetadataException
- FullyQualifiedErrorId : ValidateSetFailure (edited)
> $PSVersionTable
Name Value
---- -----
PSVersion 5.1.14393.206
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.14393.206
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1Reacted by Michael Klement and Mikey Lombardi (He/Him)
Metadata
Metadata
Assignees
Labels
KeepOpenThe bot will ignore these and not auto-closeUp-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsWG-Enginecore PowerShell engine, interpreter, and runtime
Activity
oising commentedon Oct 26, 2016
If someone does this, please widen also the validator attributes' usage constraints at the class level to include parameters (they are now constrained to property,field only currently) rather than special-case them when parsing the AST/emitting the type.
iSazonov commentedon Feb 21, 2017
Oisin Grehan (@oising) Please give examples for clarity.
microsoft-github-policy-service commentedon Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 23, 2023
This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.