-
Notifications
You must be signed in to change notification settings - Fork 5.3k
[API Implementation]: Use TimeSpan everywhere we use an int for seconds, milliseconds, and timeouts (Group 1/3) #64860
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 48 commits
377d39c
4d5b632
3477de9
ca4e786
98664c6
94412fd
31b2210
a3d856b
77e959b
ea86b67
517b8e7
47cb9f8
829d412
f413126
516041c
74fb1d9
7deaa98
6827e20
615b66e
6413304
004914c
091c289
70c4efa
eeeb61b
7446821
5fba0ab
738b9e2
e6d68f9
4a35788
486a761
0a0794f
9ffe1ae
7d4af1d
27fa0ce
abea06f
340e5eb
0ff42de
e61acf0
5279de8
aad5405
1529601
c3ea515
53bed23
80f10be
6805ad4
f5e4844
cf68f4d
ff9c0e6
3be4f23
099aacb
d659806
eef5d71
b9aca93
ca7edd2
3a47e9d
a469722
6251c56
a888f6e
c6a6c05
cfba2b9
75b8554
03aa02d
25484a4
4c06f93
ea03c06
4d2e023
bba4bd3
c774885
2f47067
0d0015f
77f921f
a97f7d3
7cdf76c
4a73007
f56905d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -31,6 +31,29 @@ public RegularExpressionAttribute([StringSyntax(StringSyntaxAttribute.Regex)] st | |||||||||||
| /// </summary> | ||||||||||||
| public int MatchTimeoutInMilliseconds { get; set; } | ||||||||||||
|
|
||||||||||||
| /// <summary> | ||||||||||||
| /// Gets or sets the timeout to use when matching the regular expression pattern | ||||||||||||
|
||||||||||||
| /// </summary> | ||||||||||||
| public TimeSpan MatchTimeout | ||||||||||||
| { | ||||||||||||
| get => TimeSpan.FromMilliseconds(MatchTimeoutInMilliseconds); | ||||||||||||
| set | ||||||||||||
| { | ||||||||||||
| long timeoutMilliseconds = (long)value.TotalMilliseconds; | ||||||||||||
|
||||||||||||
| long totalMilliseconds = (long)timeout.TotalMilliseconds; | |
| if (totalMilliseconds < -1 || totalMilliseconds > int.MaxValue) | |
| { | |
| ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.timeout); | |
| } |
that will be half the strings, and less duplicated code.
if it's important to tell them what's wrong, you could include the value in the string. (Task doesn't bother)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed the setter because we don't need it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right, but you're still repeating this validation code. my suggestion is to replace it everywhere with just the 5 lines above, effectively.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
then you don't need new strings (or just 1 if you choose to include the value, which is nice)
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.ComponentModel.DataAnnotations; | ||
| using Xunit; | ||
|
|
||
| namespace System.ComponentModel.Annotations.Tests.System.ComponentModel.DataAnnotations | ||
| { | ||
| public sealed partial class RegularExpressionAttributeTests | ||
| { | ||
| [Theory] | ||
| [InlineData(12345)] | ||
| [InlineData(-1)] | ||
| public static void MatchTimeout_Get_ReturnsExpected(int newValue) | ||
| { | ||
| var attribute = new RegularExpressionAttribute("SomePattern") { MatchTimeoutInMilliseconds = newValue }; | ||
| Assert.Equal(TimeSpan.FromMilliseconds(newValue), attribute.MatchTimeout); | ||
deeprobin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.