8000 Use pattern matching by JeremyKuhne · Pull Request #11030 · dotnet/winforms · GitHub
[go: up one dir, main page]

Skip to content

Use pattern matching #11030

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

Merged
merged 1 commit into from
Mar 12, 2024
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
2 changes: 1 addition & 1 deletion src/Common/src/RTLAwareMessageBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static DialogResult Show(
MessageBoxDefaultButton defaultButton,
MessageBoxOptions options)
{
if (RTLAwareMessageBox.IsRTLResources)
if (IsRTLResources)
{
options |= (MessageBoxOptions.RightAlign | MessageBoxOptions.RtlReading);
}
Expand Down

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/System.Windows.Forms/src/SRDescriptionAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public override string Description
if (!_replaced)
{
_replaced = true;
base.DescriptionValue = SR.GetResourceString(base.Description);
DescriptionValue = SR.GetResourceString(base.Description);
}

return base.Description;
Expand Down
42 changes: 21 additions & 21 deletions src/System.Windows.Forms/src/System/Windows/Forms/Control.Ime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ private static bool IgnoreWmImeNotify
Debug.WriteLineIf(CompModSwitches.ImeMode.Level >= TraceLevel.Info, "Inside get_IgnoreWmImeNotify()");
Debug.Indent();

bool val = Control.ignoreWmImeNotify;
bool val = ignoreWmImeNotify;

Debug.WriteLineIf(CompModSwitches.ImeMode.Level >= TraceLevel.Info, $"Value: {val}");
Debug.Unindent();
Expand All @@ -180,7 +180,7 @@ private static bool IgnoreWmImeNotify
set
{
Debug.WriteLineIf(CompModSwitches.ImeMode.Level >= TraceLevel.Info, $"Inside set_IgnoreWmImeNotify(): {value}");
Control.ignoreWmImeNotify = value;
ignoreWmImeNotify = value;
}
}

Expand Down Expand Up @@ -377,7 +377,7 @@ protected static ImeMode PropagatingImeMode
Debug.WriteLineIf(CompModSwitches.ImeMode.Level >= TraceLevel.Info, "Inside get_PropagatingImeMode()");
Debug.Indent();

if (Control.propagatingImeMode == ImeMode.Inherit)
if (propagatingImeMode == ImeMode.Inherit)
{
// Initialize the propagating IME mode to the value the IME associated to the focused window currently has,
// this enables propagating the IME mode from/to unmanaged applications hosting winforms controls.
Expand Down Expand Up @@ -410,14 +410,14 @@ protected static ImeMode PropagatingImeMode
Debug.WriteLineIf(CompModSwitches.ImeMode.Level >= TraceLevel.Verbose, $"Value: {propagatingImeMode}");
Debug.Unindent();

return Control.propagatingImeMode;
return propagatingImeMode;
}
private set
{
Debug.WriteLineIf(CompModSwitches.ImeMode.Level >= TraceLevel.Info, "Inside set_PropagatingImeMode()");
Debug.Indent();

if (Control.propagatingImeMode != value)
if (propagatingImeMode != value)
{
switch (value)
{
Expand All @@ -433,7 +433,7 @@ private set
Debug.WriteLineIf(
CompModSwitches.ImeMode.Level >= TraceLevel.Warning,
$"Setting PropagatingImeMode: Current value = {propagatingImeMode}, New value = {value}");
Control.propagatingImeMode = value;
propagatingImeMode = value;
break;
}
}
Expand Down Expand Up @@ -774,7 +774,7 @@ private void WmImeNotify(ref Message m)
// We guard against re-entrancy since the ImeModeChanged event can be raised and any changes from the handler could
// lead to another WM_IME_NOTIFY loop.

if (wparam == (int)PInvoke.IMN_SETCONVERSIONMODE || wparam == (int)PInvoke.IMN_SETOPENSTATUS)
if (wparam is ((int)PInvoke.IMN_SETCONVERSIONMODE) or ((int)PInvoke.IMN_SETOPENSTATUS))
{
Debug.WriteLineIf(
CompModSwitches.ImeMode.Level >= TraceLevel.Info,
Expand Down Expand Up @@ -847,7 +847,7 @@ private void WmImeKillFocus()
// See the PropagatingImeMode property

// Note: We need to check the static field here directly to avoid initialization of the property.
if (Control.propagatingImeMode != ImeMode.Inherit)
if (propagatingImeMode != ImeMode.Inherit)
{
// Setting the ime context of the top window will generate a WM_IME_NOTIFY on the focused control which will
// update its ImeMode, we need to prevent this temporarily.
Expand Down Expand Up @@ -895,9 +895,9 @@ public static void Disable(IntPtr handle)
{
// Close the IME if necessary
//
if (ImeContext.IsOpen(handle))
if (IsOpen(handle))
{
ImeContext.SetOpenStatus(false, handle);
SetOpenStatus(false, handle);
}

// Disable the IME by disassociating the context from the window.
Expand All @@ -910,7 +910,7 @@ public static void Disable(IntPtr handle)
}
}

ImeContext.TraceImeStatus(handle);
TraceImeStatus(handle);
Debug.Unindent();
}

Expand Down Expand Up @@ -954,13 +954,13 @@ public static void Enable(IntPtr handle)
}

// Make sure the IME is opened.
if (!ImeContext.IsOpen(handle))
if (!IsOpen(handle))
{
ImeContext.SetOpenStatus(true, handle);
SetOpenStatus(true, handle);
}
}

