Skip to content

Commit

Permalink
Fix NativeControl throwing NRE when handler is not set (fixes #10).
Browse files Browse the repository at this point in the history
  • Loading branch information
Dreamescaper committed May 16, 2022
1 parent 5eded2c commit 3999d03
Show file tree
Hide file tree
Showing 123 changed files with 262 additions and 230 deletions.
2 changes: 1 addition & 1 deletion src/BlazorBindings.Maui.SkiaSharp/Elements/SKCanvasView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ static SKCanvasView()

[Parameter] public EventCallback<SKPaintSurfaceEventArgs> OnPaintSurface { get; set; }

public new SK.SKCanvasView NativeControl => ((SKCanvasViewHandler)ElementHandler).SKCanvasViewControl;
public new SK.SKCanvasView NativeControl => (ElementHandler as SKCanvasViewHandler)?.SKCanvasViewControl;
public void InvalidateSurface()
{
NativeControl.InvalidateSurface();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

using BlazorBindings.Core;
using BlazorBindings.Maui.Elements.Handlers;
using MC = Microsoft.Maui.Controls;
using Microsoft.AspNetCore.Components;
using Microsoft.Maui.Graphics;
using BlazorBindings.Core;
using BlazorBindings.Maui.Elements.Handlers;
using System.Threading.Tasks;

namespace BlazorBindings.Maui.Elements
Expand All @@ -23,7 +23,7 @@ static ActivityIndicator()
[Parameter] public Color Color { get; set; }
[Parameter] public bool? IsRunning { get; set; }

public new MC.ActivityIndicator NativeControl => ((ActivityIndicatorHandler)ElementHandler).ActivityIndicatorControl;
public new MC.ActivityIndicator NativeControl => (ElementHandler as ActivityIndicatorHandler)?.ActivityIndicatorControl;

protected override void RenderAttributes(AttributesBuilder builder)
{
Expand Down
6 changes: 3 additions & 3 deletions src/BlazorBindings.Maui/Elements/BaseMenuItem.generated.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

using MC = Microsoft.Maui.Controls;
using Microsoft.AspNetCore.Components;
using BlazorBindings.Core;
using BlazorBindings.Maui.Elements.Handlers;
using MC = Microsoft.Maui.Controls;
using Microsoft.AspNetCore.Components;
using System.Threading.Tasks;

namespace BlazorBindings.Maui.Elements
Expand All @@ -16,7 +16,7 @@ static BaseMenuItem()
RegisterAdditionalHandlers();
}

public new MC.BaseMenuItem NativeControl => ((BaseMenuItemHandler)ElementHandler).BaseMenuItemControl;
public new MC.BaseMenuItem NativeControl => (ElementHandler as BaseMenuItemHandler)?.BaseMenuItemControl;

protected override void RenderAttributes(AttributesBuilder builder)
{
Expand Down
6 changes: 3 additions & 3 deletions src/BlazorBindings.Maui/Elements/BaseShellItem.generated.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

using MC = Microsoft.Maui.Controls;
using Microsoft.AspNetCore.Components;
using BlazorBindings.Core;
using BlazorBindings.Maui.Elements.Handlers;
using MC = Microsoft.Maui.Controls;
using Microsoft.AspNetCore.Components;
using System.Threading.Tasks;

namespace BlazorBindings.Maui.Elements
Expand All @@ -27,7 +27,7 @@ static BaseShellItem()
[Parameter] public string Route { get; set; }
[Parameter] public string Title { get; set; }

public new MC.BaseShellItem NativeControl => ((BaseShellItemHandler)ElementHandler).BaseShellItemControl;
public new MC.BaseShellItem NativeControl => (ElementHandler as BaseShellItemHandler)?.BaseShellItemControl;

protected override void RenderAttributes(AttributesBuilder builder)
{
Expand Down
6 changes: 3 additions & 3 deletions src/BlazorBindings.Maui/Elements/BoxView.generated.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

using BlazorBindings.Core;
using BlazorBindings.Maui.Elements.Handlers;
using MC = Microsoft.Maui.Controls;
using Microsoft.AspNetCore.Components;
using Microsoft.Maui;
using Microsoft.Maui.Graphics;
using BlazorBindings.Core;
using BlazorBindings.Maui.Elements.Handlers;
using System.Threading.Tasks;

namespace BlazorBindings.Maui.Elements
Expand All @@ -24,7 +24,7 @@ static BoxView()
[Parameter] public Color Color { get; set; }
[Parameter] public CornerRadius? CornerRadius { get; set; }

public new MC.BoxView NativeControl => ((BoxViewHandler)ElementHandler).BoxViewControl;
public new MC.BoxView NativeControl => (ElementHandler as BoxViewHandler)?.BoxViewControl;

protected override void RenderAttributes(AttributesBuilder builder)
{
Expand Down
6 changes: 3 additions & 3 deletions src/BlazorBindings.Maui/Elements/Brush.generated.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

using MC = Microsoft.Maui.Controls;
using Microsoft.AspNetCore.Components;
using BlazorBindings.Core;
using BlazorBindings.Maui.Elements.Handlers;
using MC = Microsoft.Maui.Controls;
using Microsoft.AspNetCore.Components;
using System.Threading.Tasks;

namespace BlazorBindings.Maui.Elements
Expand All @@ -16,7 +16,7 @@ static Brush()
RegisterAdditionalHandlers();
}

public new MC.Brush NativeControl => ((BrushHandler)ElementHandler).BrushControl;
public new MC.Brush NativeControl => (ElementHandler as BrushHandler)?.BrushControl;

protected override void RenderAttributes(AttributesBuilder builder)
{
Expand Down
6 changes: 3 additions & 3 deletions src/BlazorBindings.Maui/Elements/Button.generated.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

using BlazorBindings.Core;
using BlazorBindings.Maui.Elements.Handlers;
using MC = Microsoft.Maui.Controls;
using Microsoft.AspNetCore.Components;
using Microsoft.Maui;
using Microsoft.Maui.Graphics;
using BlazorBindings.Core;
using BlazorBindings.Maui.Elements.Handlers;
using System.Threading.Tasks;

namespace BlazorBindings.Maui.Elements
Expand Down Expand Up @@ -36,7 +36,7 @@ static Button()
[Parameter] public Color TextColor { get; set; }
[Parameter] public TextTransform? TextTransform { get; set; }

public new MC.Button NativeControl => ((ButtonHandler)ElementHandler).ButtonControl;
public new MC.Button NativeControl => (ElementHandler as ButtonHandler)?.ButtonControl;

protected override void RenderAttributes(AttributesBuilder builder)
{
Expand Down
6 changes: 3 additions & 3 deletions src/BlazorBindings.Maui/Elements/CheckBox.generated.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

using BlazorBindings.Core;
using BlazorBindings.Maui.Elements.Handlers;
using MC = Microsoft.Maui.Controls;
using Microsoft.AspNetCore.Components;
using Microsoft.Maui.Graphics;
using BlazorBindings.Core;
using BlazorBindings.Maui.Elements.Handlers;
using System.Threading.Tasks;

namespace BlazorBindings.Maui.Elements
Expand All @@ -23,7 +23,7 @@ static CheckBox()
[Parameter] public Color Color { get; set; }
[Parameter] public bool? IsChecked { get; set; }

public new MC.CheckBox NativeControl => ((CheckBoxHandler)ElementHandler).CheckBoxControl;
public new MC.CheckBox NativeControl => (ElementHandler as CheckBoxHandler)?.CheckBoxControl;

protected override void RenderAttributes(AttributesBuilder builder)
{
Expand Down
2 changes: 1 addition & 1 deletion src/BlazorBindings.Maui/Elements/CollectionView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ static CollectionView()
renderer => new CollectionViewHandler(renderer, new MC.CollectionView()));
}

public new MC.CollectionView NativeControl => ((CollectionViewHandler)ElementHandler).CollectionViewControl;
public new MC.CollectionView NativeControl => (ElementHandler as CollectionViewHandler)?.CollectionViewControl;
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

using BlazorBindings.Core;
using MCC = Microsoft.Maui.Controls.Compatibility;
using Microsoft.Maui;
using BlazorBindings.Core;
using System;

namespace BlazorBindings.Maui.Elements.Compatibility.Handlers
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

using MCC = Microsoft.Maui.Controls.Compatibility;
using Microsoft.AspNetCore.Components;
using Microsoft.Maui;
using BlazorBindings.Core;
using BlazorBindings.Maui.Elements;
using BlazorBindings.Maui.Elements.Compatibility.Handlers;
using MCC = Microsoft.Maui.Controls.Compatibility;
using Microsoft.AspNetCore.Components;
using Microsoft.Maui;
using System.Threading.Tasks;

namespace BlazorBindings.Maui.Elements.Compatibility
Expand All @@ -22,7 +22,7 @@ static Layout()
[Parameter] public bool? IsClippedToBounds { get; set; }
[Parameter] public Thickness? Padding { get; set; }

public new MCC.Layout NativeControl => ((LayoutHandler)ElementHandler).LayoutControl;
public new MCC.Layout NativeControl => (ElementHandler as LayoutHandler)?.LayoutControl;

protected override void RenderAttributes(AttributesBuilder builder)
{
Expand Down
6 changes: 3 additions & 3 deletions src/BlazorBindings.Maui/Elements/ContentPage.generated.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

using MC = Microsoft.Maui.Controls;
using Microsoft.AspNetCore.Components;
using BlazorBindings.Core;
using BlazorBindings.Maui.Elements.Handlers;
using MC = Microsoft.Maui.Controls;
using Microsoft.AspNetCore.Components;
using System.Threading.Tasks;

namespace BlazorBindings.Maui.Elements
Expand All @@ -19,7 +19,7 @@ static ContentPage()
RegisterAdditionalHandlers();
}

public new MC.ContentPage NativeControl => ((ContentPageHandler)ElementHandler).ContentPageControl;
public new MC.ContentPage NativeControl => (ElementHandler as ContentPageHandler)?.ContentPageControl;

protected override void RenderAttributes(AttributesBuilder builder)
{
Expand Down
6 changes: 3 additions & 3 deletions src/BlazorBindings.Maui/Elements/ContentView.generated.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

using MC = Microsoft.Maui.Controls;
using Microsoft.AspNetCore.Components;
using BlazorBindings.Core;
using BlazorBindings.Maui.Elements.Handlers;
using MC = Microsoft.Maui.Controls;
using Microsoft.AspNetCore.Components;
using System.Threading.Tasks;

namespace BlazorBindings.Maui.Elements
Expand All @@ -19,7 +19,7 @@ static ContentView()
RegisterAdditionalHandlers();
}

public new MC.ContentView NativeControl => ((ContentViewHandler)ElementHandler).ContentViewControl;
public new MC.ContentView NativeControl => (ElementHandler as ContentViewHandler)?.ContentViewControl;

protected override void RenderAttributes(AttributesBuilder builder)
{
Expand Down
6 changes: 3 additions & 3 deletions src/BlazorBindings.Maui/Elements/DatePicker.generated.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

using BlazorBindings.Core;
using BlazorBindings.Maui.Elements.Handlers;
using MC = Microsoft.Maui.Controls;
using Microsoft.AspNetCore.Components;
using Microsoft.Maui.Graphics;
using BlazorBindings.Core;
using BlazorBindings.Maui.Elements.Handlers;
using System;
using System.Threading.Tasks;

Expand All @@ -32,7 +32,7 @@ static DatePicker()
[Parameter] public DateTime? MinimumDate { get; set; }
[Parameter] public Color TextColor { get; set; }

public new MC.DatePicker NativeControl => ((DatePickerHandler)ElementHandler).DatePickerControl;
public new MC.DatePicker NativeControl => (ElementHandler as DatePickerHandler)?.DatePickerControl;

protected override void RenderAttributes(AttributesBuilder builder)
{
Expand Down
6 changes: 3 additions & 3 deletions src/BlazorBindings.Maui/Elements/Editor.generated.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

using BlazorBindings.Core;
using BlazorBindings.Maui.Elements.Handlers;
using MC = Microsoft.Maui.Controls;
using Microsoft.AspNetCore.Components;
using Microsoft.Maui;
using BlazorBindings.Core;
using BlazorBindings.Maui.Elements.Handlers;
using System.Threading.Tasks;

namespace BlazorBindings.Maui.Elements
Expand All @@ -31,7 +31,7 @@ static Editor()
[Parameter] public int? SelectionLength { get; set; }
[Parameter] public TextAlignment? VerticalTextAlignment { get; set; }

public new MC.Editor NativeControl => ((EditorHandler)ElementHandler).EditorControl;
public new MC.Editor NativeControl => (ElementHandler as EditorHandler)?.EditorControl;

protected override void RenderAttributes(AttributesBuilder builder)
{
Expand Down
2 changes: 1 addition & 1 deletion src/BlazorBindings.Maui/Elements/Element.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public abstract class Element : NativeControlComponentBase
[Parameter] public string ClassId { get; set; }
[Parameter] public string StyleId { get; set; }

public MC.Element NativeControl => ((Handlers.ElementHandler)ElementHandler).ElementControl;
public MC.Element NativeControl => (ElementHandler as Handlers.ElementHandler)?.ElementControl;

protected override void RenderAttributes(AttributesBuilder builder)
{
Expand Down
6 changes: 3 additions & 3 deletions src/BlazorBindings.Maui/Elements/Entry.generated.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

using BlazorBindings.Core;
using BlazorBindings.Maui.Elements.Handlers;
using MC = Microsoft.Maui.Controls;
using Microsoft.AspNetCore.Components;
using Microsoft.Maui;
using BlazorBindings.Core;
using BlazorBindings.Maui.Elements.Handlers;
using System.Threading.Tasks;

namespace BlazorBindings.Maui.Elements
Expand Down Expand Up @@ -33,7 +33,7 @@ static Entry()
[Parameter] public int? SelectionLength { get; set; }
[Parameter] public TextAlignment? VerticalTextAlignment { get; set; }

public new MC.Entry NativeControl => ((EntryHandler)ElementHandler).EntryControl;
public new MC.Entry NativeControl => (ElementHandler as EntryHandler)?.EntryControl;

protected override void RenderAttributes(AttributesBuilder builder)
{
Expand Down
6 changes: 3 additions & 3 deletions src/BlazorBindings.Maui/Elements/FlyoutItem.generated.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

using MC = Microsoft.Maui.Controls;
using Microsoft.AspNetCore.Components;
using BlazorBindings.Core;
using BlazorBindings.Maui.Elements.Handlers;
using MC = Microsoft.Maui.Controls;
using Microsoft.AspNetCore.Components;
using System.Threading.Tasks;

namespace BlazorBindings.Maui.Elements
Expand All @@ -19,7 +19,7 @@ static FlyoutItem()
RegisterAdditionalHandlers();
}

public new MC.FlyoutItem NativeControl => ((FlyoutItemHandler)ElementHandler).FlyoutItemControl;
public new MC.FlyoutItem NativeControl => (ElementHandler as FlyoutItemHandler)?.FlyoutItemControl;

protected override void RenderAttributes(AttributesBuilder builder)
{
Expand Down
6 changes: 3 additions & 3 deletions src/BlazorBindings.Maui/Elements/FlyoutPage.generated.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

using MC = Microsoft.Maui.Controls;
using Microsoft.AspNetCore.Components;
using BlazorBindings.Core;
using BlazorBindings.Maui.Elements.Handlers;
using MC = Microsoft.Maui.Controls;
using Microsoft.AspNetCore.Components;
using System.Threading.Tasks;

namespace BlazorBindings.Maui.Elements
Expand All @@ -23,7 +23,7 @@ static FlyoutPage()
[Parameter] public bool? IsGestureEnabled { get; set; }
[Parameter] public bool? IsPresented { get; set; }

public new MC.FlyoutPage NativeControl => ((FlyoutPageHandler)ElementHandler).FlyoutPageControl;
public new MC.FlyoutPage NativeControl => (ElementHandler as FlyoutPageHandler)?.FlyoutPageControl;

protected override void RenderAttributes(AttributesBuilder builder)
{
Expand Down
Loading

0 comments on commit 3999d03

Please sign in to comment.