Skip to content

Commit

Permalink
Code cleanup for null checks (Megabit#5165)
Browse files Browse the repository at this point in the history
* Null check with is null

* Not-Null check with is not null

* is null check
  • Loading branch information
stsrki authored Nov 28, 2023
1 parent 3b3ca0e commit 7846675
Show file tree
Hide file tree
Showing 121 changed files with 322 additions and 322 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<span class="htmlAttributeName">Data</span><span class="htmlOperator">=</span><span class="quot">&quot;</span><span class="sharpVariable"><span class="atSign">&#64;</span>employeeList</span><span class="quot">&quot;</span>
<span class="htmlAttributeName"><span class="atSign">&#64;</span>bind-SelectedRow</span><span class="htmlOperator">=</span><span class="quot">&quot;</span><span class="sharpVariable"><span class="atSign">&#64;</span>selectedEmployee</span><span class="quot">&quot;</span>
<span class="htmlAttributeName">Responsive</span>
<span class="htmlAttributeName">RowStyling</span><span class="htmlOperator">=</span><span class="htmlAttributeValue">&#39;(x,y ) =&gt; y.Style = &quot;height: 70px;&quot;&#39;</span>
<span class="htmlAttributeName">RowStyling</span><span class="htmlOperator">=</span><span class="htmlAttributeValue">&#39;(x,y ) =&gt; y.Style = &quot;height: 70px;&quot;&#39;</span>
<span class="htmlAttributeName">Virtualize</span>
<span class="htmlAttributeName">VirtualizeOptions</span><span class="htmlOperator">=</span><span class="quot">&quot;</span><span class="htmlAttributeValue"><span class="atSign">&#64;</span>(new() { DataGridHeight = &quot;250px&quot;})</span><span class="quot">&quot;</span><span class="htmlTagDelimiter">&gt;</span>
<span class="htmlTagDelimiter">&lt;</span><span class="htmlElementName">DataGridCommandColumn</span> <span class="htmlTagDelimiter">/&gt;</span>
Expand Down
2 changes: 1 addition & 1 deletion Source/Blazorise/Base/BaseColumnComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public abstract class BaseColumnComponent : BaseComponent, IColumnComponent
/// <inheritdoc/>
protected override void BuildClasses( ClassBuilder builder )
{
if ( ColumnSize != null && !PreventColumnSize )
if ( ColumnSize is not null && !PreventColumnSize )
builder.Append( ColumnSize.Class( InsideGrid, ClassProvider ) );

base.BuildClasses( builder );
Expand Down
30 changes: 15 additions & 15 deletions Source/Blazorise/Base/BaseComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,12 @@ public override Task SetParametersAsync( ParameterView parameters )

Attributes ??= new();

if ( widthAttribute != null && parametersDictionary.Remove( "width" ) )
if ( widthAttribute is not null && parametersDictionary.Remove( "width" ) )
{
Attributes.Add( "width", widthAttribute );
}

if ( heightAttribute != null && parametersDictionary.Remove( "height" ) )
if ( heightAttribute is not null && parametersDictionary.Remove( "height" ) )
{
Attributes.Add( "height", heightAttribute );
}
Expand All @@ -122,7 +122,7 @@ public override Task SetParametersAsync( ParameterView parameters )
/// <inheritdoc/>
protected override void OnInitialized()
{
if ( ShouldAutoGenerateId && ElementId == null )
if ( ShouldAutoGenerateId && ElementId is null )
{
ElementId = IdGenerator.Generate;
}
Expand Down Expand Up @@ -174,31 +174,31 @@ protected override ValueTask DisposeAsync( bool disposing )
/// <param name="builder">Class builder used to append the classnames.</param>
protected virtual void BuildClasses( ClassBuilder builder )
{
if ( Class != null )
if ( Class is not null )
builder.Append( Class );

if ( Margin != null )
if ( Margin is not null )
builder.Append( Margin.Class( ClassProvider ) );

if ( Padding != null )
if ( Padding is not null )
builder.Append( Padding.Class( ClassProvider ) );

if ( Gap != null )
if ( Gap is not null )
builder.Append( Gap.Class( ClassProvider ) );

if ( Display != null )
if ( Display is not null )
builder.Append( Display.Class( ClassProvider ) );

if ( Border != null )
if ( Border is not null )
builder.Append( Border.Class( ClassProvider ) );

if ( Flex != null )
if ( Flex is not null )
builder.Append( Flex.Class( ClassProvider ) );

if ( Position != null )
if ( Position is not null )
builder.Append( Position.Class( ClassProvider ) );

if ( Overflow != null )
if ( Overflow is not null )
builder.Append( Overflow.Class( ClassProvider ) );

if ( Float != Float.Default )
Expand All @@ -213,10 +213,10 @@ protected virtual void BuildClasses( ClassBuilder builder )
if ( VerticalAlignment != VerticalAlignment.Default )
builder.Append( ClassProvider.VerticalAlignment( VerticalAlignment ) );

if ( Width != null )
if ( Width is not null )
builder.Append( Width.Class( ClassProvider ) );

if ( Height != null )
if ( Height is not null )
builder.Append( Height.Class( ClassProvider ) );

if ( Casing != CharacterCasing.Normal )
Expand Down Expand Up @@ -254,7 +254,7 @@ protected virtual void BuildClasses( ClassBuilder builder )
/// <param name="builder">Style builder used to append the styles.</param>
protected virtual void BuildStyles( StyleBuilder builder )
{
if ( Style != null )
if ( Style is not null )
builder.Append( Style );
}

Expand Down
10 changes: 5 additions & 5 deletions Source/Blazorise/Base/BaseFocusableContainerComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected override async ValueTask DisposeAsync( bool disposing )
{
if ( disposing && Rendered )
{
if ( focusableComponents != null )
if ( focusableComponents is not null )
{
focusableComponents.Clear();
focusableComponents = null;
Expand All @@ -57,10 +57,10 @@ protected Task HandleFocusableComponent()
var firstFocusableComponent = FocusableComponents.FirstOrDefault( x => x.Autofocus );

// take first component if Autofocus is unspecified
if ( firstFocusableComponent == null )
if ( firstFocusableComponent is null )
firstFocusableComponent = FocusableComponents.FirstOrDefault();

if ( firstFocusableComponent != null )
if ( firstFocusableComponent is not null )
{
return firstFocusableComponent.Focus();
}
Expand All @@ -72,7 +72,7 @@ protected Task HandleFocusableComponent()
/// <inheritdoc/>
public void NotifyFocusableComponentInitialized( IFocusableComponent focusableComponent )
{
if ( focusableComponent == null )
if ( focusableComponent is null )
return;

if ( !FocusableComponents.Contains( focusableComponent ) )
Expand All @@ -84,7 +84,7 @@ public void NotifyFocusableComponentInitialized( IFocusableComponent focusableCo
/// <inheritdoc/>
public void NotifyFocusableComponentRemoved( IFocusableComponent focusableComponent )
{
if ( focusableComponent == null )
if ( focusableComponent is null )
return;

if ( FocusableComponents.Contains( focusableComponent ) )
Expand Down
16 changes: 8 additions & 8 deletions Source/Blazorise/Base/BaseInputComponent.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public override async Task SetParametersAsync( ParameterView parameters )

if ( autofocus )
{
if ( ParentFocusableContainer != null )
if ( ParentFocusableContainer is not null )
{
ParentFocusableContainer.NotifyFocusableComponentInitialized( this );
}
Expand All @@ -76,7 +76,7 @@ public override async Task SetParametersAsync( ParameterView parameters )
/// <inheritdoc/>
protected override void OnInitialized()
{
if ( Theme != null )
if ( Theme is not null )
{
Theme.Changed += OnThemeChanged;
}
Expand Down Expand Up @@ -111,15 +111,15 @@ protected override ValueTask DisposeAsync( bool disposing )
/// </summary>
protected virtual void ReleaseResources()
{
if ( ParentValidation != null )
if ( ParentValidation is not null )
{
// To avoid leaking memory, it's important to detach any event handlers in Dispose()
ParentValidation.ValidationStatusChanged -= OnValidationStatusChanged;
}

ParentFocusableContainer?.NotifyFocusableComponentRemoved( this );

if ( Theme != null )
if ( Theme is not null )
{
Theme.Changed -= OnThemeChanged;
}
Expand Down Expand Up @@ -166,7 +166,7 @@ protected async Task CurrentValueHandler( string value )
}
}
// send the value to the validation for processing
if ( ParentValidation != null )
if ( ParentValidation is not null )
{
await ParentValidation.NotifyInputChanged<TValue>( default );
}
Expand Down Expand Up @@ -294,7 +294,7 @@ protected virtual Task OnFocusOutHandler( FocusEventArgs eventArgs )
/// </summary>
public Task Revalidate()
{
if ( ParentValidation != null )
if ( ParentValidation is not null )
return ParentValidation.NotifyInputChanged<TValue>( default );

return Task.CompletedTask;
Expand Down Expand Up @@ -334,14 +334,14 @@ private void OnThemeChanged( object sender, EventArgs eventArgs )
protected override bool ShouldAutoGenerateId => true;

/// <inheritdoc/>
public virtual object ValidationValue => CustomValidationValue != null
public virtual object ValidationValue => CustomValidationValue is not null
? CustomValidationValue.Invoke()
: InternalValue;

/// <summary>
/// Returns true if input belong to a <see cref="FieldBody"/>.
/// </summary>
protected bool ParentIsFieldBody => ParentFieldBody != null;
protected bool ParentIsFieldBody => ParentFieldBody is not null;

/// <summary>
/// Returns the default value for the <typeparamref name="TValue"/> type.
Expand Down
8 changes: 4 additions & 4 deletions Source/Blazorise/Base/BaseLinkComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ protected override void OnParametersSet()
PreventDefault = false;

// in case the user has specified href instead of To we need to use that instead
if ( Attributes != null && Attributes.TryGetValue( "href", out var href ) )
if ( Attributes is not null && Attributes.TryGetValue( "href", out var href ) )
To = $"{href}";

if ( To != null && To.StartsWith( "#" ) )
if ( To is not null && To.StartsWith( "#" ) )
{
// If the href contains an anchor link we don't want the default click action to occur, but
// rather take care of the click in our own method.
Expand Down Expand Up @@ -76,7 +76,7 @@ protected override void Dispose( bool disposing )
if ( disposing )
{
// To avoid leaking memory, it's important to detach any event handlers in Dispose()
if ( NavigationManager != null )
if ( NavigationManager is not null )
{
NavigationManager.LocationChanged -= OnLocationChanged;
}
Expand Down Expand Up @@ -146,7 +146,7 @@ private string GetAbsoluteUri( string relativeUri )
{
try
{
if ( relativeUri == null )
if ( relativeUri is null )
return string.Empty;

if ( relativeUri.StartsWith( "mailto:", StringComparison.OrdinalIgnoreCase ) )
Expand Down
2 changes: 1 addition & 1 deletion Source/Blazorise/Base/BaseTextInput.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected override ValueTask DisposeAsync( bool disposing )
/// </summary>
protected override void ReleaseResources()
{
if ( inputValueDebouncer != null )
if ( inputValueDebouncer is not null )
{
inputValueDebouncer.Debounce -= OnInputValueDebounce;
inputValueDebouncer = null;
Expand Down
2 changes: 1 addition & 1 deletion Source/Blazorise/Base/BaseValidationResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ protected override void OnParametersSet()

private void DetachValidationStatusChangedListener()
{
if ( previousParentValidation != null )
if ( previousParentValidation is not null )
{
previousParentValidation.ValidationStatusChanged -= OnValidationStatusChanged;
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Blazorise/ComponentActivator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public IComponent CreateInstance( Type componentType )
{
var instance = ServiceProvider.GetService( componentType );

if ( instance == null )
if ( instance is null )
{
instance = Activator.CreateInstance( componentType );
}
Expand Down
10 changes: 5 additions & 5 deletions Source/Blazorise/Components/Addon/Addons.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();

if ( Theme != null )
if ( Theme is not null )
{
Theme.Changed += OnThemeChanged;
}
Expand All @@ -52,7 +52,7 @@ protected override void Dispose( bool disposing )
{
if ( disposing )
{
if ( Theme != null )
if ( Theme is not null )
{
Theme.Changed -= OnThemeChanged;
}
Expand All @@ -77,7 +77,7 @@ protected override void BuildClasses( ClassBuilder builder )
/// <param name="button">A button reference that is placed inside of the addons.</param>
internal void NotifyButtonInitialized( Button button )
{
if ( button == null )
if ( button is null )
return;

registeredButtons ??= new();
Expand All @@ -94,10 +94,10 @@ internal void NotifyButtonInitialized( Button button )
/// <param name="button">A button reference that is placed inside of the addons.</param>
internal void NotifyButtonRemoved( Button button )
{
if ( button == null )
if ( button is null )
return;

if ( registeredButtons != null && registeredButtons.Contains( button ) )
if ( registeredButtons is not null && registeredButtons.Contains( button ) )
{
registeredButtons.Remove( button );
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Blazorise/Components/Badge/Badge.razor
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@namespace Blazorise
@inherits BaseComponent
@if ( Link != null )
@if ( Link is not null )
{
<a id="@ElementId" href="@Link" class="@ClassNames" style="@StyleNames" @attributes="@Attributes">
@ChildContent
Expand Down
2 changes: 1 addition & 1 deletion Source/Blazorise/Components/Bar/BarBrand.razor
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@inherits BaseComponent
<div id="@ElementId" class="@ClassNames" style="@StyleNames" @attributes="@Attributes">
@ChildContent
@if ( ParentBarState != null && ParentBarState.Mode != BarMode.Horizontal )
@if ( ParentBarState is not null && ParentBarState.Mode != BarMode.Horizontal )
{
<BarToggler Class="b-bar-mobile-toggle"
Clicked="@(ParentBarState.BarTogglerState?.Clicked ?? EventCallback<MouseEventArgs>.Empty)"
Expand Down
14 changes: 7 additions & 7 deletions Source/Blazorise/Components/Bar/BarDropdown.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public Task Toggle( string dropdownToggleElementId )
{
// Don't allow Toggle when menu is in a vertical "popout" style mode.
// This will be handled by mouse over actions below.
if ( ParentBarItemState != null && ParentBarItemState.Mode != BarMode.Horizontal && !State.IsInlineDisplay )
if ( ParentBarItemState is not null && ParentBarItemState.Mode != BarMode.Horizontal && !State.IsInlineDisplay )
return Task.CompletedTask;

SetWasJustToggled( true );
Expand Down Expand Up @@ -155,7 +155,7 @@ public Task OnMouseEnterHandler()
{
ShouldClose = false;

if ( ParentBarItemState != null && ParentBarItemState.Mode == BarMode.Horizontal || State.IsInlineDisplay )
if ( ParentBarItemState is not null && ParentBarItemState.Mode == BarMode.Horizontal || State.IsInlineDisplay )
return Task.CompletedTask;

return Show();
Expand All @@ -169,7 +169,7 @@ public Task OnMouseLeaveHandler()
{
ShouldClose = true;

if ( ParentBarItemState != null && ParentBarItemState.Mode == BarMode.Horizontal || State.IsInlineDisplay )
if ( ParentBarItemState is not null && ParentBarItemState.Mode == BarMode.Horizontal || State.IsInlineDisplay )
return Task.CompletedTask;

return Hide();
Expand All @@ -181,7 +181,7 @@ public Task OnMouseLeaveHandler()
/// <param name="barDropdown">Reference to the <see cref="BarDropdown"/> that is placed inside of this <see cref="BarDropdown"/>.</param>
internal void NotifyChildDropdownInitialized( BarDropdown barDropdown )
{
if ( childBarDropdown == null )
if ( childBarDropdown is null )
childBarDropdown = barDropdown;
}

Expand All @@ -199,7 +199,7 @@ protected override void Dispose( bool disposing )
{
if ( disposing )
{
if ( ParentBarDropdown != null )
if ( ParentBarDropdown is not null )
{
ParentBarDropdown.NotifyChildDropdownRemoved( this );
}
Expand Down Expand Up @@ -233,12 +233,12 @@ protected override void Dispose( bool disposing )
/// <summary>
/// Returns true if the BarDropdown is placed inside of another BarDropdown.
/// </summary>
protected internal bool IsBarDropdownSubmenu => ParentBarDropdown != null;
protected internal bool IsBarDropdownSubmenu => ParentBarDropdown is not null;

/// <summary>
/// Returns true if this BarDropdown contains any child BarDropdown.
/// </summary>
protected internal bool HasSubmenu => childBarDropdown != null;
protected internal bool HasSubmenu => childBarDropdown is not null;

/// <summary>
/// Gets the <see cref="Visible"/> flag represented as a string.
Expand Down
Loading

0 comments on commit 7846675

Please sign in to comment.