Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions 40 src/System.Management.Automation/engine/Attributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -902,26 +902,26 @@ public ValidateLengthAttribute(int minLength, int maxLength) : base()
/// <Summary>
/// Predefined range kind to use with ValidateRangeAttribute.
/// </Summary>
public enum ValidateRangeKind
public enum ValidateRangeKind
{
/// <Summary>
/// Range is greater than 0.
/// </Summary>
Positive,

/// <Summary>
/// Range is greater than or equal to 0.
/// </Summary>
NonNegative,

/// <Summary>
/// Range is less than 0.
/// </Summary>
Negative,

/// <Summary>
/// Range is less than or equal to 0.
/// </Summary>
/// </Summary>
NonPositive
}
/// <summary>
Expand Down Expand Up @@ -978,7 +978,7 @@ protected override void ValidateElement(object element)
{
element = o.BaseObject;
}

if (_rangeKind.HasValue)
{
ValidateRange(element, (ValidateRangeKind)_rangeKind);
Expand Down Expand Up @@ -1078,9 +1078,9 @@ private void ValidateRange(object element, ValidateRangeKind rangeKind)
{
throw new ValidationMetadataException(
"ValidationRangeElementType",
null,
null,
Metadata.ValidateRangeElementType,
element.GetType().Name,
element.GetType().Name,
typeof(int).Name);
}

Expand All @@ -1090,19 +1090,19 @@ private void ValidateRange(object element, ValidateRangeKind rangeKind)
if (LanguagePrimitives.TryConvertTo(element, commonType, out resultValue))
{
element = resultValue;

if (LanguagePrimitives.TryConvertTo(0, commonType, out resultValue))
{
dynamicZero = (IComparable)resultValue;
}
}
}
else
{
throw new ValidationMetadataException(
"ValidationRangeElementType",
null,
null,
Metadata.ValidateRangeElementType,
element.GetType().Name,
element.GetType().Name,
commonType.Name);
}

Expand All @@ -1113,7 +1113,7 @@ private void ValidateRange(object element, ValidateRangeKind rangeKind)
{
throw new ValidationMetadataException(
"ValidateRangePositiveFailure",
null,
null,
Metadata.ValidateRangePositiveFailure,
element.ToString());
}
Expand All @@ -1123,7 +1123,7 @@ private void ValidateRange(object element, ValidateRangeKind rangeKind)
{
throw new ValidationMetadataException(
"ValidateRangeNonNegativeFailure",
null,
null,
Metadata.ValidateRangeNonNegativeFailure,
element.ToString());
}
Expand All @@ -1133,7 +1133,7 @@ private void ValidateRange(object element, ValidateRangeKind rangeKind)
{
throw new ValidationMetadataException(
"ValidateRangeNegativeFailure",
null,
null,
Metadata.ValidateRangeNegativeFailure,
element.ToString());
}
Expand All @@ -1143,7 +1143,7 @@ private void ValidateRange(object element, ValidateRangeKind rangeKind)
{
throw new ValidationMetadataException(
"ValidateRangeNonPositiveFailure",
null,
null,
Metadata.ValidateRangeNonPositiveFailure,
element.ToString());
}
Expand All @@ -1166,9 +1166,9 @@ private void ValidateRange(object element)
{
throw new ValidationMetadataException(
"ValidationRangeElementType",
null,
null,
Metadata.ValidateRangeElementType,
element.GetType().Name,
element.GetType().Name,
MinRange.GetType().Name);
}
}
Expand All @@ -1178,9 +1178,9 @@ private void ValidateRange(object element)
{
throw new ValidationMetadataException(
"ValidateRangeTooSmall",
null,
null,
Metadata.ValidateRangeSmallerThanMinRangeFailure,
element.ToString(),
element.ToString(),
MinRange.ToString());
}

Expand Down Expand Up @@ -1646,7 +1646,7 @@ protected override void ValidateElement(object element)

private string SetAsString()
{
return string.Join(CultureInfo.CurrentUICulture.TextInfo.ListSeparator, _validValues);
return string.Join(CultureInfo.CurrentUICulture.TextInfo.ListSeparator, ValidValues);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,10 @@ Describe 'ValidateSet support a dynamically generated set' -Tag "CI" {
Get-TestValidateSetPS4 -Param1 "TestString1" -ErrorAction SilentlyContinue | Should BeExactly "TestString1"
}

It 'Get the appropriate error message' {
{Get-TestValidateSetPS4 -Param1 "TestStringWrong" -ErrorAction Stop} | ShouldBeErrorId "ParameterArgumentValidationError,Get-TestValidateSetPS4"
}

It 'Empty dynamically generated set throws in PowerShell script' {
$exc = {
Get-TestValidateSetPS5 -Param1 "TestString1" -ErrorAction Stop
Expand Down Expand Up @@ -476,6 +480,5 @@ Describe 'ValidateSet support a dynamically generated set' -Tag "CI" {
Start-Sleep 3
Get-TestValidateSetPS5 -Param1 "TestString2" -ErrorAction SilentlyContinue | Should BeExactly "TestString2"
}

}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.