Skip to content

Commit

Permalink
Use 'is not null' in some System.Windows.Forms files (#6112)
Browse files Browse the repository at this point in the history
## Proposed changes

- Contributes to #3459
  • Loading branch information
gpetrou committed Nov 3, 2021
1 parent 0de6ec2 commit 4381586
Show file tree
Hide file tree
Showing 27 changed files with 89 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static IntPtr WriteAutomationText(string text)
IntPtr fileId = IntPtr.Zero;
string fullFileName = GenerateLogFileName(ref fileId);

if (fullFileName != null)
if (fullFileName is not null)
{
try
{
Expand Down Expand Up @@ -96,9 +96,9 @@ private static string GenerateLogFileName(ref IntPtr fileId)
string fullFileName = null;

string filePath = System.Environment.GetEnvironmentVariable("TEMP");
Debug.Assert(filePath != null, "Could not get value of the TEMP environment variable");
Debug.Assert(filePath is not null, "Could not get value of the TEMP environment variable");

if (filePath != null)
if (filePath is not null)
{
if (fileId == IntPtr.Zero) // Create id
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ public partial class Control
internal bool TryGetService<T>(
[NotNullWhen(true)] out T? service)
where T : class
=> (service = GetService(typeof(T)) as T) != null;
=> (service = GetService(typeof(T)) as T) is not null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ private unsafe void OnCustomDraw(ref Message m)
case ComCtl32.CDDS.ITEMPREPAINT:
{
TreeNode itemNode = TreeNode.FromHandle(this, nmtvcd->nmcd.dwItemSpec);
if (itemNode != null)
if (itemNode is not null)
{
int state = STATE_NORMAL;
ComCtl32.CDIS itemState = nmtvcd->nmcd.uItemState;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,10 @@ private void OnButtonClick(object sender, EventArgs e)
private void OnConfigureUI()
{
Font uiFont = Control.DefaultFont;
if (component.Site != null)
if (component.Site is not null)
{
IUIService uiService = (IUIService)component.Site.GetService(typeof(IUIService));
if (uiService != null)
if (uiService is not null)
{
uiFont = (Font)uiService.Styles["DialogFont"];
}
Expand Down Expand Up @@ -200,7 +200,7 @@ private void OnConfigureUI()

int selectorWidth = MIN_SELECTOR_WIDTH;

if (pageSites != null)
if (pageSites is not null)
{
// Add the nodes corresponding to the pages
for (int n = 0; n < pageSites.Length; n++)
Expand All @@ -225,7 +225,7 @@ private void OnConfigureUI()

string caption = string.Empty;
ISite site = component.Site;
if (site != null)
if (site is not null)
{
caption = string.Format(SR.ComponentEditorFormProperties, site.Name);
}
Expand All @@ -242,7 +242,7 @@ private void OnConfigureUI()
grayStrip.Bounds = new Rectangle(pageHostBounds.X, BUTTON_PAD,
pageHostBounds.Width, STRIP_HEIGHT);

if (pageSites != null)
if (pageSites is not null)
{
Rectangle pageBounds = new Rectangle(0, 0, pageHostBounds.Width, pageHostBounds.Height);
for (int n = 0; n < pageSites.Length; n++)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ protected virtual void ReloadComponent()
/// </summary>
protected virtual void SetDirty()
{
if (!IsLoading() && PageSite != null)
if (!IsLoading() && PageSite is not null)
{
PageSite.SetDirty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ private void SelectIndex(int index)
{
// Sanity check index

Debug.Assert(_domainItems != null, "Domain values array is null");
Debug.Assert(_domainItems is not null, "Domain values array is null");
Debug.Assert(index < _domainItems.Count && index >= -1, "SelectValue: index out of range");
if (_domainItems is null || index < -1 || index >= _domainItems.Count)
{
Expand Down Expand Up @@ -453,7 +453,7 @@ private void SortDomainItems()
// Sanity check
Debug.Assert(_sorted, "Sorted == false");

if (_domainItems != null)
if (_domainItems is not null)
{
// Sort the domain values
ArrayList.Adapter(_domainItems).Sort(new DomainUpDownItemCompare());
Expand Down Expand Up @@ -482,7 +482,7 @@ public override string ToString()
{
string s = base.ToString();

if (Items != null)
if (Items is not null)
{
s += ", Items.Count: " + Items.Count.ToString(CultureInfo.CurrentCulture);
s += ", SelectedIndex: " + SelectedIndex.ToString(CultureInfo.CurrentCulture);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public void DrawText(TextFormatFlags flags)
private Rectangle UpdateBounds(Rectangle originalBounds, bool drawText)
{
Rectangle resultBounds = originalBounds;
if (Item.ListView != null && Item.ListView.View == View.Details)
if (Item.ListView is not null && Item.ListView.View == View.Details)
{
// Note: this logic will compute the bounds so they align w/ the system drawn bounds only
// for the default font.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ HRESULT Ole32.IDropTarget.DragEnter(object pDataObj, uint grfKeyState, Point pt,
{
Debug.WriteLineIf(CompModSwitches.DragDrop.TraceInfo, "OleDragEnter received");
Debug.WriteLineIf(CompModSwitches.DragDrop.TraceInfo, "\t" + (pt.X) + "," + (pt.Y));
Debug.Assert(pDataObj != null, "OleDragEnter didn't give us a valid data object.");
Debug.Assert(pDataObj is not null, "OleDragEnter didn't give us a valid data object.");
DragEventArgs? drgevent = CreateDragEventArgs(pDataObj, grfKeyState, pt, pdwEffect);

if (drgevent is not null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public void NotifyAboutMouseEnter(IKeyboardToolTip sender)

private bool IsToolTracked(IKeyboardToolTip sender)
{
return _toolToTip[sender] != null;
return _toolToTip[sender] is not null;
}

public void NotifyAboutLostFocus(IKeyboardToolTip sender)
Expand Down Expand Up @@ -246,7 +246,7 @@ private void Transit(SmEvent @event, IKeyboardToolTip source)
try
{
ToolTip toolTip = _toolToTip[source];
if ((_currentTool is null || _currentTool.CanShowToolTipsNow()) && toolTip != null)
if ((_currentTool is null || _currentTool.CanShowToolTipsNow()) && toolTip is not null)
{
_currentState = Transition(source, toolTip, @event);
}
Expand Down Expand Up @@ -290,10 +290,10 @@ private void HidePersistent()

private SmState FullFsmReset()
{
if (_currentState == SmState.Shown && _currentTool != null)
if (_currentState == SmState.Shown && _currentTool is not null)
{
ToolTip currentToolTip = _toolToTip[_currentTool];
if (currentToolTip != null)
if (currentToolTip is not null)
{
currentToolTip.HideToolTip(_currentTool);
}
Expand All @@ -312,7 +312,7 @@ private void ResetTimer()

private void Reset(ToolTip toolTipToReset)
{
if (toolTipToReset is null || (_currentTool != null && _toolToTip[_currentTool] == toolTipToReset))
if (toolTipToReset is null || (_currentTool is not null && _toolToTip[_currentTool] == toolTipToReset))
{
FullFsmReset();
}
Expand All @@ -332,7 +332,7 @@ private void StopTracking(IKeyboardToolTip tool, ToolTip toolTip)

private void OnFormDeactivation(ToolTip sender)
{
if (_currentTool != null && _toolToTip[_currentTool] == sender)
if (_currentTool is not null && _toolToTip[_currentTool] == sender)
{
FullFsmReset();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo c
obj = Enum.Parse(typeof(Keys), tokens[i]);
}

if (obj != null)
if (obj is not null)
{
Keys currentKey = (Keys)obj;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ internal static Rectangle GetSpecifiedBounds(IArrangedElement element)
internal static void ResetPadding(IArrangedElement element)
{
object value = element.Properties.GetObject(_paddingProperty);
if (value != null)
if (value is not null)
{
element.Properties.RemoveObject(_paddingProperty);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ private static void LayoutAnchoredControls(IArrangedElement container)
IArrangedElement element = children[i];
if (CommonProperties.GetNeedsAnchorLayout(element))
{
Debug.Assert(GetAnchorInfo(element) != null, "AnchorInfo should be initialized before LayoutAnchorControls().");
Debug.Assert(GetAnchorInfo(element) is not null, "AnchorInfo should be initialized before LayoutAnchorControls().");
SetCachedBounds(element, GetAnchorDestination(element, displayRectangle, /*measureOnly=*/false));
}
}
Expand Down Expand Up @@ -403,7 +403,7 @@ private static Size LayoutDockedControls(IArrangedElement container, bool measur
}

// Treat the MDI client specially, since it's supposed to blend in with the parent form
if (mdiClient != null)
if (mdiClient is not null)
{
SetCachedBounds(mdiClient, remainingBounds);
}
Expand Down Expand Up @@ -641,7 +641,7 @@ private static void UpdateAnchorInfo(IArrangedElement element)
Debug.Indent();
Debug.WriteLineIf(CompModSwitches.RichLayout.TraceInfo, element.Container is null ? "No parent" : "Parent");

if (CommonProperties.GetNeedsAnchorLayout(element) && element.Container != null)
if (CommonProperties.GetNeedsAnchorLayout(element) && element.Container is not null)
{
Rectangle bounds = GetCachedBounds(element);
AnchorInfo oldAnchorInfo = new AnchorInfo
Expand Down Expand Up @@ -750,11 +750,11 @@ public static void SetAnchor(IArrangedElement container, IArrangedElement elemen
SetAnchorInfo(element, null);
}

if (element.Container != null)
if (element.Container is not null)
{
bool rightReleased = IsAnchored(oldValue, AnchorStyles.Right) && !IsAnchored(value, AnchorStyles.Right);
bool bottomReleased = IsAnchored(oldValue, AnchorStyles.Bottom) && !IsAnchored(value, AnchorStyles.Bottom);
if (element.Container.Container != null && (rightReleased || bottomReleased))
if (element.Container.Container is not null && (rightReleased || bottomReleased))
{
// If the right or bottom anchor is being released, we have a special case where the element's
// margin may affect preferredSize where it didn't previously. Rather than do an expensive
Expand Down Expand Up @@ -810,7 +810,7 @@ public static void ScaleAnchorInfo(IArrangedElement element, SizeF factor)
AnchorInfo anchorInfo = GetAnchorInfo(element);

// some controls don't have AnchorInfo, i.e. Panels
if (anchorInfo != null)
if (anchorInfo is not null)
{
anchorInfo.Left = (int)((float)anchorInfo.Left * factor.Width);
anchorInfo.Top = (int)((float)anchorInfo.Top * factor.Height);
Expand All @@ -823,13 +823,13 @@ public static void ScaleAnchorInfo(IArrangedElement element, SizeF factor)

private static Rectangle GetCachedBounds(IArrangedElement element)
{
if (element.Container != null)
if (element.Container is not null)
{
IDictionary dictionary = (IDictionary)element.Container.Properties.GetObject(s_cachedBoundsProperty);
if (dictionary != null)
if (dictionary is not null)
{
object bounds = dictionary[element];
if (bounds != null)
if (bounds is not null)
{
return (Rectangle)bounds;
}
Expand All @@ -841,7 +841,7 @@ private static Rectangle GetCachedBounds(IArrangedElement element)

private static bool HasCachedBounds(IArrangedElement container)
{
return container != null && container.Properties.GetObject(s_cachedBoundsProperty) != null;
return container is not null && container.Properties.GetObject(s_cachedBoundsProperty) is not null;
}

private static void ApplyCachedBounds(IArrangedElement container)
Expand All @@ -858,7 +858,7 @@ private static void ApplyCachedBounds(IArrangedElement container)
}

IDictionary dictionary = (IDictionary)container.Properties.GetObject(s_cachedBoundsProperty);
if (dictionary != null)
if (dictionary is not null)
{
#if DEBUG
// In debug builds, we need to modify the collection, so we add a break and an
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ private void Debug_VerifyAlignment(IArrangedElement container, FlowDirection flo
// We cannot apply any of these checks @ design-time since dragging new children into a FlowLayoutPanel
// will attempt to set the children at the mouse position when the child was dropped - we rely on the control
// to reposition the children once added.
if (container is Control flp && flp.Site != null && flp.Site.DesignMode)
if (container is Control flp && flp.Site is not null && flp.Site.DesignMode)
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public LayoutTransaction(Control? controlToLayout, IArrangedElement? controlCaus
_controlToLayout = controlToLayout;

_resumeLayout = resumeLayout;
if (_controlToLayout != null)
if (_controlToLayout is not null)
{
#if DEBUG
_layoutSuspendCount = _controlToLayout.LayoutSuspendCount;
Expand All @@ -62,7 +62,7 @@ public LayoutTransaction(Control? controlToLayout, IArrangedElement? controlCaus

public void Dispose()
{
if (_controlToLayout != null)
if (_controlToLayout is not null)
{
_controlToLayout.ResumeLayout(_resumeLayout);

Expand Down Expand Up @@ -90,17 +90,17 @@ public static IDisposable CreateTransactionIf(bool condition, Control? controlTo

public static void DoLayout(IArrangedElement? elementToLayout, IArrangedElement? elementCausingLayout, string? property)
{
if (elementCausingLayout != null)
if (elementCausingLayout is not null)
{
CommonProperties.xClearPreferredSizeCache(elementCausingLayout);
if (elementToLayout != null)
if (elementToLayout is not null)
{
CommonProperties.xClearPreferredSizeCache(elementToLayout);
elementToLayout.PerformLayout(elementCausingLayout, property);
}
}

Debug.Assert(elementCausingLayout != null, "LayoutTransaction.DoLayout - elementCausingLayout is null, no layout performed - did you mix up your parameters?");
Debug.Assert(elementCausingLayout is not null, "LayoutTransaction.DoLayout - elementCausingLayout is null, no layout performed - did you mix up your parameters?");
}

// This overload should be used when a property has changed that affects preferred size,
Expand All @@ -110,7 +110,7 @@ public static void DoLayoutIf(bool condition, IArrangedElement? elementToLayout,
{
if (!condition)
{
if (elementCausingLayout != null)
if (elementCausingLayout is not null)
{
CommonProperties.xClearPreferredSizeCache(elementCausingLayout);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ internal partial class LayoutUtils
public static Size OldGetLargestStringSizeInCollection(Font? font, ICollection? objects)
{
Size largestSize = Size.Empty;
if (objects != null)
if (objects is not null)
{
foreach (object obj in objects)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public TableLayoutRowStyleCollection RowStyles
set
{
_rowStyles = value;
if (_rowStyles != null)
if (_rowStyles is not null)
{
_rowStyles.EnsureOwnership(_container);
}
Expand All @@ -226,7 +226,7 @@ public TableLayoutColumnStyleCollection ColumnStyles
set
{
_colStyles = value;
if (_colStyles != null)
if (_colStyles is not null)
{
_colStyles.EnsureOwnership(_container);
}
Expand Down Expand Up @@ -348,7 +348,7 @@ public bool HasMultiplePercentColumns
{
get
{
if (_colStyles != null)
if (_colStyles is not null)
{
bool foundAny = false;
foreach (ColumnStyle style in _colStyles)
Expand Down
Loading

0 comments on commit 4381586

Please sign in to comment.