Skip to content

Commit 0cf6b94

Browse files
wreuelRussKie
authored andcommitted
Replace EnumValidator on some class
1 parent 420aa59 commit 0cf6b94

7 files changed

Lines changed: 9 additions & 55 deletions

File tree

src/System.Windows.Forms/src/System/Windows/Forms/ButtonBase.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -382,10 +382,7 @@ public ContentAlignment ImageAlign
382382
}
383383
set
384384
{
385-
if (!WindowsFormsUtils.EnumValidator.IsValidContentAlignment(value))
386-
{
387-
throw new InvalidEnumArgumentException(nameof(value), (int)value, typeof(ContentAlignment));
388-
}
385+
SourceGenerated.EnumValidator.Validate(value);
389386

390387
if (value != _imageAlign)
391388
{
@@ -671,10 +668,7 @@ public virtual ContentAlignment TextAlign
671668
}
672669
set
673670
{
674-
if (!WindowsFormsUtils.EnumValidator.IsValidContentAlignment(value))
675-
{
676-
throw new InvalidEnumArgumentException(nameof(value), (int)value, typeof(ContentAlignment));
677-
}
671+
SourceGenerated.EnumValidator.Validate(value);
678672

679673
if (value == TextAlign)
680674
{

src/System.Windows.Forms/src/System/Windows/Forms/CheckBox.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,7 @@ public ContentAlignment CheckAlign
139139
}
140140
set
141141
{
142-
if (!WindowsFormsUtils.EnumValidator.IsValidContentAlignment(value))
143-
{
144-
throw new InvalidEnumArgumentException(nameof(value), (int)value, typeof(ContentAlignment));
145-
}
142+
SourceGenerated.EnumValidator.Validate(value);
146143

147144
if (_checkAlign != value)
148145
{

src/System.Windows.Forms/src/System/Windows/Forms/Label.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -565,10 +565,7 @@ public ContentAlignment ImageAlign
565565
}
566566
set
567567
{
568-
if (!WindowsFormsUtils.EnumValidator.IsValidContentAlignment(value))
569-
{
570-
throw new InvalidEnumArgumentException(nameof(value), (int)value, typeof(ContentAlignment));
571-
}
568+
SourceGenerated.EnumValidator.Validate(value);
572569

573570
if (value != ImageAlign)
574571
{
@@ -724,10 +721,7 @@ public virtual ContentAlignment TextAlign
724721
}
725722
set
726723
{
727-
if (!WindowsFormsUtils.EnumValidator.IsValidContentAlignment(value))
728-
{
729-
throw new InvalidEnumArgumentException(nameof(value), (int)value, typeof(ContentAlignment));
730-
}
724+
SourceGenerated.EnumValidator.Validate(value);
731725

732726
if (TextAlign != value)
733727
{

src/System.Windows.Forms/src/System/Windows/Forms/RadioButton.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,7 @@ public ContentAlignment CheckAlign
156156
}
157157
set
158158
{
159-
if (!WindowsFormsUtils.EnumValidator.IsValidContentAlignment(value))
160-
{
161-
throw new InvalidEnumArgumentException(nameof(value), (int)value, typeof(ContentAlignment));
162-
}
159+
SourceGenerated.EnumValidator.Validate(value);
163160

164161
checkAlign = value;
165162
if (OwnerDraw)

src/System.Windows.Forms/src/System/Windows/Forms/ToolStripControlHost.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,7 @@ public ContentAlignment ControlAlign
115115
get => _controlAlign;
116116
set
117117
{
118-
if (!WindowsFormsUtils.EnumValidator.IsValidContentAlignment(value))
119-
{
120-
throw new InvalidEnumArgumentException(nameof(value), (int)value, typeof(ContentAlignment));
121-
}
118+
SourceGenerated.EnumValidator.Validate(value);
122119

123120
if (_controlAlign != value)
124121
{

src/System.Windows.Forms/src/System/Windows/Forms/ToolStripItem.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -982,10 +982,7 @@ public ContentAlignment ImageAlign
982982
get => _imageAlign;
983983
set
984984
{
985-
if (!WindowsFormsUtils.EnumValidator.IsValidContentAlignment(value))
986-
{
987-
throw new InvalidEnumArgumentException(nameof(value), (int)value, typeof(ContentAlignment));
988-
}
985+
SourceGenerated.EnumValidator.Validate(value);
989986

990987
if (_imageAlign != value)
991988
{
@@ -1875,10 +1872,7 @@ public virtual ContentAlignment TextAlign
18751872
get => _textAlign;
18761873
set
18771874
{
1878-
if (!WindowsFormsUtils.EnumValidator.IsValidContentAlignment(value))
1879-
{
1880-
throw new InvalidEnumArgumentException(nameof(value), (int)value, typeof(ContentAlignment));
1881-
}
1875+
SourceGenerated.EnumValidator.Validate(value);
18821876

18831877
if (_textAlign != value)
18841878
{

src/System.Windows.Forms/src/System/Windows/Forms/WinFormsUtils.cs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -340,25 +340,6 @@ public static string GetComponentName(IComponent component, string defaultNameVa
340340

341341
public static class EnumValidator
342342
{
343-
/// <summary>
344-
/// Valid values are 0x001,0x002,0x004, 0x010,0x020,0x040, 0x100, 0x200,0x400
345-
/// Method for verifying
346-
/// Verify that the number passed in has only one bit on
347-
/// Verify that the bit that is on is a valid bit by bitwise anding it to a mask.
348-
/// </summary>
349-
public static bool IsValidContentAlignment(ContentAlignment contentAlign)
350-
{
351-
if (BitOperations.PopCount((uint)contentAlign) != 1)
352-
{
353-
return false;
354-
}
355-
356-
// to calculate:
357-
// foreach (int val in Enum.GetValues(typeof(ContentAlignment))) { mask |= val; }
358-
int contentAlignmentMask = 0x777;
359-
return ((contentAlignmentMask & (int)contentAlign) != 0);
360-
}
361-
362343
/// <summary>
363344
/// shifts off the number of bits specified by numBitsToShift
364345
/// - makes sure the bits we've shifted off are just zeros

0 commit comments

Comments
 (0)