ImeContext.TraceImeStatus(handle);
TraceImeStatus(handle);
Debug.Unindent();
}

Expand Down Expand Up @@ -996,7 +996,7 @@ public static ImeMode GetImeMode(IntPtr handle)
goto cleanup;
}

if (!ImeContext.IsOpen(handle))
if (!IsOpen(handle))
{
// There's an IME associated with the window but is closed - the input is taken from the keyboard as is (English).
retval = countryTable[ImeModeConversion.ImeClosed];
Expand Down Expand Up @@ -1045,7 +1045,7 @@ public static ImeMode GetImeMode(IntPtr handle)
PInvoke.ImmReleaseContext((HWND)handle, inputContext);
}

ImeContext.TraceImeStatus(handle);
TraceImeStatus(handle);

Debug.Unindent();
return retval;
Expand Down Expand Up @@ -1193,12 +1193,12 @@ public static void SetImeStatus(ImeMode imeMode, IntPtr handle)

if (imeMode == ImeMode.Disable)
{
ImeContext.Disable(handle);
Disable(handle);
}
else
{
// This will make sure the IME is opened.
ImeContext.Enable(handle);
Enable(handle);
}

switch (imeMode)
Expand Down Expand Up @@ -1234,7 +1234,7 @@ public static void SetImeStatus(ImeMode imeMode, IntPtr handle)
goto default;
}

ImeContext.SetOpenStatus(false, handle);
SetOpenStatus(false, handle);
break;

default:
Expand Down Expand Up @@ -1267,7 +1267,7 @@ public static void SetImeStatus(ImeMode imeMode, IntPtr handle)
}

cleanup:
ImeContext.TraceImeStatus(handle);
TraceImeStatus(handle);
Debug.Unindent();
}

Expand Down Expand Up @@ -1300,7 +1300,7 @@ public static void SetOpenStatus(bool open, IntPtr handle)
}
}

ImeContext.TraceImeStatus(handle);
TraceImeStatus(handle);
Debug.Unindent();
}
}// end ImeContext class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ private void ClearChildAccessibleObject()
{
_owner.ClearChildEditAccessibleObject();
}
else if (_childWindowType == ChildWindowType.ListBox || _childWindowType == ChildWindowType.DropDownList)
else if (_childWindowType is ChildWindowType.ListBox or ChildWindowType.DropDownList)
{
_owner.ClearChildListAccessibleObject();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public AutoCompleteSource AutoCompleteSource
throw new NotSupportedException(SR.ComboBoxAutoCompleteSourceOnlyListItemsAllowed);
}

if (Application.OleRequired() != System.Threading.ApartmentState.STA)
if (Application.OleRequired() != ApartmentState.STA)
{
throw new ThreadStateException(SR.ThreadMustBeSTA);
}
Expand Down Expand Up @@ -2028,8 +2028,8 @@ internal int FindStringExact(string? s, int startIndex, bool ignoreCase)
// constraints on their size.
internal override Rectangle ApplyBoundsConstraints(int suggestedX, int suggestedY, int proposedWidth, int proposedHeight)
{
if (DropDownStyle == ComboBoxStyle.DropDown
|| DropDownStyle == ComboBoxStyle.DropDownList)
if (DropDownStyle is ComboBoxStyle.DropDown
or ComboBoxStyle.DropDownList)
{
proposedHeight = PreferredHeight;
}
Expand Down Expand Up @@ -2242,7 +2242,7 @@ private unsafe void InvalidateEverything()
protected override bool IsInputKey(Keys keyData)
{
Keys keyCode = keyData & (Keys.KeyCode | Keys.Alt);
if (keyCode == Keys.Return || keyCode == Keys.Escape)
if (keyCode is Keys.Return or Keys.Escape)
{
if (DroppedDown || _autoCompleteDroppedDown)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ private AccessibleObject SelectedCellsAccessibilityObject

if (owner.Columns.Count == 0)
{
Diagnostics.Debug.Assert(GetChildCount() == 0);
Debug.Assert(GetChildCount() == 0);
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,9 @@ private void currencyManager_ListChanged(object? sender, ListChangedEventArgs e)

private void ProcessListChanged(ListChangedEventArgs e)
{
if (e.ListChangedType == ListChangedType.PropertyDescriptorAdded ||
e.ListChangedType == ListChangedType.PropertyDescriptorDeleted ||
e.ListChangedType == ListChangedType.PropertyDescriptorChanged)
if (e.ListChangedType is ListChangedType.PropertyDescriptorAdded
or ListChangedType.PropertyDescriptorDeleted
or ListChangedType.PropertyDescriptorChanged)
{
_dataConnectionState[DATACONNECTIONSTATE_processingMetaDataChanges] = true;
try
Expand Down Expand Up @@ -1518,7 +1518,7 @@ public bool ShouldChangeDataMember(object? newDataSource)
return true;
}

if (!(_owner.BindingContext[newDataSource] is CurrencyManager cm))
if (_owner.BindingContext[newDataSource] is not CurrencyManager cm)
{
// if we don't have a currency manager then the data member can be valid
return false;
Expand Down
Loading
0