diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md index 1bc38e94..0a53a4cb 100644 --- a/.github/copilot-instructions.md +++ b/.github/copilot-instructions.md @@ -85,6 +85,9 @@ This repository is the **source code for the Ignite UI for Blazor component libr - Use the latest C# version supported by the target frameworks; prefer modern features (pattern matching, file-scoped namespaces) when they compile on all TFMs - Use strict nullability (`#nullable enable`) in new files +- Annotate honestly: a member is `T?` only when `null` is a meaningful state; never use `!`, `null!` or `default!` to satisfy the analyzer, and keep runtime null checks at public entry points, since annotations are not enforced at runtime +- Prefer non-nullable collections: array and collection properties, parameters and return values are non-nullable and default to an empty collection, unless the web component treats a missing collection differently from an empty one +- Mirror the web component contract on data and option types: a field the `.d.ts` declares required is non-nullable (`required` when only user code constructs the type); a field declared optional or `| null` is `T?`; a definite-assignment attribute (`name!: string`) that the template renders with `ifDefined` is optional too, so check the render when the `.d.ts` shows a bare attribute string - All public types live in `namespace IgniteUI.Blazor.Controls` - Use PascalCase for public members; camelCase for private fields - Prefix interfaces with `I` (e.g., `IIgniteUIBlazor`) diff --git a/CHANGELOG.md b/CHANGELOG.md index de7eb98a..5750f18e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +### Breaking Changes + +#### Public API nullability + +> [!NOTE] +> As part of this release the public API was annotated for nullable reference types. Beyond the members listed below, reference-type parameters, properties, and return values now declare whether they accept or produce `null`. Consumers building with nullable reference types enabled may see new nullable warnings — or errors, if warnings are treated as errors — and may need to update their code accordingly. + +The following public members changed from nullable to non-nullable. Value-type changes (`double?` → `double`) are binary-breaking. + +| Type | Member | Before | After | +|------|--------|--------|-------| +| `IgbTile` | `ColStart` | `double?` | `double` | +| `IgbTile` | `RowStart` | `double?` | `double` | +| `IgbCalendar` | `SpecialDates` | `IgbDateRangeDescriptor[]?` | `IgbDateRangeDescriptor[]` | +| `IgbCalendar` | `DisabledDates` | `IgbDateRangeDescriptor[]?` | `IgbDateRangeDescriptor[]` | + ## 0.1.0 - 2026-07-14 This release updates the Ignite UI for Blazor to the latest [igniteui-webcomponents@7.2.4 release](https://github.com/IgniteUI/igniteui-webcomponents/releases/tag/7.2.4) and matching related changes from `IgniteUI.Blazor` [25.2.77 (March 2026)](https://www.infragistics.com/products/ignite-ui-blazor/blazor/components/general-changelog-dv-blazor#25277-march-2026), [25.2.102 (May 2026)](https://www.infragistics.com/products/ignite-ui-blazor/blazor/components/general-changelog-dv-blazor#252102-may-2026) and [26.1.51 (June 2026)](https://www.infragistics.com/products/ignite-ui-blazor/blazor/components/general-changelog-dv-blazor#26151-june-2026) with highlights noted below: diff --git a/Directory.Build.props b/Directory.Build.props index e4adda19..2f8c7318 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -4,6 +4,7 @@ Infragistics true enable + $(WarningsAsErrors);nullable enable diff --git a/src/IgniteUI.Blazor.Lite.csproj b/src/IgniteUI.Blazor.Lite.csproj index 16dc6390..fe0d757b 100644 --- a/src/IgniteUI.Blazor.Lite.csproj +++ b/src/IgniteUI.Blazor.Lite.csproj @@ -2,9 +2,6 @@ .Lite - - disable diff --git a/src/components/Blazor/Accordion.cs b/src/components/Blazor/Accordion.cs index d1fffdab..56adae88 100644 --- a/src/components/Blazor/Accordion.cs +++ b/src/components/Blazor/Accordion.cs @@ -80,7 +80,7 @@ public bool SingleExpand } /// - public override object FindByName(string name) + public override object? FindByName(string name) { var baseResult = base.FindByName(name); if (baseResult != null) @@ -103,7 +103,7 @@ public override object FindByName(string name) /// public async Task HideAllAsync() { - await InvokeMethod("hideAll", new object[] { }, new string[] { }); + await InvokeMethod("hideAll", new object?[] { }, new string[] { }); } /// @@ -111,14 +111,14 @@ public async Task HideAllAsync() /// public void HideAll() { - InvokeMethodSync("hideAll", new object[] { }, new string[] { }); + InvokeMethodSync("hideAll", new object?[] { }, new string[] { }); } /// /// Shows all of the child expansion panels' contents. /// public async Task ShowAllAsync() { - await InvokeMethod("showAll", new object[] { }, new string[] { }); + await InvokeMethod("showAll", new object?[] { }, new string[] { }); } /// @@ -126,11 +126,11 @@ public async Task ShowAllAsync() /// public void ShowAll() { - InvokeMethodSync("showAll", new object[] { }, new string[] { }); + InvokeMethodSync("showAll", new object?[] { }, new string[] { }); } - private string _openingRef = null; - private string _openingScript = null; + private string? _openingRef = null; + private string? _openingScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -140,7 +140,7 @@ public void ShowAll() /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string OpeningScript + public string? OpeningScript { set @@ -148,7 +148,7 @@ public string OpeningScript if (value != this._openingScript) { this._openingScript = value; - this.OnRefChanged("Opening", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Opening", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._openingRef = refName; this.MarkPropDirty("OpeningRef"); @@ -201,8 +201,8 @@ public EventCallback Opening } } - private string _openedRef = null; - private string _openedScript = null; + private string? _openedRef = null; + private string? _openedScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -212,7 +212,7 @@ public EventCallback Opening /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string OpenedScript + public string? OpenedScript { set @@ -220,7 +220,7 @@ public string OpenedScript if (value != this._openedScript) { this._openedScript = value; - this.OnRefChanged("Opened", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Opened", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._openedRef = refName; this.MarkPropDirty("OpenedRef"); @@ -273,8 +273,8 @@ public EventCallback Opened } } - private string _closingRef = null; - private string _closingScript = null; + private string? _closingRef = null; + private string? _closingScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -284,7 +284,7 @@ public EventCallback Opened /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string ClosingScript + public string? ClosingScript { set @@ -292,7 +292,7 @@ public string ClosingScript if (value != this._closingScript) { this._closingScript = value; - this.OnRefChanged("Closing", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Closing", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._closingRef = refName; this.MarkPropDirty("ClosingRef"); @@ -345,8 +345,8 @@ public EventCallback Closing } } - private string _closedRef = null; - private string _closedScript = null; + private string? _closedRef = null; + private string? _closedScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -356,7 +356,7 @@ public EventCallback Closing /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string ClosedScript + public string? ClosedScript { set @@ -364,7 +364,7 @@ public string ClosedScript if (value != this._closedScript) { this._closedScript = value; - this.OnRefChanged("Closed", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Closed", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._closedRef = refName; this.MarkPropDirty("ClosedRef"); diff --git a/src/components/Blazor/ActiveStepChangedEventArgs.cs b/src/components/Blazor/ActiveStepChangedEventArgs.cs index d3b973c0..cd9364c5 100644 --- a/src/components/Blazor/ActiveStepChangedEventArgs.cs +++ b/src/components/Blazor/ActiveStepChangedEventArgs.cs @@ -13,7 +13,7 @@ public partial class IgbActiveStepChangedEventArgs : BaseRendererElement private static bool _marshalByValue = true; - private IgbActiveStepChangedEventArgsDetail _detail; + private IgbActiveStepChangedEventArgsDetail _detail = new IgbActiveStepChangedEventArgsDetail(); /// /// The payload of the event, carrying the index of the step that became active. @@ -25,15 +25,16 @@ public IgbActiveStepChangedEventArgsDetail Detail set { MarkPropDirty("Detail"); + if (this._detail != null) { this.DetachChild(this._detail); } + this._detail = value; if (value != null) { this.AttachChild(value); } - this._detail = value; } } @@ -48,7 +49,7 @@ internal override void SerializeCore(RendererSerializer ser) } /// - protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) + protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) { base.ToEventJson(control, args); @@ -58,13 +59,13 @@ protected internal override void ToEventJson(BaseRendererControl control, Dictio } /// - protected internal override void FromEventJson(BaseRendererControl control, Dictionary args) + protected internal override void FromEventJson(BaseRendererControl control, Dictionary? args) { base.FromEventJson(control, args); this.SuppressParentNotify = true; - if (args.ContainsKey("detail")) - { this.Detail = (IgbActiveStepChangedEventArgsDetail)ConvertReturnValue(args["detail"], "ActiveStepChangedEventArgsDetail", true); } + if (args != null && args.TryGetValue("detail", out var detailObj) && ConvertReturnValue(detailObj, "ActiveStepChangedEventArgsDetail", true) is IgbActiveStepChangedEventArgsDetail detail) + { this.Detail = detail; } this.SuppressParentNotify = false; } diff --git a/src/components/Blazor/ActiveStepChangedEventArgsDetail.cs b/src/components/Blazor/ActiveStepChangedEventArgsDetail.cs index 430f79a5..88492c05 100644 --- a/src/components/Blazor/ActiveStepChangedEventArgsDetail.cs +++ b/src/components/Blazor/ActiveStepChangedEventArgsDetail.cs @@ -42,7 +42,7 @@ internal override void SerializeCore(RendererSerializer ser) } /// - protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) + protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) { base.ToEventJson(control, args); @@ -52,12 +52,12 @@ protected internal override void ToEventJson(BaseRendererControl control, Dictio } /// - protected internal override void FromEventJson(BaseRendererControl control, Dictionary args) + protected internal override void FromEventJson(BaseRendererControl control, Dictionary? args) { base.FromEventJson(control, args); this.SuppressParentNotify = true; - if (args.ContainsKey("index")) + if (args != null && args.ContainsKey("index")) { this.Index = ReturnToDouble(args["index"]); } this.SuppressParentNotify = false; diff --git a/src/components/Blazor/ActiveStepChangingEventArgs.cs b/src/components/Blazor/ActiveStepChangingEventArgs.cs index ad2ff8c2..66bde4f3 100644 --- a/src/components/Blazor/ActiveStepChangingEventArgs.cs +++ b/src/components/Blazor/ActiveStepChangingEventArgs.cs @@ -13,7 +13,7 @@ public partial class IgbActiveStepChangingEventArgs : BaseRendererElement private static bool _marshalByValue = true; - private IgbActiveStepChangingEventArgsDetail _detail; + private IgbActiveStepChangingEventArgsDetail _detail = new IgbActiveStepChangingEventArgsDetail(); /// /// The payload of the event, carrying the index of the currently active step and the index of @@ -30,11 +30,11 @@ public IgbActiveStepChangingEventArgsDetail Detail { this.DetachChild(this._detail); } + this._detail = value; if (value != null) { this.AttachChild(value); } - this._detail = value; } } @@ -49,7 +49,7 @@ internal override void SerializeCore(RendererSerializer ser) } /// - protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) + protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) { base.ToEventJson(control, args); @@ -59,13 +59,13 @@ protected internal override void ToEventJson(BaseRendererControl control, Dictio } /// - protected internal override void FromEventJson(BaseRendererControl control, Dictionary args) + protected internal override void FromEventJson(BaseRendererControl control, Dictionary? args) { base.FromEventJson(control, args); this.SuppressParentNotify = true; - if (args.ContainsKey("detail")) - { this.Detail = (IgbActiveStepChangingEventArgsDetail)ConvertReturnValue(args["detail"], "ActiveStepChangingEventArgsDetail", true); } + if (args != null && args.TryGetValue("detail", out var detailObj) && ConvertReturnValue(detailObj, "ActiveStepChangingEventArgsDetail", true) is IgbActiveStepChangingEventArgsDetail detail) + { this.Detail = detail; } this.SuppressParentNotify = false; } diff --git a/src/components/Blazor/ActiveStepChangingEventArgsDetail.cs b/src/components/Blazor/ActiveStepChangingEventArgsDetail.cs index 688cac2a..716b16d8 100644 --- a/src/components/Blazor/ActiveStepChangingEventArgsDetail.cs +++ b/src/components/Blazor/ActiveStepChangingEventArgsDetail.cs @@ -63,7 +63,7 @@ internal override void SerializeCore(RendererSerializer ser) } /// - protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) + protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) { base.ToEventJson(control, args); @@ -75,14 +75,14 @@ protected internal override void ToEventJson(BaseRendererControl control, Dictio } /// - protected internal override void FromEventJson(BaseRendererControl control, Dictionary args) + protected internal override void FromEventJson(BaseRendererControl control, Dictionary? args) { base.FromEventJson(control, args); this.SuppressParentNotify = true; - if (args.ContainsKey("oldIndex")) + if (args != null && args.ContainsKey("oldIndex")) { this.OldIndex = ReturnToDouble(args["oldIndex"]); } - if (args.ContainsKey("newIndex")) + if (args != null && args.ContainsKey("newIndex")) { this.NewIndex = ReturnToDouble(args["newIndex"]); } this.SuppressParentNotify = false; diff --git a/src/components/Blazor/Avatar.cs b/src/components/Blazor/Avatar.cs index fea625c8..5754d438 100644 --- a/src/components/Blazor/Avatar.cs +++ b/src/components/Blazor/Avatar.cs @@ -59,13 +59,13 @@ protected override ControlEventBehavior DefaultEventBehavior get { return ControlEventBehavior.Immediate; } } - private string _src; + private string? _src; /// /// The image source to use. /// [Parameter] - public string Src + public string? Src { get { return this._src; } set @@ -78,13 +78,13 @@ public string Src } } - private string _alt; + private string? _alt; /// /// Alternative text for the image. /// [Parameter] - public string Alt + public string? Alt { get { return this._alt; } set @@ -97,13 +97,13 @@ public string Alt } } - private string _initials; + private string? _initials; /// /// Initials to use as a fallback when no image is available. /// [Parameter] - public string Initials + public string? Initials { get { return this._initials; } set diff --git a/src/components/Blazor/Banner.cs b/src/components/Blazor/Banner.cs index dce6165b..39a118e1 100644 --- a/src/components/Blazor/Banner.cs +++ b/src/components/Blazor/Banner.cs @@ -92,7 +92,7 @@ public bool Open /// or if it was already open. public async Task ShowAsync() { - var iv = await InvokeMethod("show", new object[] { }, new string[] { }); + var iv = await InvokeMethod("show", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } @@ -103,7 +103,7 @@ public async Task ShowAsync() /// or if it was already open. public bool Show() { - var iv = InvokeMethodSync("show", new object[] { }, new string[] { }); + var iv = InvokeMethodSync("show", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } /// @@ -113,7 +113,7 @@ public bool Show() /// or if it was already closed. public async Task HideAsync() { - var iv = await InvokeMethod("hide", new object[] { }, new string[] { }); + var iv = await InvokeMethod("hide", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } @@ -124,7 +124,7 @@ public async Task HideAsync() /// or if it was already closed. public bool Hide() { - var iv = InvokeMethodSync("hide", new object[] { }, new string[] { }); + var iv = InvokeMethodSync("hide", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } /// @@ -134,7 +134,7 @@ public bool Hide() /// when the transition completed successfully. public async Task ToggleAsync() { - var iv = await InvokeMethod("toggle", new object[] { }, new string[] { }); + var iv = await InvokeMethod("toggle", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } @@ -145,12 +145,12 @@ public async Task ToggleAsync() /// when the transition completed successfully. public bool Toggle() { - var iv = InvokeMethodSync("toggle", new object[] { }, new string[] { }); + var iv = InvokeMethodSync("toggle", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } - private string _closingRef = null; - private string _closingScript = null; + private string? _closingRef = null; + private string? _closingScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -160,7 +160,7 @@ public bool Toggle() /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string ClosingScript + public string? ClosingScript { set @@ -168,7 +168,7 @@ public string ClosingScript if (value != this._closingScript) { this._closingScript = value; - this.OnRefChanged("Closing", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Closing", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._closingRef = refName; this.MarkPropDirty("ClosingRef"); @@ -221,8 +221,8 @@ public EventCallback Closing } } - private string _closedRef = null; - private string _closedScript = null; + private string? _closedRef = null; + private string? _closedScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -232,7 +232,7 @@ public EventCallback Closing /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string ClosedScript + public string? ClosedScript { set @@ -240,7 +240,7 @@ public string ClosedScript if (value != this._closedScript) { this._closedScript = value; - this.OnRefChanged("Closed", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Closed", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._closedRef = refName; this.MarkPropDirty("ClosedRef"); diff --git a/src/components/Blazor/BaseAlertLike.cs b/src/components/Blazor/BaseAlertLike.cs index 639a3fcc..ff255d50 100644 --- a/src/components/Blazor/BaseAlertLike.cs +++ b/src/components/Blazor/BaseAlertLike.cs @@ -170,11 +170,11 @@ public NotificationPositioning Positioning public async Task ConnectedCallbackAsync() { - await InvokeMethod("connectedCallback", new object[] { }, new string[] { }); + await InvokeMethod("connectedCallback", new object?[] { }, new string[] { }); } public void ConnectedCallback() { - InvokeMethodSync("connectedCallback", new object[] { }, new string[] { }); + InvokeMethodSync("connectedCallback", new object?[] { }, new string[] { }); } /// /// Opens the component. @@ -186,7 +186,7 @@ public void ConnectedCallback() /// public async Task ShowAsync() { - var iv = await InvokeMethod("show", new object[] { }, new string[] { }); + var iv = await InvokeMethod("show", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } @@ -200,7 +200,7 @@ public async Task ShowAsync() /// public bool Show() { - var iv = InvokeMethodSync("show", new object[] { }, new string[] { }); + var iv = InvokeMethodSync("show", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } /// @@ -212,7 +212,7 @@ public bool Show() /// public async Task HideAsync() { - var iv = await InvokeMethod("hide", new object[] { }, new string[] { }); + var iv = await InvokeMethod("hide", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } @@ -225,7 +225,7 @@ public async Task HideAsync() /// public bool Hide() { - var iv = InvokeMethodSync("hide", new object[] { }, new string[] { }); + var iv = InvokeMethodSync("hide", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } /// @@ -237,7 +237,7 @@ public bool Hide() /// public async Task ToggleAsync() { - var iv = await InvokeMethod("toggle", new object[] { }, new string[] { }); + var iv = await InvokeMethod("toggle", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } @@ -250,7 +250,7 @@ public async Task ToggleAsync() /// public bool Toggle() { - var iv = InvokeMethodSync("toggle", new object[] { }, new string[] { }); + var iv = InvokeMethodSync("toggle", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } diff --git a/src/components/Blazor/BaseComboBox.cs b/src/components/Blazor/BaseComboBox.cs index 90097d9e..92c63d80 100644 --- a/src/components/Blazor/BaseComboBox.cs +++ b/src/components/Blazor/BaseComboBox.cs @@ -49,7 +49,7 @@ public bool Open /// or if it was already open. public async Task ShowAsync() { - var iv = await InvokeMethod("show", new object[] { }, new string[] { }); + var iv = await InvokeMethod("show", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } @@ -60,7 +60,7 @@ public async Task ShowAsync() /// or if it was already open. public bool Show() { - var iv = InvokeMethodSync("show", new object[] { }, new string[] { }); + var iv = InvokeMethodSync("show", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } /// @@ -70,7 +70,7 @@ public bool Show() /// or if it was already closed. public async Task HideAsync() { - var iv = await InvokeMethod("hide", new object[] { }, new string[] { }); + var iv = await InvokeMethod("hide", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } @@ -81,7 +81,7 @@ public async Task HideAsync() /// or if it was already closed. public bool Hide() { - var iv = InvokeMethodSync("hide", new object[] { }, new string[] { }); + var iv = InvokeMethodSync("hide", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } /// @@ -90,7 +90,7 @@ public bool Hide() /// when the open state was changed. public async Task ToggleAsync() { - var iv = await InvokeMethod("toggle", new object[] { }, new string[] { }); + var iv = await InvokeMethod("toggle", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } @@ -100,7 +100,7 @@ public async Task ToggleAsync() /// when the open state was changed. public bool Toggle() { - var iv = InvokeMethodSync("toggle", new object[] { }, new string[] { }); + var iv = InvokeMethodSync("toggle", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } diff --git a/src/components/Blazor/BaseOptionLike.cs b/src/components/Blazor/BaseOptionLike.cs index 28e2ca7b..743b54a9 100644 --- a/src/components/Blazor/BaseOptionLike.cs +++ b/src/components/Blazor/BaseOptionLike.cs @@ -106,14 +106,14 @@ public bool Selected } } - private string _value; + private string? _value; /// /// The current value of the item. /// If not specified, the text content of the item is used. /// [Parameter] - public string Value + public string? Value { get { return this._value; } set diff --git a/src/components/Blazor/ButtonBase.cs b/src/components/Blazor/ButtonBase.cs index 173286ab..6f7b2363 100644 --- a/src/components/Blazor/ButtonBase.cs +++ b/src/components/Blazor/ButtonBase.cs @@ -54,10 +54,10 @@ protected override ControlEventBehavior DefaultEventBehavior /// /// The type of the button, which determines its behavior and semantics. /// - /// – no default action. - /// – submits the associated form when + /// — no default action. + /// — submits the associated form when /// clicked. - /// – resets the associated form fields to + /// — resets the associated form fields to /// their initial values. /// /// Ignored when the button is rendered as a link (i.e. is set). @@ -77,7 +77,7 @@ public ButtonBaseType DisplayType } } - private string _href; + private string? _href; /// /// The URL the button points to. When set, the component renders as an @@ -86,7 +86,7 @@ public ButtonBaseType DisplayType /// for full anchor semantics. /// [Parameter] - public string Href + public string? Href { get { return this._href; } set @@ -99,7 +99,7 @@ public string Href } } - private string _download; + private string? _download; /// /// Prompts the browser to download the linked resource rather than navigating @@ -107,7 +107,7 @@ public string Href /// Only effective when is set. /// [Parameter] - public string Download + public string? Download { get { return this._download; } set @@ -125,12 +125,12 @@ public string Download /// /// Where to open the linked document. Only effective when is set. /// - /// – current browsing context + /// — current browsing context /// (default browser behavior). - /// – new tab or window. - /// – parent browsing context; falls back to + /// — new tab or window. + /// — parent browsing context; falls back to /// if none. - /// – top-level browsing context; falls back to + /// — top-level browsing context; falls back to /// if none. /// /// @@ -148,7 +148,7 @@ public ButtonBaseTarget Target } } - private string _rel; + private string? _rel; /// /// The relationship between the current document and the linked URL. @@ -158,7 +158,7 @@ public ButtonBaseTarget Target /// strongly recommended for security. /// [Parameter] - public string Rel + public string? Rel { get { return this._rel; } set @@ -190,7 +190,7 @@ public bool Disabled } } - private string _command; + private string? _command; /// /// The command to invoke on the target element specified by . @@ -199,7 +199,7 @@ public bool Disabled /// Custom commands must start with two dashes (e.g. --my-command). /// [Parameter] - public string Command + public string? Command { get { return this._command; } set @@ -241,7 +241,7 @@ public string? Commandfor [WCWidgetMemberName("Focus")] public async Task FocusComponentAsync(IgbFocusOptions options) { - await InvokeMethod("focus", new object[] { ObjectToParam(options) }, new string[] { "Json" }); + await InvokeMethod("focus", new object?[] { ObjectToParam(options) }, new string[] { "Json" }); } /// @@ -250,7 +250,7 @@ public async Task FocusComponentAsync(IgbFocusOptions options) [WCWidgetMemberName("Focus")] public void FocusComponent(IgbFocusOptions options) { - InvokeMethodSync("focus", new object[] { ObjectToParam(options) }, new string[] { "Json" }); + InvokeMethodSync("focus", new object?[] { ObjectToParam(options) }, new string[] { "Json" }); } /// /// Removes focus from the button. @@ -259,7 +259,7 @@ public void FocusComponent(IgbFocusOptions options) [WCWidgetMemberName("Blur")] public async Task BlurComponentAsync() { - await InvokeMethod("blur", new object[] { }, new string[] { }); + await InvokeMethod("blur", new object?[] { }, new string[] { }); } /// @@ -268,14 +268,14 @@ public async Task BlurComponentAsync() [WCWidgetMemberName("Blur")] public void BlurComponent() { - InvokeMethodSync("blur", new object[] { }, new string[] { }); + InvokeMethodSync("blur", new object?[] { }, new string[] { }); } /// /// Simulates a mouse click on the button, triggering its click handler and any associated form action. /// public async Task ClickAsync() { - await InvokeMethod("click", new object[] { }, new string[] { }); + await InvokeMethod("click", new object?[] { }, new string[] { }); } /// @@ -283,11 +283,11 @@ public async Task ClickAsync() /// public void Click() { - InvokeMethodSync("click", new object[] { }, new string[] { }); + InvokeMethodSync("click", new object?[] { }, new string[] { }); } - private string _focusRef = null; - private string _focusScript = null; + private string? _focusRef = null; + private string? _focusScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -297,7 +297,7 @@ public void Click() /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string FocusScript + public string? FocusScript { set @@ -305,7 +305,7 @@ public string FocusScript if (value != this._focusScript) { this._focusScript = value; - this.OnRefChanged("Focus", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Focus", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._focusRef = refName; this.MarkPropDirty("FocusRef"); @@ -358,8 +358,8 @@ public EventCallback Focus } } - private string _blurRef = null; - private string _blurScript = null; + private string? _blurRef = null; + private string? _blurScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -369,7 +369,7 @@ public EventCallback Focus /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string BlurScript + public string? BlurScript { set @@ -377,7 +377,7 @@ public string BlurScript if (value != this._blurScript) { this._blurScript = value; - this.OnRefChanged("Blur", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Blur", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._blurRef = refName; this.MarkPropDirty("BlurRef"); diff --git a/src/components/Blazor/ButtonGroup.cs b/src/components/Blazor/ButtonGroup.cs index ee3e62ea..cc02d440 100644 --- a/src/components/Blazor/ButtonGroup.cs +++ b/src/components/Blazor/ButtonGroup.cs @@ -116,7 +116,7 @@ public ButtonGroupSelection Selection } } - private string[] _selectedItems; + private string[] _selectedItems = Array.Empty(); /// /// Gets or sets the values of the currently selected buttons. @@ -137,8 +137,8 @@ public string[] SelectedItems } - private string _selectRef = null; - private string _selectScript = null; + private string? _selectRef = null; + private string? _selectScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -148,7 +148,7 @@ public string[] SelectedItems /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string SelectScript + public string? SelectScript { set @@ -156,7 +156,7 @@ public string SelectScript if (value != this._selectScript) { this._selectScript = value; - this.OnRefChanged("Select", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Select", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._selectRef = refName; this.MarkPropDirty("SelectRef"); @@ -209,8 +209,8 @@ public EventCallback Select } } - private string _deselectRef = null; - private string _deselectScript = null; + private string? _deselectRef = null; + private string? _deselectScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -220,7 +220,7 @@ public EventCallback Select /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string DeselectScript + public string? DeselectScript { set @@ -228,7 +228,7 @@ public string DeselectScript if (value != this._deselectScript) { this._deselectScript = value; - this.OnRefChanged("Deselect", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Deselect", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._deselectRef = refName; this.MarkPropDirty("DeselectRef"); diff --git a/src/components/Blazor/Calendar.cs b/src/components/Blazor/Calendar.cs index 1f37de61..e8ecb5b2 100644 --- a/src/components/Blazor/Calendar.cs +++ b/src/components/Blazor/Calendar.cs @@ -62,7 +62,7 @@ public DateTime Value /// public async Task GetCurrentValueAsync() { - var iv = await InvokeMethod("p:Value", new object[] { }, new string[] { }); + var iv = await InvokeMethod("p:Value", new object?[] { }, new string[] { }); return ReturnToDate(iv); } @@ -72,10 +72,10 @@ public async Task GetCurrentValueAsync() /// public DateTime GetCurrentValue() { - var iv = InvokeMethodSync("p:Value", new object[] { }, new string[] { }); + var iv = InvokeMethodSync("p:Value", new object?[] { }, new string[] { }); return ReturnToDate(iv); } - private DateTime[] _values; + private DateTime[] _values = Array.Empty(); /// /// The current values of the calendar. @@ -104,7 +104,7 @@ public DateTime[] Values /// public async Task GetCurrentValuesAsync() { - var iv = await InvokeMethod("p:Values", new object[] { }, new string[] { }); + var iv = await InvokeMethod("p:Values", new object?[] { }, new string[] { }); return ReturnToDateArray(iv); } @@ -115,7 +115,7 @@ public async Task GetCurrentValuesAsync() /// public DateTime[] GetCurrentValues() { - var iv = InvokeMethodSync("p:Values", new object[] { }, new string[] { }); + var iv = InvokeMethodSync("p:Values", new object?[] { }, new string[] { }); return ReturnToDateArray(iv); } private DateTime _activeDate = DateTime.MinValue; @@ -254,7 +254,11 @@ public CalendarActiveView ActiveView } } - private IgbCalendarFormatOptions _formatOptions; + private IgbCalendarFormatOptions _formatOptions = new IgbCalendarFormatOptions() + { + Month = "long", + Weekday = "narrow", + }; /// /// The options used to format the months and the weekdays in the calendar views. @@ -270,11 +274,11 @@ public IgbCalendarFormatOptions FormatOptions { this.DetachChild(this._formatOptions); } + this._formatOptions = value; if (value != null) { this.AttachChild(value); } - this._formatOptions = value; } } @@ -341,8 +345,8 @@ public EventCallback ValuesChanged } } - private string _changeRef = null; - private string _changeScript = null; + private string? _changeRef = null; + private string? _changeScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -352,7 +356,7 @@ public EventCallback ValuesChanged /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string ChangeScript + public string? ChangeScript { set @@ -360,7 +364,7 @@ public string ChangeScript if (value != this._changeScript) { this._changeScript = value; - this.OnRefChanged("Change", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Change", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._changeRef = refName; this.MarkPropDirty("ChangeRef"); diff --git a/src/components/Blazor/CalendarBase.cs b/src/components/Blazor/CalendarBase.cs index b7f03942..9a106541 100644 --- a/src/components/Blazor/CalendarBase.cs +++ b/src/components/Blazor/CalendarBase.cs @@ -79,13 +79,13 @@ public WeekDays WeekStart } } - private string _locale; + private string? _locale; /// /// Gets/Sets the locale used for formatting and displaying the dates in the component. /// [Parameter] - public string Locale + public string? Locale { get { return this._locale; } set @@ -98,13 +98,13 @@ public string Locale } } - private IgbCalendarResourceStrings _resourceStrings; + private IgbCalendarResourceStrings? _resourceStrings; /// /// The resource strings for localization. /// [Parameter] - public IgbCalendarResourceStrings ResourceStrings + public IgbCalendarResourceStrings? ResourceStrings { get { return this._resourceStrings; } set @@ -122,13 +122,13 @@ public IgbCalendarResourceStrings ResourceStrings } } - private IgbDateRangeDescriptor[]? _specialDates; + private IgbDateRangeDescriptor[] _specialDates = Array.Empty(); /// /// Gets/Sets the special dates for the component. /// [Parameter] - public IgbDateRangeDescriptor[]? SpecialDates + public IgbDateRangeDescriptor[] SpecialDates { get { return this._specialDates; } set @@ -141,13 +141,13 @@ public IgbDateRangeDescriptor[]? SpecialDates } } - private IgbDateRangeDescriptor[]? _disabledDates; + private IgbDateRangeDescriptor[] _disabledDates = Array.Empty(); /// /// Gets/Sets the disabled dates for the component. /// [Parameter] - public IgbDateRangeDescriptor[]? DisabledDates + public IgbDateRangeDescriptor[] DisabledDates { get { return this._disabledDates; } set diff --git a/src/components/Blazor/CalendarFormatOptions.cs b/src/components/Blazor/CalendarFormatOptions.cs index 8dfbfa9b..3470067e 100644 --- a/src/components/Blazor/CalendarFormatOptions.cs +++ b/src/components/Blazor/CalendarFormatOptions.cs @@ -13,14 +13,14 @@ public partial class IgbCalendarFormatOptions : BaseRendererElement private static bool _marshalByValue = true; - private string _weekday; + private string? _weekday; /// /// The representation of the weekday names, one of long, short or narrow. /// Defaults to narrow. /// [Parameter] - public string Weekday + public string? Weekday { get { return this._weekday; } set @@ -33,14 +33,14 @@ public string Weekday } } - private string _month; + private string? _month; /// /// The representation of the month names, one of numeric, 2-digit, long, /// short or narrow. Defaults to long. /// [Parameter] - public string Month + public string? Month { get { return this._month; } set @@ -66,7 +66,7 @@ internal override void SerializeCore(RendererSerializer ser) } /// - protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) + protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) { base.ToEventJson(control, args); @@ -78,14 +78,14 @@ protected internal override void ToEventJson(BaseRendererControl control, Dictio } /// - protected internal override void FromEventJson(BaseRendererControl control, Dictionary args) + protected internal override void FromEventJson(BaseRendererControl control, Dictionary? args) { base.FromEventJson(control, args); this.SuppressParentNotify = true; - if (args.ContainsKey("weekday")) + if (args != null && args.ContainsKey("weekday")) { this.Weekday = ReturnToString(args["weekday"]); } - if (args.ContainsKey("month")) + if (args != null && args.ContainsKey("month")) { this.Month = ReturnToString(args["month"]); } this.SuppressParentNotify = false; diff --git a/src/components/Blazor/CalendarResourceStrings.cs b/src/components/Blazor/CalendarResourceStrings.cs index 064c7609..8d50e454 100644 --- a/src/components/Blazor/CalendarResourceStrings.cs +++ b/src/components/Blazor/CalendarResourceStrings.cs @@ -1,4 +1,4 @@ -using Microsoft.AspNetCore.Components; +using Microsoft.AspNetCore.Components; namespace IgniteUI.Blazor.Controls { @@ -11,13 +11,13 @@ public partial class IgbCalendarResourceStrings : BaseRendererElement /// public override string Type { get { return "WebCalendarResourceStrings"; } } - private string _selectMonth; + private string? _selectMonth; /// /// The accessible label of the header button that switches the calendar to the months view. /// [Parameter] - public string SelectMonth + public string? SelectMonth { get { return this._selectMonth; } set @@ -30,13 +30,13 @@ public string SelectMonth } } - private string _selectYear; + private string? _selectYear; /// /// The accessible label of the header button that switches the calendar to the years view. /// [Parameter] - public string SelectYear + public string? SelectYear { get { return this._selectYear; } set @@ -49,14 +49,14 @@ public string SelectYear } } - private string _selectDate; + private string? _selectDate; /// /// Title shown in the calendar header in single selection mode. /// Defaults to Select Date. /// [Parameter] - public string SelectDate + public string? SelectDate { get { return this._selectDate; } set @@ -69,14 +69,14 @@ public string SelectDate } } - private string _selectRange; + private string? _selectRange; /// /// Title shown in the calendar header in range selection mode. /// Defaults to Select Range. /// [Parameter] - public string SelectRange + public string? SelectRange { get { return this._selectRange; } set @@ -89,14 +89,14 @@ public string SelectRange } } - private string _selectedDate; + private string? _selectedDate; /// /// The label for the currently selected date. /// [Parameter] [Obsolete("This property is not used in the current localization pipeline and has no effect. It will be removed in a future release.")] - public string SelectedDate + public string? SelectedDate { get { return this._selectedDate; } set @@ -109,14 +109,14 @@ public string SelectedDate } } - private string _startDate; + private string? _startDate; /// /// Placeholder shown in the calendar header in place of the range start date until one is selected. /// Defaults to Start. /// [Parameter] - public string StartDate + public string? StartDate { get { return this._startDate; } set @@ -129,14 +129,14 @@ public string StartDate } } - private string _endDate; + private string? _endDate; /// /// Placeholder shown in the calendar header in place of the range end date until one is selected. /// Defaults to End. /// [Parameter] - public string EndDate + public string? EndDate { get { return this._endDate; } set @@ -149,14 +149,14 @@ public string EndDate } } - private string _previousMonth; + private string? _previousMonth; /// /// The accessible label of the navigation button that moves the days view one month back. /// Defaults to Previous Month. /// [Parameter] - public string PreviousMonth + public string? PreviousMonth { get { return this._previousMonth; } set @@ -169,14 +169,14 @@ public string PreviousMonth } } - private string _nextMonth; + private string? _nextMonth; /// /// The accessible label of the navigation button that moves the days view one month forward. /// Defaults to Next Month. /// [Parameter] - public string NextMonth + public string? NextMonth { get { return this._nextMonth; } set @@ -189,14 +189,14 @@ public string NextMonth } } - private string _previousYear; + private string? _previousYear; /// /// The accessible label of the navigation button that moves the months view one year back. /// Defaults to Previous Year. /// [Parameter] - public string PreviousYear + public string? PreviousYear { get { return this._previousYear; } set @@ -209,14 +209,14 @@ public string PreviousYear } } - private string _nextYear; + private string? _nextYear; /// /// The accessible label of the navigation button that moves the months view one year forward. /// Defaults to Next Year. /// [Parameter] - public string NextYear + public string? NextYear { get { return this._nextYear; } set @@ -229,14 +229,14 @@ public string NextYear } } - private string _previousYears; + private string? _previousYears; /// /// The accessible label of the navigation button that moves the years view one page back. /// Defaults to Previous {0} Years, where {0} is the number of years on a page. /// [Parameter] - public string PreviousYears + public string? PreviousYears { get { return this._previousYears; } set @@ -249,14 +249,14 @@ public string PreviousYears } } - private string _nextYears; + private string? _nextYears; /// /// The accessible label of the navigation button that moves the years view one page forward. /// Defaults to Next {0} Years, where {0} is the number of years on a page. /// [Parameter] - public string NextYears + public string? NextYears { get { return this._nextYears; } set @@ -269,13 +269,13 @@ public string NextYears } } - private string _weekLabel; + private string? _weekLabel; /// /// The header of the week numbers column in the days view. Defaults to Wk. /// [Parameter] - public string WeekLabel + public string? WeekLabel { get { return this._weekLabel; } set diff --git a/src/components/Blazor/Carousel.cs b/src/components/Blazor/Carousel.cs index e8d79980..2ab378f5 100644 --- a/src/components/Blazor/Carousel.cs +++ b/src/components/Blazor/Carousel.cs @@ -173,14 +173,14 @@ public CarouselIndicatorsOrientation IndicatorsOrientation } } - private string _indicatorsLabelFormat; + private string? _indicatorsLabelFormat; /// /// The format used to set the aria-label on the carousel indicators. /// Instances of {0} will be replaced with the index of the corresponding slide. /// [Parameter] - public string IndicatorsLabelFormat + public string? IndicatorsLabelFormat { get { return this._indicatorsLabelFormat; } set @@ -193,7 +193,7 @@ public string IndicatorsLabelFormat } } - private string _slidesLabelFormat; + private string? _slidesLabelFormat; /// /// The format used to set the aria-label on the carousel slides and the text displayed @@ -202,7 +202,7 @@ public string IndicatorsLabelFormat /// Instances of {1} will be replaced with the total amount of slides. /// [Parameter] - public string SlidesLabelFormat + public string? SlidesLabelFormat { get { return this._slidesLabelFormat; } set @@ -278,7 +278,7 @@ public HorizontalTransitionAnimation AnimationType /// public async Task GetTotalAsync() { - var iv = await InvokeMethod("p:Total", new object[] { }, new string[] { }); + var iv = await InvokeMethod("p:Total", new object?[] { }, new string[] { }); return ReturnToDouble(iv); } @@ -287,7 +287,7 @@ public async Task GetTotalAsync() /// public double GetTotal() { - var iv = InvokeMethodSync("p:Total", new object[] { }, new string[] { }); + var iv = InvokeMethodSync("p:Total", new object?[] { }, new string[] { }); return ReturnToDouble(iv); } @@ -296,7 +296,7 @@ public double GetTotal() /// public async Task GetCurrentAsync() { - var iv = await InvokeMethod("p:Current", new object[] { }, new string[] { }); + var iv = await InvokeMethod("p:Current", new object?[] { }, new string[] { }); return ReturnToDouble(iv); } @@ -305,7 +305,7 @@ public async Task GetCurrentAsync() /// public double GetCurrent() { - var iv = InvokeMethodSync("p:Current", new object[] { }, new string[] { }); + var iv = InvokeMethodSync("p:Current", new object?[] { }, new string[] { }); return ReturnToDouble(iv); } @@ -314,7 +314,7 @@ public double GetCurrent() /// public async Task GetIsPlayingAsync() { - var iv = await InvokeMethod("p:IsPlaying", new object[] { }, new string[] { }); + var iv = await InvokeMethod("p:IsPlaying", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } @@ -323,7 +323,7 @@ public async Task GetIsPlayingAsync() /// public bool GetIsPlaying() { - var iv = InvokeMethodSync("p:IsPlaying", new object[] { }, new string[] { }); + var iv = InvokeMethodSync("p:IsPlaying", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } @@ -332,7 +332,7 @@ public bool GetIsPlaying() /// public async Task GetIsPausedAsync() { - var iv = await InvokeMethod("p:IsPaused", new object[] { }, new string[] { }); + var iv = await InvokeMethod("p:IsPaused", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } @@ -341,7 +341,7 @@ public async Task GetIsPausedAsync() /// public bool GetIsPaused() { - var iv = InvokeMethodSync("p:IsPaused", new object[] { }, new string[] { }); + var iv = InvokeMethodSync("p:IsPaused", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } @@ -350,7 +350,7 @@ public bool GetIsPaused() /// public async Task PlayAsync() { - await InvokeMethod("play", new object[] { }, new string[] { }); + await InvokeMethod("play", new object?[] { }, new string[] { }); } /// @@ -358,14 +358,14 @@ public async Task PlayAsync() /// public void Play() { - InvokeMethodSync("play", new object[] { }, new string[] { }); + InvokeMethodSync("play", new object?[] { }, new string[] { }); } /// /// Pauses the rotation of the carousel slides. /// public async Task PauseAsync() { - await InvokeMethod("pause", new object[] { }, new string[] { }); + await InvokeMethod("pause", new object?[] { }, new string[] { }); } /// @@ -373,7 +373,7 @@ public async Task PauseAsync() /// public void Pause() { - InvokeMethodSync("pause", new object[] { }, new string[] { }); + InvokeMethodSync("pause", new object?[] { }, new string[] { }); } /// /// Switches to the next slide, running any animations. @@ -383,7 +383,7 @@ public void Pause() /// public async Task NextAsync() { - var iv = await InvokeMethod("next", new object[] { }, new string[] { }); + var iv = await InvokeMethod("next", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } @@ -395,7 +395,7 @@ public async Task NextAsync() /// public bool Next() { - var iv = InvokeMethodSync("next", new object[] { }, new string[] { }); + var iv = InvokeMethodSync("next", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } /// @@ -406,7 +406,7 @@ public bool Next() /// public async Task PrevAsync() { - var iv = await InvokeMethod("prev", new object[] { }, new string[] { }); + var iv = await InvokeMethod("prev", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } @@ -418,7 +418,7 @@ public async Task PrevAsync() /// public bool Prev() { - var iv = InvokeMethodSync("prev", new object[] { }, new string[] { }); + var iv = InvokeMethodSync("prev", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } @@ -430,7 +430,7 @@ public bool Prev() /// public async Task SelectAsync(double index, CarouselAnimationDirection? animationDirection = null) { - var iv = await InvokeMethod("select", new object[] { index, ObjectToParam(animationDirection, typeof(CarouselAnimationDirection)) }, new string[] { "Number", "Json" }); + var iv = await InvokeMethod("select", new object?[] { index, ObjectToParam(animationDirection, typeof(CarouselAnimationDirection)) }, new string[] { "Number", "Json" }); return ReturnToBoolean(iv); } @@ -442,12 +442,12 @@ public async Task SelectAsync(double index, CarouselAnimationDirection? an /// public bool Select(double index, CarouselAnimationDirection? animationDirection = null) { - var iv = InvokeMethodSync("select", new object[] { index, ObjectToParam(animationDirection, typeof(CarouselAnimationDirection)) }, new string[] { "Number", "Json" }); + var iv = InvokeMethodSync("select", new object?[] { index, ObjectToParam(animationDirection, typeof(CarouselAnimationDirection)) }, new string[] { "Number", "Json" }); return ReturnToBoolean(iv); } - private string _slideChangedRef = null; - private string _slideChangedScript = null; + private string? _slideChangedRef = null; + private string? _slideChangedScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -457,7 +457,7 @@ public bool Select(double index, CarouselAnimationDirection? animationDirection /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string SlideChangedScript + public string? SlideChangedScript { set @@ -465,7 +465,7 @@ public string SlideChangedScript if (value != this._slideChangedScript) { this._slideChangedScript = value; - this.OnRefChanged("SlideChanged", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("SlideChanged", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._slideChangedRef = refName; this.MarkPropDirty("SlideChangedRef"); @@ -518,8 +518,8 @@ public EventCallback SlideChanged } } - private string _playingRef = null; - private string _playingScript = null; + private string? _playingRef = null; + private string? _playingScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -529,7 +529,7 @@ public EventCallback SlideChanged /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string PlayingScript + public string? PlayingScript { set @@ -537,7 +537,7 @@ public string PlayingScript if (value != this._playingScript) { this._playingScript = value; - this.OnRefChanged("Playing", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Playing", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._playingRef = refName; this.MarkPropDirty("PlayingRef"); @@ -590,8 +590,8 @@ public EventCallback Playing } } - private string _pausedRef = null; - private string _pausedScript = null; + private string? _pausedRef = null; + private string? _pausedScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -601,7 +601,7 @@ public EventCallback Playing /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string PausedScript + public string? PausedScript { set @@ -609,7 +609,7 @@ public string PausedScript if (value != this._pausedScript) { this._pausedScript = value; - this.OnRefChanged("Paused", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Paused", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._pausedRef = refName; this.MarkPropDirty("PausedRef"); diff --git a/src/components/Blazor/Chat.cs b/src/components/Blazor/Chat.cs index 4a0553b7..6db6d49e 100644 --- a/src/components/Blazor/Chat.cs +++ b/src/components/Blazor/Chat.cs @@ -49,7 +49,7 @@ public IgbChat() : base() this.Options = new IgbChatOptions(); } - private IgbChatMessage[] _messages; + private IgbChatMessage[] _messages = Array.Empty(); /// /// The list of chat messages currently displayed. @@ -69,7 +69,7 @@ public IgbChatMessage[] Messages } } - private IgbChatDraftMessage _draftMessage; + private IgbChatDraftMessage _draftMessage = new IgbChatDraftMessage(); /// /// The chat message currently being composed but not yet sent. @@ -86,11 +86,11 @@ public IgbChatDraftMessage DraftMessage { this.DetachChild(this._draftMessage); } + this._draftMessage = value; if (value != null) { this.AttachChild(value); } - this._draftMessage = value; } } @@ -128,7 +128,7 @@ public IgbChatOptions? Options /// public async Task ScrollToMessageAsync(String messageId) { - await InvokeMethod("scrollToMessage", new object[] { StringToString(messageId) }, new string[] { "String" }); + await InvokeMethod("scrollToMessage", new object?[] { StringToString(messageId) }, new string[] { "String" }); } /// @@ -136,11 +136,11 @@ public async Task ScrollToMessageAsync(String messageId) /// public void ScrollToMessage(String messageId) { - InvokeMethodSync("scrollToMessage", new object[] { StringToString(messageId) }, new string[] { "String" }); + InvokeMethodSync("scrollToMessage", new object?[] { StringToString(messageId) }, new string[] { "String" }); } - private string _messageCreatedRef = null; - private string _messageCreatedScript = null; + private string? _messageCreatedRef = null; + private string? _messageCreatedScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -150,7 +150,7 @@ public void ScrollToMessage(String messageId) /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string MessageCreatedScript + public string? MessageCreatedScript { set @@ -158,7 +158,7 @@ public string MessageCreatedScript if (value != this._messageCreatedScript) { this._messageCreatedScript = value; - this.OnRefChanged("MessageCreated", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("MessageCreated", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._messageCreatedRef = refName; this.MarkPropDirty("MessageCreatedRef"); @@ -211,8 +211,8 @@ public EventCallback MessageCreated } } - private string _messageReactRef = null; - private string _messageReactScript = null; + private string? _messageReactRef = null; + private string? _messageReactScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -222,7 +222,7 @@ public EventCallback MessageCreated /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string MessageReactScript + public string? MessageReactScript { set @@ -230,7 +230,7 @@ public string MessageReactScript if (value != this._messageReactScript) { this._messageReactScript = value; - this.OnRefChanged("MessageReact", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("MessageReact", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._messageReactRef = refName; this.MarkPropDirty("MessageReactRef"); @@ -283,8 +283,8 @@ public EventCallback MessageReact } } - private string _attachmentClickRef = null; - private string _attachmentClickScript = null; + private string? _attachmentClickRef = null; + private string? _attachmentClickScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -294,7 +294,7 @@ public EventCallback MessageReact /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string AttachmentClickScript + public string? AttachmentClickScript { set @@ -302,7 +302,7 @@ public string AttachmentClickScript if (value != this._attachmentClickScript) { this._attachmentClickScript = value; - this.OnRefChanged("AttachmentClick", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("AttachmentClick", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._attachmentClickRef = refName; this.MarkPropDirty("AttachmentClickRef"); @@ -355,8 +355,8 @@ public EventCallback AttachmentClick } } - private string _typingChangeRef = null; - private string _typingChangeScript = null; + private string? _typingChangeRef = null; + private string? _typingChangeScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -366,7 +366,7 @@ public EventCallback AttachmentClick /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string TypingChangeScript + public string? TypingChangeScript { set @@ -374,7 +374,7 @@ public string TypingChangeScript if (value != this._typingChangeScript) { this._typingChangeScript = value; - this.OnRefChanged("TypingChange", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("TypingChange", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._typingChangeRef = refName; this.MarkPropDirty("TypingChangeRef"); @@ -427,8 +427,8 @@ public EventCallback TypingChange } } - private string _inputFocusRef = null; - private string _inputFocusScript = null; + private string? _inputFocusRef = null; + private string? _inputFocusScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -438,7 +438,7 @@ public EventCallback TypingChange /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string InputFocusScript + public string? InputFocusScript { set @@ -446,7 +446,7 @@ public string InputFocusScript if (value != this._inputFocusScript) { this._inputFocusScript = value; - this.OnRefChanged("InputFocus", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("InputFocus", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._inputFocusRef = refName; this.MarkPropDirty("InputFocusRef"); @@ -499,8 +499,8 @@ public EventCallback InputFocus } } - private string _inputBlurRef = null; - private string _inputBlurScript = null; + private string? _inputBlurRef = null; + private string? _inputBlurScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -510,7 +510,7 @@ public EventCallback InputFocus /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string InputBlurScript + public string? InputBlurScript { set @@ -518,7 +518,7 @@ public string InputBlurScript if (value != this._inputBlurScript) { this._inputBlurScript = value; - this.OnRefChanged("InputBlur", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("InputBlur", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._inputBlurRef = refName; this.MarkPropDirty("InputBlurRef"); @@ -571,8 +571,8 @@ public EventCallback InputBlur } } - private string _inputChangeRef = null; - private string _inputChangeScript = null; + private string? _inputChangeRef = null; + private string? _inputChangeScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -582,7 +582,7 @@ public EventCallback InputBlur /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string InputChangeScript + public string? InputChangeScript { set @@ -590,7 +590,7 @@ public string InputChangeScript if (value != this._inputChangeScript) { this._inputChangeScript = value; - this.OnRefChanged("InputChange", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("InputChange", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._inputChangeRef = refName; this.MarkPropDirty("InputChangeRef"); diff --git a/src/components/Blazor/ChatAttachmentRenderContext.cs b/src/components/Blazor/ChatAttachmentRenderContext.cs index 3c6c583a..871da4fb 100644 --- a/src/components/Blazor/ChatAttachmentRenderContext.cs +++ b/src/components/Blazor/ChatAttachmentRenderContext.cs @@ -10,7 +10,7 @@ public partial class IgbChatAttachmentRenderContext : BaseRendererElement /// public override string Type { get { return "WebChatAttachmentRenderContext"; } } - private IgbChatMessageAttachment _attachment; + private IgbChatMessageAttachment _attachment = new IgbChatMessageAttachment(); /// /// The specific attachment being rendered. @@ -26,11 +26,11 @@ public IgbChatMessageAttachment Attachment { this.DetachChild(this._attachment); } + this._attachment = value; if (value != null) { this.AttachChild(value); } - this._attachment = value; } } diff --git a/src/components/Blazor/ChatDraftMessage.cs b/src/components/Blazor/ChatDraftMessage.cs index 03d07c5b..851bdfad 100644 --- a/src/components/Blazor/ChatDraftMessage.cs +++ b/src/components/Blazor/ChatDraftMessage.cs @@ -9,7 +9,7 @@ public partial class IgbChatDraftMessage : BaseRendererElement private static bool _marshalByValue = true; - private string _text; + private string _text = string.Empty; /// /// The textual content of the draft message. @@ -28,7 +28,7 @@ public string Text } } - private IgbChatMessageAttachment[] _attachments; + private IgbChatMessageAttachment[] _attachments = Array.Empty(); /// /// An array of attachments associated with the draft message. @@ -61,7 +61,7 @@ internal override void SerializeCore(RendererSerializer ser) } /// - protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) + protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) { base.ToEventJson(control, args); @@ -73,15 +73,15 @@ protected internal override void ToEventJson(BaseRendererControl control, Dictio } /// - protected internal override void FromEventJson(BaseRendererControl control, Dictionary args) + protected internal override void FromEventJson(BaseRendererControl control, Dictionary? args) { base.FromEventJson(control, args); this.SuppressParentNotify = true; - if (args.ContainsKey("text")) + if (args != null && args.ContainsKey("text")) { this.Text = ReturnToString(args["text"]); } - if (args.ContainsKey("attachments")) - { this.Attachments = ReturnToObjectArray(args["attachments"]); } + if (args != null && args.ContainsKey("attachments")) + { this.Attachments = ReturnToObjectArray(args["attachments"]) ?? Array.Empty(); } this.SuppressParentNotify = false; } diff --git a/src/components/Blazor/ChatInputRenderContext.cs b/src/components/Blazor/ChatInputRenderContext.cs index 426a9c00..4942fd0d 100644 --- a/src/components/Blazor/ChatInputRenderContext.cs +++ b/src/components/Blazor/ChatInputRenderContext.cs @@ -10,7 +10,7 @@ public partial class IgbChatInputRenderContext : BaseRendererElement /// public override string Type { get { return "WebChatInputRenderContext"; } } - private string _value; + private string _value = string.Empty; /// /// The current value of the input field. diff --git a/src/components/Blazor/ChatMessage.cs b/src/components/Blazor/ChatMessage.cs index 2659586e..36a24a76 100644 --- a/src/components/Blazor/ChatMessage.cs +++ b/src/components/Blazor/ChatMessage.cs @@ -12,7 +12,7 @@ public partial class IgbChatMessage : BaseRendererElement private static bool _marshalByValue = true; - private string _id; + private string _id = string.Empty; /// /// A unique identifier for the message. @@ -31,7 +31,7 @@ public string Id } } - private string _text; + private string _text = string.Empty; /// /// The textual content of the message. @@ -50,7 +50,7 @@ public string Text } } - private string _sender; + private string _sender = string.Empty; /// /// The identifier or name of the sender of the message. @@ -69,13 +69,13 @@ public string Sender } } - private string _timestamp; + private string? _timestamp; /// /// The timestamp indicating when the message was sent. /// [Parameter] - public string Timestamp + public string? Timestamp { get { return this._timestamp; } set @@ -88,7 +88,7 @@ public string Timestamp } } - private IgbChatMessageAttachment[] _attachments; + private IgbChatMessageAttachment[] _attachments = Array.Empty(); /// /// Optional list of attachments associated with the message, @@ -108,7 +108,7 @@ public IgbChatMessageAttachment[] Attachments } } - private string[] _reactions; + private string[] _reactions = Array.Empty(); /// /// Optional list of reactions associated with the message. @@ -149,7 +149,7 @@ internal override void SerializeCore(RendererSerializer ser) } /// - protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) + protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) { base.ToEventJson(control, args); @@ -169,23 +169,23 @@ protected internal override void ToEventJson(BaseRendererControl control, Dictio } /// - protected internal override void FromEventJson(BaseRendererControl control, Dictionary args) + protected internal override void FromEventJson(BaseRendererControl control, Dictionary? args) { base.FromEventJson(control, args); this.SuppressParentNotify = true; - if (args.ContainsKey("id")) + if (args != null && args.ContainsKey("id")) { this.Id = ReturnToString(args["id"]); } - if (args.ContainsKey("text")) + if (args != null && args.ContainsKey("text")) { this.Text = ReturnToString(args["text"]); } - if (args.ContainsKey("sender")) + if (args != null && args.ContainsKey("sender")) { this.Sender = ReturnToString(args["sender"]); } - if (args.ContainsKey("timestamp")) + if (args != null && args.ContainsKey("timestamp")) { this.Timestamp = ReturnToString(args["timestamp"]); } - if (args.ContainsKey("attachments")) - { this.Attachments = ReturnToObjectArray(args["attachments"]); } - if (args.ContainsKey("reactions")) - { this.Reactions = ReturnToStringArray(args["reactions"]); } + if (args != null && args.ContainsKey("attachments")) + { this.Attachments = ReturnToObjectArray(args["attachments"]) ?? Array.Empty(); } + if (args != null && args.ContainsKey("reactions")) + { this.Reactions = ReturnToStringArray(args["reactions"]) ?? Array.Empty(); } this.SuppressParentNotify = false; } diff --git a/src/components/Blazor/ChatMessageAttachment.cs b/src/components/Blazor/ChatMessageAttachment.cs index d4f80004..85f1883c 100644 --- a/src/components/Blazor/ChatMessageAttachment.cs +++ b/src/components/Blazor/ChatMessageAttachment.cs @@ -12,7 +12,7 @@ public partial class IgbChatMessageAttachment : BaseRendererElement private static bool _marshalByValue = true; - private string _id; + private string _id = string.Empty; /// /// A unique identifier for the attachment. @@ -31,14 +31,14 @@ public string Id } } - private string _url; + private string? _url; /// /// The URL from which the attachment can be downloaded or viewed. /// Typically used for attachments stored on a server or CDN. /// [Parameter] - public string Url + public string? Url { get { return this._url; } set @@ -51,14 +51,14 @@ public string Url } } - private string _attachmentType; + private string? _attachmentType; /// /// The MIME type or a custom type identifier for the attachment (e.g. "image/png", "pdf", "audio"). /// [Parameter] [WCWidgetMemberName("Type")] - public string AttachmentType + public string? AttachmentType { get { return this._attachmentType; } set @@ -71,13 +71,13 @@ public string AttachmentType } } - private string _thumbnail; + private string? _thumbnail; /// /// Optional URL to a thumbnail preview of the attachment (e.g. for images or videos). /// [Parameter] - public string Thumbnail + public string? Thumbnail { get { return this._thumbnail; } set @@ -108,7 +108,7 @@ internal override void SerializeCore(RendererSerializer ser) } /// - protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) + protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) { base.ToEventJson(control, args); @@ -126,20 +126,20 @@ protected internal override void ToEventJson(BaseRendererControl control, Dictio } /// - protected internal override void FromEventJson(BaseRendererControl control, Dictionary args) + protected internal override void FromEventJson(BaseRendererControl control, Dictionary? args) { base.FromEventJson(control, args); this.SuppressParentNotify = true; - if (args.ContainsKey("id")) + if (args != null && args.ContainsKey("id")) { this.Id = ReturnToString(args["id"]); } - if (args.ContainsKey("name")) + if (args != null && args.ContainsKey("name")) { this.Name = ReturnToString(args["name"]); } - if (args.ContainsKey("url")) + if (args != null && args.ContainsKey("url")) { this.Url = ReturnToString(args["url"]); } - if (args.ContainsKey("attachmentType")) + if (args != null && args.ContainsKey("attachmentType")) { this.AttachmentType = ReturnToString(args["attachmentType"]); } - if (args.ContainsKey("thumbnail")) + if (args != null && args.ContainsKey("thumbnail")) { this.Thumbnail = ReturnToString(args["thumbnail"]); } this.SuppressParentNotify = false; diff --git a/src/components/Blazor/ChatMessageAttachmentEventArgs.cs b/src/components/Blazor/ChatMessageAttachmentEventArgs.cs index 6133eca6..91b06dad 100644 --- a/src/components/Blazor/ChatMessageAttachmentEventArgs.cs +++ b/src/components/Blazor/ChatMessageAttachmentEventArgs.cs @@ -13,7 +13,7 @@ public partial class IgbChatMessageAttachmentEventArgs : BaseRendererElement private static bool _marshalByValue = true; - private IgbChatMessageAttachment _detail; + private IgbChatMessageAttachment _detail = new IgbChatMessageAttachment(); /// /// The chat message attachment the event was raised for. @@ -29,11 +29,11 @@ public IgbChatMessageAttachment Detail { this.DetachChild(this._detail); } + this._detail = value; if (value != null) { this.AttachChild(value); } - this._detail = value; } } @@ -48,7 +48,7 @@ internal override void SerializeCore(RendererSerializer ser) } /// - protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) + protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) { base.ToEventJson(control, args); @@ -58,13 +58,13 @@ protected internal override void ToEventJson(BaseRendererControl control, Dictio } /// - protected internal override void FromEventJson(BaseRendererControl control, Dictionary args) + protected internal override void FromEventJson(BaseRendererControl control, Dictionary? args) { base.FromEventJson(control, args); this.SuppressParentNotify = true; - if (args.ContainsKey("detail")) - { this.Detail = (IgbChatMessageAttachment)ConvertReturnValue(args["detail"], "ChatMessageAttachment", true); } + if (args != null && args.TryGetValue("detail", out var detailObj) && ConvertReturnValue(detailObj, "ChatMessageAttachment", true) is IgbChatMessageAttachment detail) + { this.Detail = detail; } this.SuppressParentNotify = false; } diff --git a/src/components/Blazor/ChatMessageEventArgs.cs b/src/components/Blazor/ChatMessageEventArgs.cs index 2be669f0..e19da866 100644 --- a/src/components/Blazor/ChatMessageEventArgs.cs +++ b/src/components/Blazor/ChatMessageEventArgs.cs @@ -13,7 +13,7 @@ public partial class IgbChatMessageEventArgs : BaseRendererElement private static bool _marshalByValue = true; - private IgbChatMessage _detail; + private IgbChatMessage _detail = new IgbChatMessage(); /// /// The chat message the event was raised for. @@ -29,11 +29,11 @@ public IgbChatMessage Detail { this.DetachChild(this._detail); } + this._detail = value; if (value != null) { this.AttachChild(value); } - this._detail = value; } } @@ -48,7 +48,7 @@ internal override void SerializeCore(RendererSerializer ser) } /// - protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) + protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) { base.ToEventJson(control, args); @@ -58,13 +58,13 @@ protected internal override void ToEventJson(BaseRendererControl control, Dictio } /// - protected internal override void FromEventJson(BaseRendererControl control, Dictionary args) + protected internal override void FromEventJson(BaseRendererControl control, Dictionary? args) { base.FromEventJson(control, args); this.SuppressParentNotify = true; - if (args.ContainsKey("detail")) - { this.Detail = (IgbChatMessage)ConvertReturnValue(args["detail"], "ChatMessage", true); } + if (args != null && args.TryGetValue("detail", out var detailObj) && ConvertReturnValue(detailObj, "ChatMessage", true) is IgbChatMessage detail) + { this.Detail = detail; } this.SuppressParentNotify = false; } diff --git a/src/components/Blazor/ChatMessageReaction.cs b/src/components/Blazor/ChatMessageReaction.cs index 98e53cae..5b8ae37b 100644 --- a/src/components/Blazor/ChatMessageReaction.cs +++ b/src/components/Blazor/ChatMessageReaction.cs @@ -12,7 +12,7 @@ public partial class IgbChatMessageReaction : BaseRendererElement private static bool _marshalByValue = true; - private IgbChatMessage _message; + private IgbChatMessage _message = new IgbChatMessage(); /// /// The chat message that the reaction is associated with. @@ -28,15 +28,15 @@ public IgbChatMessage Message { this.DetachChild(this._message); } + this._message = value; if (value != null) { this.AttachChild(value); } - this._message = value; } } - private string _reaction; + private string _reaction = string.Empty; /// /// The string representation of the reaction, such as an emoji or a string; @@ -69,7 +69,7 @@ internal override void SerializeCore(RendererSerializer ser) } /// - protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) + protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) { base.ToEventJson(control, args); @@ -81,14 +81,14 @@ protected internal override void ToEventJson(BaseRendererControl control, Dictio } /// - protected internal override void FromEventJson(BaseRendererControl control, Dictionary args) + protected internal override void FromEventJson(BaseRendererControl control, Dictionary? args) { base.FromEventJson(control, args); this.SuppressParentNotify = true; - if (args.ContainsKey("message")) - { this.Message = (IgbChatMessage)ConvertReturnValue(args["message"], "ChatMessage", true); } - if (args.ContainsKey("reaction")) + if (args != null && args.TryGetValue("message", out var messageObj) && ConvertReturnValue(messageObj, "ChatMessage", true) is IgbChatMessage message) + { this.Message = message; } + if (args != null && args.ContainsKey("reaction")) { this.Reaction = ReturnToString(args["reaction"]); } this.SuppressParentNotify = false; diff --git a/src/components/Blazor/ChatMessageReactionEventArgs.cs b/src/components/Blazor/ChatMessageReactionEventArgs.cs index cb9345a3..aef0703b 100644 --- a/src/components/Blazor/ChatMessageReactionEventArgs.cs +++ b/src/components/Blazor/ChatMessageReactionEventArgs.cs @@ -13,7 +13,7 @@ public partial class IgbChatMessageReactionEventArgs : BaseRendererElement private static bool _marshalByValue = true; - private IgbChatMessageReaction _detail; + private IgbChatMessageReaction _detail = new IgbChatMessageReaction(); /// /// The reaction the event was raised for, together with the chat message it is associated with. @@ -29,11 +29,11 @@ public IgbChatMessageReaction Detail { this.DetachChild(this._detail); } + this._detail = value; if (value != null) { this.AttachChild(value); } - this._detail = value; } } @@ -48,7 +48,7 @@ internal override void SerializeCore(RendererSerializer ser) } /// - protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) + protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) { base.ToEventJson(control, args); @@ -58,13 +58,13 @@ protected internal override void ToEventJson(BaseRendererControl control, Dictio } /// - protected internal override void FromEventJson(BaseRendererControl control, Dictionary args) + protected internal override void FromEventJson(BaseRendererControl control, Dictionary? args) { base.FromEventJson(control, args); this.SuppressParentNotify = true; - if (args.ContainsKey("detail")) - { this.Detail = (IgbChatMessageReaction)ConvertReturnValue(args["detail"], "ChatMessageReaction", true); } + if (args != null && args.TryGetValue("detail", out var detailObj) && ConvertReturnValue(detailObj, "ChatMessageReaction", true) is IgbChatMessageReaction detail) + { this.Detail = detail; } this.SuppressParentNotify = false; } diff --git a/src/components/Blazor/ChatMessageRenderContext.cs b/src/components/Blazor/ChatMessageRenderContext.cs index c3adfe14..1045ea0b 100644 --- a/src/components/Blazor/ChatMessageRenderContext.cs +++ b/src/components/Blazor/ChatMessageRenderContext.cs @@ -10,7 +10,7 @@ public partial class IgbChatMessageRenderContext : BaseRendererElement /// public override string Type { get { return "WebChatMessageRenderContext"; } } - private IgbChatMessage _message; + private IgbChatMessage _message = new IgbChatMessage(); /// /// The specific chat message being rendered. @@ -26,11 +26,11 @@ public IgbChatMessage Message { this.DetachChild(this._message); } + this._message = value; if (value != null) { this.AttachChild(value); } - this._message = value; } } diff --git a/src/components/Blazor/ChatOptions.cs b/src/components/Blazor/ChatOptions.cs index 1c5ee690..341ec5a4 100644 --- a/src/components/Blazor/ChatOptions.cs +++ b/src/components/Blazor/ChatOptions.cs @@ -10,13 +10,13 @@ public partial class IgbChatOptions : BaseRendererElement /// public override string Type { get { return "WebChatOptions"; } } - private string _currentUserId; + private string? _currentUserId; /// /// The ID of the current user. Used to differentiate between incoming and outgoing messages. /// [Parameter] - public string CurrentUserId + public string? CurrentUserId { get { return this._currentUserId; } set @@ -87,13 +87,13 @@ public bool IsTyping } } - private string _headerText; + private string? _headerText; /// /// Optional header text to display at the top of the chat component. /// [Parameter] - public string HeaderText + public string? HeaderText { get { return this._headerText; } set @@ -106,14 +106,14 @@ public string HeaderText } } - private string _inputPlaceholder; + private string? _inputPlaceholder; /// /// Optional placeholder text for the chat input area. /// Provides a hint to the user about what they can type (e.g. "Type a message..."). /// [Parameter] - public string InputPlaceholder + public string? InputPlaceholder { get { return this._inputPlaceholder; } set @@ -126,7 +126,7 @@ public string InputPlaceholder } } - private string[] _suggestions; + private string[] _suggestions = Array.Empty(); /// /// Suggested text snippets or quick replies that can be shown as user-selectable options. @@ -216,13 +216,13 @@ public bool AdoptRootStyles } } - private IgbChatRenderers _renderers; + private IgbChatRenderers? _renderers; /// /// An object containing a collection of custom renderers for different parts of the chat UI. /// [Parameter] - public IgbChatRenderers Renderers + public IgbChatRenderers? Renderers { get { return this._renderers; } set diff --git a/src/components/Blazor/ChatRenderContext.cs b/src/components/Blazor/ChatRenderContext.cs index 51807cc9..7d493c61 100644 --- a/src/components/Blazor/ChatRenderContext.cs +++ b/src/components/Blazor/ChatRenderContext.cs @@ -11,7 +11,7 @@ public partial class IgbChatRenderContext : BaseRendererElement /// public override string Type { get { return "WebChatRenderContext"; } } - private IgbChat _instance; + private IgbChat _instance = new IgbChat(); /// /// The instance of the component. diff --git a/src/components/Blazor/ChatRenderers.cs b/src/components/Blazor/ChatRenderers.cs index 49f3c7c0..cb4348b5 100644 --- a/src/components/Blazor/ChatRenderers.cs +++ b/src/components/Blazor/ChatRenderers.cs @@ -7,14 +7,14 @@ public partial class IgbChatRenderers : BaseRendererElement /// public override string Type { get { return "WebChatRenderers"; } } - private string _attachmentRef; - private RenderFragment _attachment; + private string? _attachmentRef; + private RenderFragment? _attachment; /// /// Custom renderer for a single chat message attachment. /// [Parameter] - public RenderFragment Attachment + public RenderFragment? Attachment { get { return this._attachment; } @@ -27,7 +27,7 @@ public RenderFragment Attachment this._attachment = value; this._attachmentTemplateId = Guid.NewGuid().ToString(); this.UpdateTemplate(this._attachmentTemplateId, this._attachment, typeof(IgbChatAttachmentRenderContext)); - this.OnRefChanged("Attachment", null, "template:::" + this._attachmentTemplateId, true, false, (string refName, object old, object newValue) => + this.OnRefChanged("Attachment", null, "template:::" + this._attachmentTemplateId, true, false, (string refName, object? old, object? newValue) => { this._attachmentRef = refName; this.MarkPropDirty("AttachmentRef"); @@ -36,8 +36,8 @@ public RenderFragment Attachment } } - private string _attachmentTemplateId; - private string _attachmentScript; + private string? _attachmentTemplateId; + private string? _attachmentScript; /// /// Name of a client-side function that renders a single chat message attachment. @@ -47,7 +47,7 @@ public RenderFragment Attachment /// igRegisterScript("MyTemplate", function (ctx) { return ...; }, false). /// [Parameter] - public string AttachmentScript + public string? AttachmentScript { get { return _attachmentScript; } @@ -58,7 +58,7 @@ public string AttachmentScript { this._attachmentScript = value; MarkPropDirty("Attachment"); - this.OnRefChanged("Attachment", oldValue, value, true, false, (string refName, object old, object newValue) => + this.OnRefChanged("Attachment", oldValue, value, true, false, (string refName, object? old, object? newValue) => { this._attachmentRef = refName; this.MarkPropDirty("AttachmentRef"); @@ -66,14 +66,14 @@ public string AttachmentScript } } } - private string _attachmentContentRef; - private RenderFragment _attachmentContent; + private string? _attachmentContentRef; + private RenderFragment? _attachmentContent; /// /// Custom renderer for the content of an attachment. /// [Parameter] - public RenderFragment AttachmentContent + public RenderFragment? AttachmentContent { get { return this._attachmentContent; } @@ -86,7 +86,7 @@ public RenderFragment AttachmentContent this._attachmentContent = value; this._attachmentContentTemplateId = Guid.NewGuid().ToString(); this.UpdateTemplate(this._attachmentContentTemplateId, this._attachmentContent, typeof(IgbChatAttachmentRenderContext)); - this.OnRefChanged("AttachmentContent", null, "template:::" + this._attachmentContentTemplateId, true, false, (string refName, object old, object newValue) => + this.OnRefChanged("AttachmentContent", null, "template:::" + this._attachmentContentTemplateId, true, false, (string refName, object? old, object? newValue) => { this._attachmentContentRef = refName; this.MarkPropDirty("AttachmentContentRef"); @@ -95,8 +95,8 @@ public RenderFragment AttachmentContent } } - private string _attachmentContentTemplateId; - private string _attachmentContentScript; + private string? _attachmentContentTemplateId; + private string? _attachmentContentScript; /// /// Name of a client-side function that renders the content of an attachment. @@ -106,7 +106,7 @@ public RenderFragment AttachmentContent /// igRegisterScript("MyTemplate", function (ctx) { return ...; }, false). /// [Parameter] - public string AttachmentContentScript + public string? AttachmentContentScript { get { return _attachmentContentScript; } @@ -117,7 +117,7 @@ public string AttachmentContentScript { this._attachmentContentScript = value; MarkPropDirty("AttachmentContent"); - this.OnRefChanged("AttachmentContent", oldValue, value, true, false, (string refName, object old, object newValue) => + this.OnRefChanged("AttachmentContent", oldValue, value, true, false, (string refName, object? old, object? newValue) => { this._attachmentContentRef = refName; this.MarkPropDirty("AttachmentContentRef"); @@ -125,14 +125,14 @@ public string AttachmentContentScript } } } - private string _attachmentHeaderRef; - private RenderFragment _attachmentHeader; + private string? _attachmentHeaderRef; + private RenderFragment? _attachmentHeader; /// /// Custom renderer for the header of an attachment. /// [Parameter] - public RenderFragment AttachmentHeader + public RenderFragment? AttachmentHeader { get { return this._attachmentHeader; } @@ -145,7 +145,7 @@ public RenderFragment AttachmentHeader this._attachmentHeader = value; this._attachmentHeaderTemplateId = Guid.NewGuid().ToString(); this.UpdateTemplate(this._attachmentHeaderTemplateId, this._attachmentHeader, typeof(IgbChatAttachmentRenderContext)); - this.OnRefChanged("AttachmentHeader", null, "template:::" + this._attachmentHeaderTemplateId, true, false, (string refName, object old, object newValue) => + this.OnRefChanged("AttachmentHeader", null, "template:::" + this._attachmentHeaderTemplateId, true, false, (string refName, object? old, object? newValue) => { this._attachmentHeaderRef = refName; this.MarkPropDirty("AttachmentHeaderRef"); @@ -154,8 +154,8 @@ public RenderFragment AttachmentHeader } } - private string _attachmentHeaderTemplateId; - private string _attachmentHeaderScript; + private string? _attachmentHeaderTemplateId; + private string? _attachmentHeaderScript; /// /// Name of a client-side function that renders the header of an attachment. @@ -165,7 +165,7 @@ public RenderFragment AttachmentHeader /// igRegisterScript("MyTemplate", function (ctx) { return ...; }, false). /// [Parameter] - public string AttachmentHeaderScript + public string? AttachmentHeaderScript { get { return _attachmentHeaderScript; } @@ -176,7 +176,7 @@ public string AttachmentHeaderScript { this._attachmentHeaderScript = value; MarkPropDirty("AttachmentHeader"); - this.OnRefChanged("AttachmentHeader", oldValue, value, true, false, (string refName, object old, object newValue) => + this.OnRefChanged("AttachmentHeader", oldValue, value, true, false, (string refName, object? old, object? newValue) => { this._attachmentHeaderRef = refName; this.MarkPropDirty("AttachmentHeaderRef"); @@ -184,14 +184,14 @@ public string AttachmentHeaderScript } } } - private string _inputRef; - private RenderFragment _input; + private string? _inputRef; + private RenderFragment? _input; /// /// Custom renderer for the main chat input field. /// [Parameter] - public RenderFragment Input + public RenderFragment? Input { get { return this._input; } @@ -204,7 +204,7 @@ public RenderFragment Input this._input = value; this._inputTemplateId = Guid.NewGuid().ToString(); this.UpdateTemplate(this._inputTemplateId, this._input, typeof(IgbChatInputRenderContext)); - this.OnRefChanged("Input", null, "template:::" + this._inputTemplateId, true, false, (string refName, object old, object newValue) => + this.OnRefChanged("Input", null, "template:::" + this._inputTemplateId, true, false, (string refName, object? old, object? newValue) => { this._inputRef = refName; this.MarkPropDirty("InputRef"); @@ -213,8 +213,8 @@ public RenderFragment Input } } - private string _inputTemplateId; - private string _inputScript; + private string? _inputTemplateId; + private string? _inputScript; /// /// Name of a client-side function that renders the main chat input field. @@ -224,7 +224,7 @@ public RenderFragment Input /// igRegisterScript("MyTemplate", function (ctx) { return ...; }, false). /// [Parameter] - public string InputScript + public string? InputScript { get { return _inputScript; } @@ -235,7 +235,7 @@ public string InputScript { this._inputScript = value; MarkPropDirty("Input"); - this.OnRefChanged("Input", oldValue, value, true, false, (string refName, object old, object newValue) => + this.OnRefChanged("Input", oldValue, value, true, false, (string refName, object? old, object? newValue) => { this._inputRef = refName; this.MarkPropDirty("InputRef"); @@ -243,14 +243,14 @@ public string InputScript } } } - private string _inputActionsRef; - private RenderFragment _inputActions; + private string? _inputActionsRef; + private RenderFragment? _inputActions; /// /// Custom renderer for the actions container within the input area. /// [Parameter] - public RenderFragment InputActions + public RenderFragment? InputActions { get { return this._inputActions; } @@ -263,7 +263,7 @@ public RenderFragment InputActions this._inputActions = value; this._inputActionsTemplateId = Guid.NewGuid().ToString(); this.UpdateTemplate(this._inputActionsTemplateId, this._inputActions, typeof(IgbChatRenderContext)); - this.OnRefChanged("InputActions", null, "template:::" + this._inputActionsTemplateId, true, false, (string refName, object old, object newValue) => + this.OnRefChanged("InputActions", null, "template:::" + this._inputActionsTemplateId, true, false, (string refName, object? old, object? newValue) => { this._inputActionsRef = refName; this.MarkPropDirty("InputActionsRef"); @@ -272,8 +272,8 @@ public RenderFragment InputActions } } - private string _inputActionsTemplateId; - private string _inputActionsScript; + private string? _inputActionsTemplateId; + private string? _inputActionsScript; /// /// Name of a client-side function that renders the actions container within the input area. @@ -283,7 +283,7 @@ public RenderFragment InputActions /// igRegisterScript("MyTemplate", function (ctx) { return ...; }, false). /// [Parameter] - public string InputActionsScript + public string? InputActionsScript { get { return _inputActionsScript; } @@ -294,7 +294,7 @@ public string InputActionsScript { this._inputActionsScript = value; MarkPropDirty("InputActions"); - this.OnRefChanged("InputActions", oldValue, value, true, false, (string refName, object old, object newValue) => + this.OnRefChanged("InputActions", oldValue, value, true, false, (string refName, object? old, object? newValue) => { this._inputActionsRef = refName; this.MarkPropDirty("InputActionsRef"); @@ -302,14 +302,14 @@ public string InputActionsScript } } } - private string _inputActionsEndRef; - private RenderFragment _inputActionsEnd; + private string? _inputActionsEndRef; + private RenderFragment? _inputActionsEnd; /// /// Custom renderer for the actions at the end of the input area. /// [Parameter] - public RenderFragment InputActionsEnd + public RenderFragment? InputActionsEnd { get { return this._inputActionsEnd; } @@ -322,7 +322,7 @@ public RenderFragment InputActionsEnd this._inputActionsEnd = value; this._inputActionsEndTemplateId = Guid.NewGuid().ToString(); this.UpdateTemplate(this._inputActionsEndTemplateId, this._inputActionsEnd, typeof(IgbChatRenderContext)); - this.OnRefChanged("InputActionsEnd", null, "template:::" + this._inputActionsEndTemplateId, true, false, (string refName, object old, object newValue) => + this.OnRefChanged("InputActionsEnd", null, "template:::" + this._inputActionsEndTemplateId, true, false, (string refName, object? old, object? newValue) => { this._inputActionsEndRef = refName; this.MarkPropDirty("InputActionsEndRef"); @@ -331,8 +331,8 @@ public RenderFragment InputActionsEnd } } - private string _inputActionsEndTemplateId; - private string _inputActionsEndScript; + private string? _inputActionsEndTemplateId; + private string? _inputActionsEndScript; /// /// Name of a client-side function that renders the actions at the end of the input area. @@ -342,7 +342,7 @@ public RenderFragment InputActionsEnd /// igRegisterScript("MyTemplate", function (ctx) { return ...; }, false). /// [Parameter] - public string InputActionsEndScript + public string? InputActionsEndScript { get { return _inputActionsEndScript; } @@ -353,7 +353,7 @@ public string InputActionsEndScript { this._inputActionsEndScript = value; MarkPropDirty("InputActionsEnd"); - this.OnRefChanged("InputActionsEnd", oldValue, value, true, false, (string refName, object old, object newValue) => + this.OnRefChanged("InputActionsEnd", oldValue, value, true, false, (string refName, object? old, object? newValue) => { this._inputActionsEndRef = refName; this.MarkPropDirty("InputActionsEndRef"); @@ -361,14 +361,14 @@ public string InputActionsEndScript } } } - private string _inputActionsStartRef; - private RenderFragment _inputActionsStart; + private string? _inputActionsStartRef; + private RenderFragment? _inputActionsStart; /// /// Custom renderer for the actions at the start of the input area. /// [Parameter] - public RenderFragment InputActionsStart + public RenderFragment? InputActionsStart { get { return this._inputActionsStart; } @@ -381,7 +381,7 @@ public RenderFragment InputActionsStart this._inputActionsStart = value; this._inputActionsStartTemplateId = Guid.NewGuid().ToString(); this.UpdateTemplate(this._inputActionsStartTemplateId, this._inputActionsStart, typeof(IgbChatRenderContext)); - this.OnRefChanged("InputActionsStart", null, "template:::" + this._inputActionsStartTemplateId, true, false, (string refName, object old, object newValue) => + this.OnRefChanged("InputActionsStart", null, "template:::" + this._inputActionsStartTemplateId, true, false, (string refName, object? old, object? newValue) => { this._inputActionsStartRef = refName; this.MarkPropDirty("InputActionsStartRef"); @@ -390,8 +390,8 @@ public RenderFragment InputActionsStart } } - private string _inputActionsStartTemplateId; - private string _inputActionsStartScript; + private string? _inputActionsStartTemplateId; + private string? _inputActionsStartScript; /// /// Name of a client-side function that renders the actions at the start of the input area. @@ -401,7 +401,7 @@ public RenderFragment InputActionsStart /// igRegisterScript("MyTemplate", function (ctx) { return ...; }, false). /// [Parameter] - public string InputActionsStartScript + public string? InputActionsStartScript { get { return _inputActionsStartScript; } @@ -412,7 +412,7 @@ public string InputActionsStartScript { this._inputActionsStartScript = value; MarkPropDirty("InputActionsStart"); - this.OnRefChanged("InputActionsStart", oldValue, value, true, false, (string refName, object old, object newValue) => + this.OnRefChanged("InputActionsStart", oldValue, value, true, false, (string refName, object? old, object? newValue) => { this._inputActionsStartRef = refName; this.MarkPropDirty("InputActionsStartRef"); @@ -420,14 +420,14 @@ public string InputActionsStartScript } } } - private string _messageRef; - private RenderFragment _message; + private string? _messageRef; + private RenderFragment? _message; /// /// Custom renderer for an entire chat message bubble. /// [Parameter] - public RenderFragment Message + public RenderFragment? Message { get { return this._message; } @@ -440,7 +440,7 @@ public RenderFragment Message this._message = value; this._messageTemplateId = Guid.NewGuid().ToString(); this.UpdateTemplate(this._messageTemplateId, this._message, typeof(IgbChatMessageRenderContext)); - this.OnRefChanged("Message", null, "template:::" + this._messageTemplateId, true, false, (string refName, object old, object newValue) => + this.OnRefChanged("Message", null, "template:::" + this._messageTemplateId, true, false, (string refName, object? old, object? newValue) => { this._messageRef = refName; this.MarkPropDirty("MessageRef"); @@ -449,8 +449,8 @@ public RenderFragment Message } } - private string _messageTemplateId; - private string _messageScript; + private string? _messageTemplateId; + private string? _messageScript; /// /// Name of a client-side function that renders an entire chat message bubble. @@ -460,7 +460,7 @@ public RenderFragment Message /// igRegisterScript("MyTemplate", function (ctx) { return ...; }, false). /// [Parameter] - public string MessageScript + public string? MessageScript { get { return _messageScript; } @@ -471,7 +471,7 @@ public string MessageScript { this._messageScript = value; MarkPropDirty("Message"); - this.OnRefChanged("Message", oldValue, value, true, false, (string refName, object old, object newValue) => + this.OnRefChanged("Message", oldValue, value, true, false, (string refName, object? old, object? newValue) => { this._messageRef = refName; this.MarkPropDirty("MessageRef"); @@ -479,14 +479,14 @@ public string MessageScript } } } - private string _messageActionsRef; - private RenderFragment _messageActions; + private string? _messageActionsRef; + private RenderFragment? _messageActions; /// /// Custom renderer for message-specific actions (e.g. reply or delete buttons). /// [Parameter] - public RenderFragment MessageActions + public RenderFragment? MessageActions { get { return this._messageActions; } @@ -499,7 +499,7 @@ public RenderFragment MessageActions this._messageActions = value; this._messageActionsTemplateId = Guid.NewGuid().ToString(); this.UpdateTemplate(this._messageActionsTemplateId, this._messageActions, typeof(IgbChatMessageRenderContext)); - this.OnRefChanged("MessageActions", null, "template:::" + this._messageActionsTemplateId, true, false, (string refName, object old, object newValue) => + this.OnRefChanged("MessageActions", null, "template:::" + this._messageActionsTemplateId, true, false, (string refName, object? old, object? newValue) => { this._messageActionsRef = refName; this.MarkPropDirty("MessageActionsRef"); @@ -508,8 +508,8 @@ public RenderFragment MessageActions } } - private string _messageActionsTemplateId; - private string _messageActionsScript; + private string? _messageActionsTemplateId; + private string? _messageActionsScript; /// /// Name of a client-side function that renders message-specific actions (e.g. reply or delete buttons). @@ -519,7 +519,7 @@ public RenderFragment MessageActions /// igRegisterScript("MyTemplate", function (ctx) { return ...; }, false). /// [Parameter] - public string MessageActionsScript + public string? MessageActionsScript { get { return _messageActionsScript; } @@ -530,7 +530,7 @@ public string MessageActionsScript { this._messageActionsScript = value; MarkPropDirty("MessageActions"); - this.OnRefChanged("MessageActions", oldValue, value, true, false, (string refName, object old, object newValue) => + this.OnRefChanged("MessageActions", oldValue, value, true, false, (string refName, object? old, object? newValue) => { this._messageActionsRef = refName; this.MarkPropDirty("MessageActionsRef"); @@ -538,14 +538,14 @@ public string MessageActionsScript } } } - private string _messageAttachmentsRef; - private RenderFragment _messageAttachments; + private string? _messageAttachmentsRef; + private RenderFragment? _messageAttachments; /// /// Custom renderer for the attachments associated with a message. /// [Parameter] - public RenderFragment MessageAttachments + public RenderFragment? MessageAttachments { get { return this._messageAttachments; } @@ -558,7 +558,7 @@ public RenderFragment MessageAttachments this._messageAttachments = value; this._messageAttachmentsTemplateId = Guid.NewGuid().ToString(); this.UpdateTemplate(this._messageAttachmentsTemplateId, this._messageAttachments, typeof(IgbChatMessageRenderContext)); - this.OnRefChanged("MessageAttachments", null, "template:::" + this._messageAttachmentsTemplateId, true, false, (string refName, object old, object newValue) => + this.OnRefChanged("MessageAttachments", null, "template:::" + this._messageAttachmentsTemplateId, true, false, (string refName, object? old, object? newValue) => { this._messageAttachmentsRef = refName; this.MarkPropDirty("MessageAttachmentsRef"); @@ -567,8 +567,8 @@ public RenderFragment MessageAttachments } } - private string _messageAttachmentsTemplateId; - private string _messageAttachmentsScript; + private string? _messageAttachmentsTemplateId; + private string? _messageAttachmentsScript; /// /// Name of a client-side function that renders the attachments associated with a message. @@ -578,7 +578,7 @@ public RenderFragment MessageAttachments /// igRegisterScript("MyTemplate", function (ctx) { return ...; }, false). /// [Parameter] - public string MessageAttachmentsScript + public string? MessageAttachmentsScript { get { return _messageAttachmentsScript; } @@ -589,7 +589,7 @@ public string MessageAttachmentsScript { this._messageAttachmentsScript = value; MarkPropDirty("MessageAttachments"); - this.OnRefChanged("MessageAttachments", oldValue, value, true, false, (string refName, object old, object newValue) => + this.OnRefChanged("MessageAttachments", oldValue, value, true, false, (string refName, object? old, object? newValue) => { this._messageAttachmentsRef = refName; this.MarkPropDirty("MessageAttachmentsRef"); @@ -597,14 +597,14 @@ public string MessageAttachmentsScript } } } - private string _messageContentRef; - private RenderFragment _messageContent; + private string? _messageContentRef; + private RenderFragment? _messageContent; /// /// Custom renderer for the main text and content of a message. /// [Parameter] - public RenderFragment MessageContent + public RenderFragment? MessageContent { get { return this._messageContent; } @@ -617,7 +617,7 @@ public RenderFragment MessageContent this._messageContent = value; this._messageContentTemplateId = Guid.NewGuid().ToString(); this.UpdateTemplate(this._messageContentTemplateId, this._messageContent, typeof(IgbChatMessageRenderContext)); - this.OnRefChanged("MessageContent", null, "template:::" + this._messageContentTemplateId, true, false, (string refName, object old, object newValue) => + this.OnRefChanged("MessageContent", null, "template:::" + this._messageContentTemplateId, true, false, (string refName, object? old, object? newValue) => { this._messageContentRef = refName; this.MarkPropDirty("MessageContentRef"); @@ -626,8 +626,8 @@ public RenderFragment MessageContent } } - private string _messageContentTemplateId; - private string _messageContentScript; + private string? _messageContentTemplateId; + private string? _messageContentScript; /// /// Name of a client-side function that renders the main text and content of a message. @@ -637,7 +637,7 @@ public RenderFragment MessageContent /// igRegisterScript("MyTemplate", function (ctx) { return ...; }, false). /// [Parameter] - public string MessageContentScript + public string? MessageContentScript { get { return _messageContentScript; } @@ -648,7 +648,7 @@ public string MessageContentScript { this._messageContentScript = value; MarkPropDirty("MessageContent"); - this.OnRefChanged("MessageContent", oldValue, value, true, false, (string refName, object old, object newValue) => + this.OnRefChanged("MessageContent", oldValue, value, true, false, (string refName, object? old, object? newValue) => { this._messageContentRef = refName; this.MarkPropDirty("MessageContentRef"); @@ -656,14 +656,14 @@ public string MessageContentScript } } } - private string _messageHeaderRef; - private RenderFragment _messageHeader; + private string? _messageHeaderRef; + private RenderFragment? _messageHeader; /// /// Custom renderer for the header of a message, including sender and timestamp. /// [Parameter] - public RenderFragment MessageHeader + public RenderFragment? MessageHeader { get { return this._messageHeader; } @@ -676,7 +676,7 @@ public RenderFragment MessageHeader this._messageHeader = value; this._messageHeaderTemplateId = Guid.NewGuid().ToString(); this.UpdateTemplate(this._messageHeaderTemplateId, this._messageHeader, typeof(IgbChatMessageRenderContext)); - this.OnRefChanged("MessageHeader", null, "template:::" + this._messageHeaderTemplateId, true, false, (string refName, object old, object newValue) => + this.OnRefChanged("MessageHeader", null, "template:::" + this._messageHeaderTemplateId, true, false, (string refName, object? old, object? newValue) => { this._messageHeaderRef = refName; this.MarkPropDirty("MessageHeaderRef"); @@ -685,8 +685,8 @@ public RenderFragment MessageHeader } } - private string _messageHeaderTemplateId; - private string _messageHeaderScript; + private string? _messageHeaderTemplateId; + private string? _messageHeaderScript; /// /// Name of a client-side function that renders the header of a message, including sender and timestamp. @@ -696,7 +696,7 @@ public RenderFragment MessageHeader /// igRegisterScript("MyTemplate", function (ctx) { return ...; }, false). /// [Parameter] - public string MessageHeaderScript + public string? MessageHeaderScript { get { return _messageHeaderScript; } @@ -707,7 +707,7 @@ public string MessageHeaderScript { this._messageHeaderScript = value; MarkPropDirty("MessageHeader"); - this.OnRefChanged("MessageHeader", oldValue, value, true, false, (string refName, object old, object newValue) => + this.OnRefChanged("MessageHeader", oldValue, value, true, false, (string refName, object? old, object? newValue) => { this._messageHeaderRef = refName; this.MarkPropDirty("MessageHeaderRef"); @@ -715,14 +715,14 @@ public string MessageHeaderScript } } } - private string _sendButtonRef; - private RenderFragment _sendButton; + private string? _sendButtonRef; + private RenderFragment? _sendButton; /// /// Custom renderer for the message send button. /// [Parameter] - public RenderFragment SendButton + public RenderFragment? SendButton { get { return this._sendButton; } @@ -735,7 +735,7 @@ public RenderFragment SendButton this._sendButton = value; this._sendButtonTemplateId = Guid.NewGuid().ToString(); this.UpdateTemplate(this._sendButtonTemplateId, this._sendButton, typeof(IgbChatRenderContext)); - this.OnRefChanged("SendButton", null, "template:::" + this._sendButtonTemplateId, true, false, (string refName, object old, object newValue) => + this.OnRefChanged("SendButton", null, "template:::" + this._sendButtonTemplateId, true, false, (string refName, object? old, object? newValue) => { this._sendButtonRef = refName; this.MarkPropDirty("SendButtonRef"); @@ -744,8 +744,8 @@ public RenderFragment SendButton } } - private string _sendButtonTemplateId; - private string _sendButtonScript; + private string? _sendButtonTemplateId; + private string? _sendButtonScript; /// /// Name of a client-side function that renders the message send button. @@ -755,7 +755,7 @@ public RenderFragment SendButton /// igRegisterScript("MyTemplate", function (ctx) { return ...; }, false). /// [Parameter] - public string SendButtonScript + public string? SendButtonScript { get { return _sendButtonScript; } @@ -766,7 +766,7 @@ public string SendButtonScript { this._sendButtonScript = value; MarkPropDirty("SendButton"); - this.OnRefChanged("SendButton", oldValue, value, true, false, (string refName, object old, object newValue) => + this.OnRefChanged("SendButton", oldValue, value, true, false, (string refName, object? old, object? newValue) => { this._sendButtonRef = refName; this.MarkPropDirty("SendButtonRef"); @@ -774,14 +774,14 @@ public string SendButtonScript } } } - private string _suggestionPrefixRef; - private RenderFragment _suggestionPrefix; + private string? _suggestionPrefixRef; + private RenderFragment? _suggestionPrefix; /// /// Custom renderer for the prefix text shown before suggestions. /// [Parameter] - public RenderFragment SuggestionPrefix + public RenderFragment? SuggestionPrefix { get { return this._suggestionPrefix; } @@ -794,7 +794,7 @@ public RenderFragment SuggestionPrefix this._suggestionPrefix = value; this._suggestionPrefixTemplateId = Guid.NewGuid().ToString(); this.UpdateTemplate(this._suggestionPrefixTemplateId, this._suggestionPrefix, typeof(IgbChatRenderContext)); - this.OnRefChanged("SuggestionPrefix", null, "template:::" + this._suggestionPrefixTemplateId, true, false, (string refName, object old, object newValue) => + this.OnRefChanged("SuggestionPrefix", null, "template:::" + this._suggestionPrefixTemplateId, true, false, (string refName, object? old, object? newValue) => { this._suggestionPrefixRef = refName; this.MarkPropDirty("SuggestionPrefixRef"); @@ -803,8 +803,8 @@ public RenderFragment SuggestionPrefix } } - private string _suggestionPrefixTemplateId; - private string _suggestionPrefixScript; + private string? _suggestionPrefixTemplateId; + private string? _suggestionPrefixScript; /// /// Name of a client-side function that renders the prefix text shown before suggestions. @@ -814,7 +814,7 @@ public RenderFragment SuggestionPrefix /// igRegisterScript("MyTemplate", function (ctx) { return ...; }, false). /// [Parameter] - public string SuggestionPrefixScript + public string? SuggestionPrefixScript { get { return _suggestionPrefixScript; } @@ -825,7 +825,7 @@ public string SuggestionPrefixScript { this._suggestionPrefixScript = value; MarkPropDirty("SuggestionPrefix"); - this.OnRefChanged("SuggestionPrefix", oldValue, value, true, false, (string refName, object old, object newValue) => + this.OnRefChanged("SuggestionPrefix", oldValue, value, true, false, (string refName, object? old, object? newValue) => { this._suggestionPrefixRef = refName; this.MarkPropDirty("SuggestionPrefixRef"); diff --git a/src/components/Blazor/CheckboxBase.cs b/src/components/Blazor/CheckboxBase.cs index 4bf0b297..327e6492 100644 --- a/src/components/Blazor/CheckboxBase.cs +++ b/src/components/Blazor/CheckboxBase.cs @@ -49,13 +49,13 @@ protected override ControlEventBehavior DefaultEventBehavior get { return ControlEventBehavior.Immediate; } } - private string _value; + private string? _value; /// /// The value of the control. /// [Parameter] - public string Value + public string? Value { get { return this._value; } set @@ -93,7 +93,7 @@ public bool Checked /// public async Task GetCurrentCheckedAsync() { - var iv = await InvokeMethod("p:Checked", new object[] { }, new string[] { }); + var iv = await InvokeMethod("p:Checked", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } @@ -102,7 +102,7 @@ public async Task GetCurrentCheckedAsync() /// public bool GetCurrentChecked() { - var iv = InvokeMethodSync("p:Checked", new object[] { }, new string[] { }); + var iv = InvokeMethodSync("p:Checked", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } private ToggleLabelPosition _labelPosition = ToggleLabelPosition.After; @@ -187,7 +187,7 @@ public bool Invalid /// public async Task ClickAsync() { - await InvokeMethod("click", new object[] { }, new string[] { }); + await InvokeMethod("click", new object?[] { }, new string[] { }); } /// @@ -195,7 +195,7 @@ public async Task ClickAsync() /// public void Click() { - InvokeMethodSync("click", new object[] { }, new string[] { }); + InvokeMethodSync("click", new object?[] { }, new string[] { }); } /// /// Sets focus on the control. @@ -204,7 +204,7 @@ public void Click() [WCWidgetMemberName("Focus")] public async Task FocusComponentAsync(IgbFocusOptions options) { - await InvokeMethod("focus", new object[] { ObjectToParam(options) }, new string[] { "Json" }); + await InvokeMethod("focus", new object?[] { ObjectToParam(options) }, new string[] { "Json" }); } /// @@ -213,7 +213,7 @@ public async Task FocusComponentAsync(IgbFocusOptions options) [WCWidgetMemberName("Focus")] public void FocusComponent(IgbFocusOptions options) { - InvokeMethodSync("focus", new object[] { ObjectToParam(options) }, new string[] { "Json" }); + InvokeMethodSync("focus", new object?[] { ObjectToParam(options) }, new string[] { "Json" }); } /// /// Removes focus from the control. @@ -222,7 +222,7 @@ public void FocusComponent(IgbFocusOptions options) [WCWidgetMemberName("Blur")] public async Task BlurComponentAsync() { - await InvokeMethod("blur", new object[] { }, new string[] { }); + await InvokeMethod("blur", new object?[] { }, new string[] { }); } /// @@ -231,14 +231,14 @@ public async Task BlurComponentAsync() [WCWidgetMemberName("Blur")] public void BlurComponent() { - InvokeMethodSync("blur", new object[] { }, new string[] { }); + InvokeMethodSync("blur", new object?[] { }, new string[] { }); } /// /// Checks for validity of the control and shows the browser message if it's invalid. /// public async Task ReportValidityAsync() { - var iv = await InvokeMethod("reportValidity", new object[] { }, new string[] { }); + var iv = await InvokeMethod("reportValidity", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } @@ -247,7 +247,7 @@ public async Task ReportValidityAsync() /// public bool ReportValidity() { - var iv = InvokeMethodSync("reportValidity", new object[] { }, new string[] { }); + var iv = InvokeMethodSync("reportValidity", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } /// @@ -255,7 +255,7 @@ public bool ReportValidity() /// public async Task CheckValidityAsync() { - var iv = await InvokeMethod("checkValidity", new object[] { }, new string[] { }); + var iv = await InvokeMethod("checkValidity", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } @@ -264,7 +264,7 @@ public async Task CheckValidityAsync() /// public bool CheckValidity() { - var iv = InvokeMethodSync("checkValidity", new object[] { }, new string[] { }); + var iv = InvokeMethodSync("checkValidity", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } /// @@ -273,7 +273,7 @@ public bool CheckValidity() /// public async Task SetCustomValidityAsync(String message) { - await InvokeMethod("setCustomValidity", new object[] { StringToString(message) }, new string[] { "String" }); + await InvokeMethod("setCustomValidity", new object?[] { StringToString(message) }, new string[] { "String" }); } /// @@ -282,7 +282,7 @@ public async Task SetCustomValidityAsync(String message) /// public void SetCustomValidity(String message) { - InvokeMethodSync("setCustomValidity", new object[] { StringToString(message) }, new string[] { "String" }); + InvokeMethodSync("setCustomValidity", new object?[] { StringToString(message) }, new string[] { "String" }); } private EventCallback? _checkedChanged = null; @@ -316,8 +316,8 @@ public EventCallback CheckedChanged } } - private string _changeRef = null; - private string _changeScript = null; + private string? _changeRef = null; + private string? _changeScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -327,7 +327,7 @@ public EventCallback CheckedChanged /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string ChangeScript + public string? ChangeScript { set @@ -335,7 +335,7 @@ public string ChangeScript if (value != this._changeScript) { this._changeScript = value; - this.OnRefChanged("Change", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Change", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._changeRef = refName; this.MarkPropDirty("ChangeRef"); @@ -423,8 +423,8 @@ internal void EnsureChangeHandled() } } - private string _focusRef = null; - private string _focusScript = null; + private string? _focusRef = null; + private string? _focusScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -434,7 +434,7 @@ internal void EnsureChangeHandled() /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string FocusScript + public string? FocusScript { set @@ -442,7 +442,7 @@ public string FocusScript if (value != this._focusScript) { this._focusScript = value; - this.OnRefChanged("Focus", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Focus", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._focusRef = refName; this.MarkPropDirty("FocusRef"); @@ -495,8 +495,8 @@ public EventCallback Focus } } - private string _blurRef = null; - private string _blurScript = null; + private string? _blurRef = null; + private string? _blurScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -506,7 +506,7 @@ public EventCallback Focus /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string BlurScript + public string? BlurScript { set @@ -514,7 +514,7 @@ public string BlurScript if (value != this._blurScript) { this._blurScript = value; - this.OnRefChanged("Blur", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Blur", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._blurRef = refName; this.MarkPropDirty("BlurRef"); diff --git a/src/components/Blazor/CheckboxChangeEventArgs.cs b/src/components/Blazor/CheckboxChangeEventArgs.cs index f540ea7d..312f9d84 100644 --- a/src/components/Blazor/CheckboxChangeEventArgs.cs +++ b/src/components/Blazor/CheckboxChangeEventArgs.cs @@ -13,7 +13,7 @@ public partial class IgbCheckboxChangeEventArgs : BaseRendererElement private static bool _marshalByValue = true; - private IgbCheckboxChangeEventArgsDetail _detail; + private IgbCheckboxChangeEventArgsDetail _detail = new IgbCheckboxChangeEventArgsDetail(); /// /// The payload of the event, carrying the new checked state and the value of the control. @@ -29,11 +29,11 @@ public IgbCheckboxChangeEventArgsDetail Detail { this.DetachChild(this._detail); } + this._detail = value; if (value != null) { this.AttachChild(value); } - this._detail = value; } } @@ -48,7 +48,7 @@ internal override void SerializeCore(RendererSerializer ser) } /// - protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) + protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) { base.ToEventJson(control, args); @@ -58,13 +58,13 @@ protected internal override void ToEventJson(BaseRendererControl control, Dictio } /// - protected internal override void FromEventJson(BaseRendererControl control, Dictionary args) + protected internal override void FromEventJson(BaseRendererControl control, Dictionary? args) { base.FromEventJson(control, args); this.SuppressParentNotify = true; - if (args.ContainsKey("detail")) - { this.Detail = (IgbCheckboxChangeEventArgsDetail)ConvertReturnValue(args["detail"], "CheckboxChangeEventArgsDetail", true); } + if (args != null && args.TryGetValue("detail", out var detailObj) && ConvertReturnValue(detailObj, "CheckboxChangeEventArgsDetail", true) is IgbCheckboxChangeEventArgsDetail detail) + { this.Detail = detail; } this.SuppressParentNotify = false; } diff --git a/src/components/Blazor/CheckboxChangeEventArgsDetail.cs b/src/components/Blazor/CheckboxChangeEventArgsDetail.cs index 950d503b..3490c544 100644 --- a/src/components/Blazor/CheckboxChangeEventArgsDetail.cs +++ b/src/components/Blazor/CheckboxChangeEventArgsDetail.cs @@ -31,13 +31,13 @@ public bool Checked } } - private string _value; + private string? _value; /// /// The value of the control. /// [Parameter] - public string Value + public string? Value { get { return this._value; } set @@ -64,7 +64,7 @@ internal override void SerializeCore(RendererSerializer ser) } /// - protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) + protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) { base.ToEventJson(control, args); @@ -76,14 +76,14 @@ protected internal override void ToEventJson(BaseRendererControl control, Dictio } /// - protected internal override void FromEventJson(BaseRendererControl control, Dictionary args) + protected internal override void FromEventJson(BaseRendererControl control, Dictionary? args) { base.FromEventJson(control, args); this.SuppressParentNotify = true; - if (args.ContainsKey("checked")) + if (args != null && args.ContainsKey("checked")) { this.Checked = ReturnToBoolean(args["checked"]); } - if (args.ContainsKey("value")) + if (args != null && args.ContainsKey("value")) { this.Value = ReturnToString(args["value"]); } this.SuppressParentNotify = false; diff --git a/src/components/Blazor/Chip.cs b/src/components/Blazor/Chip.cs index dbc3d76b..fc9f1e1d 100644 --- a/src/components/Blazor/Chip.cs +++ b/src/components/Blazor/Chip.cs @@ -140,7 +140,7 @@ public bool Selected /// public async Task GetCurrentSelectedAsync() { - var iv = await InvokeMethod("p:Selected", new object[] { }, new string[] { }); + var iv = await InvokeMethod("p:Selected", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } @@ -149,7 +149,7 @@ public async Task GetCurrentSelectedAsync() /// public bool GetCurrentSelected() { - var iv = InvokeMethodSync("p:Selected", new object[] { }, new string[] { }); + var iv = InvokeMethodSync("p:Selected", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } private StyleVariant _variant = StyleVariant.Primary; @@ -204,8 +204,8 @@ public EventCallback SelectedChanged } } - private string _removeRef = null; - private string _removeScript = null; + private string? _removeRef = null; + private string? _removeScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -215,7 +215,7 @@ public EventCallback SelectedChanged /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string RemoveScript + public string? RemoveScript { set @@ -223,7 +223,7 @@ public string RemoveScript if (value != this._removeScript) { this._removeScript = value; - this.OnRefChanged("Remove", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Remove", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._removeRef = refName; this.MarkPropDirty("RemoveRef"); @@ -276,8 +276,8 @@ public EventCallback Remove } } - private string _selectRef = null; - private string _selectScript = null; + private string? _selectRef = null; + private string? _selectScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -287,7 +287,7 @@ public EventCallback Remove /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string SelectScript + public string? SelectScript { set @@ -295,7 +295,7 @@ public string SelectScript if (value != this._selectScript) { this._selectScript = value; - this.OnRefChanged("Select", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Select", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._selectRef = refName; this.MarkPropDirty("SelectRef"); diff --git a/src/components/Blazor/CircularGradient.cs b/src/components/Blazor/CircularGradient.cs index 1dbfdbc9..20250f55 100644 --- a/src/components/Blazor/CircularGradient.cs +++ b/src/components/Blazor/CircularGradient.cs @@ -62,13 +62,13 @@ protected override ControlEventBehavior DefaultEventBehavior get { return ControlEventBehavior.Immediate; } } - private string _offset; + private string? _offset; /// /// Defines where the gradient stop is placed along the gradient vector. /// [Parameter] - public string Offset + public string? Offset { get { return this._offset; } set @@ -81,13 +81,13 @@ public string Offset } } - private string _color; + private string? _color; /// /// Defines the color of the gradient stop. /// [Parameter] - public string Color + public string? Color { get { return this._color; } set diff --git a/src/components/Blazor/Combo.cs b/src/components/Blazor/Combo.cs index b2334725..156e4c4b 100644 --- a/src/components/Blazor/Combo.cs +++ b/src/components/Blazor/Combo.cs @@ -1,4 +1,4 @@ -using Microsoft.AspNetCore.Components; +using Microsoft.AspNetCore.Components; namespace IgniteUI.Blazor.Controls { @@ -41,14 +41,14 @@ protected override bool SupportsVisualChildren } } - private string _dataRef; - private Object _data; + private string? _dataRef; + private Object? _data; /// /// The data source used to generate the list of options. /// [Parameter] - public Object Data + public Object? Data { get { return this._data; } @@ -60,7 +60,7 @@ public Object Data { MarkPropDirty("Data"); this._data = value; - this.OnRefChanged("Data", oldValue, value, false, false, (string refName, object old, object newValue) => + this.OnRefChanged("Data", oldValue, value, false, false, (string refName, object? old, object? newValue) => { this._dataRef = refName; this.MarkPropDirty("DataRef"); @@ -69,11 +69,11 @@ public Object Data } } - private string _dataScript; + private string? _dataScript; ///Provides a means of setting Data in the JavaScript environment. [Parameter] - public string DataScript + public string? DataScript { get { return _dataScript; } @@ -84,7 +84,7 @@ public string DataScript { this._dataScript = value; MarkPropDirty("Data"); - this.OnRefChanged("Data", oldValue, value, true, false, (string refName, object old, object newValue) => + this.OnRefChanged("Data", oldValue, value, true, false, (string refName, object? old, object? newValue) => { this._dataRef = refName; this.MarkPropDirty("DataRef"); @@ -168,13 +168,13 @@ public bool AutofocusList } } - private string _locale; + private string? _locale; /// /// Gets/Sets the locale used for getting language, affecting resource strings. /// [Parameter] - public string Locale + public string? Locale { get { return this._locale; } set @@ -187,13 +187,13 @@ public string Locale } } - private string _label; + private string? _label; /// /// The label of the control. /// [Parameter] - public string Label + public string? Label { get { return this._label; } set @@ -206,13 +206,13 @@ public string Label } } - private string _placeholder; + private string? _placeholder; /// /// The placeholder text of the control. /// [Parameter] - public string Placeholder + public string? Placeholder { get { return this._placeholder; } set @@ -225,13 +225,13 @@ public string Placeholder } } - private string _placeholderSearch; + private string? _placeholderSearch; /// /// The placeholder text of the search input. /// [Parameter] - public string PlaceholderSearch + public string? PlaceholderSearch { get { return this._placeholderSearch; } set @@ -282,13 +282,13 @@ public string? DisplayKey } } - private string _groupKey; + private string? _groupKey; /// /// The key in the data source used to group items in the list. /// [Parameter] - public string GroupKey + public string? GroupKey { get { return this._groupKey; } set @@ -320,7 +320,7 @@ public GroupingDirection GroupSorting } } - private IgbFilteringOptions _filteringOptions; + private IgbFilteringOptions _filteringOptions = new IgbFilteringOptions(); /// /// An object that configures the filtering of the combo. @@ -336,11 +336,11 @@ public IgbFilteringOptions FilteringOptions { this.DetachChild(this._filteringOptions); } + this._filteringOptions = value; if (value != null) { this.AttachChild(value); } - this._filteringOptions = value; } } @@ -401,7 +401,7 @@ public bool DisableClear } } - private T[] _value; + private T[] _value = Array.Empty(); /// /// The value of the control, that is the currently selected items. @@ -430,7 +430,7 @@ public T[] Value /// The selected values, represented by when provided. public async Task GetCurrentValueAsync() { - var iv = await InvokeMethod("p:Value", new object[] { }, new string[] { }); + var iv = await InvokeMethod("p:Value", new object?[] { }, new string[] { }); return ReturnToObjectArray(iv).Cast().ToArray(); } @@ -440,10 +440,10 @@ public async Task GetCurrentValueAsync() /// The selected values, represented by when provided. public T[] GetCurrentValue() { - var iv = InvokeMethodSync("p:Value", new object[] { }, new string[] { }); + var iv = InvokeMethodSync("p:Value", new object?[] { }, new string[] { }); return ReturnToObjectArray(iv).Cast().ToArray(); } - private string _selectionRef; + private string? _selectionRef; /// /// Returns the current selection of the combo. @@ -451,7 +451,7 @@ public T[] GetCurrentValue() /// The selected items as provided in the source. public async Task GetSelectionAsync() { - var iv = await InvokeMethod("p:Selection", new object[] { }, new string[] { }); + var iv = await InvokeMethod("p:Selection", new object?[] { }, new string[] { }); return ReturnToObjectArray(iv); } @@ -461,7 +461,7 @@ public async Task GetSelectionAsync() /// The selected items as provided in the source. public object[] GetSelection() { - var iv = InvokeMethodSync("p:Selection", new object[] { }, new string[] { }); + var iv = InvokeMethodSync("p:Selection", new object?[] { }, new string[] { }); return ReturnToObjectArray(iv); } private bool _disabled = false; @@ -521,14 +521,14 @@ public bool Invalid } } - private string _itemTemplateRef; - private RenderFragment _itemTemplate; + private string? _itemTemplateRef; + private RenderFragment? _itemTemplate; /// /// The template used for the content of each combo item. /// [Parameter] - public RenderFragment ItemTemplate + public RenderFragment? ItemTemplate { get { return this._itemTemplate; } @@ -541,7 +541,7 @@ public RenderFragment ItemTemplate this._itemTemplate = value; this._itemTemplateTemplateId = Guid.NewGuid().ToString(); this.UpdateTemplate(this._itemTemplateTemplateId, this._itemTemplate, typeof(object)); - this.OnRefChanged("ItemTemplate", null, "template:::" + this._itemTemplateTemplateId, true, false, (string refName, object old, object newValue) => + this.OnRefChanged("ItemTemplate", null, "template:::" + this._itemTemplateTemplateId, true, false, (string refName, object? old, object? newValue) => { this._itemTemplateRef = refName; this.MarkPropDirty("ItemTemplateRef"); @@ -550,8 +550,8 @@ public RenderFragment ItemTemplate } } - private string _itemTemplateTemplateId; - private string _itemTemplateScript; + private string? _itemTemplateTemplateId; + private string? _itemTemplateScript; /// /// Name of a client-side function that renders the template used for the content of each combo item. @@ -561,7 +561,7 @@ public RenderFragment ItemTemplate /// igRegisterScript("MyTemplate", function (ctx) { return ...; }, false). /// [Parameter] - public string ItemTemplateScript + public string? ItemTemplateScript { get { return _itemTemplateScript; } @@ -572,7 +572,7 @@ public string ItemTemplateScript { this._itemTemplateScript = value; MarkPropDirty("ItemTemplate"); - this.OnRefChanged("ItemTemplate", oldValue, value, true, false, (string refName, object old, object newValue) => + this.OnRefChanged("ItemTemplate", oldValue, value, true, false, (string refName, object? old, object? newValue) => { this._itemTemplateRef = refName; this.MarkPropDirty("ItemTemplateRef"); @@ -580,14 +580,14 @@ public string ItemTemplateScript } } } - private string _groupHeaderTemplateRef; - private RenderFragment _groupHeaderTemplate; + private string? _groupHeaderTemplateRef; + private RenderFragment? _groupHeaderTemplate; /// /// The template used for the content of each combo group header. /// [Parameter] - public RenderFragment GroupHeaderTemplate + public RenderFragment? GroupHeaderTemplate { get { return this._groupHeaderTemplate; } @@ -600,7 +600,7 @@ public RenderFragment GroupHeaderTemplate this._groupHeaderTemplate = value; this._groupHeaderTemplateTemplateId = Guid.NewGuid().ToString(); this.UpdateTemplate(this._groupHeaderTemplateTemplateId, this._groupHeaderTemplate, typeof(object)); - this.OnRefChanged("GroupHeaderTemplate", null, "template:::" + this._groupHeaderTemplateTemplateId, true, false, (string refName, object old, object newValue) => + this.OnRefChanged("GroupHeaderTemplate", null, "template:::" + this._groupHeaderTemplateTemplateId, true, false, (string refName, object? old, object? newValue) => { this._groupHeaderTemplateRef = refName; this.MarkPropDirty("GroupHeaderTemplateRef"); @@ -609,8 +609,8 @@ public RenderFragment GroupHeaderTemplate } } - private string _groupHeaderTemplateTemplateId; - private string _groupHeaderTemplateScript; + private string? _groupHeaderTemplateTemplateId; + private string? _groupHeaderTemplateScript; /// /// Name of a client-side function that renders the template used for the content of each combo group header. @@ -620,7 +620,7 @@ public RenderFragment GroupHeaderTemplate /// igRegisterScript("MyTemplate", function (ctx) { return ...; }, false). /// [Parameter] - public string GroupHeaderTemplateScript + public string? GroupHeaderTemplateScript { get { return _groupHeaderTemplateScript; } @@ -631,7 +631,7 @@ public string GroupHeaderTemplateScript { this._groupHeaderTemplateScript = value; MarkPropDirty("GroupHeaderTemplate"); - this.OnRefChanged("GroupHeaderTemplate", oldValue, value, true, false, (string refName, object old, object newValue) => + this.OnRefChanged("GroupHeaderTemplate", oldValue, value, true, false, (string refName, object? old, object? newValue) => { this._groupHeaderTemplateRef = refName; this.MarkPropDirty("GroupHeaderTemplateRef"); @@ -647,7 +647,7 @@ public string GroupHeaderTemplateScript [WCWidgetMemberName("Focus")] public async Task FocusComponentAsync(IgbFocusOptions options) { - await InvokeMethod("focus", new object[] { ObjectToParam(options) }, new string[] { "Json" }); + await InvokeMethod("focus", new object?[] { ObjectToParam(options) }, new string[] { "Json" }); } /// @@ -656,7 +656,7 @@ public async Task FocusComponentAsync(IgbFocusOptions options) [WCWidgetMemberName("Focus")] public void FocusComponent(IgbFocusOptions options) { - InvokeMethodSync("focus", new object[] { ObjectToParam(options) }, new string[] { "Json" }); + InvokeMethodSync("focus", new object?[] { ObjectToParam(options) }, new string[] { "Json" }); } /// /// Removes focus from the component. @@ -665,7 +665,7 @@ public void FocusComponent(IgbFocusOptions options) [WCWidgetMemberName("Blur")] public async Task BlurComponentAsync() { - await InvokeMethod("blur", new object[] { }, new string[] { }); + await InvokeMethod("blur", new object?[] { }, new string[] { }); } /// @@ -674,7 +674,7 @@ public async Task BlurComponentAsync() [WCWidgetMemberName("Blur")] public void BlurComponent() { - InvokeMethodSync("blur", new object[] { }, new string[] { }); + InvokeMethodSync("blur", new object?[] { }, new string[] { }); } /// @@ -685,7 +685,7 @@ public void BlurComponent() /// the corresponding value should be used in place of the item reference. public async Task SelectAsync(object[] items) { - await InvokeMethod("select", new object[] { ObjectArrayToParam(items) }, new string[] { "" }); + await InvokeMethod("select", new object?[] { ObjectArrayToParam(items) }, new string[] { "" }); } /// @@ -696,7 +696,7 @@ public async Task SelectAsync(object[] items) /// the corresponding value should be used in place of the item reference. public void Select(object[] items) { - InvokeMethodSync("select", new object[] { ObjectArrayToParam(items) }, new string[] { "" }); + InvokeMethodSync("select", new object?[] { ObjectArrayToParam(items) }, new string[] { "" }); } /// @@ -707,7 +707,7 @@ public void Select(object[] items) /// the corresponding value should be used in place of the item reference. public async Task DeselectAsync(object[] items) { - await InvokeMethod("deselect", new object[] { ObjectArrayToParam(items) }, new string[] { "" }); + await InvokeMethod("deselect", new object?[] { ObjectArrayToParam(items) }, new string[] { "" }); } /// @@ -718,14 +718,14 @@ public async Task DeselectAsync(object[] items) /// the corresponding value should be used in place of the item reference. public void Deselect(object[] items) { - InvokeMethodSync("deselect", new object[] { ObjectArrayToParam(items) }, new string[] { "" }); + InvokeMethodSync("deselect", new object?[] { ObjectArrayToParam(items) }, new string[] { "" }); } /// /// Checks for validity of the control and shows the browser message if it's invalid. /// public async Task ReportValidityAsync() { - var iv = await InvokeMethod("reportValidity", new object[] { }, new string[] { }); + var iv = await InvokeMethod("reportValidity", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } @@ -734,7 +734,7 @@ public async Task ReportValidityAsync() /// public bool ReportValidity() { - var iv = InvokeMethodSync("reportValidity", new object[] { }, new string[] { }); + var iv = InvokeMethodSync("reportValidity", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } /// @@ -742,7 +742,7 @@ public bool ReportValidity() /// public async Task CheckValidityAsync() { - var iv = await InvokeMethod("checkValidity", new object[] { }, new string[] { }); + var iv = await InvokeMethod("checkValidity", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } @@ -751,7 +751,7 @@ public async Task CheckValidityAsync() /// public bool CheckValidity() { - var iv = InvokeMethodSync("checkValidity", new object[] { }, new string[] { }); + var iv = InvokeMethodSync("checkValidity", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } /// @@ -760,7 +760,7 @@ public bool CheckValidity() /// public async Task SetCustomValidityAsync(String message) { - await InvokeMethod("setCustomValidity", new object[] { StringToString(message) }, new string[] { "String" }); + await InvokeMethod("setCustomValidity", new object?[] { StringToString(message) }, new string[] { "String" }); } /// @@ -769,7 +769,7 @@ public async Task SetCustomValidityAsync(String message) /// public void SetCustomValidity(String message) { - InvokeMethodSync("setCustomValidity", new object[] { StringToString(message) }, new string[] { "String" }); + InvokeMethodSync("setCustomValidity", new object?[] { StringToString(message) }, new string[] { "String" }); } private EventCallback? _valueChanged = null; @@ -803,8 +803,8 @@ public EventCallback ValueChanged } } - private string _changeRef = null; - private string _changeScript = null; + private string? _changeRef = null; + private string? _changeScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -814,7 +814,7 @@ public EventCallback ValueChanged /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string ChangeScript + public string? ChangeScript { set @@ -822,7 +822,7 @@ public string ChangeScript if (value != this._changeScript) { this._changeScript = value; - this.OnRefChanged("Change", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Change", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._changeRef = refName; this.MarkPropDirty("ChangeRef"); @@ -910,8 +910,8 @@ internal void EnsureChangeHandled() } } - private string _focusRef = null; - private string _focusScript = null; + private string? _focusRef = null; + private string? _focusScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -921,7 +921,7 @@ internal void EnsureChangeHandled() /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string FocusScript + public string? FocusScript { set @@ -929,7 +929,7 @@ public string FocusScript if (value != this._focusScript) { this._focusScript = value; - this.OnRefChanged("Focus", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Focus", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._focusRef = refName; this.MarkPropDirty("FocusRef"); @@ -982,8 +982,8 @@ public EventCallback Focus } } - private string _blurRef = null; - private string _blurScript = null; + private string? _blurRef = null; + private string? _blurScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -993,7 +993,7 @@ public EventCallback Focus /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string BlurScript + public string? BlurScript { set @@ -1001,7 +1001,7 @@ public string BlurScript if (value != this._blurScript) { this._blurScript = value; - this.OnRefChanged("Blur", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Blur", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._blurRef = refName; this.MarkPropDirty("BlurRef"); @@ -1054,8 +1054,8 @@ public EventCallback Blur } } - private string _openingRef = null; - private string _openingScript = null; + private string? _openingRef = null; + private string? _openingScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -1065,7 +1065,7 @@ public EventCallback Blur /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string OpeningScript + public string? OpeningScript { set @@ -1073,7 +1073,7 @@ public string OpeningScript if (value != this._openingScript) { this._openingScript = value; - this.OnRefChanged("Opening", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Opening", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._openingRef = refName; this.MarkPropDirty("OpeningRef"); @@ -1126,8 +1126,8 @@ public EventCallback Opening } } - private string _openedRef = null; - private string _openedScript = null; + private string? _openedRef = null; + private string? _openedScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -1137,7 +1137,7 @@ public EventCallback Opening /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string OpenedScript + public string? OpenedScript { set @@ -1145,7 +1145,7 @@ public string OpenedScript if (value != this._openedScript) { this._openedScript = value; - this.OnRefChanged("Opened", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Opened", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._openedRef = refName; this.MarkPropDirty("OpenedRef"); @@ -1198,8 +1198,8 @@ public EventCallback Opened } } - private string _closingRef = null; - private string _closingScript = null; + private string? _closingRef = null; + private string? _closingScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -1209,7 +1209,7 @@ public EventCallback Opened /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string ClosingScript + public string? ClosingScript { set @@ -1217,7 +1217,7 @@ public string ClosingScript if (value != this._closingScript) { this._closingScript = value; - this.OnRefChanged("Closing", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Closing", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._closingRef = refName; this.MarkPropDirty("ClosingRef"); @@ -1270,8 +1270,8 @@ public EventCallback Closing } } - private string _closedRef = null; - private string _closedScript = null; + private string? _closedRef = null; + private string? _closedScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -1281,7 +1281,7 @@ public EventCallback Closing /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string ClosedScript + public string? ClosedScript { set @@ -1289,7 +1289,7 @@ public string ClosedScript if (value != this._closedScript) { this._closedScript = value; - this.OnRefChanged("Closed", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Closed", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._closedRef = refName; this.MarkPropDirty("ClosedRef"); diff --git a/src/components/Blazor/ComboChangeEventArgs.cs b/src/components/Blazor/ComboChangeEventArgs.cs index 9d149642..b48e69d3 100644 --- a/src/components/Blazor/ComboChangeEventArgs.cs +++ b/src/components/Blazor/ComboChangeEventArgs.cs @@ -12,7 +12,7 @@ public partial class IgbComboChangeEventArgs : BaseRendererElement private static bool _marshalByValue = true; - private IgbComboChangeEventArgsDetail _detail; + private IgbComboChangeEventArgsDetail _detail = new IgbComboChangeEventArgsDetail(); /// /// Describes the selection change: the new value, the items it affected and the kind of change. @@ -28,13 +28,12 @@ public IgbComboChangeEventArgsDetail Detail { this.DetachChild(this._detail); } + this._detail = value; if (value != null) { this.AttachChild(value); } - this._detail = value; } - } internal override void SerializeCore(RendererSerializer ser) @@ -47,7 +46,7 @@ internal override void SerializeCore(RendererSerializer ser) } /// - protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) + protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) { base.ToEventJson(control, args); @@ -57,13 +56,13 @@ protected internal override void ToEventJson(BaseRendererControl control, Dictio } /// - protected internal override void FromEventJson(BaseRendererControl control, Dictionary args) + protected internal override void FromEventJson(BaseRendererControl control, Dictionary? args) { base.FromEventJson(control, args); this.SuppressParentNotify = true; - if (args.ContainsKey("detail")) - { this.Detail = (IgbComboChangeEventArgsDetail)ConvertReturnValue(args["detail"], "ComboChangeEventArgsDetail", true); } + if (args != null && args.TryGetValue("detail", out var detailObj) && ConvertReturnValue(detailObj, "ComboChangeEventArgsDetail", true) is IgbComboChangeEventArgsDetail detail) + { this.Detail = detail; } this.SuppressParentNotify = false; } diff --git a/src/components/Blazor/ComboChangeEventArgsDetail.cs b/src/components/Blazor/ComboChangeEventArgsDetail.cs index 36e7940e..af298453 100644 --- a/src/components/Blazor/ComboChangeEventArgsDetail.cs +++ b/src/components/Blazor/ComboChangeEventArgsDetail.cs @@ -9,8 +9,8 @@ public partial class IgbComboChangeEventArgsDetail : BaseRendererElement private static bool _marshalByValue = true; - private string _newValueRef; - private object[] _newValue; + private string? _newValueRef; + private object[] _newValue = Array.Empty(); [Parameter] public object[] NewValue @@ -25,7 +25,7 @@ public object[] NewValue { MarkPropDirty("NewValue"); this._newValue = value; - this.OnRefChanged("NewValue", oldValue, value, false, false, (string refName, object old, object newValue) => + this.OnRefChanged("NewValue", oldValue, value, false, false, (string refName, object? old, object? newValue) => { this._newValueRef = refName; this.MarkPropDirty("NewValueRef"); @@ -34,11 +34,11 @@ public object[] NewValue } } - private string _newValueScript; + private string? _newValueScript; ///Provides a means of setting NewValue in the JavaScript environment. [Parameter] - public string NewValueScript + public string? NewValueScript { get { return _newValueScript; } @@ -49,7 +49,7 @@ public string NewValueScript { this._newValueScript = value; MarkPropDirty("NewValue"); - this.OnRefChanged("NewValue", oldValue, value, true, false, (string refName, object old, object newValue) => + this.OnRefChanged("NewValue", oldValue, value, true, false, (string refName, object? old, object? newValue) => { this._newValueRef = refName; this.MarkPropDirty("NewValueRef"); @@ -57,8 +57,8 @@ public string NewValueScript } } } - private string _itemsRef; - private object[] _items; + private string? _itemsRef; + private object[] _items = Array.Empty(); [Parameter] public object[] Items @@ -73,7 +73,7 @@ public object[] Items { MarkPropDirty("Items"); this._items = value; - this.OnRefChanged("Items", oldValue, value, false, false, (string refName, object old, object newValue) => + this.OnRefChanged("Items", oldValue, value, false, false, (string refName, object? old, object? newValue) => { this._itemsRef = refName; this.MarkPropDirty("ItemsRef"); @@ -82,11 +82,11 @@ public object[] Items } } - private string _itemsScript; + private string? _itemsScript; ///Provides a means of setting Items in the JavaScript environment. [Parameter] - public string ItemsScript + public string? ItemsScript { get { return _itemsScript; } @@ -97,7 +97,7 @@ public string ItemsScript { this._itemsScript = value; MarkPropDirty("Items"); - this.OnRefChanged("Items", oldValue, value, true, false, (string refName, object old, object newValue) => + this.OnRefChanged("Items", oldValue, value, true, false, (string refName, object? old, object? newValue) => { this._itemsRef = refName; this.MarkPropDirty("ItemsRef"); @@ -138,7 +138,7 @@ internal override void SerializeCore(RendererSerializer ser) } /// - protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) + protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) { base.ToEventJson(control, args); @@ -152,16 +152,16 @@ protected internal override void ToEventJson(BaseRendererControl control, Dictio } /// - protected internal override void FromEventJson(BaseRendererControl control, Dictionary args) + protected internal override void FromEventJson(BaseRendererControl control, Dictionary? args) { base.FromEventJson(control, args); this.SuppressParentNotify = true; - if (args.ContainsKey("newValue")) + if (args != null && args.ContainsKey("newValue")) { this.NewValue = ReturnToObjectArray(args["newValue"]); } - if (args.ContainsKey("items")) + if (args != null && args.ContainsKey("items")) { this.Items = ReturnToObjectArray(args["items"]); } - if (args.ContainsKey("type")) + if (args != null && args.ContainsKey("type")) { this.ChangeType = StringToEnum(args["type"]); } this.SuppressParentNotify = false; diff --git a/src/components/Blazor/ComponentBoolValueChangedEventArgs.cs b/src/components/Blazor/ComponentBoolValueChangedEventArgs.cs index 521b93b9..6b60608b 100644 --- a/src/components/Blazor/ComponentBoolValueChangedEventArgs.cs +++ b/src/components/Blazor/ComponentBoolValueChangedEventArgs.cs @@ -43,7 +43,7 @@ internal override void SerializeCore(RendererSerializer ser) } /// - protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) + protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) { base.ToEventJson(control, args); @@ -53,12 +53,12 @@ protected internal override void ToEventJson(BaseRendererControl control, Dictio } /// - protected internal override void FromEventJson(BaseRendererControl control, Dictionary args) + protected internal override void FromEventJson(BaseRendererControl control, Dictionary? args) { base.FromEventJson(control, args); this.SuppressParentNotify = true; - if (args.ContainsKey("detail")) + if (args != null && args.ContainsKey("detail")) { this.Detail = ReturnToBoolean(args["detail"]); } this.SuppressParentNotify = false; diff --git a/src/components/Blazor/ComponentDataValueChangedEventArgs.cs b/src/components/Blazor/ComponentDataValueChangedEventArgs.cs index c323a6a9..9fd240ab 100644 --- a/src/components/Blazor/ComponentDataValueChangedEventArgs.cs +++ b/src/components/Blazor/ComponentDataValueChangedEventArgs.cs @@ -11,7 +11,7 @@ public partial class IgbComponentDataValueChangedEventArgs : BaseRendererElement /// public override string Type { get { return "WebComponentDataValueChangedEventArgs"; } } - private object _detail; + private object _detail = new object(); /// /// The value carried by the event. @@ -41,7 +41,7 @@ internal override void SerializeCore(RendererSerializer ser) } /// - protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) + protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) { base.ToEventJson(control, args); @@ -51,13 +51,13 @@ protected internal override void ToEventJson(BaseRendererControl control, Dictio } /// - protected internal override void FromEventJson(BaseRendererControl control, Dictionary args) + protected internal override void FromEventJson(BaseRendererControl control, Dictionary? args) { base.FromEventJson(control, args); this.SuppressParentNotify = true; - if (args.ContainsKey("detail")) - { this.Detail = ReturnToPrimitive(args["detail"]); } + if (args != null && args.TryGetValue("detail", out var detailObj) && ReturnToPrimitive(detailObj) is object detail) + { this.Detail = detail; } this.SuppressParentNotify = false; } diff --git a/src/components/Blazor/ComponentDateValueChangedEventArgs.cs b/src/components/Blazor/ComponentDateValueChangedEventArgs.cs index 0a0f1543..38db9d70 100644 --- a/src/components/Blazor/ComponentDateValueChangedEventArgs.cs +++ b/src/components/Blazor/ComponentDateValueChangedEventArgs.cs @@ -43,7 +43,7 @@ internal override void SerializeCore(RendererSerializer ser) } /// - protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) + protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) { base.ToEventJson(control, args); @@ -53,12 +53,12 @@ protected internal override void ToEventJson(BaseRendererControl control, Dictio } /// - protected internal override void FromEventJson(BaseRendererControl control, Dictionary args) + protected internal override void FromEventJson(BaseRendererControl control, Dictionary? args) { base.FromEventJson(control, args); this.SuppressParentNotify = true; - if (args.ContainsKey("detail")) + if (args != null && args.ContainsKey("detail")) { this.Detail = ReturnToDate(args["detail"]); } this.SuppressParentNotify = false; diff --git a/src/components/Blazor/ComponentValueChangedEventArgs.cs b/src/components/Blazor/ComponentValueChangedEventArgs.cs index 40e19ac1..d8d83a2e 100644 --- a/src/components/Blazor/ComponentValueChangedEventArgs.cs +++ b/src/components/Blazor/ComponentValueChangedEventArgs.cs @@ -13,13 +13,13 @@ public partial class IgbComponentValueChangedEventArgs : BaseRendererElement private static bool _marshalByValue = true; - private string _detail; + private string? _detail = ""; /// /// The string value carried by the event. /// [Parameter] - public string Detail + public string? Detail { get { return this._detail; } set @@ -43,7 +43,7 @@ internal override void SerializeCore(RendererSerializer ser) } /// - protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) + protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) { base.ToEventJson(control, args); @@ -53,12 +53,12 @@ protected internal override void ToEventJson(BaseRendererControl control, Dictio } /// - protected internal override void FromEventJson(BaseRendererControl control, Dictionary args) + protected internal override void FromEventJson(BaseRendererControl control, Dictionary? args) { base.FromEventJson(control, args); this.SuppressParentNotify = true; - if (args.ContainsKey("detail")) + if (args != null && args.ContainsKey("detail")) { this.Detail = ReturnToString(args["detail"]); } this.SuppressParentNotify = false; diff --git a/src/components/Blazor/CustomDateRange.cs b/src/components/Blazor/CustomDateRange.cs index a7138e7c..f9fbb633 100644 --- a/src/components/Blazor/CustomDateRange.cs +++ b/src/components/Blazor/CustomDateRange.cs @@ -10,13 +10,13 @@ public partial class IgbCustomDateRange : BaseRendererElement /// public override string Type { get { return "WebCustomDateRange"; } } - private string _label; + private string _label = string.Empty; /// /// The text rendered in the chip for this range. /// [Parameter] - public string Label + public required string Label { get { return this._label; } set @@ -29,13 +29,13 @@ public string Label } } - private IgbDateRangeValue _dateRange; + private IgbDateRangeValue _dateRange = new IgbDateRangeValue(); /// /// The date range applied when the chip is selected. /// [Parameter] - public IgbDateRangeValue DateRange + public required IgbDateRangeValue DateRange { get { return this._dateRange; } set @@ -45,11 +45,11 @@ public IgbDateRangeValue DateRange { this.DetachChild(this._dateRange); } + this._dateRange = value; if (value != null) { this.AttachChild(value); } - this._dateRange = value; } } diff --git a/src/components/Blazor/DatePicker.cs b/src/components/Blazor/DatePicker.cs index 449bb996..c1dc60fe 100644 --- a/src/components/Blazor/DatePicker.cs +++ b/src/components/Blazor/DatePicker.cs @@ -35,13 +35,13 @@ protected override bool SupportsVisualChildren } } - private string _label; + private string? _label; /// /// The label of the datepicker. /// [Parameter] - public string Label + public string? Label { get { return this._label; } set @@ -137,7 +137,7 @@ public DateTime? Value /// public async Task GetCurrentValueAsync() { - var iv = await InvokeMethod("p:Value", new object[] { }, new string[] { }); + var iv = await InvokeMethod("p:Value", new object?[] { }, new string[] { }); return ReturnToDate(iv); } @@ -146,7 +146,7 @@ public DateTime? Value /// public DateTime? GetCurrentValue() { - var iv = InvokeMethodSync("p:Value", new object[] { }, new string[] { }); + var iv = InvokeMethodSync("p:Value", new object?[] { }, new string[] { }); return ReturnToDate(iv); } private DateTime _activeDate = DateTime.MinValue; @@ -283,7 +283,7 @@ public bool HideOutsideDays } } - private IgbDateRangeDescriptor[] _disabledDates; + private IgbDateRangeDescriptor[] _disabledDates = Array.Empty(); /// /// Gets/sets disabled dates. @@ -302,7 +302,7 @@ public IgbDateRangeDescriptor[] DisabledDates } } - private IgbDateRangeDescriptor[] _specialDates; + private IgbDateRangeDescriptor[] _specialDates = Array.Empty(); /// /// Gets/sets special dates. @@ -340,13 +340,13 @@ public bool Outlined } } - private string _placeholder; + private string? _placeholder; /// /// The placeholder text of the control. /// [Parameter] - public string Placeholder + public string? Placeholder { get { return this._placeholder; } set @@ -397,14 +397,14 @@ public bool ShowWeekNumbers } } - private string _displayFormat; + private string? _displayFormat; /// /// Format to display the value in when not editing. /// Defaults to the locale format if not set. /// [Parameter] - public string DisplayFormat + public string? DisplayFormat { get { return this._displayFormat; } set @@ -417,14 +417,14 @@ public string DisplayFormat } } - private string _inputFormat; + private string? _inputFormat; /// /// The date format to apply on the input. /// Defaults to the current locale of the client Intl.DateTimeFormat /// [Parameter] - public string InputFormat + public string? InputFormat { get { return this._inputFormat; } set @@ -437,13 +437,13 @@ public string InputFormat } } - private string _prompt; + private string? _prompt; /// /// The prompt symbol to use for unfilled parts of the mask. /// [Parameter] - public string Prompt + public string? Prompt { get { return this._prompt; } set @@ -456,13 +456,13 @@ public string Prompt } } - private string _locale; + private string? _locale; /// /// Gets/Sets the locale used for formatting the display value. /// [Parameter] - public string Locale + public string? Locale { get { return this._locale; } set @@ -475,13 +475,13 @@ public string Locale } } - private IgbCalendarResourceStrings _resourceStrings; + private IgbCalendarResourceStrings? _resourceStrings; /// /// The resource strings for localization. /// [Parameter] - public IgbCalendarResourceStrings ResourceStrings + public IgbCalendarResourceStrings? ResourceStrings { get { return this._resourceStrings; } set @@ -581,7 +581,7 @@ public bool Invalid /// public async Task ClearAsync() { - await InvokeMethod("clear", new object[] { }, new string[] { }); + await InvokeMethod("clear", new object?[] { }, new string[] { }); } /// @@ -589,7 +589,7 @@ public async Task ClearAsync() /// public void Clear() { - InvokeMethodSync("clear", new object[] { }, new string[] { }); + InvokeMethodSync("clear", new object?[] { }, new string[] { }); } /// @@ -597,7 +597,7 @@ public void Clear() /// public async Task StepUpAsync(DatePart? datePart = null, double delta = -1) { - await InvokeMethod("stepUp", new object[] { ObjectToParam(datePart, typeof(DatePart)), delta }, new string[] { "Json", "Number" }); + await InvokeMethod("stepUp", new object?[] { ObjectToParam(datePart, typeof(DatePart)), delta }, new string[] { "Json", "Number" }); } /// @@ -605,7 +605,7 @@ public async Task StepUpAsync(DatePart? datePart = null, double delta = -1) /// public void StepUp(DatePart? datePart = null, double delta = -1) { - InvokeMethodSync("stepUp", new object[] { ObjectToParam(datePart, typeof(DatePart)), delta }, new string[] { "Json", "Number" }); + InvokeMethodSync("stepUp", new object?[] { ObjectToParam(datePart, typeof(DatePart)), delta }, new string[] { "Json", "Number" }); } /// @@ -613,7 +613,7 @@ public void StepUp(DatePart? datePart = null, double delta = -1) /// public async Task StepDownAsync(DatePart? datePart = null, double delta = -1) { - await InvokeMethod("stepDown", new object[] { ObjectToParam(datePart, typeof(DatePart)), delta }, new string[] { "Json", "Number" }); + await InvokeMethod("stepDown", new object?[] { ObjectToParam(datePart, typeof(DatePart)), delta }, new string[] { "Json", "Number" }); } /// @@ -621,14 +621,14 @@ public async Task StepDownAsync(DatePart? datePart = null, double delta = -1) /// public void StepDown(DatePart? datePart = null, double delta = -1) { - InvokeMethodSync("stepDown", new object[] { ObjectToParam(datePart, typeof(DatePart)), delta }, new string[] { "Json", "Number" }); + InvokeMethodSync("stepDown", new object?[] { ObjectToParam(datePart, typeof(DatePart)), delta }, new string[] { "Json", "Number" }); } /// /// Selects the text in the input of the component. /// public async Task SelectAsync() { - await InvokeMethod("select", new object[] { }, new string[] { }); + await InvokeMethod("select", new object?[] { }, new string[] { }); } /// @@ -636,14 +636,14 @@ public async Task SelectAsync() /// public void Select() { - InvokeMethodSync("select", new object[] { }, new string[] { }); + InvokeMethodSync("select", new object?[] { }, new string[] { }); } /// /// Checks for validity of the control and shows the browser message if it's invalid. /// public async Task ReportValidityAsync() { - var iv = await InvokeMethod("reportValidity", new object[] { }, new string[] { }); + var iv = await InvokeMethod("reportValidity", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } @@ -652,7 +652,7 @@ public async Task ReportValidityAsync() /// public bool ReportValidity() { - var iv = InvokeMethodSync("reportValidity", new object[] { }, new string[] { }); + var iv = InvokeMethodSync("reportValidity", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } /// @@ -660,7 +660,7 @@ public bool ReportValidity() /// public async Task CheckValidityAsync() { - var iv = await InvokeMethod("checkValidity", new object[] { }, new string[] { }); + var iv = await InvokeMethod("checkValidity", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } @@ -669,7 +669,7 @@ public async Task CheckValidityAsync() /// public bool CheckValidity() { - var iv = InvokeMethodSync("checkValidity", new object[] { }, new string[] { }); + var iv = InvokeMethodSync("checkValidity", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } /// @@ -678,7 +678,7 @@ public bool CheckValidity() /// public async Task SetCustomValidityAsync(String message) { - await InvokeMethod("setCustomValidity", new object[] { StringToString(message) }, new string[] { "String" }); + await InvokeMethod("setCustomValidity", new object?[] { StringToString(message) }, new string[] { "String" }); } /// @@ -687,7 +687,7 @@ public async Task SetCustomValidityAsync(String message) /// public void SetCustomValidity(String message) { - InvokeMethodSync("setCustomValidity", new object[] { StringToString(message) }, new string[] { "String" }); + InvokeMethodSync("setCustomValidity", new object?[] { StringToString(message) }, new string[] { "String" }); } private EventCallback? _valueChanged = null; @@ -721,8 +721,8 @@ public EventCallback ValueChanged } } - private string _openingRef = null; - private string _openingScript = null; + private string? _openingRef = null; + private string? _openingScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -732,7 +732,7 @@ public EventCallback ValueChanged /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string OpeningScript + public string? OpeningScript { set @@ -740,7 +740,7 @@ public string OpeningScript if (value != this._openingScript) { this._openingScript = value; - this.OnRefChanged("Opening", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Opening", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._openingRef = refName; this.MarkPropDirty("OpeningRef"); @@ -793,8 +793,8 @@ public EventCallback Opening } } - private string _openedRef = null; - private string _openedScript = null; + private string? _openedRef = null; + private string? _openedScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -804,7 +804,7 @@ public EventCallback Opening /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string OpenedScript + public string? OpenedScript { set @@ -812,7 +812,7 @@ public string OpenedScript if (value != this._openedScript) { this._openedScript = value; - this.OnRefChanged("Opened", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Opened", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._openedRef = refName; this.MarkPropDirty("OpenedRef"); @@ -865,8 +865,8 @@ public EventCallback Opened } } - private string _closingRef = null; - private string _closingScript = null; + private string? _closingRef = null; + private string? _closingScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -876,7 +876,7 @@ public EventCallback Opened /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string ClosingScript + public string? ClosingScript { set @@ -884,7 +884,7 @@ public string ClosingScript if (value != this._closingScript) { this._closingScript = value; - this.OnRefChanged("Closing", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Closing", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._closingRef = refName; this.MarkPropDirty("ClosingRef"); @@ -937,8 +937,8 @@ public EventCallback Closing } } - private string _closedRef = null; - private string _closedScript = null; + private string? _closedRef = null; + private string? _closedScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -948,7 +948,7 @@ public EventCallback Closing /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string ClosedScript + public string? ClosedScript { set @@ -956,7 +956,7 @@ public string ClosedScript if (value != this._closedScript) { this._closedScript = value; - this.OnRefChanged("Closed", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Closed", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._closedRef = refName; this.MarkPropDirty("ClosedRef"); @@ -1009,8 +1009,8 @@ public EventCallback Closed } } - private string _changeRef = null; - private string _changeScript = null; + private string? _changeRef = null; + private string? _changeScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -1020,7 +1020,7 @@ public EventCallback Closed /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string ChangeScript + public string? ChangeScript { set @@ -1028,7 +1028,7 @@ public string ChangeScript if (value != this._changeScript) { this._changeScript = value; - this.OnRefChanged("Change", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Change", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._changeRef = refName; this.MarkPropDirty("ChangeRef"); @@ -1116,8 +1116,8 @@ internal void EnsureChangeHandled() } } - private string _inputRef = null; - private string _inputScript = null; + private string? _inputRef = null; + private string? _inputScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -1127,7 +1127,7 @@ internal void EnsureChangeHandled() /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string InputScript + public string? InputScript { set @@ -1135,7 +1135,7 @@ public string InputScript if (value != this._inputScript) { this._inputScript = value; - this.OnRefChanged("Input", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Input", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._inputRef = refName; this.MarkPropDirty("InputRef"); diff --git a/src/components/Blazor/DateRangeDescriptor.cs b/src/components/Blazor/DateRangeDescriptor.cs index 82564a46..1547b9fc 100644 --- a/src/components/Blazor/DateRangeDescriptor.cs +++ b/src/components/Blazor/DateRangeDescriptor.cs @@ -30,7 +30,7 @@ public DateRangeType RangeType } } - private object _dateRange; + private object? _dateRange; /// /// The date or dates the descriptor applies to, interpreted according to . @@ -40,7 +40,7 @@ public DateRangeType RangeType /// and . /// [Parameter] - public object DateRange + public object? DateRange { get { return this._dateRange; } set diff --git a/src/components/Blazor/DateRangePicker.cs b/src/components/Blazor/DateRangePicker.cs index 8e7cf077..c9008ef6 100644 --- a/src/components/Blazor/DateRangePicker.cs +++ b/src/components/Blazor/DateRangePicker.cs @@ -64,13 +64,13 @@ public IgbDateRangeValue? Value /// public async Task GetCurrentValueAsync() { - var iv = await InvokeMethod("p:Value", new object[] { }, new string[] { }); + var iv = await InvokeMethod("p:Value", new object?[] { }, new string[] { }); if (iv == null) { return default(IgbDateRangeValue); } - var retVal = (IgbDateRangeValue)ConvertReturnValue(iv); + var retVal = (IgbDateRangeValue?)ConvertReturnValue(iv); if (retVal == null) { return default(IgbDateRangeValue); @@ -84,13 +84,13 @@ public IgbDateRangeValue? Value /// public IgbDateRangeValue? GetCurrentValue() { - var iv = InvokeMethodSync("p:Value", new object[] { }, new string[] { }); + var iv = InvokeMethodSync("p:Value", new object?[] { }, new string[] { }); if (iv == null) { return default(IgbDateRangeValue); } - var retVal = (IgbDateRangeValue)ConvertReturnValue(iv); + var retVal = (IgbDateRangeValue?)ConvertReturnValue(iv); if (retVal == null) { return default(IgbDateRangeValue); @@ -98,7 +98,7 @@ public IgbDateRangeValue? Value return retVal; } - private IgbCustomDateRange[] _customRanges; + private IgbCustomDateRange[] _customRanges = Array.Empty(); /// /// Renders chips with custom ranges based on the elements of the array. @@ -174,13 +174,13 @@ public bool UsePredefinedRanges } } - private string _locale; + private string? _locale; /// /// The locale settings used to display the value. /// [Parameter] - public string Locale + public string? Locale { get { return this._locale; } set @@ -193,13 +193,13 @@ public string Locale } } - private IgbDateRangePickerResourceStrings _resourceStrings; + private IgbDateRangePickerResourceStrings? _resourceStrings; /// /// The resource strings of the date range picker. /// [Parameter] - public IgbDateRangePickerResourceStrings ResourceStrings + public IgbDateRangePickerResourceStrings? ResourceStrings { get { return this._resourceStrings; } set @@ -275,13 +275,13 @@ public bool Outlined } } - private string _label; + private string? _label; /// /// The label of the control (single input). /// [Parameter] - public string Label + public string? Label { get { return this._label; } set @@ -294,13 +294,13 @@ public string Label } } - private string _labelStart; + private string? _labelStart; /// /// The label of the start input. /// [Parameter] - public string LabelStart + public string? LabelStart { get { return this._labelStart; } set @@ -313,13 +313,13 @@ public string LabelStart } } - private string _labelEnd; + private string? _labelEnd; /// /// The label of the end input. /// [Parameter] - public string LabelEnd + public string? LabelEnd { get { return this._labelEnd; } set @@ -332,13 +332,13 @@ public string LabelEnd } } - private string _placeholder; + private string? _placeholder; /// /// The placeholder text of the control (single input). /// [Parameter] - public string Placeholder + public string? Placeholder { get { return this._placeholder; } set @@ -351,13 +351,13 @@ public string Placeholder } } - private string _placeholderStart; + private string? _placeholderStart; /// /// The placeholder text of the start input. /// [Parameter] - public string PlaceholderStart + public string? PlaceholderStart { get { return this._placeholderStart; } set @@ -370,13 +370,13 @@ public string PlaceholderStart } } - private string _placeholderEnd; + private string? _placeholderEnd; /// /// The placeholder text of the end input. /// [Parameter] - public string PlaceholderEnd + public string? PlaceholderEnd { get { return this._placeholderEnd; } set @@ -389,13 +389,13 @@ public string PlaceholderEnd } } - private string _prompt; + private string? _prompt; /// /// The prompt symbol to use for unfilled parts of the mask. /// [Parameter] - public string Prompt + public string? Prompt { get { return this._prompt; } set @@ -408,14 +408,14 @@ public string Prompt } } - private string _displayFormat; + private string? _displayFormat; /// /// Format to display the value in when not editing. /// Defaults to the locale format if not set. /// [Parameter] - public string DisplayFormat + public string? DisplayFormat { get { return this._displayFormat; } set @@ -428,14 +428,14 @@ public string DisplayFormat } } - private string _inputFormat; + private string? _inputFormat; /// /// The date format to apply on the inputs. /// Defaults to the current locale of the client Intl.DateTimeFormat /// [Parameter] - public string InputFormat + public string? InputFormat { get { return this._inputFormat; } set @@ -486,7 +486,7 @@ public DateTime? Max } } - private IgbDateRangeDescriptor[] _disabledDates; + private IgbDateRangeDescriptor[] _disabledDates = Array.Empty(); /// /// Gets/sets disabled dates. @@ -639,7 +639,7 @@ public bool HideOutsideDays } } - private IgbDateRangeDescriptor[] _specialDates; + private IgbDateRangeDescriptor[] _specialDates = Array.Empty(); /// /// Gets/sets special dates. @@ -740,7 +740,7 @@ public bool Invalid /// public async Task ClearAsync() { - await InvokeMethod("clear", new object[] { }, new string[] { }); + await InvokeMethod("clear", new object?[] { }, new string[] { }); } /// @@ -748,14 +748,14 @@ public async Task ClearAsync() /// public void Clear() { - InvokeMethodSync("clear", new object[] { }, new string[] { }); + InvokeMethodSync("clear", new object?[] { }, new string[] { }); } /// /// Selects a date range value in the picker. /// public async Task SelectAsync(IgbDateRangeValue value) { - await InvokeMethod("select", new object[] { ObjectToParam(value) }, new string[] { "Json" }); + await InvokeMethod("select", new object?[] { ObjectToParam(value) }, new string[] { "Json" }); } /// @@ -763,14 +763,14 @@ public async Task SelectAsync(IgbDateRangeValue value) /// public void Select(IgbDateRangeValue value) { - InvokeMethodSync("select", new object[] { ObjectToParam(value) }, new string[] { "Json" }); + InvokeMethodSync("select", new object?[] { ObjectToParam(value) }, new string[] { "Json" }); } /// /// Checks for validity of the control and shows the browser message if it's invalid. /// public async Task ReportValidityAsync() { - var iv = await InvokeMethod("reportValidity", new object[] { }, new string[] { }); + var iv = await InvokeMethod("reportValidity", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } @@ -779,7 +779,7 @@ public async Task ReportValidityAsync() /// public bool ReportValidity() { - var iv = InvokeMethodSync("reportValidity", new object[] { }, new string[] { }); + var iv = InvokeMethodSync("reportValidity", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } /// @@ -787,7 +787,7 @@ public bool ReportValidity() /// public async Task CheckValidityAsync() { - var iv = await InvokeMethod("checkValidity", new object[] { }, new string[] { }); + var iv = await InvokeMethod("checkValidity", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } @@ -796,7 +796,7 @@ public async Task CheckValidityAsync() /// public bool CheckValidity() { - var iv = InvokeMethodSync("checkValidity", new object[] { }, new string[] { }); + var iv = InvokeMethodSync("checkValidity", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } /// @@ -805,7 +805,7 @@ public bool CheckValidity() /// public async Task SetCustomValidityAsync(String message) { - await InvokeMethod("setCustomValidity", new object[] { StringToString(message) }, new string[] { "String" }); + await InvokeMethod("setCustomValidity", new object?[] { StringToString(message) }, new string[] { "String" }); } /// @@ -814,7 +814,7 @@ public async Task SetCustomValidityAsync(String message) /// public void SetCustomValidity(String message) { - InvokeMethodSync("setCustomValidity", new object[] { StringToString(message) }, new string[] { "String" }); + InvokeMethodSync("setCustomValidity", new object?[] { StringToString(message) }, new string[] { "String" }); } private EventCallback? _valueChanged = null; @@ -848,8 +848,8 @@ public EventCallback ValueChanged } } - private string _openingRef = null; - private string _openingScript = null; + private string? _openingRef = null; + private string? _openingScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -859,7 +859,7 @@ public EventCallback ValueChanged /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string OpeningScript + public string? OpeningScript { set @@ -867,7 +867,7 @@ public string OpeningScript if (value != this._openingScript) { this._openingScript = value; - this.OnRefChanged("Opening", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Opening", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._openingRef = refName; this.MarkPropDirty("OpeningRef"); @@ -920,8 +920,8 @@ public EventCallback Opening } } - private string _openedRef = null; - private string _openedScript = null; + private string? _openedRef = null; + private string? _openedScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -931,7 +931,7 @@ public EventCallback Opening /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string OpenedScript + public string? OpenedScript { set @@ -939,7 +939,7 @@ public string OpenedScript if (value != this._openedScript) { this._openedScript = value; - this.OnRefChanged("Opened", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Opened", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._openedRef = refName; this.MarkPropDirty("OpenedRef"); @@ -992,8 +992,8 @@ public EventCallback Opened } } - private string _closingRef = null; - private string _closingScript = null; + private string? _closingRef = null; + private string? _closingScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -1003,7 +1003,7 @@ public EventCallback Opened /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string ClosingScript + public string? ClosingScript { set @@ -1011,7 +1011,7 @@ public string ClosingScript if (value != this._closingScript) { this._closingScript = value; - this.OnRefChanged("Closing", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Closing", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._closingRef = refName; this.MarkPropDirty("ClosingRef"); @@ -1064,8 +1064,8 @@ public EventCallback Closing } } - private string _closedRef = null; - private string _closedScript = null; + private string? _closedRef = null; + private string? _closedScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -1075,7 +1075,7 @@ public EventCallback Closing /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string ClosedScript + public string? ClosedScript { set @@ -1083,7 +1083,7 @@ public string ClosedScript if (value != this._closedScript) { this._closedScript = value; - this.OnRefChanged("Closed", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Closed", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._closedRef = refName; this.MarkPropDirty("ClosedRef"); @@ -1136,8 +1136,8 @@ public EventCallback Closed } } - private string _changeRef = null; - private string _changeScript = null; + private string? _changeRef = null; + private string? _changeScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -1147,7 +1147,7 @@ public EventCallback Closed /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string ChangeScript + public string? ChangeScript { set @@ -1155,7 +1155,7 @@ public string ChangeScript if (value != this._changeScript) { this._changeScript = value; - this.OnRefChanged("Change", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Change", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._changeRef = refName; this.MarkPropDirty("ChangeRef"); @@ -1248,8 +1248,8 @@ internal void EnsureChangeHandled() } } - private string _inputRef = null; - private string _inputScript = null; + private string? _inputRef = null; + private string? _inputScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -1259,7 +1259,7 @@ internal void EnsureChangeHandled() /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string InputScript + public string? InputScript { set @@ -1267,7 +1267,7 @@ public string InputScript if (value != this._inputScript) { this._inputScript = value; - this.OnRefChanged("Input", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Input", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._inputRef = refName; this.MarkPropDirty("InputRef"); diff --git a/src/components/Blazor/DateRangePickerResourceStrings.cs b/src/components/Blazor/DateRangePickerResourceStrings.cs index 5ba3f419..98de47b4 100644 --- a/src/components/Blazor/DateRangePickerResourceStrings.cs +++ b/src/components/Blazor/DateRangePickerResourceStrings.cs @@ -11,12 +11,12 @@ public partial class IgbDateRangePickerResourceStrings : IgbCalendarResourceStri /// public override string Type { get { return "WebDateRangePickerResourceStrings"; } } - private string _separator; + private string? _separator; /// /// The text shown between the start and end inputs when the date range picker is configured with separate inputs. /// [Parameter] - public string Separator + public string? Separator { get { return this._separator; } set @@ -30,13 +30,13 @@ public string Separator } } - private string _doneButton; + private string? _doneButton; /// /// Text for the button that commits the range selection when the picker is in dialog mode. /// [Parameter] [WCWidgetMemberName("done")] - public string DoneButton + public string? DoneButton { get { return this._doneButton; } set @@ -50,13 +50,13 @@ public string DoneButton } } - private string _cancelButton; + private string? _cancelButton; /// /// Text for the button that cancels the range selection when the picker is in dialog mode. /// [Parameter] [WCWidgetMemberName("cancel")] - public string CancelButton + public string? CancelButton { get { return this._cancelButton; } set @@ -70,12 +70,12 @@ public string CancelButton } } - private string _last7Days; + private string? _last7Days; /// /// Text for the preset range button that selects the last 7 days. /// [Parameter] - public string Last7Days + public string? Last7Days { get { return this._last7Days; } set @@ -89,12 +89,12 @@ public string Last7Days } } - private string _last30Days; + private string? _last30Days; /// /// Text for the preset range button that selects the last 30 days. /// [Parameter] - public string Last30Days + public string? Last30Days { get { return this._last30Days; } set @@ -108,12 +108,12 @@ public string Last30Days } } - private string _currentMonth; + private string? _currentMonth; /// /// Text for the preset range button that selects the current month. /// [Parameter] - public string CurrentMonth + public string? CurrentMonth { get { return this._currentMonth; } set @@ -127,12 +127,12 @@ public string CurrentMonth } } - private string _yearToDate; + private string? _yearToDate; /// /// Text for the preset range button that selects from the start of the current year to today. /// [Parameter] - public string YearToDate + public string? YearToDate { get { return this._yearToDate; } set diff --git a/src/components/Blazor/DateRangeValueDetail.cs b/src/components/Blazor/DateRangeValueDetail.cs index a28c277a..7d5d26b3 100644 --- a/src/components/Blazor/DateRangeValueDetail.cs +++ b/src/components/Blazor/DateRangeValueDetail.cs @@ -65,7 +65,7 @@ internal override void SerializeCore(RendererSerializer ser) } /// - protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) + protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) { base.ToEventJson(control, args); @@ -77,14 +77,14 @@ protected internal override void ToEventJson(BaseRendererControl control, Dictio } /// - protected internal override void FromEventJson(BaseRendererControl control, Dictionary args) + protected internal override void FromEventJson(BaseRendererControl control, Dictionary? args) { base.FromEventJson(control, args); this.SuppressParentNotify = true; - if (args.ContainsKey("start")) + if (args != null && args.ContainsKey("start")) { this.Start = ReturnToDate(args["start"]); } - if (args.ContainsKey("end")) + if (args != null && args.ContainsKey("end")) { this.End = ReturnToDate(args["end"]); } this.SuppressParentNotify = false; diff --git a/src/components/Blazor/DateRangeValueEventArgs.cs b/src/components/Blazor/DateRangeValueEventArgs.cs index 0cd051b2..a929d116 100644 --- a/src/components/Blazor/DateRangeValueEventArgs.cs +++ b/src/components/Blazor/DateRangeValueEventArgs.cs @@ -12,7 +12,7 @@ public partial class IgbDateRangeValueEventArgs : BaseRendererElement private static bool _marshalByValue = true; - private IgbDateRangeValueDetail _detail; + private IgbDateRangeValueDetail _detail = new IgbDateRangeValueDetail(); /// /// The date range carried by the event. @@ -28,11 +28,11 @@ public IgbDateRangeValueDetail Detail { this.DetachChild(this._detail); } + this._detail = value; if (value != null) { this.AttachChild(value); } - this._detail = value; } } @@ -47,7 +47,7 @@ internal override void SerializeCore(RendererSerializer ser) } /// - protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) + protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) { base.ToEventJson(control, args); @@ -57,13 +57,13 @@ protected internal override void ToEventJson(BaseRendererControl control, Dictio } /// - protected internal override void FromEventJson(BaseRendererControl control, Dictionary args) + protected internal override void FromEventJson(BaseRendererControl control, Dictionary? args) { base.FromEventJson(control, args); this.SuppressParentNotify = true; - if (args.ContainsKey("detail")) - { this.Detail = (IgbDateRangeValueDetail)ConvertReturnValue(args["detail"], "DateRangeValueDetail", true); } + if (args != null && args.TryGetValue("detail", out var detailObj) && ConvertReturnValue(detailObj, "DateRangeValueDetail", true) is IgbDateRangeValueDetail detail) + { this.Detail = detail; } this.SuppressParentNotify = false; } diff --git a/src/components/Blazor/DateTimeInput.cs b/src/components/Blazor/DateTimeInput.cs index effafd95..6ccefece 100644 --- a/src/components/Blazor/DateTimeInput.cs +++ b/src/components/Blazor/DateTimeInput.cs @@ -60,7 +60,7 @@ public DateTime? Value /// public async Task GetCurrentValueAsync() { - var iv = await InvokeMethod("p:Value", new object[] { }, new string[] { }); + var iv = await InvokeMethod("p:Value", new object?[] { }, new string[] { }); return ReturnToDate(iv); } @@ -69,7 +69,7 @@ public DateTime? Value /// public DateTime? GetCurrentValue() { - var iv = InvokeMethodSync("p:Value", new object[] { }, new string[] { }); + var iv = InvokeMethodSync("p:Value", new object?[] { }, new string[] { }); return ReturnToDate(iv); } @@ -78,7 +78,7 @@ public DateTime? Value /// public async Task StepUpAsync(DatePart? datePart = null, double delta = -1) { - await InvokeMethod("stepUp", new object[] { ObjectToParam(datePart, typeof(DatePart)), delta }, new string[] { "Json", "Number" }); + await InvokeMethod("stepUp", new object?[] { ObjectToParam(datePart, typeof(DatePart)), delta }, new string[] { "Json", "Number" }); } /// @@ -86,7 +86,7 @@ public async Task StepUpAsync(DatePart? datePart = null, double delta = -1) /// public void StepUp(DatePart? datePart = null, double delta = -1) { - InvokeMethodSync("stepUp", new object[] { ObjectToParam(datePart, typeof(DatePart)), delta }, new string[] { "Json", "Number" }); + InvokeMethodSync("stepUp", new object?[] { ObjectToParam(datePart, typeof(DatePart)), delta }, new string[] { "Json", "Number" }); } /// @@ -94,7 +94,7 @@ public void StepUp(DatePart? datePart = null, double delta = -1) /// public async Task StepDownAsync(DatePart? datePart = null, double delta = -1) { - await InvokeMethod("stepDown", new object[] { ObjectToParam(datePart, typeof(DatePart)), delta }, new string[] { "Json", "Number" }); + await InvokeMethod("stepDown", new object?[] { ObjectToParam(datePart, typeof(DatePart)), delta }, new string[] { "Json", "Number" }); } /// @@ -102,14 +102,14 @@ public async Task StepDownAsync(DatePart? datePart = null, double delta = -1) /// public void StepDown(DatePart? datePart = null, double delta = -1) { - InvokeMethodSync("stepDown", new object[] { ObjectToParam(datePart, typeof(DatePart)), delta }, new string[] { "Json", "Number" }); + InvokeMethodSync("stepDown", new object?[] { ObjectToParam(datePart, typeof(DatePart)), delta }, new string[] { "Json", "Number" }); } /// /// Clears the component of any user input. /// public async Task ClearAsync() { - await InvokeMethod("clear", new object[] { }, new string[] { }); + await InvokeMethod("clear", new object?[] { }, new string[] { }); } /// @@ -117,7 +117,7 @@ public async Task ClearAsync() /// public void Clear() { - InvokeMethodSync("clear", new object[] { }, new string[] { }); + InvokeMethodSync("clear", new object?[] { }, new string[] { }); } private EventCallback? _valueChanged = null; @@ -151,8 +151,8 @@ public EventCallback ValueChanged } } - private string _inputOcurredRef = null; - private string _inputOcurredScript = null; + private string? _inputOcurredRef = null; + private string? _inputOcurredScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -162,7 +162,7 @@ public EventCallback ValueChanged /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string InputOcurredScript + public string? InputOcurredScript { set @@ -170,7 +170,7 @@ public string InputOcurredScript if (value != this._inputOcurredScript) { this._inputOcurredScript = value; - this.OnRefChanged("InputOcurred", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("InputOcurred", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._inputOcurredRef = refName; this.MarkPropDirty("InputOcurredRef"); @@ -223,8 +223,8 @@ public EventCallback InputOcurred } } - private string _changeRef = null; - private string _changeScript = null; + private string? _changeRef = null; + private string? _changeScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -234,7 +234,7 @@ public EventCallback InputOcurred /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string ChangeScript + public string? ChangeScript { set @@ -242,7 +242,7 @@ public string ChangeScript if (value != this._changeScript) { this._changeScript = value; - this.OnRefChanged("Change", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Change", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._changeRef = refName; this.MarkPropDirty("ChangeRef"); @@ -330,8 +330,8 @@ internal void EnsureChangeHandled() } } - private string _focusRef = null; - private string _focusScript = null; + private string? _focusRef = null; + private string? _focusScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -341,7 +341,7 @@ internal void EnsureChangeHandled() /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string FocusScript + public string? FocusScript { set @@ -349,7 +349,7 @@ public string FocusScript if (value != this._focusScript) { this._focusScript = value; - this.OnRefChanged("Focus", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Focus", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._focusRef = refName; this.MarkPropDirty("FocusRef"); @@ -402,8 +402,8 @@ public EventCallback Focus } } - private string _blurRef = null; - private string _blurScript = null; + private string? _blurRef = null; + private string? _blurScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -413,7 +413,7 @@ public EventCallback Focus /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string BlurScript + public string? BlurScript { set @@ -421,7 +421,7 @@ public string BlurScript if (value != this._blurScript) { this._blurScript = value; - this.OnRefChanged("Blur", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Blur", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._blurRef = refName; this.MarkPropDirty("BlurRef"); diff --git a/src/components/Blazor/DateTimeInputBase.cs b/src/components/Blazor/DateTimeInputBase.cs index 23f52958..94de4bc9 100644 --- a/src/components/Blazor/DateTimeInputBase.cs +++ b/src/components/Blazor/DateTimeInputBase.cs @@ -50,13 +50,13 @@ public bool Outlined } } - private string _placeholder; + private string? _placeholder; /// /// The placeholder text of the control. /// [Parameter] - public string Placeholder + public string? Placeholder { get { return this._placeholder; } set @@ -69,13 +69,13 @@ public string Placeholder } } - private string _label; + private string? _label; /// /// The label for the control. /// [Parameter] - public string Label + public string? Label { get { return this._label; } set @@ -88,13 +88,13 @@ public string Label } } - private string _inputFormat; + private string? _inputFormat; /// /// The date format to apply on the input. /// [Parameter] - public string InputFormat + public string? InputFormat { get { return this._inputFormat; } set @@ -145,14 +145,14 @@ public DateTime? Max } } - private string _displayFormat; + private string? _displayFormat; /// /// Format to display the value in when not editing. /// Defaults to the locale format if not set. /// [Parameter] - public string DisplayFormat + public string? DisplayFormat { get { return this._displayFormat; } set @@ -165,14 +165,14 @@ public string DisplayFormat } } - private IgbDatePartDeltas _spinDelta; + private IgbDatePartDeltas? _spinDelta; /// /// Delta values used to increment or decrement each date part on step actions. /// All values default to 1. /// [Parameter] - public IgbDatePartDeltas SpinDelta + public IgbDatePartDeltas? SpinDelta { get { return this._spinDelta; } set @@ -209,13 +209,13 @@ public bool SpinLoop } } - private string _locale; + private string? _locale; /// /// Gets/Sets the locale used for formatting the display value. /// [Parameter] - public string Locale + public string? Locale { get { return this._locale; } set @@ -247,13 +247,13 @@ public bool ReadOnly } } - private string _mask; + private string? _mask; /// /// The mask pattern of the component. /// [Parameter] - public string Mask + public string? Mask { get { return this._mask; } set @@ -266,14 +266,14 @@ public string Mask } } - private string _prompt; + private string? _prompt; /// /// The prompt symbol to use for unfilled parts of the mask pattern. /// Defaults to _. /// [Parameter] - public string Prompt + public string? Prompt { get { return this._prompt; } set @@ -349,7 +349,7 @@ public bool Invalid /// public async Task SelectAsync() { - await InvokeMethod("select", new object[] { }, new string[] { }); + await InvokeMethod("select", new object?[] { }, new string[] { }); } /// @@ -357,7 +357,7 @@ public async Task SelectAsync() /// public void Select() { - InvokeMethodSync("select", new object[] { }, new string[] { }); + InvokeMethodSync("select", new object?[] { }, new string[] { }); } /// /// Sets focus on the control. @@ -366,7 +366,7 @@ public void Select() [WCWidgetMemberName("Focus")] public async Task FocusComponentAsync(IgbFocusOptions options) { - await InvokeMethod("focus", new object[] { ObjectToParam(options) }, new string[] { "Json" }); + await InvokeMethod("focus", new object?[] { ObjectToParam(options) }, new string[] { "Json" }); } /// @@ -375,7 +375,7 @@ public async Task FocusComponentAsync(IgbFocusOptions options) [WCWidgetMemberName("Focus")] public void FocusComponent(IgbFocusOptions options) { - InvokeMethodSync("focus", new object[] { ObjectToParam(options) }, new string[] { "Json" }); + InvokeMethodSync("focus", new object?[] { ObjectToParam(options) }, new string[] { "Json" }); } /// /// Removes focus from the control. @@ -384,7 +384,7 @@ public void FocusComponent(IgbFocusOptions options) [WCWidgetMemberName("Blur")] public async Task BlurComponentAsync() { - await InvokeMethod("blur", new object[] { }, new string[] { }); + await InvokeMethod("blur", new object?[] { }, new string[] { }); } /// @@ -393,14 +393,14 @@ public async Task BlurComponentAsync() [WCWidgetMemberName("Blur")] public void BlurComponent() { - InvokeMethodSync("blur", new object[] { }, new string[] { }); + InvokeMethodSync("blur", new object?[] { }, new string[] { }); } /// /// Clears the component of any user input. /// public async Task ClearAsync() { - await InvokeMethod("clear", new object[] { }, new string[] { }); + await InvokeMethod("clear", new object?[] { }, new string[] { }); } /// @@ -408,66 +408,66 @@ public async Task ClearAsync() /// public void Clear() { - InvokeMethodSync("clear", new object[] { }, new string[] { }); + InvokeMethodSync("clear", new object?[] { }, new string[] { }); } public async Task HasDatePartsAsync() { - var iv = await InvokeMethod("hasDateParts", new object[] { }, new string[] { }); + var iv = await InvokeMethod("hasDateParts", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } public bool HasDateParts() { - var iv = InvokeMethodSync("hasDateParts", new object[] { }, new string[] { }); + var iv = InvokeMethodSync("hasDateParts", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } public async Task HasTimePartsAsync() { - var iv = await InvokeMethod("hasTimeParts", new object[] { }, new string[] { }); + var iv = await InvokeMethod("hasTimeParts", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } public bool HasTimeParts() { - var iv = InvokeMethodSync("hasTimeParts", new object[] { }, new string[] { }); + var iv = InvokeMethodSync("hasTimeParts", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } /// /// Sets the text selection range of the control. /// - public async Task SetSelectionRangeAsync(double start = -1, double end = -1, String direction = null) + public async Task SetSelectionRangeAsync(double start = -1, double end = -1, String? direction = null) { - await InvokeMethod("setSelectionRange", new object[] { start, end, StringToString(direction) }, new string[] { "Number", "Number", "String" }); + await InvokeMethod("setSelectionRange", new object?[] { start, end, StringToString(direction) }, new string[] { "Number", "Number", "String" }); } /// /// Sets the text selection range of the control. /// - public void SetSelectionRange(double start = -1, double end = -1, String direction = null) + public void SetSelectionRange(double start = -1, double end = -1, String? direction = null) { - InvokeMethodSync("setSelectionRange", new object[] { start, end, StringToString(direction) }, new string[] { "Number", "Number", "String" }); + InvokeMethodSync("setSelectionRange", new object?[] { start, end, StringToString(direction) }, new string[] { "Number", "Number", "String" }); } /// /// Replaces the selected text in the control and re-applies the mask. /// - public async Task SetRangeTextAsync(String replacement, double start = -1, double end = -1, String selectMode = null) + public async Task SetRangeTextAsync(String replacement, double start = -1, double end = -1, String? selectMode = null) { - await InvokeMethod("setRangeText", new object[] { StringToString(replacement), start, end, StringToString(selectMode) }, new string[] { "String", "Number", "Number", "String" }); + await InvokeMethod("setRangeText", new object?[] { StringToString(replacement), start, end, StringToString(selectMode) }, new string[] { "String", "Number", "Number", "String" }); } /// /// Replaces the selected text in the control and re-applies the mask. /// - public void SetRangeText(String replacement, double start = -1, double end = -1, String selectMode = null) + public void SetRangeText(String replacement, double start = -1, double end = -1, String? selectMode = null) { - InvokeMethodSync("setRangeText", new object[] { StringToString(replacement), start, end, StringToString(selectMode) }, new string[] { "String", "Number", "Number", "String" }); + InvokeMethodSync("setRangeText", new object?[] { StringToString(replacement), start, end, StringToString(selectMode) }, new string[] { "String", "Number", "Number", "String" }); } /// /// Checks for validity of the control and shows the browser message if it's invalid. /// public async Task ReportValidityAsync() { - var iv = await InvokeMethod("reportValidity", new object[] { }, new string[] { }); + var iv = await InvokeMethod("reportValidity", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } @@ -476,7 +476,7 @@ public async Task ReportValidityAsync() /// public bool ReportValidity() { - var iv = InvokeMethodSync("reportValidity", new object[] { }, new string[] { }); + var iv = InvokeMethodSync("reportValidity", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } /// @@ -484,7 +484,7 @@ public bool ReportValidity() /// public async Task CheckValidityAsync() { - var iv = await InvokeMethod("checkValidity", new object[] { }, new string[] { }); + var iv = await InvokeMethod("checkValidity", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } @@ -493,7 +493,7 @@ public async Task CheckValidityAsync() /// public bool CheckValidity() { - var iv = InvokeMethodSync("checkValidity", new object[] { }, new string[] { }); + var iv = InvokeMethodSync("checkValidity", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } /// @@ -502,7 +502,7 @@ public bool CheckValidity() /// public async Task SetCustomValidityAsync(String message) { - await InvokeMethod("setCustomValidity", new object[] { StringToString(message) }, new string[] { "String" }); + await InvokeMethod("setCustomValidity", new object?[] { StringToString(message) }, new string[] { "String" }); } /// @@ -511,7 +511,7 @@ public async Task SetCustomValidityAsync(String message) /// public void SetCustomValidity(String message) { - InvokeMethodSync("setCustomValidity", new object[] { StringToString(message) }, new string[] { "String" }); + InvokeMethodSync("setCustomValidity", new object?[] { StringToString(message) }, new string[] { "String" }); } internal override void SerializeCore(RendererSerializer ser) diff --git a/src/components/Blazor/Dialog.cs b/src/components/Blazor/Dialog.cs index 44679420..ea0186dc 100644 --- a/src/components/Blazor/Dialog.cs +++ b/src/components/Blazor/Dialog.cs @@ -154,14 +154,14 @@ public bool Open } } - private string _title; + private string? _title; /// /// The title displayed in the dialog header. /// Overridden by any content projected into the title slot. /// [Parameter] - public string Title + public string? Title { get { return this._title; } set @@ -174,7 +174,7 @@ public string Title } } - private string _returnValue; + private string? _returnValue; /// /// The return value of the dialog. @@ -183,7 +183,7 @@ public string Title /// be set programmatically before calling . /// [Parameter] - public string ReturnValue + public string? ReturnValue { get { return this._returnValue; } set @@ -204,7 +204,7 @@ public string ReturnValue /// or if it was already open. public async Task ShowAsync() { - var iv = await InvokeMethod("show", new object[] { }, new string[] { }); + var iv = await InvokeMethod("show", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } @@ -215,7 +215,7 @@ public async Task ShowAsync() /// or if it was already open. public bool Show() { - var iv = InvokeMethodSync("show", new object[] { }, new string[] { }); + var iv = InvokeMethodSync("show", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } /// @@ -225,7 +225,7 @@ public bool Show() /// or if it was already closed. public async Task HideAsync() { - var iv = await InvokeMethod("hide", new object[] { }, new string[] { }); + var iv = await InvokeMethod("hide", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } @@ -236,7 +236,7 @@ public async Task HideAsync() /// or if it was already closed. public bool Hide() { - var iv = InvokeMethodSync("hide", new object[] { }, new string[] { }); + var iv = InvokeMethodSync("hide", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } /// @@ -246,7 +246,7 @@ public bool Hide() /// when the transition completed successfully. public async Task ToggleAsync() { - var iv = await InvokeMethod("toggle", new object[] { }, new string[] { }); + var iv = await InvokeMethod("toggle", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } @@ -257,12 +257,12 @@ public async Task ToggleAsync() /// when the transition completed successfully. public bool Toggle() { - var iv = InvokeMethodSync("toggle", new object[] { }, new string[] { }); + var iv = InvokeMethodSync("toggle", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } - private string _closingRef = null; - private string _closingScript = null; + private string? _closingRef = null; + private string? _closingScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -272,7 +272,7 @@ public bool Toggle() /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string ClosingScript + public string? ClosingScript { set @@ -280,7 +280,7 @@ public string ClosingScript if (value != this._closingScript) { this._closingScript = value; - this.OnRefChanged("Closing", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Closing", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._closingRef = refName; this.MarkPropDirty("ClosingRef"); @@ -333,8 +333,8 @@ public EventCallback Closing } } - private string _closedRef = null; - private string _closedScript = null; + private string? _closedRef = null; + private string? _closedScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -344,7 +344,7 @@ public EventCallback Closing /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string ClosedScript + public string? ClosedScript { set @@ -352,7 +352,7 @@ public string ClosedScript if (value != this._closedScript) { this._closedScript = value; - this.OnRefChanged("Closed", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Closed", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._closedRef = refName; this.MarkPropDirty("ClosedRef"); diff --git a/src/components/Blazor/Dropdown.cs b/src/components/Blazor/Dropdown.cs index 176a7542..342a87b0 100644 --- a/src/components/Blazor/Dropdown.cs +++ b/src/components/Blazor/Dropdown.cs @@ -154,16 +154,11 @@ public bool SameWidth /// public async Task GetItemsAsync() { - var iv = await InvokeMethod("p:Items", new object[] { }, new string[] { }); - - if (iv == null) - { - return default(IgbDropdownItem[]); - } + var iv = await InvokeMethod("p:Items", new object?[] { }, new string[] { }); var retVal = ReturnToObjectArray(iv); if (retVal == null) { - return default(IgbDropdownItem[]); + return Array.Empty(); } return retVal; @@ -174,16 +169,11 @@ public async Task GetItemsAsync() /// public IgbDropdownItem[] GetItems() { - var iv = InvokeMethodSync("p:Items", new object[] { }, new string[] { }); - - if (iv == null) - { - return default(IgbDropdownItem[]); - } + var iv = InvokeMethodSync("p:Items", new object?[] { }, new string[] { }); var retVal = ReturnToObjectArray(iv); if (retVal == null) { - return default(IgbDropdownItem[]); + return Array.Empty(); } return retVal; @@ -194,16 +184,11 @@ public IgbDropdownItem[] GetItems() /// public async Task GetGroupsAsync() { - var iv = await InvokeMethod("p:Groups", new object[] { }, new string[] { }); - - if (iv == null) - { - return default(IgbDropdownGroup[]); - } + var iv = await InvokeMethod("p:Groups", new object?[] { }, new string[] { }); var retVal = ReturnToObjectArray(iv); if (retVal == null) { - return default(IgbDropdownGroup[]); + return Array.Empty(); } return retVal; @@ -214,16 +199,11 @@ public async Task GetGroupsAsync() /// public IgbDropdownGroup[] GetGroups() { - var iv = InvokeMethodSync("p:Groups", new object[] { }, new string[] { }); - - if (iv == null) - { - return default(IgbDropdownGroup[]); - } + var iv = InvokeMethodSync("p:Groups", new object?[] { }, new string[] { }); var retVal = ReturnToObjectArray(iv); if (retVal == null) { - return default(IgbDropdownGroup[]); + return Array.Empty(); } return retVal; @@ -234,13 +214,13 @@ public IgbDropdownGroup[] GetGroups() /// public async Task GetSelectedItemAsync() { - var iv = await InvokeMethod("p:SelectedItem", new object[] { }, new string[] { }); + var iv = await InvokeMethod("p:SelectedItem", new object?[] { }, new string[] { }); if (iv == null) { return default(IgbDropdownItem); } - var retVal = (IgbDropdownItem)ConvertReturnValue(iv); + var retVal = (IgbDropdownItem?)ConvertReturnValue(iv); if (retVal == null) { return default(IgbDropdownItem); @@ -254,13 +234,13 @@ public IgbDropdownGroup[] GetGroups() /// public IgbDropdownItem? GetSelectedItem() { - var iv = InvokeMethodSync("p:SelectedItem", new object[] { }, new string[] { }); + var iv = InvokeMethodSync("p:SelectedItem", new object?[] { }, new string[] { }); if (iv == null) { return default(IgbDropdownItem); } - var retVal = (IgbDropdownItem)ConvertReturnValue(iv); + var retVal = (IgbDropdownItem?)ConvertReturnValue(iv); if (retVal == null) { return default(IgbDropdownItem); @@ -270,7 +250,7 @@ public IgbDropdownGroup[] GetGroups() } /// - public override object FindByName(string name) + public override object? FindByName(string name) { var baseResult = base.FindByName(name); if (baseResult != null) @@ -292,15 +272,15 @@ public override object FindByName(string name) /// Navigates to the item at the specified index. /// /// The found item, or if no such item exists. - public async Task NavigateToAsync(Object index) + public async Task NavigateToAsync(Object index) { - var iv = await InvokeMethod("navigateTo", new object[] { ObjectToParam(index) }, new string[] { "Json" }); + var iv = await InvokeMethod("navigateTo", new object?[] { ObjectToParam(index) }, new string[] { "Json" }); if (iv == null) { return default(IgbDropdownItem); } - var retVal = (IgbDropdownItem)ConvertReturnValue(iv); + var retVal = (IgbDropdownItem?)ConvertReturnValue(iv); if (retVal == null) { return default(IgbDropdownItem); @@ -313,15 +293,15 @@ public async Task NavigateToAsync(Object index) /// Navigates to the item at the specified index. /// /// The found item, or if no such item exists. - public IgbDropdownItem NavigateTo(Object index) + public IgbDropdownItem? NavigateTo(Object index) { - var iv = InvokeMethodSync("navigateTo", new object[] { ObjectToParam(index) }, new string[] { "Json" }); + var iv = InvokeMethodSync("navigateTo", new object?[] { ObjectToParam(index) }, new string[] { "Json" }); if (iv == null) { return default(IgbDropdownItem); } - var retVal = (IgbDropdownItem)ConvertReturnValue(iv); + var retVal = (IgbDropdownItem?)ConvertReturnValue(iv); if (retVal == null) { return default(IgbDropdownItem); @@ -333,15 +313,15 @@ public IgbDropdownItem NavigateTo(Object index) /// Selects the item with the specified value. /// /// The found item, or if no such item exists. - public async Task SelectAsync(Object value) + public async Task SelectAsync(Object value) { - var iv = await InvokeMethod("select", new object[] { ObjectToParam(value) }, new string[] { "Json" }); + var iv = await InvokeMethod("select", new object?[] { ObjectToParam(value) }, new string[] { "Json" }); if (iv == null) { return default(IgbDropdownItem); } - var retVal = (IgbDropdownItem)ConvertReturnValue(iv); + var retVal = (IgbDropdownItem?)ConvertReturnValue(iv); if (retVal == null) { return default(IgbDropdownItem); @@ -354,15 +334,15 @@ public async Task SelectAsync(Object value) /// Selects the item with the specified value. /// /// The found item, or if no such item exists. - public IgbDropdownItem Select(Object value) + public IgbDropdownItem? Select(Object value) { - var iv = InvokeMethodSync("select", new object[] { ObjectToParam(value) }, new string[] { "Json" }); + var iv = InvokeMethodSync("select", new object?[] { ObjectToParam(value) }, new string[] { "Json" }); if (iv == null) { return default(IgbDropdownItem); } - var retVal = (IgbDropdownItem)ConvertReturnValue(iv); + var retVal = (IgbDropdownItem?)ConvertReturnValue(iv); if (retVal == null) { return default(IgbDropdownItem); @@ -372,18 +352,18 @@ public IgbDropdownItem Select(Object value) } public async Task DisconnectedCallbackAsync() { - await InvokeMethod("disconnectedCallback", new object[] { }, new string[] { }); + await InvokeMethod("disconnectedCallback", new object?[] { }, new string[] { }); } public void DisconnectedCallback() { - InvokeMethodSync("disconnectedCallback", new object[] { }, new string[] { }); + InvokeMethodSync("disconnectedCallback", new object?[] { }, new string[] { }); } /// /// Clears the current selection of the dropdown. /// public async Task ClearSelectionAsync() { - await InvokeMethod("clearSelection", new object[] { }, new string[] { }); + await InvokeMethod("clearSelection", new object?[] { }, new string[] { }); } /// @@ -391,11 +371,11 @@ public async Task ClearSelectionAsync() /// public void ClearSelection() { - InvokeMethodSync("clearSelection", new object[] { }, new string[] { }); + InvokeMethodSync("clearSelection", new object?[] { }, new string[] { }); } - private string _openingRef = null; - private string _openingScript = null; + private string? _openingRef = null; + private string? _openingScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -405,7 +385,7 @@ public void ClearSelection() /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string OpeningScript + public string? OpeningScript { set @@ -413,7 +393,7 @@ public string OpeningScript if (value != this._openingScript) { this._openingScript = value; - this.OnRefChanged("Opening", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Opening", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._openingRef = refName; this.MarkPropDirty("OpeningRef"); @@ -466,8 +446,8 @@ public EventCallback Opening } } - private string _openedRef = null; - private string _openedScript = null; + private string? _openedRef = null; + private string? _openedScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -477,7 +457,7 @@ public EventCallback Opening /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string OpenedScript + public string? OpenedScript { set @@ -485,7 +465,7 @@ public string OpenedScript if (value != this._openedScript) { this._openedScript = value; - this.OnRefChanged("Opened", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Opened", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._openedRef = refName; this.MarkPropDirty("OpenedRef"); @@ -538,8 +518,8 @@ public EventCallback Opened } } - private string _closingRef = null; - private string _closingScript = null; + private string? _closingRef = null; + private string? _closingScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -549,7 +529,7 @@ public EventCallback Opened /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string ClosingScript + public string? ClosingScript { set @@ -557,7 +537,7 @@ public string ClosingScript if (value != this._closingScript) { this._closingScript = value; - this.OnRefChanged("Closing", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Closing", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._closingRef = refName; this.MarkPropDirty("ClosingRef"); @@ -610,8 +590,8 @@ public EventCallback Closing } } - private string _closedRef = null; - private string _closedScript = null; + private string? _closedRef = null; + private string? _closedScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -621,7 +601,7 @@ public EventCallback Closing /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string ClosedScript + public string? ClosedScript { set @@ -629,7 +609,7 @@ public string ClosedScript if (value != this._closedScript) { this._closedScript = value; - this.OnRefChanged("Closed", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Closed", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._closedRef = refName; this.MarkPropDirty("ClosedRef"); @@ -682,8 +662,8 @@ public EventCallback Closed } } - private string _changeRef = null; - private string _changeScript = null; + private string? _changeRef = null; + private string? _changeScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -693,7 +673,7 @@ public EventCallback Closed /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string ChangeScript + public string? ChangeScript { set @@ -701,7 +681,7 @@ public string ChangeScript if (value != this._changeScript) { this._changeScript = value; - this.OnRefChanged("Change", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Change", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._changeRef = refName; this.MarkPropDirty("ChangeRef"); diff --git a/src/components/Blazor/DropdownItemComponentEventArgs.cs b/src/components/Blazor/DropdownItemComponentEventArgs.cs index bfe6d754..caa2f94a 100644 --- a/src/components/Blazor/DropdownItemComponentEventArgs.cs +++ b/src/components/Blazor/DropdownItemComponentEventArgs.cs @@ -13,7 +13,7 @@ public partial class IgbDropdownItemComponentEventArgs : BaseRendererElement private static bool _marshalByValue = true; - private IgbDropdownItem _detail; + private IgbDropdownItem _detail = new IgbDropdownItem(); /// /// The dropdown item that became selected. @@ -43,7 +43,7 @@ internal override void SerializeCore(RendererSerializer ser) } /// - protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) + protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) { base.ToEventJson(control, args); @@ -53,13 +53,13 @@ protected internal override void ToEventJson(BaseRendererControl control, Dictio } /// - protected internal override void FromEventJson(BaseRendererControl control, Dictionary args) + protected internal override void FromEventJson(BaseRendererControl control, Dictionary? args) { base.FromEventJson(control, args); this.SuppressParentNotify = true; - if (args.ContainsKey("detail")) - { this.Detail = (IgbDropdownItem)ConvertReturnValue(args["detail"], "DropdownItem", true); } + if (args != null && args.TryGetValue("detail", out var detailObj) && ConvertReturnValue(detailObj, "DropdownItem", true) is IgbDropdownItem detail) + { this.Detail = detail; } this.SuppressParentNotify = false; } diff --git a/src/components/Blazor/ExpansionPanel.cs b/src/components/Blazor/ExpansionPanel.cs index 623ceb13..78dccb54 100644 --- a/src/components/Blazor/ExpansionPanel.cs +++ b/src/components/Blazor/ExpansionPanel.cs @@ -125,7 +125,7 @@ public ExpansionPanelIndicatorPosition IndicatorPosition /// when the open state changed. public async Task ToggleAsync() { - var iv = await InvokeMethod("toggle", new object[] { }, new string[] { }); + var iv = await InvokeMethod("toggle", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } @@ -135,7 +135,7 @@ public async Task ToggleAsync() /// when the open state was successfully changed. public bool Toggle() { - var iv = InvokeMethodSync("toggle", new object[] { }, new string[] { }); + var iv = InvokeMethodSync("toggle", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } /// @@ -145,7 +145,7 @@ public bool Toggle() /// if already closed. public async Task HideAsync() { - var iv = await InvokeMethod("hide", new object[] { }, new string[] { }); + var iv = await InvokeMethod("hide", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } @@ -156,7 +156,7 @@ public async Task HideAsync() /// if already closed. public bool Hide() { - var iv = InvokeMethodSync("hide", new object[] { }, new string[] { }); + var iv = InvokeMethodSync("hide", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } /// @@ -166,7 +166,7 @@ public bool Hide() /// if already open. public async Task ShowAsync() { - var iv = await InvokeMethod("show", new object[] { }, new string[] { }); + var iv = await InvokeMethod("show", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } @@ -177,12 +177,12 @@ public async Task ShowAsync() /// if already open. public bool Show() { - var iv = InvokeMethodSync("show", new object[] { }, new string[] { }); + var iv = InvokeMethodSync("show", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } - private string _openingRef = null; - private string _openingScript = null; + private string? _openingRef = null; + private string? _openingScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -192,7 +192,7 @@ public bool Show() /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string OpeningScript + public string? OpeningScript { set @@ -200,7 +200,7 @@ public string OpeningScript if (value != this._openingScript) { this._openingScript = value; - this.OnRefChanged("Opening", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Opening", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._openingRef = refName; this.MarkPropDirty("OpeningRef"); @@ -253,8 +253,8 @@ public EventCallback Opening } } - private string _openedRef = null; - private string _openedScript = null; + private string? _openedRef = null; + private string? _openedScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -264,7 +264,7 @@ public EventCallback Opening /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string OpenedScript + public string? OpenedScript { set @@ -272,7 +272,7 @@ public string OpenedScript if (value != this._openedScript) { this._openedScript = value; - this.OnRefChanged("Opened", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Opened", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._openedRef = refName; this.MarkPropDirty("OpenedRef"); @@ -325,8 +325,8 @@ public EventCallback Opened } } - private string _closingRef = null; - private string _closingScript = null; + private string? _closingRef = null; + private string? _closingScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -336,7 +336,7 @@ public EventCallback Opened /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string ClosingScript + public string? ClosingScript { set @@ -344,7 +344,7 @@ public string ClosingScript if (value != this._closingScript) { this._closingScript = value; - this.OnRefChanged("Closing", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Closing", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._closingRef = refName; this.MarkPropDirty("ClosingRef"); @@ -397,8 +397,8 @@ public EventCallback Closing } } - private string _closedRef = null; - private string _closedScript = null; + private string? _closedRef = null; + private string? _closedScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -408,7 +408,7 @@ public EventCallback Closing /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string ClosedScript + public string? ClosedScript { set @@ -416,7 +416,7 @@ public string ClosedScript if (value != this._closedScript) { this._closedScript = value; - this.OnRefChanged("Closed", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Closed", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._closedRef = refName; this.MarkPropDirty("ClosedRef"); diff --git a/src/components/Blazor/ExpansionPanelComponentEventArgs.cs b/src/components/Blazor/ExpansionPanelComponentEventArgs.cs index 388d8395..cffa1567 100644 --- a/src/components/Blazor/ExpansionPanelComponentEventArgs.cs +++ b/src/components/Blazor/ExpansionPanelComponentEventArgs.cs @@ -15,7 +15,7 @@ public partial class IgbExpansionPanelComponentEventArgs : BaseRendererElement private static bool _marshalByValue = true; - private IgbExpansionPanel _detail; + private IgbExpansionPanel _detail = new IgbExpansionPanel(); /// /// The expansion panel the event was raised for. @@ -45,7 +45,7 @@ internal override void SerializeCore(RendererSerializer ser) } /// - protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) + protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) { base.ToEventJson(control, args); @@ -55,13 +55,13 @@ protected internal override void ToEventJson(BaseRendererControl control, Dictio } /// - protected internal override void FromEventJson(BaseRendererControl control, Dictionary args) + protected internal override void FromEventJson(BaseRendererControl control, Dictionary? args) { base.FromEventJson(control, args); this.SuppressParentNotify = true; - if (args.ContainsKey("detail")) - { this.Detail = (IgbExpansionPanel)ConvertReturnValue(args["detail"], "ExpansionPanel", true); } + if (args != null && args.TryGetValue("detail", out var detailObj) && ConvertReturnValue(detailObj, "ExpansionPanel", true) is IgbExpansionPanel detail) + { this.Detail = detail; } this.SuppressParentNotify = false; } diff --git a/src/components/Blazor/FilteringOptions.cs b/src/components/Blazor/FilteringOptions.cs index 58c2f35c..e1ed97e2 100644 --- a/src/components/Blazor/FilteringOptions.cs +++ b/src/components/Blazor/FilteringOptions.cs @@ -10,13 +10,13 @@ public partial class IgbFilteringOptions : BaseRendererElement /// public override string Type { get { return "WebFilteringOptions"; } } - private string _filterKey; + private string? _filterKey; /// /// The key in the data source used when filtering the list of options. /// [Parameter] - public string FilterKey + public string? FilterKey { get { return this._filterKey; } set diff --git a/src/components/Blazor/FormatSpecifier.cs b/src/components/Blazor/FormatSpecifier.cs index 945b4dfa..1f7e1137 100644 --- a/src/components/Blazor/FormatSpecifier.cs +++ b/src/components/Blazor/FormatSpecifier.cs @@ -42,14 +42,14 @@ public String GetLocalCulture() } /// - protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) + protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) { base.ToEventJson(control, args); } /// - protected internal override void FromEventJson(BaseRendererControl control, Dictionary args) + protected internal override void FromEventJson(BaseRendererControl control, Dictionary? args) { base.FromEventJson(control, args); this.SuppressParentNotify = true; diff --git a/src/components/Blazor/Highlight.cs b/src/components/Blazor/Highlight.cs index aef03653..90a608cb 100644 --- a/src/components/Blazor/Highlight.cs +++ b/src/components/Blazor/Highlight.cs @@ -82,7 +82,7 @@ public bool CaseSensitive } } - private string _searchText; + private string? _searchText; /// /// The string to search and highlight in the DOM content of the component. @@ -90,7 +90,7 @@ public bool CaseSensitive /// An empty string clears all highlights. /// [Parameter] - public string SearchText + public string? SearchText { get { return this._searchText; } set @@ -112,7 +112,7 @@ public string SearchText /// public async Task GetSizeAsync() { - var iv = await InvokeMethod("p:Size", new object[] { }, new string[] { }); + var iv = await InvokeMethod("p:Size", new object?[] { }, new string[] { }); return ReturnToDouble(iv); } @@ -124,7 +124,7 @@ public async Task GetSizeAsync() /// public double GetSize() { - var iv = InvokeMethodSync("p:Size", new object[] { }, new string[] { }); + var iv = InvokeMethodSync("p:Size", new object?[] { }, new string[] { }); return ReturnToDouble(iv); } @@ -134,7 +134,7 @@ public double GetSize() /// The index of the active match, or 0 when there are no matches. public async Task GetCurrentAsync() { - var iv = await InvokeMethod("p:Current", new object[] { }, new string[] { }); + var iv = await InvokeMethod("p:Current", new object?[] { }, new string[] { }); return ReturnToDouble(iv); } @@ -144,7 +144,7 @@ public async Task GetCurrentAsync() /// The index of the active match, or 0 when there are no matches. public double GetCurrent() { - var iv = InvokeMethodSync("p:Current", new object[] { }, new string[] { }); + var iv = InvokeMethodSync("p:Current", new object?[] { }, new string[] { }); return ReturnToDouble(iv); } @@ -157,7 +157,7 @@ public double GetCurrent() /// public async Task NextAsync(IgbHighlightNavigation options) { - await InvokeMethod("next", new object[] { ObjectToParam(options) }, new string[] { "Json" }); + await InvokeMethod("next", new object?[] { ObjectToParam(options) }, new string[] { "Json" }); } /// @@ -169,7 +169,7 @@ public async Task NextAsync(IgbHighlightNavigation options) /// public void Next(IgbHighlightNavigation options) { - InvokeMethodSync("next", new object[] { ObjectToParam(options) }, new string[] { "Json" }); + InvokeMethodSync("next", new object?[] { ObjectToParam(options) }, new string[] { "Json" }); } /// /// Moves the active highlight to the previous match. @@ -180,7 +180,7 @@ public void Next(IgbHighlightNavigation options) /// public async Task PreviousAsync(IgbHighlightNavigation options) { - await InvokeMethod("previous", new object[] { ObjectToParam(options) }, new string[] { "Json" }); + await InvokeMethod("previous", new object?[] { ObjectToParam(options) }, new string[] { "Json" }); } /// @@ -192,7 +192,7 @@ public async Task PreviousAsync(IgbHighlightNavigation options) /// public void Previous(IgbHighlightNavigation options) { - InvokeMethodSync("previous", new object[] { ObjectToParam(options) }, new string[] { "Json" }); + InvokeMethodSync("previous", new object?[] { ObjectToParam(options) }, new string[] { "Json" }); } /// @@ -204,7 +204,7 @@ public void Previous(IgbHighlightNavigation options) /// public async Task SetActiveAsync(double index, IgbHighlightNavigation options) { - await InvokeMethod("setActive", new object[] { index, ObjectToParam(options) }, new string[] { "Number", "Json" }); + await InvokeMethod("setActive", new object?[] { index, ObjectToParam(options) }, new string[] { "Number", "Json" }); } /// @@ -216,7 +216,7 @@ public async Task SetActiveAsync(double index, IgbHighlightNavigation options) /// public void SetActive(double index, IgbHighlightNavigation options) { - InvokeMethodSync("setActive", new object[] { index, ObjectToParam(options) }, new string[] { "Number", "Json" }); + InvokeMethodSync("setActive", new object?[] { index, ObjectToParam(options) }, new string[] { "Number", "Json" }); } /// /// Re-runs the highlight search based on the current @@ -226,7 +226,7 @@ public void SetActive(double index, IgbHighlightNavigation options) /// public async Task SearchAsync() { - await InvokeMethod("search", new object[] { }, new string[] { }); + await InvokeMethod("search", new object?[] { }, new string[] { }); } /// @@ -237,7 +237,7 @@ public async Task SearchAsync() /// public void Search() { - InvokeMethodSync("search", new object[] { }, new string[] { }); + InvokeMethodSync("search", new object?[] { }, new string[] { }); } internal override void SerializeCore(RendererSerializer ser) diff --git a/src/components/Blazor/HighlightNavigation.cs b/src/components/Blazor/HighlightNavigation.cs index 4967319c..bc1554ae 100644 --- a/src/components/Blazor/HighlightNavigation.cs +++ b/src/components/Blazor/HighlightNavigation.cs @@ -43,7 +43,7 @@ internal override void SerializeCore(RendererSerializer ser) } /// - protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) + protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) { base.ToEventJson(control, args); @@ -53,12 +53,12 @@ protected internal override void ToEventJson(BaseRendererControl control, Dictio } /// - protected internal override void FromEventJson(BaseRendererControl control, Dictionary args) + protected internal override void FromEventJson(BaseRendererControl control, Dictionary? args) { base.FromEventJson(control, args); this.SuppressParentNotify = true; - if (args.ContainsKey("preventScroll")) + if (args != null && args.ContainsKey("preventScroll")) { this.PreventScroll = ReturnToBoolean(args["preventScroll"]); } this.SuppressParentNotify = false; diff --git a/src/components/Blazor/Icon.cs b/src/components/Blazor/Icon.cs index 14e2f8d1..a27f36a0 100644 --- a/src/components/Blazor/Icon.cs +++ b/src/components/Blazor/Icon.cs @@ -58,14 +58,14 @@ protected override ControlEventBehavior DefaultEventBehavior get { return ControlEventBehavior.Immediate; } } - private string _iconName; + private string? _iconName; /// /// The name of the icon glyph to draw. /// [Parameter] [WCWidgetMemberName("Name")] - public string IconName + public string? IconName { get { return this._iconName; } set @@ -78,13 +78,13 @@ public string IconName } } - private string _collection; + private string? _collection; /// /// The name of the registered collection for look up of icons. /// [Parameter] - public string Collection + public string? Collection { get { return this._collection; } set @@ -124,9 +124,9 @@ public bool Mirrored /// The unique name for the icon. /// The URL to fetch the SVG icon from. /// The collection to register the icon in. Defaults to default. - public async Task RegisterIconAsync(String name, String url, String collection = null) + public async Task RegisterIconAsync(String name, String url, String? collection = null) { - await InvokeMethod("registerIcon", new object[] { StringToString(name), StringToString(url), StringToString(collection) }, new string[] { "String", "String", "String" }); + await InvokeMethod("registerIcon", new object?[] { StringToString(name), StringToString(url), StringToString(collection) }, new string[] { "String", "String", "String" }); } /// @@ -135,9 +135,9 @@ public async Task RegisterIconAsync(String name, String url, String collection = /// The unique name for the icon. /// The URL to fetch the SVG icon from. /// The collection to register the icon in. Defaults to default. - public void RegisterIcon(String name, String url, String collection = null) + public void RegisterIcon(String name, String url, String? collection = null) { - InvokeMethodSync("registerIcon", new object[] { StringToString(name), StringToString(url), StringToString(collection) }, new string[] { "String", "String", "String" }); + InvokeMethodSync("registerIcon", new object?[] { StringToString(name), StringToString(url), StringToString(collection) }, new string[] { "String", "String", "String" }); } /// @@ -146,9 +146,9 @@ public void RegisterIcon(String name, String url, String collection = null) /// The unique name for the icon. /// The SVG markup as a string. /// The collection to register the icon in. Defaults to default. - public async Task RegisterIconFromTextAsync(String name, String iconText, String collection = null) + public async Task RegisterIconFromTextAsync(String name, String iconText, String? collection = null) { - await InvokeMethod("registerIconFromText", new object[] { StringToString(name), StringToString(iconText), StringToString(collection) }, new string[] { "String", "String", "String" }); + await InvokeMethod("registerIconFromText", new object?[] { StringToString(name), StringToString(iconText), StringToString(collection) }, new string[] { "String", "String", "String" }); } /// @@ -157,9 +157,9 @@ public async Task RegisterIconFromTextAsync(String name, String iconText, String /// The unique name for the icon. /// The SVG markup as a string. /// The collection to register the icon in. Defaults to default. - public void RegisterIconFromText(String name, String iconText, String collection = null) + public void RegisterIconFromText(String name, String iconText, String? collection = null) { - InvokeMethodSync("registerIconFromText", new object[] { StringToString(name), StringToString(iconText), StringToString(collection) }, new string[] { "String", "String", "String" }); + InvokeMethodSync("registerIconFromText", new object?[] { StringToString(name), StringToString(iconText), StringToString(collection) }, new string[] { "String", "String", "String" }); } /// @@ -170,7 +170,7 @@ public void RegisterIconFromText(String name, String iconText, String collection /// The target icon metadata (name and collection). public async Task SetIconRefAsync(String name, String collection, IgbIconMeta icon) { - await InvokeMethod("setIconRef", new object[] { StringToString(name), StringToString(collection), ObjectToParam(icon) }, new string[] { "String", "String", "Json" }); + await InvokeMethod("setIconRef", new object?[] { StringToString(name), StringToString(collection), ObjectToParam(icon) }, new string[] { "String", "String", "Json" }); } /// @@ -181,7 +181,7 @@ public async Task SetIconRefAsync(String name, String collection, IgbIconMeta ic /// The target icon metadata (name and collection). public void SetIconRef(String name, String collection, IgbIconMeta icon) { - InvokeMethodSync("setIconRef", new object[] { StringToString(name), StringToString(collection), ObjectToParam(icon) }, new string[] { "String", "String", "Json" }); + InvokeMethodSync("setIconRef", new object?[] { StringToString(name), StringToString(collection), ObjectToParam(icon) }, new string[] { "String", "String", "Json" }); } internal override void SerializeCore(RendererSerializer ser) diff --git a/src/components/Blazor/IconButton.cs b/src/components/Blazor/IconButton.cs index 682635bc..cec7d6f5 100644 --- a/src/components/Blazor/IconButton.cs +++ b/src/components/Blazor/IconButton.cs @@ -57,14 +57,14 @@ protected override string DirectRenderElementName } } - private string _iconName; + private string? _iconName; /// /// The name of the icon to display. /// [Parameter] [WCWidgetMemberName("Name")] - public string IconName + public string? IconName { get { return this._iconName; } set @@ -77,13 +77,13 @@ public string IconName } } - private string _collection; + private string? _collection; /// /// The collection the icon belongs to. /// [Parameter] - public string Collection + public string? Collection { get { return this._collection; } set @@ -149,9 +149,9 @@ public IconButtonVariant Variant /// The unique name for the icon. /// The URL to fetch the SVG icon from. /// The collection to register the icon in. Defaults to default. - public async Task RegisterIconAsync(String name, String url, String collection = null) + public async Task RegisterIconAsync(String name, String url, String? collection = null) { - await InvokeMethod("registerIcon", new object[] { StringToString(name), StringToString(url), StringToString(collection) }, new string[] { "String", "String", "String" }); + await InvokeMethod("registerIcon", new object?[] { StringToString(name), StringToString(url), StringToString(collection) }, new string[] { "String", "String", "String" }); } /// @@ -160,9 +160,9 @@ public async Task RegisterIconAsync(String name, String url, String collection = /// The unique name for the icon. /// The URL to fetch the SVG icon from. /// The collection to register the icon in. Defaults to default. - public void RegisterIcon(String name, String url, String collection = null) + public void RegisterIcon(String name, String url, String? collection = null) { - InvokeMethodSync("registerIcon", new object[] { StringToString(name), StringToString(url), StringToString(collection) }, new string[] { "String", "String", "String" }); + InvokeMethodSync("registerIcon", new object?[] { StringToString(name), StringToString(url), StringToString(collection) }, new string[] { "String", "String", "String" }); } /// @@ -171,9 +171,9 @@ public void RegisterIcon(String name, String url, String collection = null) /// The unique name for the icon. /// The SVG markup as a string. /// The collection to register the icon in. Defaults to default. - public async Task RegisterIconFromTextAsync(String name, String iconText, String collection = null) + public async Task RegisterIconFromTextAsync(String name, String iconText, String? collection = null) { - await InvokeMethod("registerIconFromText", new object[] { StringToString(name), StringToString(iconText), StringToString(collection) }, new string[] { "String", "String", "String" }); + await InvokeMethod("registerIconFromText", new object?[] { StringToString(name), StringToString(iconText), StringToString(collection) }, new string[] { "String", "String", "String" }); } /// @@ -182,9 +182,9 @@ public async Task RegisterIconFromTextAsync(String name, String iconText, String /// The unique name for the icon. /// The SVG markup as a string. /// The collection to register the icon in. Defaults to default. - public void RegisterIconFromText(String name, String iconText, String collection = null) + public void RegisterIconFromText(String name, String iconText, String? collection = null) { - InvokeMethodSync("registerIconFromText", new object[] { StringToString(name), StringToString(iconText), StringToString(collection) }, new string[] { "String", "String", "String" }); + InvokeMethodSync("registerIconFromText", new object?[] { StringToString(name), StringToString(iconText), StringToString(collection) }, new string[] { "String", "String", "String" }); } internal override void SerializeCore(RendererSerializer ser) diff --git a/src/components/Blazor/IconMeta.cs b/src/components/Blazor/IconMeta.cs index 2b839ecb..5de29349 100644 --- a/src/components/Blazor/IconMeta.cs +++ b/src/components/Blazor/IconMeta.cs @@ -12,7 +12,7 @@ public partial class IgbIconMeta : BaseRendererElement private static bool _marshalByValue = true; - private string _collection; + private string _collection = string.Empty; /// /// The name of the collection the icon is registered in. @@ -42,7 +42,7 @@ internal override void SerializeCore(RendererSerializer ser) } /// - protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) + protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) { base.ToEventJson(control, args); @@ -54,14 +54,14 @@ protected internal override void ToEventJson(BaseRendererControl control, Dictio } /// - protected internal override void FromEventJson(BaseRendererControl control, Dictionary args) + protected internal override void FromEventJson(BaseRendererControl control, Dictionary? args) { base.FromEventJson(control, args); this.SuppressParentNotify = true; - if (args.ContainsKey("name")) + if (args != null && args.ContainsKey("name")) { this.Name = ReturnToString(args["name"]); } - if (args.ContainsKey("collection")) + if (args != null && args.ContainsKey("collection")) { this.Collection = ReturnToString(args["collection"]); } this.SuppressParentNotify = false; diff --git a/src/components/Blazor/Input.cs b/src/components/Blazor/Input.cs index da529be0..9ca412e2 100644 --- a/src/components/Blazor/Input.cs +++ b/src/components/Blazor/Input.cs @@ -53,13 +53,13 @@ protected override string DirectRenderElementName } } - private string _value; + private string? _value; /// /// The value of the control. /// [Parameter] - public string Value + public string? Value { get { return this._value; } set @@ -78,7 +78,7 @@ public string Value /// public async Task GetCurrentValueAsync() { - var iv = await InvokeMethod("p:Value", new object[] { }, new string[] { }); + var iv = await InvokeMethod("p:Value", new object?[] { }, new string[] { }); return ReturnToString(iv); } @@ -87,7 +87,7 @@ public async Task GetCurrentValueAsync() /// public string GetCurrentValue() { - var iv = InvokeMethodSync("p:Value", new object[] { }, new string[] { }); + var iv = InvokeMethodSync("p:Value", new object?[] { }, new string[] { }); return ReturnToString(iv); } private InputType _displayType = InputType.Text; @@ -130,7 +130,7 @@ public bool ReadOnly } } - private string _inputMode; + private string? _inputMode; /// /// The input mode attribute of the control. @@ -139,7 +139,7 @@ public bool ReadOnly /// [Parameter] [WCAttributeName("inputmode")] - public string InputMode + public string? InputMode { get { return this._inputMode; } set @@ -230,7 +230,7 @@ public double? Min } } - private double? _max = 0; + private double? _max = null; /// /// The max attribute of the control. @@ -287,13 +287,13 @@ public bool Autofocus } } - private string _autocomplete; + private string? _autocomplete; /// /// The autocomplete attribute of the control. /// [Parameter] - public string Autocomplete + public string? Autocomplete { get { return this._autocomplete; } set @@ -333,7 +333,7 @@ public bool ValidateOnly /// public async Task StepUpAsync(double n = -1) { - await InvokeMethod("stepUp", new object[] { n }, new string[] { "Number" }); + await InvokeMethod("stepUp", new object?[] { n }, new string[] { "Number" }); } /// @@ -341,14 +341,14 @@ public async Task StepUpAsync(double n = -1) /// public void StepUp(double n = -1) { - InvokeMethodSync("stepUp", new object[] { n }, new string[] { "Number" }); + InvokeMethodSync("stepUp", new object?[] { n }, new string[] { "Number" }); } /// /// Decrements the numeric value of the input by one or more steps. /// public async Task StepDownAsync(double n = -1) { - await InvokeMethod("stepDown", new object[] { n }, new string[] { "Number" }); + await InvokeMethod("stepDown", new object?[] { n }, new string[] { "Number" }); } /// @@ -356,7 +356,7 @@ public async Task StepDownAsync(double n = -1) /// public void StepDown(double n = -1) { - InvokeMethodSync("stepDown", new object[] { n }, new string[] { "Number" }); + InvokeMethodSync("stepDown", new object?[] { n }, new string[] { "Number" }); } private EventCallback? _valueChanged = null; @@ -390,8 +390,8 @@ public EventCallback ValueChanged } } - private string _changeRef = null; - private string _changeScript = null; + private string? _changeRef = null; + private string? _changeScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -401,7 +401,7 @@ public EventCallback ValueChanged /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string ChangeScript + public string? ChangeScript { set @@ -409,7 +409,7 @@ public string ChangeScript if (value != this._changeScript) { this._changeScript = value; - this.OnRefChanged("Change", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Change", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._changeRef = refName; this.MarkPropDirty("ChangeRef"); @@ -446,7 +446,7 @@ public EventCallback Change var newValueValue = default(string); { - newValueValue = (string)(args.Detail); + newValueValue = (string)(args.Detail ?? string.Empty); if (UseDirectRender) { //TODO: maybe we should be doing this for everything. Need to make sure we don't infinity bounce though. diff --git a/src/components/Blazor/InputBase.cs b/src/components/Blazor/InputBase.cs index 7e7ac9d8..a85967e9 100644 --- a/src/components/Blazor/InputBase.cs +++ b/src/components/Blazor/InputBase.cs @@ -47,13 +47,13 @@ public bool Outlined } } - private string _placeholder; + private string? _placeholder; /// /// The placeholder text of the control. /// [Parameter] - public string Placeholder + public string? Placeholder { get { return this._placeholder; } set @@ -66,13 +66,13 @@ public string Placeholder } } - private string _label; + private string? _label; /// /// The label for the control. /// [Parameter] - public string Label + public string? Label { get { return this._label; } set @@ -148,7 +148,7 @@ public bool Invalid /// public async Task SelectAsync() { - await InvokeMethod("select", new object[] { }, new string[] { }); + await InvokeMethod("select", new object?[] { }, new string[] { }); } /// @@ -156,7 +156,7 @@ public async Task SelectAsync() /// public void Select() { - InvokeMethodSync("select", new object[] { }, new string[] { }); + InvokeMethodSync("select", new object?[] { }, new string[] { }); } /// /// Sets focus on the control. @@ -165,7 +165,7 @@ public void Select() [WCWidgetMemberName("Focus")] public async Task FocusComponentAsync(IgbFocusOptions options) { - await InvokeMethod("focus", new object[] { ObjectToParam(options) }, new string[] { "Json" }); + await InvokeMethod("focus", new object?[] { ObjectToParam(options) }, new string[] { "Json" }); } /// @@ -174,7 +174,7 @@ public async Task FocusComponentAsync(IgbFocusOptions options) [WCWidgetMemberName("Focus")] public void FocusComponent(IgbFocusOptions options) { - InvokeMethodSync("focus", new object[] { ObjectToParam(options) }, new string[] { "Json" }); + InvokeMethodSync("focus", new object?[] { ObjectToParam(options) }, new string[] { "Json" }); } /// /// Removes focus from the control. @@ -183,7 +183,7 @@ public void FocusComponent(IgbFocusOptions options) [WCWidgetMemberName("Blur")] public async Task BlurComponentAsync() { - await InvokeMethod("blur", new object[] { }, new string[] { }); + await InvokeMethod("blur", new object?[] { }, new string[] { }); } /// @@ -192,14 +192,14 @@ public async Task BlurComponentAsync() [WCWidgetMemberName("Blur")] public void BlurComponent() { - InvokeMethodSync("blur", new object[] { }, new string[] { }); + InvokeMethodSync("blur", new object?[] { }, new string[] { }); } /// /// Checks for validity of the control and shows the browser message if it's invalid. /// public async Task ReportValidityAsync() { - var iv = await InvokeMethod("reportValidity", new object[] { }, new string[] { }); + var iv = await InvokeMethod("reportValidity", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } @@ -208,7 +208,7 @@ public async Task ReportValidityAsync() /// public bool ReportValidity() { - var iv = InvokeMethodSync("reportValidity", new object[] { }, new string[] { }); + var iv = InvokeMethodSync("reportValidity", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } /// @@ -216,7 +216,7 @@ public bool ReportValidity() /// public async Task CheckValidityAsync() { - var iv = await InvokeMethod("checkValidity", new object[] { }, new string[] { }); + var iv = await InvokeMethod("checkValidity", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } @@ -225,7 +225,7 @@ public async Task CheckValidityAsync() /// public bool CheckValidity() { - var iv = InvokeMethodSync("checkValidity", new object[] { }, new string[] { }); + var iv = InvokeMethodSync("checkValidity", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } /// @@ -234,7 +234,7 @@ public bool CheckValidity() /// public async Task SetCustomValidityAsync(String message) { - await InvokeMethod("setCustomValidity", new object[] { StringToString(message) }, new string[] { "String" }); + await InvokeMethod("setCustomValidity", new object?[] { StringToString(message) }, new string[] { "String" }); } /// @@ -243,11 +243,11 @@ public async Task SetCustomValidityAsync(String message) /// public void SetCustomValidity(String message) { - InvokeMethodSync("setCustomValidity", new object[] { StringToString(message) }, new string[] { "String" }); + InvokeMethodSync("setCustomValidity", new object?[] { StringToString(message) }, new string[] { "String" }); } - private string _inputOcurredRef = null; - private string _inputOcurredScript = null; + private string? _inputOcurredRef = null; + private string? _inputOcurredScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -257,7 +257,7 @@ public void SetCustomValidity(String message) /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string InputOcurredScript + public string? InputOcurredScript { set @@ -265,7 +265,7 @@ public string InputOcurredScript if (value != this._inputOcurredScript) { this._inputOcurredScript = value; - this.OnRefChanged("InputOcurred", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("InputOcurred", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._inputOcurredRef = refName; this.MarkPropDirty("InputOcurredRef"); @@ -321,8 +321,8 @@ public EventCallback InputOcurred } } - private string _focusRef = null; - private string _focusScript = null; + private string? _focusRef = null; + private string? _focusScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -332,7 +332,7 @@ public EventCallback InputOcurred /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string FocusScript + public string? FocusScript { set @@ -340,7 +340,7 @@ public string FocusScript if (value != this._focusScript) { this._focusScript = value; - this.OnRefChanged("Focus", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Focus", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._focusRef = refName; this.MarkPropDirty("FocusRef"); @@ -393,8 +393,8 @@ public EventCallback Focus } } - private string _blurRef = null; - private string _blurScript = null; + private string? _blurRef = null; + private string? _blurScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -404,7 +404,7 @@ public EventCallback Focus /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string BlurScript + public string? BlurScript { set @@ -412,7 +412,7 @@ public string BlurScript if (value != this._blurScript) { this._blurScript = value; - this.OnRefChanged("Blur", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Blur", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._blurRef = refName; this.MarkPropDirty("BlurRef"); diff --git a/src/components/Blazor/MaskInput.cs b/src/components/Blazor/MaskInput.cs index 4f6d2f93..2e2efb2e 100644 --- a/src/components/Blazor/MaskInput.cs +++ b/src/components/Blazor/MaskInput.cs @@ -64,7 +64,7 @@ public MaskInputValueMode ValueMode } } - private string _value; + private string _value = string.Empty; /// /// The value of the input. @@ -91,7 +91,7 @@ public string Value /// public async Task GetCurrentValueAsync() { - var iv = await InvokeMethod("p:Value", new object[] { }, new string[] { }); + var iv = await InvokeMethod("p:Value", new object?[] { }, new string[] { }); return ReturnToString(iv); } @@ -101,10 +101,10 @@ public async Task GetCurrentValueAsync() /// public string GetCurrentValue() { - var iv = InvokeMethodSync("p:Value", new object[] { }, new string[] { }); + var iv = InvokeMethodSync("p:Value", new object?[] { }, new string[] { }); return ReturnToString(iv); } - private string _mask; + private string _mask = "CCCCCCCCCC"; /// /// The masked pattern of the component. @@ -123,7 +123,7 @@ public string Mask } } - private string _prompt; + private string _prompt = "_"; /// /// The prompt symbol to use for unfilled parts of the mask pattern. @@ -165,33 +165,33 @@ public bool ReadOnly /// /// Sets the text selection range of the control. /// - public async Task SetSelectionRangeAsync(double start = -1, double end = -1, String direction = null) + public async Task SetSelectionRangeAsync(double start = -1, double end = -1, String? direction = null) { - await InvokeMethod("setSelectionRange", new object[] { start, end, StringToString(direction) }, new string[] { "Number", "Number", "String" }); + await InvokeMethod("setSelectionRange", new object?[] { start, end, StringToString(direction) }, new string[] { "Number", "Number", "String" }); } /// /// Sets the text selection range of the control. /// - public void SetSelectionRange(double start = -1, double end = -1, String direction = null) + public void SetSelectionRange(double start = -1, double end = -1, String? direction = null) { - InvokeMethodSync("setSelectionRange", new object[] { start, end, StringToString(direction) }, new string[] { "Number", "Number", "String" }); + InvokeMethodSync("setSelectionRange", new object?[] { start, end, StringToString(direction) }, new string[] { "Number", "Number", "String" }); } /// /// Replaces the selected text in the control and re-applies the mask. /// - public async Task SetRangeTextAsync(String replacement, double start = -1, double end = -1, String selectMode = null) + public async Task SetRangeTextAsync(String replacement, double start = -1, double end = -1, String? selectMode = null) { - await InvokeMethod("setRangeText", new object[] { StringToString(replacement), start, end, StringToString(selectMode) }, new string[] { "String", "Number", "Number", "String" }); + await InvokeMethod("setRangeText", new object?[] { StringToString(replacement), start, end, StringToString(selectMode) }, new string[] { "String", "Number", "Number", "String" }); } /// /// Replaces the selected text in the control and re-applies the mask. /// - public void SetRangeText(String replacement, double start = -1, double end = -1, String selectMode = null) + public void SetRangeText(String replacement, double start = -1, double end = -1, String? selectMode = null) { - InvokeMethodSync("setRangeText", new object[] { StringToString(replacement), start, end, StringToString(selectMode) }, new string[] { "String", "Number", "Number", "String" }); + InvokeMethodSync("setRangeText", new object?[] { StringToString(replacement), start, end, StringToString(selectMode) }, new string[] { "String", "Number", "Number", "String" }); } private EventCallback? _valueChanged = null; @@ -225,8 +225,8 @@ public EventCallback ValueChanged } } - private string _changeRef = null; - private string _changeScript = null; + private string? _changeRef = null; + private string? _changeScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -236,7 +236,7 @@ public EventCallback ValueChanged /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string ChangeScript + public string? ChangeScript { set @@ -244,7 +244,7 @@ public string ChangeScript if (value != this._changeScript) { this._changeScript = value; - this.OnRefChanged("Change", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Change", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._changeRef = refName; this.MarkPropDirty("ChangeRef"); @@ -281,7 +281,7 @@ public EventCallback Change var newValueValue = default(string); { - newValueValue = (string)(args.Detail); + newValueValue = (string)(args.Detail ?? string.Empty); if (UseDirectRender) { //TODO: maybe we should be doing this for everything. Need to make sure we don't infinity bounce though. diff --git a/src/components/Blazor/NavDrawer.cs b/src/components/Blazor/NavDrawer.cs index 30b1db16..52ff3520 100644 --- a/src/components/Blazor/NavDrawer.cs +++ b/src/components/Blazor/NavDrawer.cs @@ -149,7 +149,7 @@ public bool KeepOpenOnEscape } } - private string _label; + private string? _label; /// /// Sets an accessible label for the drawer. @@ -159,7 +159,7 @@ public bool KeepOpenOnEscape /// distinct label so screen-reader users can differentiate between them. /// [Parameter] - public string Label + public string? Label { get { return this._label; } set @@ -182,7 +182,7 @@ public string Label /// public async Task ShowAsync() { - var iv = await InvokeMethod("show", new object[] { }, new string[] { }); + var iv = await InvokeMethod("show", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } @@ -195,7 +195,7 @@ public async Task ShowAsync() /// public bool Show() { - var iv = InvokeMethodSync("show", new object[] { }, new string[] { }); + var iv = InvokeMethodSync("show", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } /// @@ -207,7 +207,7 @@ public bool Show() /// public async Task HideAsync() { - var iv = await InvokeMethod("hide", new object[] { }, new string[] { }); + var iv = await InvokeMethod("hide", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } @@ -220,7 +220,7 @@ public async Task HideAsync() /// public bool Hide() { - var iv = InvokeMethodSync("hide", new object[] { }, new string[] { }); + var iv = InvokeMethodSync("hide", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } /// @@ -229,7 +229,7 @@ public bool Hide() /// public async Task ToggleAsync() { - var iv = await InvokeMethod("toggle", new object[] { }, new string[] { }); + var iv = await InvokeMethod("toggle", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } @@ -239,12 +239,12 @@ public async Task ToggleAsync() /// public bool Toggle() { - var iv = InvokeMethodSync("toggle", new object[] { }, new string[] { }); + var iv = InvokeMethodSync("toggle", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } - private string _closingRef = null; - private string _closingScript = null; + private string? _closingRef = null; + private string? _closingScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -254,7 +254,7 @@ public bool Toggle() /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string ClosingScript + public string? ClosingScript { set @@ -262,7 +262,7 @@ public string ClosingScript if (value != this._closingScript) { this._closingScript = value; - this.OnRefChanged("Closing", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Closing", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._closingRef = refName; this.MarkPropDirty("ClosingRef"); @@ -315,8 +315,8 @@ public EventCallback Closing } } - private string _closedRef = null; - private string _closedScript = null; + private string? _closedRef = null; + private string? _closedScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -326,7 +326,7 @@ public EventCallback Closing /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string ClosedScript + public string? ClosedScript { set @@ -334,7 +334,7 @@ public string ClosedScript if (value != this._closedScript) { this._closedScript = value; - this.OnRefChanged("Closed", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Closed", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._closedRef = refName; this.MarkPropDirty("ClosedRef"); diff --git a/src/components/Blazor/NumberEventArgs.cs b/src/components/Blazor/NumberEventArgs.cs index ed1c22fe..0c6491f2 100644 --- a/src/components/Blazor/NumberEventArgs.cs +++ b/src/components/Blazor/NumberEventArgs.cs @@ -43,7 +43,7 @@ internal override void SerializeCore(RendererSerializer ser) } /// - protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) + protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) { base.ToEventJson(control, args); @@ -53,12 +53,12 @@ protected internal override void ToEventJson(BaseRendererControl control, Dictio } /// - protected internal override void FromEventJson(BaseRendererControl control, Dictionary args) + protected internal override void FromEventJson(BaseRendererControl control, Dictionary? args) { base.FromEventJson(control, args); this.SuppressParentNotify = true; - if (args.ContainsKey("detail")) + if (args != null && args.ContainsKey("detail")) { this.Detail = ReturnToDouble(args["detail"]); } this.SuppressParentNotify = false; diff --git a/src/components/Blazor/NumberFormatSpecifier.cs b/src/components/Blazor/NumberFormatSpecifier.cs index 67cb6b1d..154d48f9 100644 --- a/src/components/Blazor/NumberFormatSpecifier.cs +++ b/src/components/Blazor/NumberFormatSpecifier.cs @@ -22,14 +22,14 @@ protected override void EnsureModulesLoaded() private static bool _marshalByValue = true; - private string _locale; + private string? _locale; /// /// The culture used to format the number. When not set, the browser culture returned by /// is used. /// [Parameter] - public string Locale + public string? Locale { get { return this._locale; } set @@ -42,14 +42,14 @@ public string Locale } } - private string _compactDisplay; + private string? _compactDisplay; /// /// The form of the compact notation, either short or long. Applies only when /// is compact. /// [Parameter] - public string CompactDisplay + public string? CompactDisplay { get { return this._compactDisplay; } set @@ -62,13 +62,13 @@ public string CompactDisplay } } - private string _currency; + private string? _currency; /// /// The currency used in currency formatting, given as an ISO 4217 currency code. /// [Parameter] - public string Currency + public string? Currency { get { return this._currency; } set @@ -81,14 +81,14 @@ public string Currency } } - private string _currencyDisplay; + private string? _currencyDisplay; /// /// How the currency is shown, one of symbol, narrowSymbol, code or /// name. /// [Parameter] - public string CurrencyDisplay + public string? CurrencyDisplay { get { return this._currencyDisplay; } set @@ -101,13 +101,13 @@ public string CurrencyDisplay } } - private string _currencySign; + private string? _currencySign; /// /// How negative currency amounts are rendered, either standard or accounting. /// [Parameter] - public string CurrencySign + public string? CurrencySign { get { return this._currencySign; } set @@ -120,14 +120,14 @@ public string CurrencySign } } - private string _currencyCode; + private string? _currencyCode; /// /// The currency code applied when is currency. It takes precedence /// over ; when not set, the code is resolved from the culture. /// [Parameter] - public string CurrencyCode + public string? CurrencyCode { get { return this._currencyCode; } set @@ -140,13 +140,13 @@ public string CurrencyCode } } - private string _localeMatcher; + private string? _localeMatcher; /// /// The locale matching algorithm, either lookup or best fit. /// [Parameter] - public string LocaleMatcher + public string? LocaleMatcher { get { return this._localeMatcher; } set @@ -159,14 +159,14 @@ public string LocaleMatcher } } - private string _notation; + private string? _notation; /// /// The formatting notation, one of standard, scientific, engineering or /// compact. /// [Parameter] - public string Notation + public string? Notation { get { return this._notation; } set @@ -179,13 +179,13 @@ public string Notation } } - private string _numberingSystem; + private string? _numberingSystem; /// /// The numbering system used to render the digits. /// [Parameter] - public string NumberingSystem + public string? NumberingSystem { get { return this._numberingSystem; } set @@ -198,14 +198,14 @@ public string NumberingSystem } } - private string _signDisplay; + private string? _signDisplay; /// /// When the sign is shown, one of auto, never, always or /// exceptZero. /// [Parameter] - public string SignDisplay + public string? SignDisplay { get { return this._signDisplay; } set @@ -218,14 +218,14 @@ public string SignDisplay } } - private string _style; + private string? _style; /// /// The formatting style, one of decimal, currency, percent or /// unit. /// [Parameter] - public string Style + public string? Style { get { return this._style; } set @@ -238,13 +238,13 @@ public string Style } } - private string _unit; + private string? _unit; /// /// The unit used when is unit. /// [Parameter] - public string Unit + public string? Unit { get { return this._unit; } set @@ -257,13 +257,13 @@ public string Unit } } - private string _unitDisplay; + private string? _unitDisplay; /// /// How the unit is shown, one of short, narrow or long. /// [Parameter] - public string UnitDisplay + public string? UnitDisplay { get { return this._unitDisplay; } set @@ -437,7 +437,7 @@ internal override void SerializeCore(RendererSerializer ser) } /// - protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) + protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) { base.ToEventJson(control, args); @@ -483,48 +483,48 @@ protected internal override void ToEventJson(BaseRendererControl control, Dictio } /// - protected internal override void FromEventJson(BaseRendererControl control, Dictionary args) + protected internal override void FromEventJson(BaseRendererControl control, Dictionary? args) { base.FromEventJson(control, args); this.SuppressParentNotify = true; - if (args.ContainsKey("locale")) + if (args != null && args.ContainsKey("locale")) { this.Locale = ReturnToString(args["locale"]); } - if (args.ContainsKey("compactDisplay")) + if (args != null && args.ContainsKey("compactDisplay")) { this.CompactDisplay = ReturnToString(args["compactDisplay"]); } - if (args.ContainsKey("currency")) + if (args != null && args.ContainsKey("currency")) { this.Currency = ReturnToString(args["currency"]); } - if (args.ContainsKey("currencyDisplay")) + if (args != null && args.ContainsKey("currencyDisplay")) { this.CurrencyDisplay = ReturnToString(args["currencyDisplay"]); } - if (args.ContainsKey("currencySign")) + if (args != null && args.ContainsKey("currencySign")) { this.CurrencySign = ReturnToString(args["currencySign"]); } - if (args.ContainsKey("currencyCode")) + if (args != null && args.ContainsKey("currencyCode")) { this.CurrencyCode = ReturnToString(args["currencyCode"]); } - if (args.ContainsKey("localeMatcher")) + if (args != null && args.ContainsKey("localeMatcher")) { this.LocaleMatcher = ReturnToString(args["localeMatcher"]); } - if (args.ContainsKey("notation")) + if (args != null && args.ContainsKey("notation")) { this.Notation = ReturnToString(args["notation"]); } - if (args.ContainsKey("numberingSystem")) + if (args != null && args.ContainsKey("numberingSystem")) { this.NumberingSystem = ReturnToString(args["numberingSystem"]); } - if (args.ContainsKey("signDisplay")) + if (args != null && args.ContainsKey("signDisplay")) { this.SignDisplay = ReturnToString(args["signDisplay"]); } - if (args.ContainsKey("style")) + if (args != null && args.ContainsKey("style")) { this.Style = ReturnToString(args["style"]); } - if (args.ContainsKey("unit")) + if (args != null && args.ContainsKey("unit")) { this.Unit = ReturnToString(args["unit"]); } - if (args.ContainsKey("unitDisplay")) + if (args != null && args.ContainsKey("unitDisplay")) { this.UnitDisplay = ReturnToString(args["unitDisplay"]); } - if (args.ContainsKey("useGrouping")) + if (args != null && args.ContainsKey("useGrouping")) { this.UseGrouping = ReturnToBoolean(args["useGrouping"]); } - if (args.ContainsKey("minimumIntegerDigits")) + if (args != null && args.ContainsKey("minimumIntegerDigits")) { this.MinimumIntegerDigits = ReturnToInt(args["minimumIntegerDigits"]); } - if (args.ContainsKey("minimumFractionDigits")) + if (args != null && args.ContainsKey("minimumFractionDigits")) { this.MinimumFractionDigits = ReturnToInt(args["minimumFractionDigits"]); } - if (args.ContainsKey("maximumFractionDigits")) + if (args != null && args.ContainsKey("maximumFractionDigits")) { this.MaximumFractionDigits = ReturnToInt(args["maximumFractionDigits"]); } - if (args.ContainsKey("minimumSignificantDigits")) + if (args != null && args.ContainsKey("minimumSignificantDigits")) { this.MinimumSignificantDigits = ReturnToInt(args["minimumSignificantDigits"]); } - if (args.ContainsKey("maximumSignificantDigits")) + if (args != null && args.ContainsKey("maximumSignificantDigits")) { this.MaximumSignificantDigits = ReturnToInt(args["maximumSignificantDigits"]); } this.SuppressParentNotify = false; diff --git a/src/components/Blazor/ProgressBase.cs b/src/components/Blazor/ProgressBase.cs index ca9903cf..a3d5f261 100644 --- a/src/components/Blazor/ProgressBase.cs +++ b/src/components/Blazor/ProgressBase.cs @@ -163,7 +163,7 @@ public bool HideLabel } } - private string _labelFormat; + private string? _labelFormat; /// /// Format string for the default label of the control. Placeholders: @@ -173,7 +173,7 @@ public bool HideLabel /// /// [Parameter] - public string LabelFormat + public string? LabelFormat { get { return this._labelFormat; } set diff --git a/src/components/Blazor/Radio.cs b/src/components/Blazor/Radio.cs index 56848c7b..f9b9c2d0 100644 --- a/src/components/Blazor/Radio.cs +++ b/src/components/Blazor/Radio.cs @@ -77,13 +77,13 @@ public bool Required } } - private string _value; + private string? _value; /// /// The value of the control. /// [Parameter] - public string Value + public string? Value { get { return this._value; } set @@ -121,7 +121,7 @@ public bool Checked /// public async Task GetCurrentCheckedAsync() { - var iv = await InvokeMethod("p:Checked", new object[] { }, new string[] { }); + var iv = await InvokeMethod("p:Checked", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } @@ -130,7 +130,7 @@ public async Task GetCurrentCheckedAsync() /// public bool GetCurrentChecked() { - var iv = InvokeMethodSync("p:Checked", new object[] { }, new string[] { }); + var iv = InvokeMethodSync("p:Checked", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } private ToggleLabelPosition _labelPosition = ToggleLabelPosition.After; @@ -196,7 +196,7 @@ public bool Invalid /// public async Task ClickAsync() { - await InvokeMethod("click", new object[] { }, new string[] { }); + await InvokeMethod("click", new object?[] { }, new string[] { }); } /// @@ -204,7 +204,7 @@ public async Task ClickAsync() /// public void Click() { - InvokeMethodSync("click", new object[] { }, new string[] { }); + InvokeMethodSync("click", new object?[] { }, new string[] { }); } /// /// Sets focus on the radio control. @@ -213,7 +213,7 @@ public void Click() [WCWidgetMemberName("Focus")] public async Task FocusComponentAsync(IgbFocusOptions options) { - await InvokeMethod("focus", new object[] { ObjectToParam(options) }, new string[] { "Json" }); + await InvokeMethod("focus", new object?[] { ObjectToParam(options) }, new string[] { "Json" }); } /// @@ -222,7 +222,7 @@ public async Task FocusComponentAsync(IgbFocusOptions options) [WCWidgetMemberName("Focus")] public void FocusComponent(IgbFocusOptions options) { - InvokeMethodSync("focus", new object[] { ObjectToParam(options) }, new string[] { "Json" }); + InvokeMethodSync("focus", new object?[] { ObjectToParam(options) }, new string[] { "Json" }); } /// /// Removes focus from the radio control. @@ -231,7 +231,7 @@ public void FocusComponent(IgbFocusOptions options) [WCWidgetMemberName("Blur")] public async Task BlurComponentAsync() { - await InvokeMethod("blur", new object[] { }, new string[] { }); + await InvokeMethod("blur", new object?[] { }, new string[] { }); } /// @@ -240,14 +240,14 @@ public async Task BlurComponentAsync() [WCWidgetMemberName("Blur")] public void BlurComponent() { - InvokeMethodSync("blur", new object[] { }, new string[] { }); + InvokeMethodSync("blur", new object?[] { }, new string[] { }); } /// /// Checks for validity of the control and emits the invalid event if it's invalid. /// public async Task CheckValidityAsync() { - var iv = await InvokeMethod("checkValidity", new object[] { }, new string[] { }); + var iv = await InvokeMethod("checkValidity", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } @@ -256,7 +256,7 @@ public async Task CheckValidityAsync() /// public bool CheckValidity() { - var iv = InvokeMethodSync("checkValidity", new object[] { }, new string[] { }); + var iv = InvokeMethodSync("checkValidity", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } /// @@ -264,7 +264,7 @@ public bool CheckValidity() /// public async Task ReportValidityAsync() { - var iv = await InvokeMethod("reportValidity", new object[] { }, new string[] { }); + var iv = await InvokeMethod("reportValidity", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } @@ -273,7 +273,7 @@ public async Task ReportValidityAsync() /// public bool ReportValidity() { - var iv = InvokeMethodSync("reportValidity", new object[] { }, new string[] { }); + var iv = InvokeMethodSync("reportValidity", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } /// @@ -282,7 +282,7 @@ public bool ReportValidity() /// public async Task SetCustomValidityAsync(String message) { - await InvokeMethod("setCustomValidity", new object[] { StringToString(message) }, new string[] { "String" }); + await InvokeMethod("setCustomValidity", new object?[] { StringToString(message) }, new string[] { "String" }); } /// @@ -291,7 +291,7 @@ public async Task SetCustomValidityAsync(String message) /// public void SetCustomValidity(String message) { - InvokeMethodSync("setCustomValidity", new object[] { StringToString(message) }, new string[] { "String" }); + InvokeMethodSync("setCustomValidity", new object?[] { StringToString(message) }, new string[] { "String" }); } private EventCallback? _checkedChanged = null; @@ -325,8 +325,8 @@ public EventCallback CheckedChanged } } - private string _changeRef = null; - private string _changeScript = null; + private string? _changeRef = null; + private string? _changeScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -336,7 +336,7 @@ public EventCallback CheckedChanged /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string ChangeScript + public string? ChangeScript { set @@ -344,7 +344,7 @@ public string ChangeScript if (value != this._changeScript) { this._changeScript = value; - this.OnRefChanged("Change", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Change", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._changeRef = refName; this.MarkPropDirty("ChangeRef"); @@ -432,8 +432,8 @@ internal void EnsureChangeHandled() } } - private string _focusRef = null; - private string _focusScript = null; + private string? _focusRef = null; + private string? _focusScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -443,7 +443,7 @@ internal void EnsureChangeHandled() /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string FocusScript + public string? FocusScript { set @@ -451,7 +451,7 @@ public string FocusScript if (value != this._focusScript) { this._focusScript = value; - this.OnRefChanged("Focus", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Focus", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._focusRef = refName; this.MarkPropDirty("FocusRef"); @@ -504,8 +504,8 @@ public EventCallback Focus } } - private string _blurRef = null; - private string _blurScript = null; + private string? _blurRef = null; + private string? _blurScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -515,7 +515,7 @@ public EventCallback Focus /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string BlurScript + public string? BlurScript { set @@ -523,7 +523,7 @@ public string BlurScript if (value != this._blurScript) { this._blurScript = value; - this.OnRefChanged("Blur", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Blur", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._blurRef = refName; this.MarkPropDirty("BlurRef"); diff --git a/src/components/Blazor/RadioChangeEventArgs.cs b/src/components/Blazor/RadioChangeEventArgs.cs index 05542c80..37aaa585 100644 --- a/src/components/Blazor/RadioChangeEventArgs.cs +++ b/src/components/Blazor/RadioChangeEventArgs.cs @@ -13,7 +13,7 @@ public partial class IgbRadioChangeEventArgs : BaseRendererElement private static bool _marshalByValue = true; - private IgbRadioChangeEventArgsDetail _detail; + private IgbRadioChangeEventArgsDetail _detail = new IgbRadioChangeEventArgsDetail(); /// /// The payload of the event, carrying the new checked state and the value of the radio button. @@ -29,11 +29,11 @@ public IgbRadioChangeEventArgsDetail Detail { this.DetachChild(this._detail); } + this._detail = value; if (value != null) { this.AttachChild(value); } - this._detail = value; } } @@ -48,7 +48,7 @@ internal override void SerializeCore(RendererSerializer ser) } /// - protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) + protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) { base.ToEventJson(control, args); @@ -58,13 +58,13 @@ protected internal override void ToEventJson(BaseRendererControl control, Dictio } /// - protected internal override void FromEventJson(BaseRendererControl control, Dictionary args) + protected internal override void FromEventJson(BaseRendererControl control, Dictionary? args) { base.FromEventJson(control, args); this.SuppressParentNotify = true; - if (args.ContainsKey("detail")) - { this.Detail = (IgbRadioChangeEventArgsDetail)ConvertReturnValue(args["detail"], "RadioChangeEventArgsDetail", true); } + if (args != null && args.TryGetValue("detail", out var detailObj) && ConvertReturnValue(detailObj, "RadioChangeEventArgsDetail", true) is IgbRadioChangeEventArgsDetail detail) + { this.Detail = detail; } this.SuppressParentNotify = false; } diff --git a/src/components/Blazor/RadioChangeEventArgsDetail.cs b/src/components/Blazor/RadioChangeEventArgsDetail.cs index 26df2adf..05f49b31 100644 --- a/src/components/Blazor/RadioChangeEventArgsDetail.cs +++ b/src/components/Blazor/RadioChangeEventArgsDetail.cs @@ -31,13 +31,13 @@ public bool Checked } } - private string _value; + private string? _value; /// /// The value of the radio button. /// [Parameter] - public string Value + public string? Value { get { return this._value; } set @@ -64,7 +64,7 @@ internal override void SerializeCore(RendererSerializer ser) } /// - protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) + protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) { base.ToEventJson(control, args); @@ -76,14 +76,14 @@ protected internal override void ToEventJson(BaseRendererControl control, Dictio } /// - protected internal override void FromEventJson(BaseRendererControl control, Dictionary args) + protected internal override void FromEventJson(BaseRendererControl control, Dictionary? args) { base.FromEventJson(control, args); this.SuppressParentNotify = true; - if (args.ContainsKey("checked")) + if (args != null && args.ContainsKey("checked")) { this.Checked = ReturnToBoolean(args["checked"]); } - if (args.ContainsKey("value")) + if (args != null && args.ContainsKey("value")) { this.Value = ReturnToString(args["value"]); } this.SuppressParentNotify = false; diff --git a/src/components/Blazor/RadioGroup.cs b/src/components/Blazor/RadioGroup.cs index cd1722ad..6994d3f0 100644 --- a/src/components/Blazor/RadioGroup.cs +++ b/src/components/Blazor/RadioGroup.cs @@ -77,14 +77,14 @@ public ContentOrientation Alignment } } - private string _value; + private string? _value; /// /// The value of the group, reflecting the value of the currently checked button. /// Setting it checks the button in the group with a matching value. /// [Parameter] - public string Value + public string? Value { get { return this._value; } set @@ -104,7 +104,7 @@ public string Value /// The value of the checked . public async Task GetCurrentValueAsync() { - var iv = await InvokeMethod("p:Value", new object[] { }, new string[] { }); + var iv = await InvokeMethod("p:Value", new object?[] { }, new string[] { }); return ReturnToString(iv); } @@ -114,7 +114,7 @@ public async Task GetCurrentValueAsync() /// The value of the checked . public string GetCurrentValue() { - var iv = InvokeMethodSync("p:Value", new object[] { }, new string[] { }); + var iv = InvokeMethodSync("p:Value", new object?[] { }, new string[] { }); return ReturnToString(iv); } @@ -150,8 +150,8 @@ public EventCallback ValueChanged } } - private string _changeRef = null; - private string _changeScript = null; + private string? _changeRef = null; + private string? _changeScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -161,7 +161,7 @@ public EventCallback ValueChanged /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string ChangeScript + public string? ChangeScript { set @@ -169,7 +169,7 @@ public string ChangeScript if (value != this._changeScript) { this._changeScript = value; - this.OnRefChanged("Change", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Change", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._changeRef = refName; this.MarkPropDirty("ChangeRef"); @@ -206,7 +206,7 @@ public EventCallback Change var newValueValue = default(string); { - newValueValue = (string)(args.Detail.Value); + newValueValue = (string)(args.Detail.Value ?? string.Empty); if (UseDirectRender) { //TODO: maybe we should be doing this for everything. Need to make sure we don't infinity bounce though. diff --git a/src/components/Blazor/RangeSlider.cs b/src/components/Blazor/RangeSlider.cs index 25c18eaf..76f2f0c3 100644 --- a/src/components/Blazor/RangeSlider.cs +++ b/src/components/Blazor/RangeSlider.cs @@ -90,13 +90,13 @@ public double Upper } } - private string _thumbLabelLower; + private string? _thumbLabelLower; /// /// The aria label for the lower thumb. /// [Parameter] - public string ThumbLabelLower + public string? ThumbLabelLower { get { return this._thumbLabelLower; } set @@ -109,13 +109,13 @@ public string ThumbLabelLower } } - private string _thumbLabelUpper; + private string? _thumbLabelUpper; /// /// The aria label for the upper thumb. /// [Parameter] - public string ThumbLabelUpper + public string? ThumbLabelUpper { get { return this._thumbLabelUpper; } set @@ -129,8 +129,8 @@ public string ThumbLabelUpper } } - private string _inputRef = null; - private string _inputScript = null; + private string? _inputRef = null; + private string? _inputScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -140,7 +140,7 @@ public string ThumbLabelUpper /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string InputScript + public string? InputScript { set @@ -148,7 +148,7 @@ public string InputScript if (value != this._inputScript) { this._inputScript = value; - this.OnRefChanged("Input", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Input", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._inputRef = refName; this.MarkPropDirty("InputRef"); @@ -201,8 +201,8 @@ public EventCallback Input } } - private string _changeRef = null; - private string _changeScript = null; + private string? _changeRef = null; + private string? _changeScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -212,7 +212,7 @@ public EventCallback Input /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string ChangeScript + public string? ChangeScript { set @@ -220,7 +220,7 @@ public string ChangeScript if (value != this._changeScript) { this._changeScript = value; - this.OnRefChanged("Change", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Change", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._changeRef = refName; this.MarkPropDirty("ChangeRef"); diff --git a/src/components/Blazor/RangeSliderValue.cs b/src/components/Blazor/RangeSliderValue.cs index 4c53e5fc..dd48d4af 100644 --- a/src/components/Blazor/RangeSliderValue.cs +++ b/src/components/Blazor/RangeSliderValue.cs @@ -63,7 +63,7 @@ internal override void SerializeCore(RendererSerializer ser) } /// - protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) + protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) { base.ToEventJson(control, args); @@ -75,14 +75,14 @@ protected internal override void ToEventJson(BaseRendererControl control, Dictio } /// - protected internal override void FromEventJson(BaseRendererControl control, Dictionary args) + protected internal override void FromEventJson(BaseRendererControl control, Dictionary? args) { base.FromEventJson(control, args); this.SuppressParentNotify = true; - if (args.ContainsKey("lower")) + if (args != null && args.ContainsKey("lower")) { this.Lower = ReturnToDouble(args["lower"]); } - if (args.ContainsKey("upper")) + if (args != null && args.ContainsKey("upper")) { this.Upper = ReturnToDouble(args["upper"]); } this.SuppressParentNotify = false; diff --git a/src/components/Blazor/RangeSliderValueEventArgs.cs b/src/components/Blazor/RangeSliderValueEventArgs.cs index f868831a..1cf84774 100644 --- a/src/components/Blazor/RangeSliderValueEventArgs.cs +++ b/src/components/Blazor/RangeSliderValueEventArgs.cs @@ -11,7 +11,7 @@ public partial class IgbRangeSliderValueEventArgs : BaseRendererElement /// public override string Type { get { return "WebRangeSliderValueEventArgs"; } } - private IgbRangeSliderValue _detail; + private IgbRangeSliderValue _detail = new IgbRangeSliderValue(); /// /// The lower and upper thumb values of the range slider. @@ -27,11 +27,11 @@ public IgbRangeSliderValue Detail { this.DetachChild(this._detail); } + this._detail = value; if (value != null) { this.AttachChild(value); } - this._detail = value; } } @@ -46,7 +46,7 @@ internal override void SerializeCore(RendererSerializer ser) } /// - protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) + protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) { base.ToEventJson(control, args); @@ -56,13 +56,13 @@ protected internal override void ToEventJson(BaseRendererControl control, Dictio } /// - protected internal override void FromEventJson(BaseRendererControl control, Dictionary args) + protected internal override void FromEventJson(BaseRendererControl control, Dictionary? args) { base.FromEventJson(control, args); this.SuppressParentNotify = true; - if (args.ContainsKey("detail")) - { this.Detail = (IgbRangeSliderValue)ConvertReturnValue(args["detail"], "RangeSliderValue", true); } + if (args != null && args.TryGetValue("detail", out var detailObj) && ConvertReturnValue(detailObj, "RangeSliderValue", true) is IgbRangeSliderValue detail) + { this.Detail = detail; } this.SuppressParentNotify = false; } diff --git a/src/components/Blazor/Rating.cs b/src/components/Blazor/Rating.cs index 47971d1d..49bb6014 100644 --- a/src/components/Blazor/Rating.cs +++ b/src/components/Blazor/Rating.cs @@ -101,13 +101,13 @@ public double Step } } - private string _label; + private string? _label; /// /// The label of the control. /// [Parameter] - public string Label + public string? Label { get { return this._label; } set @@ -120,7 +120,7 @@ public string Label } } - private string _valueFormat; + private string? _valueFormat; /// /// A format string which sets aria-valuetext. Instances of {0} will be replaced @@ -128,7 +128,7 @@ public string Label /// Important for screen-readers and useful for localization. /// [Parameter] - public string ValueFormat + public string? ValueFormat { get { return this._valueFormat; } set @@ -166,7 +166,7 @@ public double Value /// public async Task GetCurrentValueAsync() { - var iv = await InvokeMethod("p:Value", new object[] { }, new string[] { }); + var iv = await InvokeMethod("p:Value", new object?[] { }, new string[] { }); return ReturnToDouble(iv); } @@ -175,7 +175,7 @@ public async Task GetCurrentValueAsync() /// public double GetCurrentValue() { - var iv = InvokeMethodSync("p:Value", new object[] { }, new string[] { }); + var iv = InvokeMethodSync("p:Value", new object?[] { }, new string[] { }); return ReturnToDouble(iv); } private bool _hoverPreview = false; @@ -300,7 +300,7 @@ public bool Invalid /// public async Task StepUpAsync(double n = 1) { - await InvokeMethod("stepUp", new object[] { n }, new string[] { "Number" }); + await InvokeMethod("stepUp", new object?[] { n }, new string[] { "Number" }); } /// @@ -309,7 +309,7 @@ public async Task StepUpAsync(double n = 1) /// public void StepUp(double n = 1) { - InvokeMethodSync("stepUp", new object[] { n }, new string[] { "Number" }); + InvokeMethodSync("stepUp", new object?[] { n }, new string[] { "Number" }); } /// /// Decrements the value of the control by steps multiplied by @@ -317,7 +317,7 @@ public void StepUp(double n = 1) /// public async Task StepDownAsync(double n = 1) { - await InvokeMethod("stepDown", new object[] { n }, new string[] { "Number" }); + await InvokeMethod("stepDown", new object?[] { n }, new string[] { "Number" }); } /// @@ -326,14 +326,14 @@ public async Task StepDownAsync(double n = 1) /// public void StepDown(double n = 1) { - InvokeMethodSync("stepDown", new object[] { n }, new string[] { "Number" }); + InvokeMethodSync("stepDown", new object?[] { n }, new string[] { "Number" }); } /// /// Checks for validity of the control and shows the browser message if it's invalid. /// public async Task ReportValidityAsync() { - var iv = await InvokeMethod("reportValidity", new object[] { }, new string[] { }); + var iv = await InvokeMethod("reportValidity", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } @@ -342,7 +342,7 @@ public async Task ReportValidityAsync() /// public bool ReportValidity() { - var iv = InvokeMethodSync("reportValidity", new object[] { }, new string[] { }); + var iv = InvokeMethodSync("reportValidity", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } /// @@ -350,7 +350,7 @@ public bool ReportValidity() /// public async Task CheckValidityAsync() { - var iv = await InvokeMethod("checkValidity", new object[] { }, new string[] { }); + var iv = await InvokeMethod("checkValidity", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } @@ -359,7 +359,7 @@ public async Task CheckValidityAsync() /// public bool CheckValidity() { - var iv = InvokeMethodSync("checkValidity", new object[] { }, new string[] { }); + var iv = InvokeMethodSync("checkValidity", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } /// @@ -368,7 +368,7 @@ public bool CheckValidity() /// public async Task SetCustomValidityAsync(String message) { - await InvokeMethod("setCustomValidity", new object[] { StringToString(message) }, new string[] { "String" }); + await InvokeMethod("setCustomValidity", new object?[] { StringToString(message) }, new string[] { "String" }); } /// @@ -377,7 +377,7 @@ public async Task SetCustomValidityAsync(String message) /// public void SetCustomValidity(String message) { - InvokeMethodSync("setCustomValidity", new object[] { StringToString(message) }, new string[] { "String" }); + InvokeMethodSync("setCustomValidity", new object?[] { StringToString(message) }, new string[] { "String" }); } private EventCallback? _valueChanged = null; @@ -411,8 +411,8 @@ public EventCallback ValueChanged } } - private string _changeRef = null; - private string _changeScript = null; + private string? _changeRef = null; + private string? _changeScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -422,7 +422,7 @@ public EventCallback ValueChanged /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string ChangeScript + public string? ChangeScript { set @@ -430,7 +430,7 @@ public string ChangeScript if (value != this._changeScript) { this._changeScript = value; - this.OnRefChanged("Change", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Change", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._changeRef = refName; this.MarkPropDirty("ChangeRef"); @@ -518,8 +518,8 @@ internal void EnsureChangeHandled() } } - private string _hoverRef = null; - private string _hoverScript = null; + private string? _hoverRef = null; + private string? _hoverScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -529,7 +529,7 @@ internal void EnsureChangeHandled() /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string HoverScript + public string? HoverScript { set @@ -537,7 +537,7 @@ public string HoverScript if (value != this._hoverScript) { this._hoverScript = value; - this.OnRefChanged("Hover", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Hover", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._hoverRef = refName; this.MarkPropDirty("HoverRef"); diff --git a/src/components/Blazor/RatingSymbol.cs b/src/components/Blazor/RatingSymbol.cs index 1e3a32cf..77f3f630 100644 --- a/src/components/Blazor/RatingSymbol.cs +++ b/src/components/Blazor/RatingSymbol.cs @@ -58,11 +58,11 @@ protected override ControlEventBehavior DefaultEventBehavior public async Task ConnectedCallbackAsync() { - await InvokeMethod("connectedCallback", new object[] { }, new string[] { }); + await InvokeMethod("connectedCallback", new object?[] { }, new string[] { }); } public void ConnectedCallback() { - InvokeMethodSync("connectedCallback", new object[] { }, new string[] { }); + InvokeMethodSync("connectedCallback", new object?[] { }, new string[] { }); } } diff --git a/src/components/Blazor/Select.cs b/src/components/Blazor/Select.cs index 23fd0918..0cf14329 100644 --- a/src/components/Blazor/Select.cs +++ b/src/components/Blazor/Select.cs @@ -77,7 +77,7 @@ public string? Value /// public async Task GetCurrentValueAsync() { - var iv = await InvokeMethod("p:Value", new object[] { }, new string[] { }); + var iv = await InvokeMethod("p:Value", new object?[] { }, new string[] { }); return ReturnToString(iv); } @@ -86,7 +86,7 @@ public string? Value /// public string? GetCurrentValue() { - var iv = InvokeMethodSync("p:Value", new object[] { }, new string[] { }); + var iv = InvokeMethodSync("p:Value", new object?[] { }, new string[] { }); return ReturnToString(iv); } private bool _outlined = false; @@ -146,13 +146,13 @@ public double Distance } } - private string _label; + private string? _label; /// /// The label of the control. /// [Parameter] - public string Label + public string? Label { get { return this._label; } set @@ -165,13 +165,13 @@ public string Label } } - private string _placeholder; + private string? _placeholder; /// /// The placeholder text of the control. /// [Parameter] - public string Placeholder + public string? Placeholder { get { return this._placeholder; } set @@ -228,16 +228,11 @@ public PopoverScrollStrategy ScrollStrategy /// public async Task GetItemsAsync() { - var iv = await InvokeMethod("p:Items", new object[] { }, new string[] { }); - - if (iv == null) - { - return default(IgbSelectItem[]); - } + var iv = await InvokeMethod("p:Items", new object?[] { }, new string[] { }); var retVal = ReturnToObjectArray(iv); if (retVal == null) { - return default(IgbSelectItem[]); + return Array.Empty(); } return retVal; @@ -248,16 +243,11 @@ public async Task GetItemsAsync() /// public IgbSelectItem[] GetItems() { - var iv = InvokeMethodSync("p:Items", new object[] { }, new string[] { }); - - if (iv == null) - { - return default(IgbSelectItem[]); - } + var iv = InvokeMethodSync("p:Items", new object?[] { }, new string[] { }); var retVal = ReturnToObjectArray(iv); if (retVal == null) { - return default(IgbSelectItem[]); + return Array.Empty(); } return retVal; @@ -268,16 +258,11 @@ public IgbSelectItem[] GetItems() /// public async Task GetGroupsAsync() { - var iv = await InvokeMethod("p:Groups", new object[] { }, new string[] { }); - - if (iv == null) - { - return default(IgbSelectGroup[]); - } + var iv = await InvokeMethod("p:Groups", new object?[] { }, new string[] { }); var retVal = ReturnToObjectArray(iv); if (retVal == null) { - return default(IgbSelectGroup[]); + return Array.Empty(); } return retVal; @@ -288,16 +273,11 @@ public async Task GetGroupsAsync() /// public IgbSelectGroup[] GetGroups() { - var iv = InvokeMethodSync("p:Groups", new object[] { }, new string[] { }); - - if (iv == null) - { - return default(IgbSelectGroup[]); - } + var iv = InvokeMethodSync("p:Groups", new object?[] { }, new string[] { }); var retVal = ReturnToObjectArray(iv); if (retVal == null) { - return default(IgbSelectGroup[]); + return Array.Empty(); } return retVal; @@ -308,13 +288,13 @@ public IgbSelectGroup[] GetGroups() /// public async Task GetSelectedItemAsync() { - var iv = await InvokeMethod("p:SelectedItem", new object[] { }, new string[] { }); + var iv = await InvokeMethod("p:SelectedItem", new object?[] { }, new string[] { }); if (iv == null) { return default(IgbSelectItem); } - var retVal = (IgbSelectItem)ConvertReturnValue(iv); + var retVal = (IgbSelectItem?)ConvertReturnValue(iv); if (retVal == null) { return default(IgbSelectItem); @@ -328,13 +308,13 @@ public IgbSelectGroup[] GetGroups() /// public IgbSelectItem? GetSelectedItem() { - var iv = InvokeMethodSync("p:SelectedItem", new object[] { }, new string[] { }); + var iv = InvokeMethodSync("p:SelectedItem", new object?[] { }, new string[] { }); if (iv == null) { return default(IgbSelectItem); } - var retVal = (IgbSelectItem)ConvertReturnValue(iv); + var retVal = (IgbSelectItem?)ConvertReturnValue(iv); if (retVal == null) { return default(IgbSelectItem); @@ -401,7 +381,7 @@ public bool Invalid } /// - public override object FindByName(string name) + public override object? FindByName(string name) { var baseResult = base.FindByName(name); if (baseResult != null) @@ -426,7 +406,7 @@ public override object FindByName(string name) [WCWidgetMemberName("Focus")] public async Task FocusComponentAsync(IgbFocusOptions options) { - await InvokeMethod("focus", new object[] { ObjectToParam(options) }, new string[] { "Json" }); + await InvokeMethod("focus", new object?[] { ObjectToParam(options) }, new string[] { "Json" }); } /// @@ -435,7 +415,7 @@ public async Task FocusComponentAsync(IgbFocusOptions options) [WCWidgetMemberName("Focus")] public void FocusComponent(IgbFocusOptions options) { - InvokeMethodSync("focus", new object[] { ObjectToParam(options) }, new string[] { "Json" }); + InvokeMethodSync("focus", new object?[] { ObjectToParam(options) }, new string[] { "Json" }); } /// /// Removes focus from the component. @@ -444,7 +424,7 @@ public void FocusComponent(IgbFocusOptions options) [WCWidgetMemberName("Blur")] public async Task BlurComponentAsync() { - await InvokeMethod("blur", new object[] { }, new string[] { }); + await InvokeMethod("blur", new object?[] { }, new string[] { }); } /// @@ -453,14 +433,14 @@ public async Task BlurComponentAsync() [WCWidgetMemberName("Blur")] public void BlurComponent() { - InvokeMethodSync("blur", new object[] { }, new string[] { }); + InvokeMethodSync("blur", new object?[] { }, new string[] { }); } /// /// Checks the validity of the control and moves the focus to it if it is not valid. /// public async Task ReportValidityAsync() { - var iv = await InvokeMethod("reportValidity", new object[] { }, new string[] { }); + var iv = await InvokeMethod("reportValidity", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } @@ -469,7 +449,7 @@ public async Task ReportValidityAsync() /// public bool ReportValidity() { - var iv = InvokeMethodSync("reportValidity", new object[] { }, new string[] { }); + var iv = InvokeMethodSync("reportValidity", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } /// @@ -477,7 +457,7 @@ public bool ReportValidity() /// public async Task ClearSelectionAsync() { - await InvokeMethod("clearSelection", new object[] { }, new string[] { }); + await InvokeMethod("clearSelection", new object?[] { }, new string[] { }); } /// @@ -485,14 +465,14 @@ public async Task ClearSelectionAsync() /// public void ClearSelection() { - InvokeMethodSync("clearSelection", new object[] { }, new string[] { }); + InvokeMethodSync("clearSelection", new object?[] { }, new string[] { }); } /// /// Checks the validity of the control and emits the invalid event if it is invalid. /// public async Task CheckValidityAsync() { - var iv = await InvokeMethod("checkValidity", new object[] { }, new string[] { }); + var iv = await InvokeMethod("checkValidity", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } @@ -501,7 +481,7 @@ public async Task CheckValidityAsync() /// public bool CheckValidity() { - var iv = InvokeMethodSync("checkValidity", new object[] { }, new string[] { }); + var iv = InvokeMethodSync("checkValidity", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } /// @@ -510,7 +490,7 @@ public bool CheckValidity() /// public async Task SetCustomValidityAsync(String message) { - await InvokeMethod("setCustomValidity", new object[] { StringToString(message) }, new string[] { "String" }); + await InvokeMethod("setCustomValidity", new object?[] { StringToString(message) }, new string[] { "String" }); } /// @@ -519,7 +499,7 @@ public async Task SetCustomValidityAsync(String message) /// public void SetCustomValidity(String message) { - InvokeMethodSync("setCustomValidity", new object[] { StringToString(message) }, new string[] { "String" }); + InvokeMethodSync("setCustomValidity", new object?[] { StringToString(message) }, new string[] { "String" }); } private EventCallback? _valueChanged = null; @@ -553,8 +533,8 @@ public EventCallback ValueChanged } } - private string _changeRef = null; - private string _changeScript = null; + private string? _changeRef = null; + private string? _changeScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -564,7 +544,7 @@ public EventCallback ValueChanged /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string ChangeScript + public string? ChangeScript { set @@ -572,7 +552,7 @@ public string ChangeScript if (value != this._changeScript) { this._changeScript = value; - this.OnRefChanged("Change", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Change", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._changeRef = refName; this.MarkPropDirty("ChangeRef"); @@ -660,8 +640,8 @@ internal void EnsureChangeHandled() } } - private string _focusRef = null; - private string _focusScript = null; + private string? _focusRef = null; + private string? _focusScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -671,7 +651,7 @@ internal void EnsureChangeHandled() /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string FocusScript + public string? FocusScript { set @@ -679,7 +659,7 @@ public string FocusScript if (value != this._focusScript) { this._focusScript = value; - this.OnRefChanged("Focus", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Focus", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._focusRef = refName; this.MarkPropDirty("FocusRef"); @@ -732,8 +712,8 @@ public EventCallback Focus } } - private string _blurRef = null; - private string _blurScript = null; + private string? _blurRef = null; + private string? _blurScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -743,7 +723,7 @@ public EventCallback Focus /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string BlurScript + public string? BlurScript { set @@ -751,7 +731,7 @@ public string BlurScript if (value != this._blurScript) { this._blurScript = value; - this.OnRefChanged("Blur", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Blur", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._blurRef = refName; this.MarkPropDirty("BlurRef"); @@ -804,8 +784,8 @@ public EventCallback Blur } } - private string _openingRef = null; - private string _openingScript = null; + private string? _openingRef = null; + private string? _openingScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -815,7 +795,7 @@ public EventCallback Blur /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string OpeningScript + public string? OpeningScript { set @@ -823,7 +803,7 @@ public string OpeningScript if (value != this._openingScript) { this._openingScript = value; - this.OnRefChanged("Opening", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Opening", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._openingRef = refName; this.MarkPropDirty("OpeningRef"); @@ -876,8 +856,8 @@ public EventCallback Opening } } - private string _openedRef = null; - private string _openedScript = null; + private string? _openedRef = null; + private string? _openedScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -887,7 +867,7 @@ public EventCallback Opening /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string OpenedScript + public string? OpenedScript { set @@ -895,7 +875,7 @@ public string OpenedScript if (value != this._openedScript) { this._openedScript = value; - this.OnRefChanged("Opened", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Opened", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._openedRef = refName; this.MarkPropDirty("OpenedRef"); @@ -948,8 +928,8 @@ public EventCallback Opened } } - private string _closingRef = null; - private string _closingScript = null; + private string? _closingRef = null; + private string? _closingScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -959,7 +939,7 @@ public EventCallback Opened /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string ClosingScript + public string? ClosingScript { set @@ -967,7 +947,7 @@ public string ClosingScript if (value != this._closingScript) { this._closingScript = value; - this.OnRefChanged("Closing", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Closing", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._closingRef = refName; this.MarkPropDirty("ClosingRef"); @@ -1020,8 +1000,8 @@ public EventCallback Closing } } - private string _closedRef = null; - private string _closedScript = null; + private string? _closedRef = null; + private string? _closedScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -1031,7 +1011,7 @@ public EventCallback Closing /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string ClosedScript + public string? ClosedScript { set @@ -1039,7 +1019,7 @@ public string ClosedScript if (value != this._closedScript) { this._closedScript = value; - this.OnRefChanged("Closed", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Closed", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._closedRef = refName; this.MarkPropDirty("ClosedRef"); diff --git a/src/components/Blazor/SelectGroup.cs b/src/components/Blazor/SelectGroup.cs index 254202f7..f5a8d4ad 100644 --- a/src/components/Blazor/SelectGroup.cs +++ b/src/components/Blazor/SelectGroup.cs @@ -58,7 +58,7 @@ protected override ControlEventBehavior DefaultEventBehavior get { return ControlEventBehavior.Immediate; } } - private IgbSelectItem[] _items; + private IgbSelectItem[] _items = Array.Empty(); /// /// All child components. diff --git a/src/components/Blazor/SelectItemComponentEventArgs.cs b/src/components/Blazor/SelectItemComponentEventArgs.cs index 21834995..e298dbf2 100644 --- a/src/components/Blazor/SelectItemComponentEventArgs.cs +++ b/src/components/Blazor/SelectItemComponentEventArgs.cs @@ -13,7 +13,7 @@ public partial class IgbSelectItemComponentEventArgs : BaseRendererElement private static bool _marshalByValue = true; - private IgbSelectItem _detail; + private IgbSelectItem _detail = new IgbSelectItem(); /// /// The select item that became selected. @@ -43,7 +43,7 @@ internal override void SerializeCore(RendererSerializer ser) } /// - protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) + protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) { base.ToEventJson(control, args); @@ -53,13 +53,13 @@ protected internal override void ToEventJson(BaseRendererControl control, Dictio } /// - protected internal override void FromEventJson(BaseRendererControl control, Dictionary args) + protected internal override void FromEventJson(BaseRendererControl control, Dictionary? args) { base.FromEventJson(control, args); this.SuppressParentNotify = true; - if (args.ContainsKey("detail")) - { this.Detail = (IgbSelectItem)ConvertReturnValue(args["detail"], "SelectItem", true); } + if (args != null && args.TryGetValue("detail", out var detailObj) && ConvertReturnValue(detailObj, "SelectItem", true) is IgbSelectItem detail) + { this.Detail = detail; } this.SuppressParentNotify = false; } diff --git a/src/components/Blazor/Slider.cs b/src/components/Blazor/Slider.cs index faf3f834..c1984144 100644 --- a/src/components/Blazor/Slider.cs +++ b/src/components/Blazor/Slider.cs @@ -77,7 +77,7 @@ public double Value /// public async Task GetCurrentValueAsync() { - var iv = await InvokeMethod("p:Value", new object[] { }, new string[] { }); + var iv = await InvokeMethod("p:Value", new object?[] { }, new string[] { }); return ReturnToDouble(iv); } @@ -86,7 +86,7 @@ public async Task GetCurrentValueAsync() /// public double GetCurrentValue() { - var iv = InvokeMethodSync("p:Value", new object[] { }, new string[] { }); + var iv = InvokeMethodSync("p:Value", new object?[] { }, new string[] { }); return ReturnToDouble(iv); } private bool _invalid = false; @@ -116,7 +116,7 @@ public bool Invalid /// Optional step increment. If no parameter is passed, it defaults to 1. public async Task StepUpAsync(double stepIncrement = 1) { - await InvokeMethod("stepUp", new object[] { stepIncrement }, new string[] { "Number" }); + await InvokeMethod("stepUp", new object?[] { stepIncrement }, new string[] { "Number" }); } /// @@ -126,7 +126,7 @@ public async Task StepUpAsync(double stepIncrement = 1) /// Optional step increment. If no parameter is passed, it defaults to 1. public void StepUp(double stepIncrement = 1) { - InvokeMethodSync("stepUp", new object[] { stepIncrement }, new string[] { "Number" }); + InvokeMethodSync("stepUp", new object?[] { stepIncrement }, new string[] { "Number" }); } /// /// Decrements the value of the slider by stepDecrement * step, where @@ -135,7 +135,7 @@ public void StepUp(double stepIncrement = 1) /// Optional step decrement. If no parameter is passed, it defaults to 1. public async Task StepDownAsync(double stepDecrement = 1) { - await InvokeMethod("stepDown", new object[] { stepDecrement }, new string[] { "Number" }); + await InvokeMethod("stepDown", new object?[] { stepDecrement }, new string[] { "Number" }); } /// @@ -145,14 +145,14 @@ public async Task StepDownAsync(double stepDecrement = 1) /// Optional step decrement. If no parameter is passed, it defaults to 1. public void StepDown(double stepDecrement = 1) { - InvokeMethodSync("stepDown", new object[] { stepDecrement }, new string[] { "Number" }); + InvokeMethodSync("stepDown", new object?[] { stepDecrement }, new string[] { "Number" }); } /// /// Checks the validity of the control and shows the browser message if it is invalid. /// public async Task ReportValidityAsync() { - var iv = await InvokeMethod("reportValidity", new object[] { }, new string[] { }); + var iv = await InvokeMethod("reportValidity", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } @@ -161,7 +161,7 @@ public async Task ReportValidityAsync() /// public bool ReportValidity() { - var iv = InvokeMethodSync("reportValidity", new object[] { }, new string[] { }); + var iv = InvokeMethodSync("reportValidity", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } /// @@ -169,7 +169,7 @@ public bool ReportValidity() /// public async Task CheckValidityAsync() { - var iv = await InvokeMethod("checkValidity", new object[] { }, new string[] { }); + var iv = await InvokeMethod("checkValidity", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } @@ -178,7 +178,7 @@ public async Task CheckValidityAsync() /// public bool CheckValidity() { - var iv = InvokeMethodSync("checkValidity", new object[] { }, new string[] { }); + var iv = InvokeMethodSync("checkValidity", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } /// @@ -187,7 +187,7 @@ public bool CheckValidity() /// public async Task SetCustomValidityAsync(String message) { - await InvokeMethod("setCustomValidity", new object[] { StringToString(message) }, new string[] { "String" }); + await InvokeMethod("setCustomValidity", new object?[] { StringToString(message) }, new string[] { "String" }); } /// @@ -196,7 +196,7 @@ public async Task SetCustomValidityAsync(String message) /// public void SetCustomValidity(String message) { - InvokeMethodSync("setCustomValidity", new object[] { StringToString(message) }, new string[] { "String" }); + InvokeMethodSync("setCustomValidity", new object?[] { StringToString(message) }, new string[] { "String" }); } private EventCallback? _valueChanged = null; @@ -230,8 +230,8 @@ public EventCallback ValueChanged } } - private string _inputRef = null; - private string _inputScript = null; + private string? _inputRef = null; + private string? _inputScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -241,7 +241,7 @@ public EventCallback ValueChanged /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string InputScript + public string? InputScript { set @@ -249,7 +249,7 @@ public string InputScript if (value != this._inputScript) { this._inputScript = value; - this.OnRefChanged("Input", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Input", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._inputRef = refName; this.MarkPropDirty("InputRef"); @@ -302,8 +302,8 @@ public EventCallback Input } } - private string _changeRef = null; - private string _changeScript = null; + private string? _changeRef = null; + private string? _changeScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -313,7 +313,7 @@ public EventCallback Input /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string ChangeScript + public string? ChangeScript { set @@ -321,7 +321,7 @@ public string ChangeScript if (value != this._changeScript) { this._changeScript = value; - this.OnRefChanged("Change", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Change", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._changeRef = refName; this.MarkPropDirty("ChangeRef"); diff --git a/src/components/Blazor/SliderBase.cs b/src/components/Blazor/SliderBase.cs index 4caa7c88..d9c010f5 100644 --- a/src/components/Blazor/SliderBase.cs +++ b/src/components/Blazor/SliderBase.cs @@ -310,13 +310,13 @@ public bool HideSecondaryLabels } } - private string _locale; + private string? _locale; /// /// The locale used to format the thumb and tick label values in the slider. /// [Parameter] - public string Locale + public string? Locale { get { return this._locale; } set @@ -329,13 +329,13 @@ public string Locale } } - private string _valueFormat; + private string? _valueFormat; /// /// String format used for the thumb and tick label values in the slider. /// [Parameter] - public string ValueFormat + public string? ValueFormat { get { return this._valueFormat; } set @@ -367,13 +367,13 @@ public SliderTickLabelRotation TickLabelRotation } } - private IgbNumberFormatSpecifier _valueFormatOptions; + private IgbNumberFormatSpecifier? _valueFormatOptions; /// /// Number format options used for the thumb and tick label values in the slider. /// [Parameter] - public IgbNumberFormatSpecifier ValueFormatOptions + public IgbNumberFormatSpecifier? ValueFormatOptions { get { return this._valueFormatOptions; } set @@ -425,7 +425,7 @@ internal override void SerializeCore(RendererSerializer ser) if (IsPropDirty("TickLabelRotation")) { ser.AddEnumProp("tickLabelRotation", this._tickLabelRotation); } if (IsPropDirty("ValueFormatOptions")) - { ser.AddSerializableProp("valueFormatOptions", (JsonSerializable)this._valueFormatOptions); } + { ser.AddSerializableProp("valueFormatOptions", (JsonSerializable?)this._valueFormatOptions); } } diff --git a/src/components/Blazor/Snackbar.cs b/src/components/Blazor/Snackbar.cs index 1fda6695..c24a0f02 100644 --- a/src/components/Blazor/Snackbar.cs +++ b/src/components/Blazor/Snackbar.cs @@ -58,13 +58,13 @@ protected override string DirectRenderElementName } } - private string _actionText; + private string? _actionText; /// /// The text of the action button. /// [Parameter] - public string ActionText + public string? ActionText { get { return this._actionText; } set @@ -78,8 +78,8 @@ public string ActionText } } - private string _actionRef = null; - private string _actionScript = null; + private string? _actionRef = null; + private string? _actionScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -89,7 +89,7 @@ public string ActionText /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string ActionScript + public string? ActionScript { set @@ -97,7 +97,7 @@ public string ActionScript if (value != this._actionScript) { this._actionScript = value; - this.OnRefChanged("Action", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Action", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._actionRef = refName; this.MarkPropDirty("ActionRef"); diff --git a/src/components/Blazor/Splitter.cs b/src/components/Blazor/Splitter.cs index 211d19b3..64253f48 100644 --- a/src/components/Blazor/Splitter.cs +++ b/src/components/Blazor/Splitter.cs @@ -284,7 +284,7 @@ public string? EndSize /// public async Task ToggleAsync(PanePosition position) { - await InvokeMethod("toggle", new object[] { ObjectToParam(position, typeof(PanePosition)) }, new string[] { "Json" }); + await InvokeMethod("toggle", new object?[] { ObjectToParam(position, typeof(PanePosition)) }, new string[] { "Json" }); } /// @@ -292,11 +292,11 @@ public async Task ToggleAsync(PanePosition position) /// public void Toggle(PanePosition position) { - InvokeMethodSync("toggle", new object[] { ObjectToParam(position, typeof(PanePosition)) }, new string[] { "Json" }); + InvokeMethodSync("toggle", new object?[] { ObjectToParam(position, typeof(PanePosition)) }, new string[] { "Json" }); } - private string _resizeStartRef = null; - private string _resizeStartScript = null; + private string? _resizeStartRef = null; + private string? _resizeStartScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -306,7 +306,7 @@ public void Toggle(PanePosition position) /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string ResizeStartScript + public string? ResizeStartScript { set @@ -314,7 +314,7 @@ public string ResizeStartScript if (value != this._resizeStartScript) { this._resizeStartScript = value; - this.OnRefChanged("ResizeStart", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("ResizeStart", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._resizeStartRef = refName; this.MarkPropDirty("ResizeStartRef"); @@ -367,8 +367,8 @@ public EventCallback ResizeStart } } - private string _resizingRef = null; - private string _resizingScript = null; + private string? _resizingRef = null; + private string? _resizingScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -378,7 +378,7 @@ public EventCallback ResizeStart /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string ResizingScript + public string? ResizingScript { set @@ -386,7 +386,7 @@ public string ResizingScript if (value != this._resizingScript) { this._resizingScript = value; - this.OnRefChanged("Resizing", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Resizing", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._resizingRef = refName; this.MarkPropDirty("ResizingRef"); @@ -439,8 +439,8 @@ public EventCallback Resizing } } - private string _resizeEndRef = null; - private string _resizeEndScript = null; + private string? _resizeEndRef = null; + private string? _resizeEndScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -450,7 +450,7 @@ public EventCallback Resizing /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string ResizeEndScript + public string? ResizeEndScript { set @@ -458,7 +458,7 @@ public string ResizeEndScript if (value != this._resizeEndScript) { this._resizeEndScript = value; - this.OnRefChanged("ResizeEnd", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("ResizeEnd", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._resizeEndRef = refName; this.MarkPropDirty("ResizeEndRef"); diff --git a/src/components/Blazor/SplitterResizeEventArgs.cs b/src/components/Blazor/SplitterResizeEventArgs.cs index bf0e107e..2c20abb7 100644 --- a/src/components/Blazor/SplitterResizeEventArgs.cs +++ b/src/components/Blazor/SplitterResizeEventArgs.cs @@ -12,7 +12,7 @@ public partial class IgbSplitterResizeEventArgs : BaseRendererElement private static bool _marshalByValue = true; - private IgbSplitterResizeEventArgsDetail _detail; + private IgbSplitterResizeEventArgsDetail _detail = new IgbSplitterResizeEventArgsDetail(); /// /// The current sizes of the panes adjacent to the resized splitter bar. @@ -28,11 +28,11 @@ public IgbSplitterResizeEventArgsDetail Detail { this.DetachChild(this._detail); } + this._detail = value; if (value != null) { this.AttachChild(value); } - this._detail = value; } } @@ -47,7 +47,7 @@ internal override void SerializeCore(RendererSerializer ser) } /// - protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) + protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) { base.ToEventJson(control, args); @@ -57,13 +57,13 @@ protected internal override void ToEventJson(BaseRendererControl control, Dictio } /// - protected internal override void FromEventJson(BaseRendererControl control, Dictionary args) + protected internal override void FromEventJson(BaseRendererControl control, Dictionary? args) { base.FromEventJson(control, args); this.SuppressParentNotify = true; - if (args.ContainsKey("detail")) - { this.Detail = (IgbSplitterResizeEventArgsDetail)ConvertReturnValue(args["detail"], "SplitterResizeEventArgsDetail", true); } + if (args != null && args.TryGetValue("detail", out var detailObj) && ConvertReturnValue(detailObj, "SplitterResizeEventArgsDetail", true) is IgbSplitterResizeEventArgsDetail detail) + { this.Detail = detail; } this.SuppressParentNotify = false; } diff --git a/src/components/Blazor/SplitterResizeEventArgsDetail.cs b/src/components/Blazor/SplitterResizeEventArgsDetail.cs index 2bde5fe3..5b86a1db 100644 --- a/src/components/Blazor/SplitterResizeEventArgsDetail.cs +++ b/src/components/Blazor/SplitterResizeEventArgsDetail.cs @@ -87,7 +87,7 @@ internal override void SerializeCore(RendererSerializer ser) } /// - protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) + protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) { base.ToEventJson(control, args); @@ -101,16 +101,16 @@ protected internal override void ToEventJson(BaseRendererControl control, Dictio } /// - protected internal override void FromEventJson(BaseRendererControl control, Dictionary args) + protected internal override void FromEventJson(BaseRendererControl control, Dictionary? args) { base.FromEventJson(control, args); this.SuppressParentNotify = true; - if (args.ContainsKey("startPanelSize")) + if (args != null && args.ContainsKey("startPanelSize")) { this.StartPanelSize = ReturnToDouble(args["startPanelSize"]); } - if (args.ContainsKey("endPanelSize")) + if (args != null && args.ContainsKey("endPanelSize")) { this.EndPanelSize = ReturnToDouble(args["endPanelSize"]); } - if (args.ContainsKey("delta")) + if (args != null && args.ContainsKey("delta")) { this.Delta = ReturnToDouble(args["delta"]); } this.SuppressParentNotify = false; diff --git a/src/components/Blazor/Stepper.cs b/src/components/Blazor/Stepper.cs index fa75fe11..01986e83 100644 --- a/src/components/Blazor/Stepper.cs +++ b/src/components/Blazor/Stepper.cs @@ -63,16 +63,11 @@ protected override ControlEventBehavior DefaultEventBehavior /// public async Task GetStepsAsync() { - var iv = await InvokeMethod("p:Steps", new object[] { }, new string[] { }); - - if (iv == null) - { - return default(IgbStep[]); - } + var iv = await InvokeMethod("p:Steps", new object?[] { }, new string[] { }); var retVal = ReturnToObjectArray(iv); if (retVal == null) { - return default(IgbStep[]); + return Array.Empty(); } return retVal; @@ -83,16 +78,11 @@ public async Task GetStepsAsync() /// public IgbStep[] GetSteps() { - var iv = InvokeMethodSync("p:Steps", new object[] { }, new string[] { }); - - if (iv == null) - { - return default(IgbStep[]); - } + var iv = InvokeMethodSync("p:Steps", new object?[] { }, new string[] { }); var retVal = ReturnToObjectArray(iv); if (retVal == null) { - return default(IgbStep[]); + return Array.Empty(); } return retVal; @@ -255,7 +245,7 @@ public StepperTitlePosition TitlePosition /// public async Task NavigateToAsync(double index) { - await InvokeMethod("navigateTo", new object[] { index }, new string[] { "Number" }); + await InvokeMethod("navigateTo", new object?[] { index }, new string[] { "Number" }); } /// @@ -263,14 +253,14 @@ public async Task NavigateToAsync(double index) /// public void NavigateTo(double index) { - InvokeMethodSync("navigateTo", new object[] { index }, new string[] { "Number" }); + InvokeMethodSync("navigateTo", new object?[] { index }, new string[] { "Number" }); } /// /// Activates the next enabled step. /// public async Task NextAsync() { - await InvokeMethod("next", new object[] { }, new string[] { }); + await InvokeMethod("next", new object?[] { }, new string[] { }); } /// @@ -278,14 +268,14 @@ public async Task NextAsync() /// public void Next() { - InvokeMethodSync("next", new object[] { }, new string[] { }); + InvokeMethodSync("next", new object?[] { }, new string[] { }); } /// /// Activates the previous enabled step. /// public async Task PrevAsync() { - await InvokeMethod("prev", new object[] { }, new string[] { }); + await InvokeMethod("prev", new object?[] { }, new string[] { }); } /// @@ -293,14 +283,14 @@ public async Task PrevAsync() /// public void Prev() { - InvokeMethodSync("prev", new object[] { }, new string[] { }); + InvokeMethodSync("prev", new object?[] { }, new string[] { }); } /// /// Resets the stepper to its initial state, i.e. activates the first step. /// public async Task ResetAsync() { - await InvokeMethod("reset", new object[] { }, new string[] { }); + await InvokeMethod("reset", new object?[] { }, new string[] { }); } /// @@ -308,11 +298,11 @@ public async Task ResetAsync() /// public void Reset() { - InvokeMethodSync("reset", new object[] { }, new string[] { }); + InvokeMethodSync("reset", new object?[] { }, new string[] { }); } - private string _activeStepChangingRef = null; - private string _activeStepChangingScript = null; + private string? _activeStepChangingRef = null; + private string? _activeStepChangingScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -322,7 +312,7 @@ public void Reset() /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string ActiveStepChangingScript + public string? ActiveStepChangingScript { set @@ -330,7 +320,7 @@ public string ActiveStepChangingScript if (value != this._activeStepChangingScript) { this._activeStepChangingScript = value; - this.OnRefChanged("ActiveStepChanging", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("ActiveStepChanging", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._activeStepChangingRef = refName; this.MarkPropDirty("ActiveStepChangingRef"); @@ -383,8 +373,8 @@ public EventCallback ActiveStepChanging } } - private string _activeStepChangedRef = null; - private string _activeStepChangedScript = null; + private string? _activeStepChangedRef = null; + private string? _activeStepChangedScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -394,7 +384,7 @@ public EventCallback ActiveStepChanging /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string ActiveStepChangedScript + public string? ActiveStepChangedScript { set @@ -402,7 +392,7 @@ public string ActiveStepChangedScript if (value != this._activeStepChangedScript) { this._activeStepChangedScript = value; - this.OnRefChanged("ActiveStepChanged", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("ActiveStepChanged", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._activeStepChangedRef = refName; this.MarkPropDirty("ActiveStepChangedRef"); diff --git a/src/components/Blazor/Tab.cs b/src/components/Blazor/Tab.cs index d356983f..0cd4af5f 100644 --- a/src/components/Blazor/Tab.cs +++ b/src/components/Blazor/Tab.cs @@ -59,7 +59,7 @@ protected override ControlEventBehavior DefaultEventBehavior } [CascadingParameter(Name = "TabsParent")] - protected BaseRendererControl TabsParent + protected BaseRendererControl? TabsParent { get; set; } @@ -86,13 +86,13 @@ protected override async Task OnInitializedAsync() } - private string _label; + private string? _label; /// /// The tab item label. /// [Parameter] - public string Label + public string? Label { get { return this._label; } set diff --git a/src/components/Blazor/TabComponentEventArgs.cs b/src/components/Blazor/TabComponentEventArgs.cs index 72d7f2d9..8f6f823d 100644 --- a/src/components/Blazor/TabComponentEventArgs.cs +++ b/src/components/Blazor/TabComponentEventArgs.cs @@ -13,7 +13,7 @@ public partial class IgbTabComponentEventArgs : BaseRendererElement private static bool _marshalByValue = true; - private IgbTab _detail; + private IgbTab _detail = new IgbTab(); /// /// The tab that became selected. @@ -43,7 +43,7 @@ internal override void SerializeCore(RendererSerializer ser) } /// - protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) + protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) { base.ToEventJson(control, args); @@ -53,13 +53,13 @@ protected internal override void ToEventJson(BaseRendererControl control, Dictio } /// - protected internal override void FromEventJson(BaseRendererControl control, Dictionary args) + protected internal override void FromEventJson(BaseRendererControl control, Dictionary? args) { base.FromEventJson(control, args); this.SuppressParentNotify = true; - if (args.ContainsKey("detail")) - { this.Detail = (IgbTab)ConvertReturnValue(args["detail"], "Tab", true); } + if (args != null && args.TryGetValue("detail", out var detailObj) && ConvertReturnValue(detailObj, "Tab", true) is IgbTab detail) + { this.Detail = detail; } this.SuppressParentNotify = false; } diff --git a/src/components/Blazor/Tabs.cs b/src/components/Blazor/Tabs.cs index bccc3d8c..cda08996 100644 --- a/src/components/Blazor/Tabs.cs +++ b/src/components/Blazor/Tabs.cs @@ -71,9 +71,9 @@ protected override string ParentTypeName } } - private CollectionAdapter _tabsCollectionAdapter; - private IgbTabs_TabCollection _allTabsCollection; - private IgbTabs_TabCollection _contentTabsCollection = null; + private CollectionAdapter? _tabsCollectionAdapter; + private IgbTabs_TabCollection? _allTabsCollection; + private IgbTabs_TabCollection? _contentTabsCollection = null; public IgbTabs_TabCollection ContentTabsCollection { @@ -87,7 +87,7 @@ public IgbTabs_TabCollection ContentTabsCollection return this._contentTabsCollection; } } - private IgbTabs_TabCollection _actualTabsCollection = null; + private IgbTabs_TabCollection? _actualTabsCollection = null; public IgbTabs_TabCollection ActualTabsCollection { @@ -125,7 +125,7 @@ public IgbTabs() : base() } - private IgbTabs_TabCollection _tabsCollection = null; + private IgbTabs_TabCollection? _tabsCollection = null; public IgbTabs_TabCollection TabsCollection { @@ -197,7 +197,7 @@ public TabsActivation Activation /// The label of the selected tab, or its ID if no label is set. public async Task GetSelectedAsync() { - var iv = await InvokeMethod("p:Selected", new object[] { }, new string[] { }); + var iv = await InvokeMethod("p:Selected", new object?[] { }, new string[] { }); return ReturnToString(iv); } @@ -207,12 +207,12 @@ public async Task GetSelectedAsync() /// The label of the selected tab, or its ID if no label is set. public string GetSelected() { - var iv = InvokeMethodSync("p:Selected", new object[] { }, new string[] { }); + var iv = InvokeMethodSync("p:Selected", new object?[] { }, new string[] { }); return ReturnToString(iv); } /// - public override object FindByName(string name) + public override object? FindByName(string name) { var baseResult = base.FindByName(name); if (baseResult != null) @@ -230,7 +230,7 @@ public override object FindByName(string name) /// public async Task SelectAsync(String id) { - await InvokeMethod("select", new object[] { StringToString(id) }, new string[] { "String" }); + await InvokeMethod("select", new object?[] { StringToString(id) }, new string[] { "String" }); } /// @@ -238,11 +238,11 @@ public async Task SelectAsync(String id) /// public void Select(String id) { - InvokeMethodSync("select", new object[] { StringToString(id) }, new string[] { "String" }); + InvokeMethodSync("select", new object?[] { StringToString(id) }, new string[] { "String" }); } - private string _changeRef = null; - private string _changeScript = null; + private string? _changeRef = null; + private string? _changeScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -252,7 +252,7 @@ public void Select(String id) /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string ChangeScript + public string? ChangeScript { set @@ -260,7 +260,7 @@ public string ChangeScript if (value != this._changeScript) { this._changeScript = value; - this.OnRefChanged("Change", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Change", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._changeRef = refName; this.MarkPropDirty("ChangeRef"); diff --git a/src/components/Blazor/Textarea.cs b/src/components/Blazor/Textarea.cs index 853dc84d..9aa81341 100644 --- a/src/components/Blazor/Textarea.cs +++ b/src/components/Blazor/Textarea.cs @@ -60,7 +60,7 @@ protected override ControlEventBehavior DefaultEventBehavior get { return ControlEventBehavior.Immediate; } } - private string _autocomplete; + private string? _autocomplete; /// /// Specifies what permission, if any, the browser has to provide automated assistance in filling @@ -70,7 +70,7 @@ protected override ControlEventBehavior DefaultEventBehavior /// for additional information. /// [Parameter] - public string Autocomplete + public string? Autocomplete { get { return this._autocomplete; } set @@ -83,7 +83,7 @@ public string Autocomplete } } - private string _autocapitalize; + private string? _autocapitalize; /// /// Controls whether and how text input is automatically capitalized as it is entered/edited by the user. @@ -91,7 +91,7 @@ public string Autocomplete /// MDN documentation. /// [Parameter] - public string Autocapitalize + public string? Autocapitalize { get { return this._autocapitalize; } set @@ -104,7 +104,7 @@ public string Autocapitalize } } - private string _inputMode; + private string? _inputMode; /// /// Hints at the type of data that might be entered by the user while editing the control or its contents. @@ -114,7 +114,7 @@ public string Autocapitalize /// [Parameter] [WCAttributeName("inputmode")] - public string InputMode + public string? InputMode { get { return this._inputMode; } set @@ -127,13 +127,13 @@ public string InputMode } } - private string _label; + private string? _label; /// /// The label for the control. /// [Parameter] - public string Label + public string? Label { get { return this._label; } set @@ -206,13 +206,13 @@ public bool Outlined } } - private string _placeholder; + private string? _placeholder; /// /// The placeholder text of the control. /// [Parameter] - public string Placeholder + public string? Placeholder { get { return this._placeholder; } set @@ -285,13 +285,13 @@ public double Rows } } - private string _value; + private string? _value; /// /// The value of the component. /// [Parameter] - public string Value + public string? Value { get { return this._value; } set @@ -310,7 +310,7 @@ public string Value /// public async Task GetCurrentValueAsync() { - var iv = await InvokeMethod("p:Value", new object[] { }, new string[] { }); + var iv = await InvokeMethod("p:Value", new object?[] { }, new string[] { }); return ReturnToString(iv); } @@ -319,7 +319,7 @@ public async Task GetCurrentValueAsync() /// public string GetCurrentValue() { - var iv = InvokeMethodSync("p:Value", new object[] { }, new string[] { }); + var iv = InvokeMethodSync("p:Value", new object?[] { }, new string[] { }); return ReturnToString(iv); } private bool _spellcheck = true; @@ -447,7 +447,7 @@ public bool Invalid /// public async Task SelectAsync() { - await InvokeMethod("select", new object[] { }, new string[] { }); + await InvokeMethod("select", new object?[] { }, new string[] { }); } /// @@ -455,14 +455,14 @@ public async Task SelectAsync() /// public void Select() { - InvokeMethodSync("select", new object[] { }, new string[] { }); + InvokeMethodSync("select", new object?[] { }, new string[] { }); } /// /// Checks for validity of the control and shows the browser message if it's invalid. /// public async Task ReportValidityAsync() { - var iv = await InvokeMethod("reportValidity", new object[] { }, new string[] { }); + var iv = await InvokeMethod("reportValidity", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } @@ -471,7 +471,7 @@ public async Task ReportValidityAsync() /// public bool ReportValidity() { - var iv = InvokeMethodSync("reportValidity", new object[] { }, new string[] { }); + var iv = InvokeMethodSync("reportValidity", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } /// @@ -479,7 +479,7 @@ public bool ReportValidity() /// public async Task CheckValidityAsync() { - var iv = await InvokeMethod("checkValidity", new object[] { }, new string[] { }); + var iv = await InvokeMethod("checkValidity", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } @@ -488,7 +488,7 @@ public async Task CheckValidityAsync() /// public bool CheckValidity() { - var iv = InvokeMethodSync("checkValidity", new object[] { }, new string[] { }); + var iv = InvokeMethodSync("checkValidity", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } /// @@ -497,7 +497,7 @@ public bool CheckValidity() /// public async Task SetCustomValidityAsync(String message) { - await InvokeMethod("setCustomValidity", new object[] { StringToString(message) }, new string[] { "String" }); + await InvokeMethod("setCustomValidity", new object?[] { StringToString(message) }, new string[] { "String" }); } /// @@ -506,7 +506,7 @@ public async Task SetCustomValidityAsync(String message) /// public void SetCustomValidity(String message) { - InvokeMethodSync("setCustomValidity", new object[] { StringToString(message) }, new string[] { "String" }); + InvokeMethodSync("setCustomValidity", new object?[] { StringToString(message) }, new string[] { "String" }); } private EventCallback? _valueChanged = null; @@ -540,8 +540,8 @@ public EventCallback ValueChanged } } - private string _inputRef = null; - private string _inputScript = null; + private string? _inputRef = null; + private string? _inputScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -551,7 +551,7 @@ public EventCallback ValueChanged /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string InputScript + public string? InputScript { set @@ -559,7 +559,7 @@ public string InputScript if (value != this._inputScript) { this._inputScript = value; - this.OnRefChanged("Input", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Input", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._inputRef = refName; this.MarkPropDirty("InputRef"); @@ -612,8 +612,8 @@ public EventCallback Input } } - private string _changeRef = null; - private string _changeScript = null; + private string? _changeRef = null; + private string? _changeScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -623,7 +623,7 @@ public EventCallback Input /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string ChangeScript + public string? ChangeScript { set @@ -631,7 +631,7 @@ public string ChangeScript if (value != this._changeScript) { this._changeScript = value; - this.OnRefChanged("Change", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Change", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._changeRef = refName; this.MarkPropDirty("ChangeRef"); @@ -668,7 +668,7 @@ public EventCallback Change var newValueValue = default(string); { - newValueValue = (string)(args.Detail); + newValueValue = (string)(args.Detail ?? string.Empty); if (UseDirectRender) { //TODO: maybe we should be doing this for everything. Need to make sure we don't infinity bounce though. @@ -719,8 +719,8 @@ internal void EnsureChangeHandled() } } - private string _focusRef = null; - private string _focusScript = null; + private string? _focusRef = null; + private string? _focusScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -730,7 +730,7 @@ internal void EnsureChangeHandled() /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string FocusScript + public string? FocusScript { set @@ -738,7 +738,7 @@ public string FocusScript if (value != this._focusScript) { this._focusScript = value; - this.OnRefChanged("Focus", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Focus", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._focusRef = refName; this.MarkPropDirty("FocusRef"); @@ -791,8 +791,8 @@ public EventCallback Focus } } - private string _blurRef = null; - private string _blurScript = null; + private string? _blurRef = null; + private string? _blurScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -802,7 +802,7 @@ public EventCallback Focus /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string BlurScript + public string? BlurScript { set @@ -810,7 +810,7 @@ public string BlurScript if (value != this._blurScript) { this._blurScript = value; - this.OnRefChanged("Blur", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Blur", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._blurRef = refName; this.MarkPropDirty("BlurRef"); diff --git a/src/components/Blazor/Tile.cs b/src/components/Blazor/Tile.cs index f4745114..958c794f 100644 --- a/src/components/Blazor/Tile.cs +++ b/src/components/Blazor/Tile.cs @@ -97,13 +97,13 @@ public double RowSpan } } - private double? _colStart = 0; + private double _colStart = 0; /// /// The starting column for the tile. /// [Parameter] - public double? ColStart + public double ColStart { get { return this._colStart; } set @@ -116,13 +116,13 @@ public double? ColStart } } - private double? _rowStart = 0; + private double _rowStart = 0; /// /// The starting row for the tile. /// [Parameter] - public double? RowStart + public double RowStart { get { return this._rowStart; } set @@ -141,7 +141,7 @@ public double? RowStart /// public async Task GetFullscreenAsync() { - var iv = await InvokeMethod("p:Fullscreen", new object[] { }, new string[] { }); + var iv = await InvokeMethod("p:Fullscreen", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } @@ -150,7 +150,7 @@ public async Task GetFullscreenAsync() /// public bool GetFullscreen() { - var iv = InvokeMethodSync("p:Fullscreen", new object[] { }, new string[] { }); + var iv = InvokeMethodSync("p:Fullscreen", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } private bool _maximized = false; @@ -254,8 +254,8 @@ public double Position } - private string _tileFullscreenRef = null; - private string _tileFullscreenScript = null; + private string? _tileFullscreenRef = null; + private string? _tileFullscreenScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -265,7 +265,7 @@ public double Position /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string TileFullscreenScript + public string? TileFullscreenScript { set @@ -273,7 +273,7 @@ public string TileFullscreenScript if (value != this._tileFullscreenScript) { this._tileFullscreenScript = value; - this.OnRefChanged("TileFullscreen", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("TileFullscreen", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._tileFullscreenRef = refName; this.MarkPropDirty("TileFullscreenRef"); @@ -326,8 +326,8 @@ public EventCallback TileFullscreen } } - private string _tileMaximizeRef = null; - private string _tileMaximizeScript = null; + private string? _tileMaximizeRef = null; + private string? _tileMaximizeScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -337,7 +337,7 @@ public EventCallback TileFullscreen /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string TileMaximizeScript + public string? TileMaximizeScript { set @@ -345,7 +345,7 @@ public string TileMaximizeScript if (value != this._tileMaximizeScript) { this._tileMaximizeScript = value; - this.OnRefChanged("TileMaximize", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("TileMaximize", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._tileMaximizeRef = refName; this.MarkPropDirty("TileMaximizeRef"); @@ -398,8 +398,8 @@ public EventCallback TileMaximize } } - private string _tileDragStartRef = null; - private string _tileDragStartScript = null; + private string? _tileDragStartRef = null; + private string? _tileDragStartScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -409,7 +409,7 @@ public EventCallback TileMaximize /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string TileDragStartScript + public string? TileDragStartScript { set @@ -417,7 +417,7 @@ public string TileDragStartScript if (value != this._tileDragStartScript) { this._tileDragStartScript = value; - this.OnRefChanged("TileDragStart", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("TileDragStart", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._tileDragStartRef = refName; this.MarkPropDirty("TileDragStartRef"); @@ -470,8 +470,8 @@ public EventCallback TileDragStart } } - private string _tileDragEndRef = null; - private string _tileDragEndScript = null; + private string? _tileDragEndRef = null; + private string? _tileDragEndScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -481,7 +481,7 @@ public EventCallback TileDragStart /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string TileDragEndScript + public string? TileDragEndScript { set @@ -489,7 +489,7 @@ public string TileDragEndScript if (value != this._tileDragEndScript) { this._tileDragEndScript = value; - this.OnRefChanged("TileDragEnd", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("TileDragEnd", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._tileDragEndRef = refName; this.MarkPropDirty("TileDragEndRef"); @@ -542,8 +542,8 @@ public EventCallback TileDragEnd } } - private string _tileDragCancelRef = null; - private string _tileDragCancelScript = null; + private string? _tileDragCancelRef = null; + private string? _tileDragCancelScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -553,7 +553,7 @@ public EventCallback TileDragEnd /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string TileDragCancelScript + public string? TileDragCancelScript { set @@ -561,7 +561,7 @@ public string TileDragCancelScript if (value != this._tileDragCancelScript) { this._tileDragCancelScript = value; - this.OnRefChanged("TileDragCancel", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("TileDragCancel", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._tileDragCancelRef = refName; this.MarkPropDirty("TileDragCancelRef"); @@ -614,8 +614,8 @@ public EventCallback TileDragCancel } } - private string _tileResizeStartRef = null; - private string _tileResizeStartScript = null; + private string? _tileResizeStartRef = null; + private string? _tileResizeStartScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -625,7 +625,7 @@ public EventCallback TileDragCancel /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string TileResizeStartScript + public string? TileResizeStartScript { set @@ -633,7 +633,7 @@ public string TileResizeStartScript if (value != this._tileResizeStartScript) { this._tileResizeStartScript = value; - this.OnRefChanged("TileResizeStart", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("TileResizeStart", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._tileResizeStartRef = refName; this.MarkPropDirty("TileResizeStartRef"); @@ -686,8 +686,8 @@ public EventCallback TileResizeStart } } - private string _tileResizeEndRef = null; - private string _tileResizeEndScript = null; + private string? _tileResizeEndRef = null; + private string? _tileResizeEndScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -697,7 +697,7 @@ public EventCallback TileResizeStart /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string TileResizeEndScript + public string? TileResizeEndScript { set @@ -705,7 +705,7 @@ public string TileResizeEndScript if (value != this._tileResizeEndScript) { this._tileResizeEndScript = value; - this.OnRefChanged("TileResizeEnd", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("TileResizeEnd", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._tileResizeEndRef = refName; this.MarkPropDirty("TileResizeEndRef"); @@ -758,8 +758,8 @@ public EventCallback TileResizeEnd } } - private string _tileResizeCancelRef = null; - private string _tileResizeCancelScript = null; + private string? _tileResizeCancelRef = null; + private string? _tileResizeCancelScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -769,7 +769,7 @@ public EventCallback TileResizeEnd /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string TileResizeCancelScript + public string? TileResizeCancelScript { set @@ -777,7 +777,7 @@ public string TileResizeCancelScript if (value != this._tileResizeCancelScript) { this._tileResizeCancelScript = value; - this.OnRefChanged("TileResizeCancel", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("TileResizeCancel", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._tileResizeCancelRef = refName; this.MarkPropDirty("TileResizeCancelRef"); diff --git a/src/components/Blazor/TileChangeStateEventArgs.cs b/src/components/Blazor/TileChangeStateEventArgs.cs index 75fa0871..145bb9df 100644 --- a/src/components/Blazor/TileChangeStateEventArgs.cs +++ b/src/components/Blazor/TileChangeStateEventArgs.cs @@ -14,7 +14,7 @@ public partial class IgbTileChangeStateEventArgs : BaseRendererElement private static bool _marshalByValue = true; - private IgbTileChangeStateEventArgsDetail _detail; + private IgbTileChangeStateEventArgsDetail _detail = new IgbTileChangeStateEventArgsDetail(); /// /// The affected tile and the state it is changing to. @@ -30,11 +30,11 @@ public IgbTileChangeStateEventArgsDetail Detail { this.DetachChild(this._detail); } + this._detail = value; if (value != null) { this.AttachChild(value); } - this._detail = value; } } @@ -49,7 +49,7 @@ internal override void SerializeCore(RendererSerializer ser) } /// - protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) + protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) { base.ToEventJson(control, args); @@ -59,13 +59,13 @@ protected internal override void ToEventJson(BaseRendererControl control, Dictio } /// - protected internal override void FromEventJson(BaseRendererControl control, Dictionary args) + protected internal override void FromEventJson(BaseRendererControl control, Dictionary? args) { base.FromEventJson(control, args); this.SuppressParentNotify = true; - if (args.ContainsKey("detail")) - { this.Detail = (IgbTileChangeStateEventArgsDetail)ConvertReturnValue(args["detail"], "TileChangeStateEventArgsDetail", true); } + if (args?.ContainsKey("detail") == true && ConvertReturnValue(args["detail"], "TileChangeStateEventArgsDetail", true) is IgbTileChangeStateEventArgsDetail detail) + { this.Detail = detail; } this.SuppressParentNotify = false; } diff --git a/src/components/Blazor/TileChangeStateEventArgsDetail.cs b/src/components/Blazor/TileChangeStateEventArgsDetail.cs index 116c87d1..72a22e4d 100644 --- a/src/components/Blazor/TileChangeStateEventArgsDetail.cs +++ b/src/components/Blazor/TileChangeStateEventArgsDetail.cs @@ -12,7 +12,7 @@ public partial class IgbTileChangeStateEventArgsDetail : BaseRendererElement private static bool _marshalByValue = true; - private IgbTile _tile; + private IgbTile _tile = new IgbTile(); /// /// The tile whose state is changing. @@ -65,7 +65,7 @@ internal override void SerializeCore(RendererSerializer ser) } /// - protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) + protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) { base.ToEventJson(control, args); @@ -77,14 +77,14 @@ protected internal override void ToEventJson(BaseRendererControl control, Dictio } /// - protected internal override void FromEventJson(BaseRendererControl control, Dictionary args) + protected internal override void FromEventJson(BaseRendererControl control, Dictionary? args) { base.FromEventJson(control, args); this.SuppressParentNotify = true; - if (args.ContainsKey("tile")) - { this.Tile = (IgbTile)ConvertReturnValue(args["tile"], "Tile", true); } - if (args.ContainsKey("state")) + if (args != null && args.TryGetValue("tile", out var tileObj) && ConvertReturnValue(tileObj, "Tile", true) is IgbTile tile) + { this.Tile = tile; } + if (args != null && args.ContainsKey("state")) { this.State = ReturnToBoolean(args["state"]); } this.SuppressParentNotify = false; diff --git a/src/components/Blazor/TileComponentEventArgs.cs b/src/components/Blazor/TileComponentEventArgs.cs index 4e4c9018..3546482b 100644 --- a/src/components/Blazor/TileComponentEventArgs.cs +++ b/src/components/Blazor/TileComponentEventArgs.cs @@ -14,7 +14,7 @@ public partial class IgbTileComponentEventArgs : BaseRendererElement private static bool _marshalByValue = true; - private IgbTile _detail; + private IgbTile _detail = new IgbTile(); /// /// The tile the operation applies to. @@ -44,7 +44,7 @@ internal override void SerializeCore(RendererSerializer ser) } /// - protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) + protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) { base.ToEventJson(control, args); @@ -54,13 +54,13 @@ protected internal override void ToEventJson(BaseRendererControl control, Dictio } /// - protected internal override void FromEventJson(BaseRendererControl control, Dictionary args) + protected internal override void FromEventJson(BaseRendererControl control, Dictionary? args) { base.FromEventJson(control, args); this.SuppressParentNotify = true; - if (args.ContainsKey("detail")) - { this.Detail = (IgbTile)ConvertReturnValue(args["detail"], "Tile", true); } + if (args != null && args.TryGetValue("detail", out var detailObj) && ConvertReturnValue(detailObj, "Tile", true) is IgbTile detail) + { this.Detail = detail; } this.SuppressParentNotify = false; } diff --git a/src/components/Blazor/TileManager.cs b/src/components/Blazor/TileManager.cs index 22e4dc6c..9a68b8a4 100644 --- a/src/components/Blazor/TileManager.cs +++ b/src/components/Blazor/TileManager.cs @@ -179,16 +179,11 @@ public string? Gap /// public async Task GetTilesAsync() { - var iv = await InvokeMethod("p:Tiles", new object[] { }, new string[] { }); - - if (iv == null) - { - return default(IgbTile[]); - } + var iv = await InvokeMethod("p:Tiles", new object?[] { }, new string[] { }); var retVal = ReturnToObjectArray(iv); if (retVal == null) { - return default(IgbTile[]); + return Array.Empty(); } return retVal; @@ -199,23 +194,18 @@ public async Task GetTilesAsync() /// public IgbTile[] GetTiles() { - var iv = InvokeMethodSync("p:Tiles", new object[] { }, new string[] { }); - - if (iv == null) - { - return default(IgbTile[]); - } + var iv = InvokeMethodSync("p:Tiles", new object?[] { }, new string[] { }); var retVal = ReturnToObjectArray(iv); if (retVal == null) { - return default(IgbTile[]); + return Array.Empty(); } return retVal; } /// - public override object FindByName(string name) + public override object? FindByName(string name) { var baseResult = base.FindByName(name); if (baseResult != null) @@ -238,7 +228,7 @@ public override object FindByName(string name) /// public async Task SaveLayoutAsync() { - var iv = await InvokeMethod("saveLayout", new object[] { }, new string[] { }); + var iv = await InvokeMethod("saveLayout", new object?[] { }, new string[] { }); return ReturnToString(iv); } @@ -247,7 +237,7 @@ public async Task SaveLayoutAsync() /// public String SaveLayout() { - var iv = InvokeMethodSync("saveLayout", new object[] { }, new string[] { }); + var iv = InvokeMethodSync("saveLayout", new object?[] { }, new string[] { }); return ReturnToString(iv); } /// @@ -255,7 +245,7 @@ public String SaveLayout() /// public async Task LoadLayoutAsync(String data) { - await InvokeMethod("loadLayout", new object[] { StringToString(data) }, new string[] { "String" }); + await InvokeMethod("loadLayout", new object?[] { StringToString(data) }, new string[] { "String" }); } /// @@ -263,11 +253,11 @@ public async Task LoadLayoutAsync(String data) /// public void LoadLayout(String data) { - InvokeMethodSync("loadLayout", new object[] { StringToString(data) }, new string[] { "String" }); + InvokeMethodSync("loadLayout", new object?[] { StringToString(data) }, new string[] { "String" }); } - private string _tileFullscreenRef = null; - private string _tileFullscreenScript = null; + private string? _tileFullscreenRef = null; + private string? _tileFullscreenScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -277,7 +267,7 @@ public void LoadLayout(String data) /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string TileFullscreenScript + public string? TileFullscreenScript { set @@ -285,7 +275,7 @@ public string TileFullscreenScript if (value != this._tileFullscreenScript) { this._tileFullscreenScript = value; - this.OnRefChanged("TileFullscreen", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("TileFullscreen", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._tileFullscreenRef = refName; this.MarkPropDirty("TileFullscreenRef"); @@ -338,8 +328,8 @@ public EventCallback TileFullscreen } } - private string _tileMaximizeRef = null; - private string _tileMaximizeScript = null; + private string? _tileMaximizeRef = null; + private string? _tileMaximizeScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -349,7 +339,7 @@ public EventCallback TileFullscreen /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string TileMaximizeScript + public string? TileMaximizeScript { set @@ -357,7 +347,7 @@ public string TileMaximizeScript if (value != this._tileMaximizeScript) { this._tileMaximizeScript = value; - this.OnRefChanged("TileMaximize", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("TileMaximize", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._tileMaximizeRef = refName; this.MarkPropDirty("TileMaximizeRef"); @@ -410,8 +400,8 @@ public EventCallback TileMaximize } } - private string _tileDragStartRef = null; - private string _tileDragStartScript = null; + private string? _tileDragStartRef = null; + private string? _tileDragStartScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -421,7 +411,7 @@ public EventCallback TileMaximize /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string TileDragStartScript + public string? TileDragStartScript { set @@ -429,7 +419,7 @@ public string TileDragStartScript if (value != this._tileDragStartScript) { this._tileDragStartScript = value; - this.OnRefChanged("TileDragStart", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("TileDragStart", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._tileDragStartRef = refName; this.MarkPropDirty("TileDragStartRef"); @@ -482,8 +472,8 @@ public EventCallback TileDragStart } } - private string _tileDragEndRef = null; - private string _tileDragEndScript = null; + private string? _tileDragEndRef = null; + private string? _tileDragEndScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -493,7 +483,7 @@ public EventCallback TileDragStart /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string TileDragEndScript + public string? TileDragEndScript { set @@ -501,7 +491,7 @@ public string TileDragEndScript if (value != this._tileDragEndScript) { this._tileDragEndScript = value; - this.OnRefChanged("TileDragEnd", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("TileDragEnd", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._tileDragEndRef = refName; this.MarkPropDirty("TileDragEndRef"); @@ -554,8 +544,8 @@ public EventCallback TileDragEnd } } - private string _tileDragCancelRef = null; - private string _tileDragCancelScript = null; + private string? _tileDragCancelRef = null; + private string? _tileDragCancelScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -565,7 +555,7 @@ public EventCallback TileDragEnd /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string TileDragCancelScript + public string? TileDragCancelScript { set @@ -573,7 +563,7 @@ public string TileDragCancelScript if (value != this._tileDragCancelScript) { this._tileDragCancelScript = value; - this.OnRefChanged("TileDragCancel", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("TileDragCancel", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._tileDragCancelRef = refName; this.MarkPropDirty("TileDragCancelRef"); @@ -626,8 +616,8 @@ public EventCallback TileDragCancel } } - private string _tileResizeStartRef = null; - private string _tileResizeStartScript = null; + private string? _tileResizeStartRef = null; + private string? _tileResizeStartScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -637,7 +627,7 @@ public EventCallback TileDragCancel /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string TileResizeStartScript + public string? TileResizeStartScript { set @@ -645,7 +635,7 @@ public string TileResizeStartScript if (value != this._tileResizeStartScript) { this._tileResizeStartScript = value; - this.OnRefChanged("TileResizeStart", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("TileResizeStart", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._tileResizeStartRef = refName; this.MarkPropDirty("TileResizeStartRef"); @@ -698,8 +688,8 @@ public EventCallback TileResizeStart } } - private string _tileResizeEndRef = null; - private string _tileResizeEndScript = null; + private string? _tileResizeEndRef = null; + private string? _tileResizeEndScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -709,7 +699,7 @@ public EventCallback TileResizeStart /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string TileResizeEndScript + public string? TileResizeEndScript { set @@ -717,7 +707,7 @@ public string TileResizeEndScript if (value != this._tileResizeEndScript) { this._tileResizeEndScript = value; - this.OnRefChanged("TileResizeEnd", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("TileResizeEnd", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._tileResizeEndRef = refName; this.MarkPropDirty("TileResizeEndRef"); @@ -770,8 +760,8 @@ public EventCallback TileResizeEnd } } - private string _tileResizeCancelRef = null; - private string _tileResizeCancelScript = null; + private string? _tileResizeCancelRef = null; + private string? _tileResizeCancelScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -781,7 +771,7 @@ public EventCallback TileResizeEnd /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string TileResizeCancelScript + public string? TileResizeCancelScript { set @@ -789,7 +779,7 @@ public string TileResizeCancelScript if (value != this._tileResizeCancelScript) { this._tileResizeCancelScript = value; - this.OnRefChanged("TileResizeCancel", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("TileResizeCancel", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._tileResizeCancelRef = refName; this.MarkPropDirty("TileResizeCancelRef"); diff --git a/src/components/Blazor/ToggleButton.cs b/src/components/Blazor/ToggleButton.cs index 4c8c567b..c5363aec 100644 --- a/src/components/Blazor/ToggleButton.cs +++ b/src/components/Blazor/ToggleButton.cs @@ -61,13 +61,13 @@ protected override ControlEventBehavior DefaultEventBehavior get { return ControlEventBehavior.Immediate; } } - private string _value; + private string? _value; /// /// The value of the control. /// [Parameter] - public string Value + public string? Value { get { return this._value; } set @@ -126,7 +126,7 @@ public bool Disabled [WCWidgetMemberName("Focus")] public async Task FocusComponentAsync(IgbFocusOptions options) { - await InvokeMethod("focus", new object[] { ObjectToParam(options) }, new string[] { "Json" }); + await InvokeMethod("focus", new object?[] { ObjectToParam(options) }, new string[] { "Json" }); } /// @@ -135,7 +135,7 @@ public async Task FocusComponentAsync(IgbFocusOptions options) [WCWidgetMemberName("Focus")] public void FocusComponent(IgbFocusOptions options) { - InvokeMethodSync("focus", new object[] { ObjectToParam(options) }, new string[] { "Json" }); + InvokeMethodSync("focus", new object?[] { ObjectToParam(options) }, new string[] { "Json" }); } /// /// Removes focus from the button. @@ -144,7 +144,7 @@ public void FocusComponent(IgbFocusOptions options) [WCWidgetMemberName("Blur")] public async Task BlurComponentAsync() { - await InvokeMethod("blur", new object[] { }, new string[] { }); + await InvokeMethod("blur", new object?[] { }, new string[] { }); } /// @@ -153,14 +153,14 @@ public async Task BlurComponentAsync() [WCWidgetMemberName("Blur")] public void BlurComponent() { - InvokeMethodSync("blur", new object[] { }, new string[] { }); + InvokeMethodSync("blur", new object?[] { }, new string[] { }); } /// /// Simulates a mouse click on the button. /// public async Task ClickAsync() { - await InvokeMethod("click", new object[] { }, new string[] { }); + await InvokeMethod("click", new object?[] { }, new string[] { }); } /// @@ -168,7 +168,7 @@ public async Task ClickAsync() /// public void Click() { - InvokeMethodSync("click", new object[] { }, new string[] { }); + InvokeMethodSync("click", new object?[] { }, new string[] { }); } internal override void SerializeCore(RendererSerializer ser) diff --git a/src/components/Blazor/Tooltip.cs b/src/components/Blazor/Tooltip.cs index eabd32c1..0f95e339 100644 --- a/src/components/Blazor/Tooltip.cs +++ b/src/components/Blazor/Tooltip.cs @@ -136,13 +136,13 @@ public PopoverPlacement Placement } } - private string _anchor; + private string? _anchor; /// /// The ID of the element to use as the anchor for the tooltip. /// [Parameter] - public string Anchor + public string? Anchor { get { return this._anchor; } set @@ -155,14 +155,14 @@ public string Anchor } } - private string _showTriggers; + private string? _showTriggers; /// /// Which event triggers will show the tooltip. /// Expects a comma separated string of different event triggers. /// [Parameter] - public string ShowTriggers + public string? ShowTriggers { get { return this._showTriggers; } set @@ -175,14 +175,14 @@ public string ShowTriggers } } - private string _hideTriggers; + private string? _hideTriggers; /// /// Which event triggers will hide the tooltip. /// Expects a comma separated string of different event triggers. /// [Parameter] - public string HideTriggers + public string? HideTriggers { get { return this._hideTriggers; } set @@ -233,13 +233,13 @@ public double HideDelay } } - private string _message; + private string? _message; /// /// Specifies plain text as the tooltip content. /// [Parameter] - public string Message + public string? Message { get { return this._message; } set @@ -276,9 +276,9 @@ public bool Sticky /// Shows the tooltip if not already showing. /// If is provided, it is set as a transient anchor. /// - public async Task ShowAsync(String target = null) + public async Task ShowAsync(String? target = null) { - var iv = await InvokeMethod("show", new object[] { StringToString(target) }, new string[] { "String" }); + var iv = await InvokeMethod("show", new object?[] { StringToString(target) }, new string[] { "String" }); return ReturnToBoolean(iv); } @@ -286,9 +286,9 @@ public async Task ShowAsync(String target = null) /// Shows the tooltip if not already showing. /// If is provided, it is set as a transient anchor. /// - public bool Show(String target = null) + public bool Show(String? target = null) { - var iv = InvokeMethodSync("show", new object[] { StringToString(target) }, new string[] { "String" }); + var iv = InvokeMethodSync("show", new object?[] { StringToString(target) }, new string[] { "String" }); return ReturnToBoolean(iv); } /// @@ -296,7 +296,7 @@ public bool Show(String target = null) /// public async Task HideAsync() { - var iv = await InvokeMethod("hide", new object[] { }, new string[] { }); + var iv = await InvokeMethod("hide", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } @@ -305,7 +305,7 @@ public async Task HideAsync() /// public bool Hide() { - var iv = InvokeMethodSync("hide", new object[] { }, new string[] { }); + var iv = InvokeMethodSync("hide", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } /// @@ -313,7 +313,7 @@ public bool Hide() /// public async Task ToggleAsync() { - var iv = await InvokeMethod("toggle", new object[] { }, new string[] { }); + var iv = await InvokeMethod("toggle", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } @@ -322,12 +322,12 @@ public async Task ToggleAsync() /// public bool Toggle() { - var iv = InvokeMethodSync("toggle", new object[] { }, new string[] { }); + var iv = InvokeMethodSync("toggle", new object?[] { }, new string[] { }); return ReturnToBoolean(iv); } - private string _openingRef = null; - private string _openingScript = null; + private string? _openingRef = null; + private string? _openingScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -337,7 +337,7 @@ public bool Toggle() /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string OpeningScript + public string? OpeningScript { set @@ -345,7 +345,7 @@ public string OpeningScript if (value != this._openingScript) { this._openingScript = value; - this.OnRefChanged("Opening", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Opening", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._openingRef = refName; this.MarkPropDirty("OpeningRef"); @@ -398,8 +398,8 @@ public EventCallback Opening } } - private string _openedRef = null; - private string _openedScript = null; + private string? _openedRef = null; + private string? _openedScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -409,7 +409,7 @@ public EventCallback Opening /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string OpenedScript + public string? OpenedScript { set @@ -417,7 +417,7 @@ public string OpenedScript if (value != this._openedScript) { this._openedScript = value; - this.OnRefChanged("Opened", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Opened", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._openedRef = refName; this.MarkPropDirty("OpenedRef"); @@ -470,8 +470,8 @@ public EventCallback Opened } } - private string _closingRef = null; - private string _closingScript = null; + private string? _closingRef = null; + private string? _closingScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -481,7 +481,7 @@ public EventCallback Opened /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string ClosingScript + public string? ClosingScript { set @@ -489,7 +489,7 @@ public string ClosingScript if (value != this._closingScript) { this._closingScript = value; - this.OnRefChanged("Closing", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Closing", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._closingRef = refName; this.MarkPropDirty("ClosingRef"); @@ -542,8 +542,8 @@ public EventCallback Closing } } - private string _closedRef = null; - private string _closedScript = null; + private string? _closedRef = null; + private string? _closedScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -553,7 +553,7 @@ public EventCallback Closing /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string ClosedScript + public string? ClosedScript { set @@ -561,7 +561,7 @@ public string ClosedScript if (value != this._closedScript) { this._closedScript = value; - this.OnRefChanged("Closed", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("Closed", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._closedRef = refName; this.MarkPropDirty("ClosedRef"); diff --git a/src/components/Blazor/Tree.cs b/src/components/Blazor/Tree.cs index 0ae53207..7bb04f84 100644 --- a/src/components/Blazor/Tree.cs +++ b/src/components/Blazor/Tree.cs @@ -119,7 +119,7 @@ public TreeSelection Selection } /// - public override object FindByName(string name) + public override object? FindByName(string name) { var baseResult = base.FindByName(name); if (baseResult != null) @@ -139,15 +139,15 @@ public override object FindByName(string name) } public async Task ConnectedCallbackAsync() { - await InvokeMethod("connectedCallback", new object[] { }, new string[] { }); + await InvokeMethod("connectedCallback", new object?[] { }, new string[] { }); } public void ConnectedCallback() { - InvokeMethodSync("connectedCallback", new object[] { }, new string[] { }); + InvokeMethodSync("connectedCallback", new object?[] { }, new string[] { }); } - private string _selectionChangedRef = null; - private string _selectionChangedScript = null; + private string? _selectionChangedRef = null; + private string? _selectionChangedScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -157,7 +157,7 @@ public void ConnectedCallback() /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string SelectionChangedScript + public string? SelectionChangedScript { set @@ -165,7 +165,7 @@ public string SelectionChangedScript if (value != this._selectionChangedScript) { this._selectionChangedScript = value; - this.OnRefChanged("SelectionChanged", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("SelectionChanged", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._selectionChangedRef = refName; this.MarkPropDirty("SelectionChangedRef"); @@ -218,8 +218,8 @@ public EventCallback SelectionChanged } } - private string _itemExpandingRef = null; - private string _itemExpandingScript = null; + private string? _itemExpandingRef = null; + private string? _itemExpandingScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -229,7 +229,7 @@ public EventCallback SelectionChanged /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string ItemExpandingScript + public string? ItemExpandingScript { set @@ -237,7 +237,7 @@ public string ItemExpandingScript if (value != this._itemExpandingScript) { this._itemExpandingScript = value; - this.OnRefChanged("ItemExpanding", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("ItemExpanding", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._itemExpandingRef = refName; this.MarkPropDirty("ItemExpandingRef"); @@ -290,8 +290,8 @@ public EventCallback ItemExpanding } } - private string _itemExpandedRef = null; - private string _itemExpandedScript = null; + private string? _itemExpandedRef = null; + private string? _itemExpandedScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -301,7 +301,7 @@ public EventCallback ItemExpanding /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string ItemExpandedScript + public string? ItemExpandedScript { set @@ -309,7 +309,7 @@ public string ItemExpandedScript if (value != this._itemExpandedScript) { this._itemExpandedScript = value; - this.OnRefChanged("ItemExpanded", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("ItemExpanded", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._itemExpandedRef = refName; this.MarkPropDirty("ItemExpandedRef"); @@ -362,8 +362,8 @@ public EventCallback ItemExpanded } } - private string _itemCollapsingRef = null; - private string _itemCollapsingScript = null; + private string? _itemCollapsingRef = null; + private string? _itemCollapsingScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -373,7 +373,7 @@ public EventCallback ItemExpanded /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string ItemCollapsingScript + public string? ItemCollapsingScript { set @@ -381,7 +381,7 @@ public string ItemCollapsingScript if (value != this._itemCollapsingScript) { this._itemCollapsingScript = value; - this.OnRefChanged("ItemCollapsing", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("ItemCollapsing", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._itemCollapsingRef = refName; this.MarkPropDirty("ItemCollapsingRef"); @@ -434,8 +434,8 @@ public EventCallback ItemCollapsing } } - private string _itemCollapsedRef = null; - private string _itemCollapsedScript = null; + private string? _itemCollapsedRef = null; + private string? _itemCollapsedScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -445,7 +445,7 @@ public EventCallback ItemCollapsing /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string ItemCollapsedScript + public string? ItemCollapsedScript { set @@ -453,7 +453,7 @@ public string ItemCollapsedScript if (value != this._itemCollapsedScript) { this._itemCollapsedScript = value; - this.OnRefChanged("ItemCollapsed", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("ItemCollapsed", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._itemCollapsedRef = refName; this.MarkPropDirty("ItemCollapsedRef"); @@ -506,8 +506,8 @@ public EventCallback ItemCollapsed } } - private string _activeItemRef = null; - private string _activeItemScript = null; + private string? _activeItemRef = null; + private string? _activeItemScript = null; /// /// Name of a client-side function that handles the event in the browser instead. @@ -517,7 +517,7 @@ public EventCallback ItemCollapsed /// igRegisterScript("MyHandler", function (args) { }, false). /// [Parameter] - public string ActiveItemScript + public string? ActiveItemScript { set @@ -525,7 +525,7 @@ public string ActiveItemScript if (value != this._activeItemScript) { this._activeItemScript = value; - this.OnRefChanged("ActiveItem", null, value, true, false, (string refName, object oldValue, object newValue) => + this.OnRefChanged("ActiveItem", null, value, true, false, (string refName, object? oldValue, object? newValue) => { this._activeItemRef = refName; this.MarkPropDirty("ActiveItemRef"); diff --git a/src/components/Blazor/TreeItem.cs b/src/components/Blazor/TreeItem.cs index 5573060f..d7f8545a 100644 --- a/src/components/Blazor/TreeItem.cs +++ b/src/components/Blazor/TreeItem.cs @@ -58,13 +58,13 @@ protected override ControlEventBehavior DefaultEventBehavior get { return ControlEventBehavior.Immediate; } } - private IgbTreeItem _parent; + private IgbTreeItem? _parent; /// /// The parent item of the current tree item (if any) /// [Parameter] - public IgbTreeItem Parent + public IgbTreeItem? Parent { get { return this._parent; } set @@ -96,13 +96,13 @@ public double Level } } - private string _label; + private string? _label; /// /// The tree item label. /// [Parameter] - public string Label + public string? Label { get { return this._label; } set @@ -210,13 +210,13 @@ public bool Loading } } - private object _value; + private object? _value; /// /// The value entry that the tree item is visualizing. Required for searching through items. /// [Parameter] - public object Value + public object? Value { get { return this._value; } set @@ -235,16 +235,11 @@ public object Value /// public async Task GetPathAsync() { - var iv = await InvokeMethod("p:Path", new object[] { }, new string[] { }); - - if (iv == null) - { - return default(IgbTreeItem[]); - } + var iv = await InvokeMethod("p:Path", new object?[] { }, new string[] { }); var retVal = ReturnToObjectArray(iv); if (retVal == null) { - return default(IgbTreeItem[]); + return Array.Empty(); } return retVal; @@ -255,16 +250,11 @@ public async Task GetPathAsync() /// public IgbTreeItem[] GetPath() { - var iv = InvokeMethodSync("p:Path", new object[] { }, new string[] { }); - - if (iv == null) - { - return default(IgbTreeItem[]); - } + var iv = InvokeMethodSync("p:Path", new object?[] { }, new string[] { }); var retVal = ReturnToObjectArray(iv); if (retVal == null) { - return default(IgbTreeItem[]); + return Array.Empty(); } return retVal; @@ -272,26 +262,26 @@ public IgbTreeItem[] GetPath() public async Task ConnectedCallbackAsync() { - await InvokeMethod("connectedCallback", new object[] { }, new string[] { }); + await InvokeMethod("connectedCallback", new object?[] { }, new string[] { }); } public void ConnectedCallback() { - InvokeMethodSync("connectedCallback", new object[] { }, new string[] { }); + InvokeMethodSync("connectedCallback", new object?[] { }, new string[] { }); } public async Task DisconnectedCallbackAsync() { - await InvokeMethod("disconnectedCallback", new object[] { }, new string[] { }); + await InvokeMethod("disconnectedCallback", new object?[] { }, new string[] { }); } public void DisconnectedCallback() { - InvokeMethodSync("disconnectedCallback", new object[] { }, new string[] { }); + InvokeMethodSync("disconnectedCallback", new object?[] { }, new string[] { }); } /// /// Toggles tree item expansion state. /// public async Task ToggleAsync() { - await InvokeMethod("toggle", new object[] { }, new string[] { }); + await InvokeMethod("toggle", new object?[] { }, new string[] { }); } /// @@ -299,14 +289,14 @@ public async Task ToggleAsync() /// public void Toggle() { - InvokeMethodSync("toggle", new object[] { }, new string[] { }); + InvokeMethodSync("toggle", new object?[] { }, new string[] { }); } /// /// Expands the tree item. /// public async Task ExpandAsync() { - await InvokeMethod("expand", new object[] { }, new string[] { }); + await InvokeMethod("expand", new object?[] { }, new string[] { }); } /// @@ -314,14 +304,14 @@ public async Task ExpandAsync() /// public void Expand() { - InvokeMethodSync("expand", new object[] { }, new string[] { }); + InvokeMethodSync("expand", new object?[] { }, new string[] { }); } /// /// Collapses the tree item. /// public async Task CollapseAsync() { - await InvokeMethod("collapse", new object[] { }, new string[] { }); + await InvokeMethod("collapse", new object?[] { }, new string[] { }); } /// @@ -329,7 +319,7 @@ public async Task CollapseAsync() /// public void Collapse() { - InvokeMethodSync("collapse", new object[] { }, new string[] { }); + InvokeMethodSync("collapse", new object?[] { }, new string[] { }); } internal override void SerializeCore(RendererSerializer ser) diff --git a/src/components/Blazor/TreeItemComponentEventArgs.cs b/src/components/Blazor/TreeItemComponentEventArgs.cs index 5c191a04..481244f8 100644 --- a/src/components/Blazor/TreeItemComponentEventArgs.cs +++ b/src/components/Blazor/TreeItemComponentEventArgs.cs @@ -14,7 +14,7 @@ public partial class IgbTreeItemComponentEventArgs : BaseRendererElement private static bool _marshalByValue = true; - private IgbTreeItem _detail; + private IgbTreeItem _detail = new IgbTreeItem(); /// /// The tree item the event applies to. @@ -44,7 +44,7 @@ internal override void SerializeCore(RendererSerializer ser) } /// - protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) + protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) { base.ToEventJson(control, args); @@ -54,13 +54,13 @@ protected internal override void ToEventJson(BaseRendererControl control, Dictio } /// - protected internal override void FromEventJson(BaseRendererControl control, Dictionary args) + protected internal override void FromEventJson(BaseRendererControl control, Dictionary? args) { base.FromEventJson(control, args); this.SuppressParentNotify = true; - if (args.ContainsKey("detail")) - { this.Detail = (IgbTreeItem)ConvertReturnValue(args["detail"], "TreeItem", true); } + if (args != null && args.TryGetValue("detail", out var detailObj) && ConvertReturnValue(detailObj, "TreeItem", true) is IgbTreeItem detail) + { this.Detail = detail; } this.SuppressParentNotify = false; } diff --git a/src/components/Blazor/TreeSelectionEventArgs.cs b/src/components/Blazor/TreeSelectionEventArgs.cs index 370b0c66..25e29ae7 100644 --- a/src/components/Blazor/TreeSelectionEventArgs.cs +++ b/src/components/Blazor/TreeSelectionEventArgs.cs @@ -12,7 +12,7 @@ public partial class IgbTreeSelectionEventArgs : BaseRendererElement private static bool _marshalByValue = true; - private IgbTreeSelectionEventArgsDetail _detail; + private IgbTreeSelectionEventArgsDetail _detail = new IgbTreeSelectionEventArgsDetail(); /// /// The selection the tree is about to apply. @@ -28,11 +28,11 @@ public IgbTreeSelectionEventArgsDetail Detail { this.DetachChild(this._detail); } + this._detail = value; if (value != null) { this.AttachChild(value); } - this._detail = value; } } @@ -47,7 +47,7 @@ internal override void SerializeCore(RendererSerializer ser) } /// - protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) + protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) { base.ToEventJson(control, args); @@ -57,13 +57,13 @@ protected internal override void ToEventJson(BaseRendererControl control, Dictio } /// - protected internal override void FromEventJson(BaseRendererControl control, Dictionary args) + protected internal override void FromEventJson(BaseRendererControl control, Dictionary? args) { base.FromEventJson(control, args); this.SuppressParentNotify = true; - if (args.ContainsKey("detail")) - { this.Detail = (IgbTreeSelectionEventArgsDetail)ConvertReturnValue(args["detail"], "TreeSelectionEventArgsDetail", true); } + if (args != null && args.TryGetValue("detail", out var detailObj) && ConvertReturnValue(detailObj, "TreeSelectionEventArgsDetail", true) is IgbTreeSelectionEventArgsDetail detail) + { this.Detail = detail; } this.SuppressParentNotify = false; } diff --git a/src/components/Blazor/TreeSelectionEventArgsDetail.cs b/src/components/Blazor/TreeSelectionEventArgsDetail.cs index 5f90d8bd..d0a741c2 100644 --- a/src/components/Blazor/TreeSelectionEventArgsDetail.cs +++ b/src/components/Blazor/TreeSelectionEventArgsDetail.cs @@ -13,7 +13,7 @@ public partial class IgbTreeSelectionEventArgsDetail : BaseRendererElement private static bool _marshalByValue = true; - private IgbTreeItem[] _newSelection; + private IgbTreeItem[] _newSelection = Array.Empty(); /// /// The tree items that will make up the new selection. @@ -43,7 +43,7 @@ internal override void SerializeCore(RendererSerializer ser) } /// - protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) + protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) { base.ToEventJson(control, args); @@ -53,13 +53,13 @@ protected internal override void ToEventJson(BaseRendererControl control, Dictio } /// - protected internal override void FromEventJson(BaseRendererControl control, Dictionary args) + protected internal override void FromEventJson(BaseRendererControl control, Dictionary? args) { base.FromEventJson(control, args); this.SuppressParentNotify = true; - if (args.ContainsKey("newSelection")) - { this.NewSelection = ReturnToObjectArray(args["newSelection"]); } + if (args != null && args.ContainsKey("newSelection")) + { this.NewSelection = ReturnToObjectArray(args["newSelection"]) ?? Array.Empty(); } this.SuppressParentNotify = false; } diff --git a/src/components/Blazor/VoidEventArgs.cs b/src/components/Blazor/VoidEventArgs.cs index 8e26d77b..cddd8964 100644 --- a/src/components/Blazor/VoidEventArgs.cs +++ b/src/components/Blazor/VoidEventArgs.cs @@ -11,14 +11,14 @@ public partial class IgbVoidEventArgs : BaseRendererElement public override string Type { get { return "VoidEventArgs"; } } /// - protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) + protected internal override void ToEventJson(BaseRendererControl control, Dictionary args) { base.ToEventJson(control, args); } /// - protected internal override void FromEventJson(BaseRendererControl control, Dictionary args) + protected internal override void FromEventJson(BaseRendererControl control, Dictionary? args) { base.FromEventJson(control, args); this.SuppressParentNotify = true; diff --git a/src/componentsBase/BaseCollection.cs b/src/componentsBase/BaseCollection.cs index 3dffcf47..ee862850 100644 --- a/src/componentsBase/BaseCollection.cs +++ b/src/componentsBase/BaseCollection.cs @@ -45,10 +45,9 @@ public T[] ToArray() protected override void InsertItem(int index, T item) { base.InsertItem(index, item); - if (item is BaseRendererElement) + if (item is BaseRendererElement element) { - BaseRendererElement c = (BaseRendererElement)(object)item; - c.Parent = _parent; + element.Parent = _parent; } NotifyParent(); } @@ -58,10 +57,9 @@ protected override void RemoveItem(int index) { var item = this[index]; base.RemoveItem(index); - if (item is BaseRendererElement) + if (item is BaseRendererElement element) { - BaseRendererElement c = (BaseRendererElement)(object)item; - c.Parent = null; + element.Parent = null; } NotifyParent(); } @@ -70,15 +68,14 @@ protected override void RemoveItem(int index) protected override void SetItem(int index, T item) { base.SetItem(index, item); - if (item is BaseRendererElement) + if (item is BaseRendererElement element) { - BaseRendererElement c = (BaseRendererElement)(object)item; - c.Parent = _parent; + element.Parent = _parent; } NotifyParent(); } - internal object Parent + internal object? Parent { get { @@ -90,9 +87,9 @@ internal object Parent } } - private object _parent = null; - private string _propertyName = null; - internal string PropertyName + private object? _parent = null; + private string? _propertyName = null; + internal string? PropertyName { get { @@ -104,7 +101,7 @@ internal string PropertyName } } - public BaseCollection(object parent, string propertyName) + public BaseCollection(object? parent, string? propertyName) { _parent = parent; _propertyName = propertyName; @@ -136,17 +133,16 @@ protected override void ClearItems() for (var i = 0; i < Count; i++) { var item = this[i]; - if (item is BaseRendererElement) + if (item is BaseRendererElement element) { - BaseRendererElement c = (BaseRendererElement)(object)item; - c.Parent = null; + element.Parent = null; } } base.ClearItems(); NotifyParent(); } - public void Serialize(SerializationContext context, string propertyName = null) + public void Serialize(SerializationContext context, string? propertyName = null) { //var vals = new List(); if (propertyName != null) @@ -160,54 +156,55 @@ public void Serialize(SerializationContext context, string propertyName = null) for (var i = 0; i < Count; i++) { var val = this[i]; - if (val is JsonSerializable) + if (val is null) { - ((JsonSerializable)val).Serialize(context); + context.Writer.WriteNullValue(); + } + else if (val is JsonSerializable serializable) + { + serializable.Serialize(context); + } + else if (val is int intValue) + { + context.Writer.WriteNumberValue(intValue); + } + else if (val is long longValue) + { + context.Writer.WriteNumberValue(longValue); + } + else if (val is short shortValue) + { + context.Writer.WriteNumberValue(shortValue); + } + else if (val is decimal decimalValue) + { + context.Writer.WriteNumberValue(decimalValue); + } + else if (val is float floatValue) + { + context.Writer.WriteNumberValue(floatValue); + } + else if (val is double doubleValue) + { + context.Writer.WriteNumberValue(doubleValue); + } + else if (val is byte byteValue) + { + context.Writer.WriteNumberValue(byteValue); + } + else if (val is string stringValue) + { + context.Writer.WriteStringValue(stringValue); } else { - if (typeof(T) == typeof(int)) - { - context.Writer.WriteNumberValue((int)(object)val); - } - else if (typeof(T) == typeof(long)) - { - context.Writer.WriteNumberValue((long)(object)val); - } - else if (typeof(T) == typeof(short)) - { - context.Writer.WriteNumberValue((short)(object)val); - } - else if (typeof(T) == typeof(decimal)) - { - context.Writer.WriteNumberValue((decimal)(object)val); - } - else if (typeof(T) == typeof(float)) - { - context.Writer.WriteNumberValue((float)(object)val); - } - else if (typeof(T) == typeof(double)) - { - context.Writer.WriteNumberValue((double)(object)val); - } - else if (typeof(T) == typeof(byte)) - { - context.Writer.WriteNumberValue((byte)(object)val); - } - else if (typeof(T) == typeof(string)) + if (_parent is BaseRendererElement parentElement) { - context.Writer.WriteStringValue((string)(object)val); + parentElement.ObjectToParam(context, val); } - else + if (_parent is BaseRendererControl parentControl) { - if (_parent is BaseRendererElement) - { - ((BaseRendererElement)_parent).ObjectToParam(context, val); - } - if (_parent is BaseRendererControl) - { - ((BaseRendererControl)_parent).ObjectToParam(context, val); - } + parentControl.ObjectToParam(context, val); } } } @@ -215,31 +212,26 @@ public void Serialize(SerializationContext context, string propertyName = null) //return "[" + string.Join(", \n", vals) + "]"; } - public object FindByName(string name) + public object? FindByName(string name) { //TODO: hash map for (var i = 0; i < this.Count; i++) { var item = this[i]; - if (item is BaseRendererElement) + if (item is BaseRendererElement ele) { - var ele = (BaseRendererElement)(object)item; if (name == ele.Name) { return item; } var subEle = ele.FindByName(name); - if (subEle is BaseRendererElement) + if (subEle is BaseRendererElement childElement && name == childElement.Name) { - if (name == ((BaseRendererElement)subEle).Name) - { - return subEle; - } + return childElement; } } - else if (item is BaseRendererControl) + else if (item is BaseRendererControl element) { - BaseRendererControl element = (BaseRendererControl)(object)item; if (name == element.ContainerId) { return element; @@ -255,25 +247,20 @@ public bool HasName(string name) for (var i = 0; i < this.Count; i++) { var item = this[i]; - if (item is BaseRendererElement) + if (item is BaseRendererElement ele) { - var ele = (BaseRendererElement)(object)item; if (name == ele.Name) { return true; } var subEle = ele.FindByName(name); - if (subEle is BaseRendererElement) + if (subEle is BaseRendererElement childElement && name == childElement.Name) { - if (name == ((BaseRendererElement)subEle).Name) - { - return true; - } + return true; } } - else if (item is BaseRendererControl) + else if (item is BaseRendererControl element) { - BaseRendererControl element = (BaseRendererControl)(object)item; if (name == element.ContainerId) { return true; diff --git a/src/componentsBase/BaseRendererControl.cs b/src/componentsBase/BaseRendererControl.cs index b6273278..faa56bd6 100644 --- a/src/componentsBase/BaseRendererControl.cs +++ b/src/componentsBase/BaseRendererControl.cs @@ -35,13 +35,13 @@ public enum ControlEventBehavior [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] public partial class BaseRendererControl : ComponentBase, RefSink, JsonSerializable, IAsyncDisposable { - private IIgniteUIBlazor _igBlazor; + private IIgniteUIBlazor? _igBlazor; [Inject] protected IIgniteUIBlazor IgBlazor { get { - return _igBlazor; + return _igBlazor ?? throw new InvalidOperationException("IgBlazor accessed before dependency injection completed."); } set { @@ -62,17 +62,17 @@ protected virtual void EnsureModulesLoaded() } - private IJSRuntime JsRuntime + private IJSRuntime? JsRuntime { get { - return IgBlazor != null ? IgBlazor.JsRuntime : null; + return _igBlazor != null ? _igBlazor.JsRuntime : null; } } - private IJSInProcessRuntime _inproc = null; + private IJSInProcessRuntime? _inproc = null; private bool _checkedInproc = false; - private IJSInProcessRuntime JsInProcessRuntime + private IJSInProcessRuntime? JsInProcessRuntime { get { @@ -87,25 +87,25 @@ private IJSInProcessRuntime JsInProcessRuntime } [Parameter] - public string Height + public string? Height { get; set; } [Parameter] - public string Width + public string? Width { get; set; } [Parameter] - public string Class + public string? Class { get; set; } [Parameter(CaptureUnmatchedValues = true)] - public Dictionary AdditionalAttributes { get; set; } + public Dictionary? AdditionalAttributes { get; set; } protected virtual string ParentTypeName { @@ -141,15 +141,15 @@ protected ControlEventBehavior ResolveEventBehavior() return EventBehavior; } - [Parameter] public RenderFragment ChildContent { get; set; } + [Parameter] public RenderFragment? ChildContent { get; set; } private ElementReference contEle; private Dictionary _isDirty = new Dictionary(); private Dictionary _isDirtyRef = new Dictionary(); private bool _hasDirty = false; private bool _serializeDirty = true; - private DataSourceManager _dataSourceManager; - internal DataSourceManager DataSourceManager + private DataSourceManager? _dataSourceManager; + internal DataSourceManager? DataSourceManager { get { return _dataSourceManager; } } @@ -174,7 +174,7 @@ internal string ContainerId } private bool _ready = false; - private Dictionary> _handlers = new Dictionary>(); + private Dictionary> _handlers = new Dictionary>(); private bool _updateQueued = false; /// @@ -183,7 +183,7 @@ internal string ContainerId [Parameter] public RoundTripDateConversion RoundTripDateConversion { get; set; } = RoundTripDateConversion.Auto; - private DotNetObjectReference _objRef; + private DotNetObjectReference? _objRef; private DotNetObjectReference GetObjectRef() { @@ -209,11 +209,11 @@ protected virtual string ResolveDisplay() return "block"; } - protected string ToSpinal(string value) + protected string ToSpinal(string? value) { if (value == null) { - return null; + return String.Empty; } List output = new List(); @@ -288,20 +288,14 @@ protected virtual string DirectRenderElementName } } - private void EnsureSequenceInfo() - { - if (_sequenceInfo == null) - { - _sequenceInfo = BuildSequenceInfo(3); - } - } - private Dictionary GatherSimpleAttributes() { - EnsureSequenceInfo(); - var ser = Serialize(); var data = JsonSerializer.Deserialize(ser, SerializerContext.DictionaryStringObject); + if (data == null) + { + return new Dictionary(); + } Dictionary ret = new Dictionary(); foreach (var key in data.Keys) { @@ -372,37 +366,41 @@ private object ArrayToSimpleAttributeValue(JsonElement currValue) return ret; } - protected virtual string TransformSimpleKey(string key) + protected virtual string TransformSimpleKey(string? key) { key = Camelize(key); - return _sequenceInfo.TransformKey(key); + return Sequence.TransformKey(key); } - protected virtual bool IsTransformedEnumValue(string key) + protected virtual bool IsTransformedEnumValue(string? key) { key = Camelize(key); - if (_sequenceInfo.IsTransformedEnum(key)) + if (Sequence.IsTransformedEnum(key)) { return true; } return false; } - protected virtual object TransformPotentialEnumValue(string key, object value) + protected virtual object TransformPotentialEnumValue(string? key, object value) { key = Camelize(key); //Console.WriteLine("transforming enum value...." + (value.GetType().Name)); - if (_sequenceInfo.IsTransformedEnum(key)) + if (Sequence.IsTransformedEnum(key)) { //Console.WriteLine("transforming enum value...."); key = Camelize(key); - return _sequenceInfo.TransformEnumValue(key, value.ToString()); + return Sequence.TransformEnumValue(key, value.ToString()); } return value; } - private SequenceInfo _sequenceInfo = null; + private SequenceInfo? _sequenceInfo = null; + + // Built on first use: BuildSequenceInfo is virtual and walks this instance's properties by + // reflection, so it must not run from the constructor. + private SequenceInfo Sequence => _sequenceInfo ??= BuildSequenceInfo(3); protected virtual SequenceInfo BuildSequenceInfo(int startSequence) { @@ -413,7 +411,7 @@ protected virtual SequenceInfo BuildSequenceInfo(int startSequence) foreach (var prop in props) { bool isParam = false; - string wcName = null; + string? wcName = null; foreach (var attr in prop.GetCustomAttributes(true)) { if (attr is ParameterAttribute) @@ -431,7 +429,7 @@ protected virtual SequenceInfo BuildSequenceInfo(int startSequence) } var pType = prop.PropertyType; - Dictionary wcEnumTransform = null; + Dictionary? wcEnumTransform = null; if (pType != null) { if (pType.IsEnum) @@ -451,9 +449,9 @@ protected virtual SequenceInfo BuildSequenceInfo(int startSequence) // enumType intentionally unannotated: PropertyInfo.PropertyType cannot satisfy annotations, so one here would only move the warning to the caller. [UnconditionalSuppressMessage("Trimming", "IL2070", Justification = "The trimmer preserves all fields of enum types that are kept, and enum parameter property types are kept with their declaring component.")] - private Dictionary GetWCEnumTransform(Type enumType) + private Dictionary? GetWCEnumTransform(Type enumType) { - Dictionary wcEnumTransform = null; + Dictionary? wcEnumTransform = null; foreach (var f in enumType.GetFields()) { if (f.IsPublic && !f.IsSpecialName) @@ -477,7 +475,7 @@ private Dictionary GetWCEnumTransform(Type enumType) /// protected override void BuildRenderTree(RenderTreeBuilder builder) { - string spinalName = ToSpinal(this.Type); + string? spinalName = ToSpinal(this.Type); string className = "igb-" + spinalName; if (Class != null) { @@ -491,12 +489,11 @@ protected override void BuildRenderTree(RenderTreeBuilder builder) var attributes = GatherSimpleAttributes(); builder.AddAttribute(2, "data-ig-id", _containerId); - EnsureSequenceInfo(); - foreach (var key in _sequenceInfo.AttributeKeys) + foreach (var key in Sequence.AttributeKeys) { if (attributes.ContainsKey(key)) { - var sequence = _sequenceInfo.GetSequence(key); + var sequence = Sequence.GetSequence(key); var tKey = TransformSimpleKey(key); var val = attributes[key]; @@ -518,25 +515,25 @@ protected override void BuildRenderTree(RenderTreeBuilder builder) } } - builder.AddMultipleAttributes(4 + _sequenceInfo.MaxSequence, AdditionalAttributes); + builder.AddMultipleAttributes(4 + Sequence.MaxSequence, AdditionalAttributes); - builder.AddElementReferenceCapture(5 + 15 + _sequenceInfo.MaxSequence, delegate (ElementReference value) + builder.AddElementReferenceCapture(5 + 15 + Sequence.MaxSequence, delegate (ElementReference value) { contEle = value; }); - //builder.AddMarkupContent(6 + 15 + _sequenceInfo.MaxSequence, "\r\n "); + //builder.AddMarkupContent(6 + 15 + Sequence.MaxSequence, "\r\n "); builder.OpenComponent>(6); // TODO: This '6' here might be a bug because it doesn't seem to match the other line sequence numbers - builder.AddAttribute(7 + 15 + _sequenceInfo.MaxSequence, "Value", this); - builder.AddAttribute(8 + 15 + _sequenceInfo.MaxSequence, "Name", ParentTypeName); - builder.AddAttribute(9 + 15 + _sequenceInfo.MaxSequence, "ChildContent", (RenderFragment)delegate (RenderTreeBuilder builder2) + builder.AddAttribute(7 + 15 + Sequence.MaxSequence, "Value", this); + builder.AddAttribute(8 + 15 + Sequence.MaxSequence, "Name", ParentTypeName); + builder.AddAttribute(9 + 15 + Sequence.MaxSequence, "ChildContent", (RenderFragment)delegate (RenderTreeBuilder builder2) { - //builder2.AddMarkupContent(10 + 15 + _sequenceInfo.MaxSequence, "\r\n "); - builder2.AddContent(11 + 15 + _sequenceInfo.MaxSequence, ChildContent); - //builder2.AddMarkupContent(12 + 15 + _sequenceInfo.MaxSequence, "\r\n "); + //builder2.AddMarkupContent(10 + 15 + Sequence.MaxSequence, "\r\n "); + builder2.AddContent(11 + 15 + Sequence.MaxSequence, ChildContent); + //builder2.AddMarkupContent(12 + 15 + Sequence.MaxSequence, "\r\n "); }); builder.CloseComponent(); - //builder.AddMarkupContent(13 + 15 + _sequenceInfo.MaxSequence, "\r\n"); + //builder.AddMarkupContent(13 + 15 + Sequence.MaxSequence, "\r\n"); builder.CloseElement(); return; @@ -649,22 +646,22 @@ protected override void BuildRenderTree(RenderTreeBuilder builder) builder.CloseElement(); } - internal Dictionary[] DeserializeDictionaryArray(string batch) + internal Dictionary[]? DeserializeDictionaryArray(string batch) { return JsonSerializer.Deserialize(batch, SerializerContext.DictionaryStringObjectArray); } private Dictionary _dynamicContentInfos = new Dictionary(); - private Dictionary _contentTemplates = new Dictionary(); + private Dictionary _contentTemplates = new Dictionary(); private Dictionary _contentTemplateTypes = new Dictionary(); - internal void UpdateTemplate(string templateId, object template, Type type) + internal void UpdateTemplate(string templateId, object? template, Type type) { _contentTemplates[templateId] = template; _contentTemplateTypes[templateId] = type; } - internal object FindTemplate(string templateId) + internal object? FindTemplate(string templateId) { if (_contentTemplates.ContainsKey(templateId)) { @@ -673,13 +670,17 @@ internal object FindTemplate(string templateId) return null; } - internal void AdjustDynamicContent(string containerId, string contentType, string templateId, string contentId, string actionType, string args) + internal void AdjustDynamicContent(string? containerId, string? contentType, string? templateId, string? contentId, string? actionType, string? args) { switch (actionType) { case "Add": { - DynamicContentInfo dynamicContent = BuildDynamicContentInfo(contentType, templateId); + if (contentType == null || templateId == null || contentId == null) + { + return; + } + DynamicContentInfo? dynamicContent = BuildDynamicContentInfo(contentType, templateId); if (dynamicContent == null) { return; @@ -698,26 +699,34 @@ internal void AdjustDynamicContent(string containerId, string contentType, strin dynamicContent.UpdateTemplate(template); } - Holder.AddDynamicContent(dynamicContent); + Holder?.AddDynamicContent(dynamicContent); break; } case "Remove": { + if (contentId == null) + { + return; + } if (_dynamicContentInfos.ContainsKey(contentId)) { DynamicContentInfo dynamicContent = _dynamicContentInfos[contentId]; _dynamicContentInfos.Remove(contentId); - Holder.RemoveDynamicContent(dynamicContent); + Holder?.RemoveDynamicContent(dynamicContent); } break; } case "Update": { + if (contentId == null) + { + return; + } if (_dynamicContentInfos.ContainsKey(contentId)) { DynamicContentInfo dynamicContent = _dynamicContentInfos[contentId]; - object context = null; + object? context = null; if (args != null) { var argsDic = JsonSerializer.Deserialize(args, SerializerContext.DictionaryStringObject); @@ -730,9 +739,9 @@ internal void AdjustDynamicContent(string containerId, string contentType, strin } } - protected Type TemplateContentType(string templateId) + protected Type? TemplateContentType(string? templateId) { - if (!_contentTemplateTypes.ContainsKey(templateId)) + if (templateId == null || !_contentTemplateTypes.ContainsKey(templateId)) { return null; } @@ -740,15 +749,15 @@ protected Type TemplateContentType(string templateId) return _contentTemplateTypes[templateId]; } - private Dictionary> _dynamicContentBuilders = new Dictionary>(); - private DynamicContentInfo BuildDynamicContentInfo(string contentType, string templateId) + private Dictionary> _dynamicContentBuilders = new Dictionary>(); + private DynamicContentInfo? BuildDynamicContentInfo(string? contentType, string? templateId) { var templateContentType = TemplateContentType(templateId); if (templateContentType != null) { if (!_dynamicContentBuilders.ContainsKey(templateContentType)) { - if (contentType == "TemplateContent" && templateContentType != null) + if (contentType == "TemplateContent") { var createType = typeof(DynamicContentInfo<>).MakeGenericType(templateContentType); var nonGen = typeof(DynamicContentInfo); @@ -764,14 +773,9 @@ private DynamicContentInfo BuildDynamicContentInfo(string contentType, string te _dynamicContentBuilders[templateContentType] = () => null; } } + return _dynamicContentBuilders[templateContentType](); } - else - { - //TODO: other types - _dynamicContentBuilders[templateContentType] = () => null; - } - - return _dynamicContentBuilders[templateContentType](); + return null; } protected virtual bool NeedsDynamicContent @@ -782,7 +786,7 @@ protected virtual bool NeedsDynamicContent } } - private DynamicContentHolder Holder { get; set; } + private DynamicContentHolder? Holder { get; set; } /// protected override async Task OnAfterRenderAsync(bool firstRender) @@ -810,14 +814,20 @@ public async Task EnsureReady() return; } + var jsRuntime = JsRuntime; + if (jsRuntime == null) + { + return; + } + //Console.WriteLine("ensuring ready: " + this.GetType().Name); while (!this._ready) { - bool ready = await JsRuntime.InvokeAsync("igCheckReady", new object[] { _containerId }); + bool ready = await jsRuntime.InvokeAsync("igCheckReady", new object[] { _containerId }); //Console.WriteLine(ready + " -> " + this.GetType().Name); if (ready) { - await JsRuntime.InvokeVoidAsync("igWaitForLoaded"); + await jsRuntime.InvokeVoidAsync("igWaitForLoaded"); OnReady(); break; } @@ -832,8 +842,12 @@ internal void OnReady() QueueUpdate(); } - protected internal void MarkPropDirty(string propertyName) + protected internal void MarkPropDirty(string? propertyName) { + if (propertyName == null) + { + return; + } _isDirty[propertyName] = true; _hasDirty = true; _serializeDirty = true; @@ -915,7 +929,7 @@ internal virtual void SerializeCore(RendererSerializer ser) protected String _cachedSerializedContent = ""; - public virtual string Type + public virtual string? Type { get { @@ -928,7 +942,7 @@ public virtual string Type } } - public void Serialize(SerializationContext context, string propertyName = null) + public void Serialize(SerializationContext context, string? propertyName = null) { RendererSerializer ser = new RendererSerializer(context, this, Name); ser.Type = Type; @@ -970,33 +984,33 @@ public string Serialize() /// Only use as this is incremented from any thread. /// static long _invokeId = 0; - protected async Task InvokeMethod(string methodName, object[] arguments, string[] types, ElementReference[] nativeElements = null) + protected async Task InvokeMethod(string methodName, object?[] arguments, string[] types, ElementReference[]? nativeElements = null) { return await InvokeMethodHelper(null, methodName, arguments, types, nativeElements); } - protected object InvokeMethodSync(string methodName, object[] arguments, string[] types, ElementReference[] nativeElements = null) + protected object? InvokeMethodSync(string methodName, object?[] arguments, string[] types, ElementReference[]? nativeElements = null) { return InvokeMethodHelperSync(null, methodName, arguments, types, nativeElements); } - private IgbJsonContext _serializerContext = null; + private IgbJsonContext? _serializerContext = null; private IgbJsonContext SerializerContext { get { if (_serializerContext == null) { - var def = IgBlazor.Settings.JsonSerializerOptions; + var def = IgBlazor.Settings?.JsonSerializerOptions; var options = new JsonSerializerOptions(); - options.MaxDepth = def.MaxDepth; + options.MaxDepth = def != null ? def.MaxDepth : 0; _serializerContext = new IgbJsonContext(options); } return _serializerContext; } } - internal object InvokeMethodHelperSync(string target, string methodName, object[] arguments, string[] types, ElementReference[] nativeElements) + internal object? InvokeMethodHelperSync(string? target, string methodName, object?[] arguments, string[] types, ElementReference[]? nativeElements) { if (!_ready) { @@ -1008,7 +1022,7 @@ internal object InvokeMethodHelperSync(string target, string methodName, object[ } RendererMessage m = new RendererMessage(); m.Type = ("invokeMethod"); - string[] args = new string[arguments.Length]; + string?[] args = new string?[arguments.Length]; string[] typeStrings = new string[arguments.Length]; long invokeId = Interlocked.Increment(ref _invokeId); for (int i = 0; i < arguments.Length; i++) @@ -1031,16 +1045,19 @@ internal object InvokeMethodHelperSync(string target, string methodName, object[ if (ret is JsonElement && ((JsonElement)ret).ValueKind == JsonValueKind.String) { var str = ((JsonElement)ret).GetString(); - var retDict = JsonSerializer.Deserialize(str, SerializerContext.DictionaryStringObject); - - if (retDict.ContainsKey("retType") && - retDict["retType"] is JsonElement && - ((JsonElement)retDict["retType"]).GetString() == "promise") + if (str != null) { - throw new Exception($"Invocation of method \"{methodName}\" returned a promise. Please use the async version of the method to get the value."); - } + var retDict = JsonSerializer.Deserialize(str, SerializerContext.DictionaryStringObject); - ret = retDict; + if (retDict != null && retDict.ContainsKey("retType") && + retDict["retType"] is JsonElement && + ((JsonElement)retDict["retType"]).GetString() == "promise") + { + throw new Exception($"Invocation of method \"{methodName}\" returned a promise. Please use the async version of the method to get the value."); + } + + ret = retDict; + } } //Console.WriteLine("got return"); //Console.WriteLine(ret); @@ -1048,9 +1065,9 @@ internal object InvokeMethodHelperSync(string target, string methodName, object[ } - Dictionary> _methodTasks = new Dictionary>(); + Dictionary> _methodTasks = new Dictionary>(); - internal async Task InvokeMethodHelper(string target, string methodName, object[] arguments, string[] types, ElementReference[] nativeElements) + internal async Task InvokeMethodHelper(string? target, string methodName, object?[] arguments, string[] types, ElementReference[]? nativeElements) { if (!_ready) { @@ -1058,7 +1075,7 @@ internal async Task InvokeMethodHelper(string target, string methodName, } RendererMessage m = new RendererMessage(); m.Type = ("invokeMethod"); - string[] args = new string[arguments.Length]; + string?[] args = new string?[arguments.Length]; string[] typeStrings = new string[arguments.Length]; long invokeId = Interlocked.Increment(ref _invokeId); for (int i = 0; i < arguments.Length; i++) @@ -1077,16 +1094,16 @@ internal async Task InvokeMethodHelper(string target, string methodName, m.NativeElements = nativeElements; var ret = await SendMessageImmediate(m); - TaskCompletionSource tcs = new TaskCompletionSource(); + TaskCompletionSource tcs = new TaskCompletionSource(); _methodTasks.Add(invokeId, tcs); if (ret is JsonElement && ((JsonElement)ret).ValueKind == JsonValueKind.String) { - var str = ((JsonElement)ret).GetString(); + var str = ((JsonElement)ret).GetString() ?? ""; var retDict = JsonSerializer.Deserialize(str, SerializerContext.DictionaryStringObject); ret = retDict; - if (retDict.ContainsKey("retType") && + if (retDict != null && retDict.ContainsKey("retType") && retDict["retType"] is JsonElement && ((JsonElement)retDict["retType"]).GetString() == "promise") { @@ -1109,7 +1126,7 @@ internal async Task InvokeMethodHelper(string target, string methodName, return result; } - private string GetStringArg(object argument, string type) + private string? GetStringArg(object? argument, string type) { if (argument == null) { @@ -1207,13 +1224,13 @@ private string GetStringArg(object argument, string type) return argument.ToString(); } - internal void OnRefChanged(string propertyName, object oldValue, object newValue, bool isScript, bool isElement, Action refChanged) + internal void OnRefChanged(string propertyName, object? oldValue, object? newValue, bool isScript, bool isElement, Action refChanged) { _isDirtyRef[propertyName] = true; _isDirty[propertyName] = true; _hasDirty = true; _serializeDirty = true; - string refId = _containerId + "/" + propertyName; + string? refId = _containerId + "/" + propertyName; if (newValue is LocalJson) { @@ -1237,7 +1254,7 @@ internal void OnRefChanged(string propertyName, object oldValue, object newValue using (var writer = new System.Text.Json.Utf8JsonWriter(stream)) { var context = new SerializationContext(writer, null); - ((JsonSerializable)newValue).Serialize(context, null); + ((JsonSerializable)newValue).Serialize(context); writer.Flush(); var json = System.Text.Encoding.UTF8.GetString(stream.ToArray()); @@ -1308,7 +1325,7 @@ internal void OnRefChanged(string propertyName, object oldValue, object newValue } } } - else + else if (_dataSourceManager != null) { refId = _dataSourceManager.OnRefChanged(propertyName, newValue); } @@ -1323,7 +1340,7 @@ internal void OnRefChanged(string propertyName, object oldValue, object newValue { var str = newValue.ToString(); - if (str.StartsWith("event:::") || str.StartsWith("nativeEvent:::") || str.StartsWith("json:::") || str.StartsWith("localJson:::") || str.StartsWith("template:::")) + if (str != null && (str.StartsWith("event:::") || str.StartsWith("nativeEvent:::") || str.StartsWith("json:::") || str.StartsWith("localJson:::") || str.StartsWith("template:::"))) { OnRefChanged(refId, "\"" + newValue.ToString() + "\""); } @@ -1332,7 +1349,10 @@ internal void OnRefChanged(string propertyName, object oldValue, object newValue OnRefChanged(refId, "\"script:::" + newValue.ToString() + "\""); } } - refChanged(refId, oldValue, newValue); + if (refId != null) + { + refChanged(refId, oldValue, newValue); + } } internal string DateToString(DateTime val) @@ -1346,7 +1366,10 @@ internal string DateToString(DateTime val) /// The datasource that is being changed. public void SuspendNotifications(object dataSource) { - _dataSourceManager.SuspendNotifications(dataSource); + if (_dataSourceManager != null) + { + _dataSourceManager.SuspendNotifications(dataSource); + } } /// /// Resumes data change notifications. @@ -1355,12 +1378,15 @@ public void SuspendNotifications(object dataSource) /// Whether to notify the component that the datasource items changed. public void ResumeNotifications(object dataSource, bool notify = true) { - _dataSourceManager.ResumeNotifications(dataSource, notify); + if (_dataSourceManager != null) + { + _dataSourceManager.ResumeNotifications(dataSource, notify); + } } public void NotifyInsertItem(object dataSource, int index, object refItem) { - if (!_dataSourceManager.HasRefId(dataSource)) + if (_dataSourceManager == null || !_dataSourceManager.HasRefId(dataSource)) { return; } @@ -1374,7 +1400,7 @@ public void NotifyInsertItem(object dataSource, int index, object refItem) public void NotifyRemoveItem(object dataSource, int index, object oldItem) { - if (!_dataSourceManager.HasRefId(dataSource)) + if (_dataSourceManager == null || !_dataSourceManager.HasRefId(dataSource)) { return; } @@ -1388,7 +1414,7 @@ public void NotifyRemoveItem(object dataSource, int index, object oldItem) public void NotifyClearItems(object dataSource) { - if (!_dataSourceManager.HasRefId(dataSource)) + if (_dataSourceManager == null || !_dataSourceManager.HasRefId(dataSource)) { return; } @@ -1402,7 +1428,7 @@ public void NotifyClearItems(object dataSource) public void NotifySetItem(object dataSource, int index, object oldItem, object newItem) { - if (!_dataSourceManager.HasRefId(dataSource)) + if (_dataSourceManager == null || !_dataSourceManager.HasRefId(dataSource)) { return; } @@ -1416,7 +1442,7 @@ public void NotifySetItem(object dataSource, int index, object oldItem, object n public void NotifyUpdateItem(object dataSource, int index, object refItem, bool syncDataOnly = false) { - if (!_dataSourceManager.HasRefId(dataSource)) + if (_dataSourceManager == null || !_dataSourceManager.HasRefId(dataSource)) { return; } @@ -1428,7 +1454,7 @@ public void NotifyUpdateItem(object dataSource, int index, object refItem, bool _dataSourceManager.NotifyUpdateItem(refName, index, refItem, syncDataOnly); } - public void OnRefChanged(string refName, object refValue) + public void OnRefChanged(string refName, object? refValue) { RendererMessage m = new RendererMessage(); m.Type = ("refChanged"); @@ -1436,7 +1462,7 @@ public void OnRefChanged(string refName, object refValue) if (refValue is IJSDataSource) { var ds = (IJSDataSource)refValue; - var dataIntents = ds == null ? null : ds.GetDataIntentsAsJson(); + var dataIntents = ds.GetDataIntentsAsJson(); if (dataIntents != null) { m.SetData("dataIntents", dataIntents); @@ -1469,7 +1495,7 @@ public void OnRefChanged(string refName, object refValue) SendMessage(m); } - void RefSink.OnRefNotifyInsertItem(IJSDataSource dataSource, string refName, int index, object refItem) + void RefSink.OnRefNotifyInsertItem(IJSDataSource dataSource, string refName, int index, object? refItem) { if (dataSource.DataSourceType == JSDataSourceType.Json) { @@ -1493,7 +1519,7 @@ void RefSink.OnRefNotifyInsertItem(IJSDataSource dataSource, string refName, int } } - void RefSink.OnRefNotifyRemoveItem(IJSDataSource dataSource, string refName, int index, object oldItem) + void RefSink.OnRefNotifyRemoveItem(IJSDataSource dataSource, string refName, int index, object? oldItem) { if (dataSource.DataSourceType == JSDataSourceType.Json) { @@ -1515,7 +1541,7 @@ void RefSink.OnRefNotifyRemoveItem(IJSDataSource dataSource, string refName, int } } - void RefSink.OnRefNotifyClearItems(IJSDataSource dataSource, string refName, object refValue) + void RefSink.OnRefNotifyClearItems(IJSDataSource dataSource, string refName, object? refValue) { if (dataSource.DataSourceType == JSDataSourceType.Json) { @@ -1536,7 +1562,7 @@ void RefSink.OnRefNotifyClearItems(IJSDataSource dataSource, string refName, obj } } - void RefSink.OnRefNotifySetItem(IJSDataSource dataSource, string refName, int index, object oldItem, object newItem) + void RefSink.OnRefNotifySetItem(IJSDataSource dataSource, string refName, int index, object? oldItem, object? newItem) { if (dataSource.DataSourceType == JSDataSourceType.Json) { @@ -1545,7 +1571,7 @@ void RefSink.OnRefNotifySetItem(IJSDataSource dataSource, string refName, int in m.SetData("refName", "\"" + refName + "\""); m.SetData("index", index.ToString()); m.SetData("oldItem", oldItem == null ? "null" : ((JsonDataSourceItem)oldItem).ToJson()); - m.SetData("newItem", oldItem == null ? "null" : ((JsonDataSourceItem)newItem).ToJson()); + m.SetData("newItem", oldItem == null ? "null" : ((JsonDataSourceItem?)newItem)?.ToJson()); if (!((JsonDataSource)dataSource).DateCacheReady) { m.SetData("dateCache", ((JsonDataSource)dataSource).GetDateCacheAsJson()); @@ -1559,7 +1585,7 @@ void RefSink.OnRefNotifySetItem(IJSDataSource dataSource, string refName, int in } } - void RefSink.OnRefNotifyUpdateItem(IJSDataSource dataSource, string refName, int index, object refItem, bool syncDataOnly) + void RefSink.OnRefNotifyUpdateItem(IJSDataSource dataSource, string refName, int index, object? refItem, bool syncDataOnly) { if (dataSource.DataSourceType == JSDataSourceType.Json) { @@ -1593,7 +1619,7 @@ private void SendMessage(RendererMessage m) QueueUpdate(); } - private async Task SendMessageImmediate(RendererMessage m) + private async Task SendMessageImmediate(RendererMessage m) { if (disposedValue) { @@ -1601,7 +1627,7 @@ private async Task SendMessageImmediate(RendererMessage m) } // The send must start under this lock. - Task sent; + Task sent; lock (_messageQueueLock) { Update(); @@ -1610,7 +1636,7 @@ private async Task SendMessageImmediate(RendererMessage m) return await sent; } - private object SendMessageSyncImmediate(RendererMessage m) + private object? SendMessageSyncImmediate(RendererMessage m) { if (disposedValue) { @@ -1663,7 +1689,7 @@ private void Update() } //Console.WriteLine("updateing: " + this.GetType().Name + " " + _messageQueue.Count); - while (_messageQueue.Count > 0) + while (_messageQueue != null && _messageQueue.First != null && _messageQueue.Count > 0) { RendererMessage m = _messageQueue.First.Value; _messageQueue.RemoveFirst(); @@ -1683,7 +1709,7 @@ private void UpdateSync() return; } - while (_messageQueue.Count > 0) + while (_messageQueue.Count > 0 && _messageQueue.First != null) { RendererMessage m = _messageQueue.First.Value; _messageQueue.RemoveFirst(); @@ -1742,9 +1768,9 @@ private void ProcessMessageSync(RendererMessage m) SendJsonSync(json, m.NativeElements); } - private async Task SendJsonImmediate(RendererMessage m) + private async Task SendJsonImmediate(RendererMessage m) { - if (IgBlazor == null || !IgBlazor.IsRuntimeValid(_shouldReevaluateRuntime)) + if (_igBlazor == null || !_igBlazor.IsRuntimeValid(_shouldReevaluateRuntime) || JsRuntime == null) { return null; } @@ -1778,8 +1804,12 @@ private async Task SendJsonImmediate(RendererMessage m) } } - private object SendJsonImmediateSync(RendererMessage m) + private object? SendJsonImmediateSync(RendererMessage m) { + if (this.JsInProcessRuntime == null) + { + return null; + } if (m.Type == _description) { string ser = this.Serialize(); @@ -1792,11 +1822,11 @@ private object SendJsonImmediateSync(RendererMessage m) return SendJsonSync(json, m.NativeElements); } - private void SendJson(string json, ElementReference[] nativeElements) + private void SendJson(string json, ElementReference[]? nativeElements) { //json = "window.sendMessage(`" + this._containerId + "`, `" + json + "`)"; //Console.WriteLine(json); - if (!IgBlazor.IsRuntimeValid(_shouldReevaluateRuntime)) + if (!IgBlazor.IsRuntimeValid(_shouldReevaluateRuntime) || JsRuntime == null) { return; } @@ -1870,10 +1900,13 @@ internal void DetachChild(BaseCollection child) } [UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "Arguments are strings, DotNetObjectReference and ElementReference[]; the return value is consumed as a JsonElement and re-parsed only via the source-generated IgbJsonContext — no user types cross this boundary.")] - private object SendJsonSync(string json, ElementReference[] nativeElements) + private object SendJsonSync(string json, ElementReference[]? nativeElements) { //json = "window.sendMessage(`" + this._id + "`, `" + json + "`)"; - + if (this.JsInProcessRuntime == null) + { + throw new InvalidOperationException("JsInProcessRuntime is not available."); + } if (nativeElements != null) { return JsInProcessRuntime.Invoke("igSendMessage", @@ -1890,18 +1923,13 @@ private object SendJsonSync(string json, ElementReference[] nativeElements) } } - internal object ReturnToPrimitive(object returnValue) + internal object? ReturnToPrimitive(object? returnValue) { return ConvertReturnValue(returnValue, true); } internal T[] DowncastArray(object val) { - if (val == null) - { - return null; - } - if (val is T[]) { return (T[])val; @@ -1922,14 +1950,14 @@ internal T[] DowncastArray(object val) return (T[])val; } - internal object ConvertReturnValue(object returnValue, bool transformArrays = false, string typeGuess = null, bool acceptsNullIfMarshalDoesNotExist = false) + internal object? ConvertReturnValue(object? returnValue, bool transformArrays = false, string? typeGuess = null, bool acceptsNullIfMarshalDoesNotExist = false) { try { //Console.WriteLine(returnValue.GetType().ToString()); if (returnValue is String || returnValue is Dictionary || returnValue is JsonElement) { - Dictionary obj; + Dictionary? obj; if (returnValue is String) { obj = JsonSerializer.Deserialize((string)returnValue, SerializerContext.DictionaryStringObject); @@ -1987,7 +2015,7 @@ internal object ConvertReturnValue(object returnValue, bool transformArrays = fa { obj = (Dictionary)returnValue; } - if (obj.ContainsKey("refType")) + if (obj != null && obj.ContainsKey("refType")) { String refType = ((JsonElement)obj["refType"]).ToString(); if ("uuid".Equals(refType)) @@ -1995,12 +2023,12 @@ internal object ConvertReturnValue(object returnValue, bool transformArrays = fa String id = ((JsonElement)obj["id"]).ToString(); if (id.Contains("/")) { - returnValue = _dataSourceManager.FindItem(id); + returnValue = _dataSourceManager?.FindItem(id); } else { Guid uuid = Guid.Parse(id); - returnValue = _dataSourceManager.FindItem(uuid); + returnValue = _dataSourceManager?.FindItem(uuid); } } else @@ -2009,7 +2037,7 @@ internal object ConvertReturnValue(object returnValue, bool transformArrays = fa returnValue = FindByName(name); } } - else if (obj.ContainsKey("retType")) + else if (obj != null && obj.ContainsKey("retType")) { String retType = ((JsonElement)obj["retType"]).ToString(); if ("number".Equals(retType)) @@ -2038,14 +2066,14 @@ internal object ConvertReturnValue(object returnValue, bool transformArrays = fa } else if ("undefined".Equals(retType)) { - returnValue = null; + return null; } else if ("Array".Equals(retType)) { var arr = ((JsonElement)obj["value"]); if (transformArrays && arr.ValueKind == JsonValueKind.Array) { - object[] ret = new object[arr.GetArrayLength()]; + object?[] ret = new object?[arr.GetArrayLength()]; for (var i = 0; i < arr.GetArrayLength(); i++) { var item = arr[i]; @@ -2081,7 +2109,7 @@ internal object ConvertReturnValue(object returnValue, bool transformArrays = fa return null; } - object o = null; + object? o = null; if (type != null) { o = MarshalByValueFactory.CreateInstance(type); @@ -2095,7 +2123,16 @@ internal object ConvertReturnValue(object returnValue, bool transformArrays = fa var str = v.ToString(); //Console.WriteLine(str); var ev = JsonSerializer.Deserialize(str, SerializerContext.DictionaryStringObject); - ((BaseRendererElement)o).FromEventJson(this, ev); + Dictionary? eventArgs = null; + if (ev != null) + { + eventArgs = new Dictionary(); + foreach (var item in ev) + { + eventArgs[item.Key] = item.Value; + } + } + ((BaseRendererElement)o).FromEventJson(this, eventArgs); returnValue = o; } // else if (o is BaseRendererControl) @@ -2114,7 +2151,7 @@ internal object ConvertReturnValue(object returnValue, bool transformArrays = fa { return null; } - var ret = obj["value"].ToString(); + var ret = obj["value"].ToString() ?? ""; returnValue = JsonSerializer.Deserialize(ret, SerializerContext.DictionaryStringObject); } } @@ -2152,7 +2189,10 @@ public void OnInvokeReturn(long invokeId, Object returnValue) if (returnValue is JsonElement && ((JsonElement)returnValue).ValueKind == JsonValueKind.String) { var str = ((JsonElement)returnValue).GetString(); - result = JsonSerializer.Deserialize(str, SerializerContext.DictionaryStringObject); + if (str != null) + { + result = JsonSerializer.Deserialize(str, SerializerContext.DictionaryStringObject) ?? returnValue; + } } InvokeAsync(() => @@ -2168,23 +2208,23 @@ public void OnInvokeReturn(long invokeId, Object returnValue) }); } - internal T ReturnToObject(object val) + internal T? ReturnToObject(object val) { return ReturnToObject(val, null); } - internal T ReturnToObject(object val, string? typeGuess) + internal T? ReturnToObject(object? val, string? typeGuess) { if (val == null) { - return default(T); + return default(T?); } val = ConvertReturnValue(val, false, typeGuess); - return (T)val; + return (T?)val; } - public virtual object FindByName(string name) + public virtual object? FindByName(string name) { if ("mainControl".Equals(name)) { @@ -2194,19 +2234,23 @@ public virtual object FindByName(string name) return null; } - private object GetObjectById(long objId) + private object? GetObjectById(long objId) { //TODO: this return null; } - internal int ReturnToInt(object val) + internal int ReturnToInt(object? val) { if (val == null) { return 0; } val = ConvertReturnValue(val); + if (val == null) + { + return 0; + } if (val is String) { return int.Parse((String)val); @@ -2217,11 +2261,12 @@ internal int ReturnToInt(object val) } else { - return int.Parse(val.ToString()); + var stringVal = val.ToString(); + return stringVal != null ? int.Parse(stringVal) : 0; } } - internal double ReturnToDouble(object val) + internal double ReturnToDouble(object? val) { if (val == null) { @@ -2246,11 +2291,12 @@ internal double ReturnToDouble(object val) else { //Console.WriteLine(val); - return Double.Parse(val.ToString()); + var stringVal = val.ToString(); + return stringVal != null ? Double.Parse(stringVal) : double.NaN; } } - internal long ReturnToLong(object val) + internal long ReturnToLong(object? val) { if (val == null) { @@ -2274,25 +2320,35 @@ internal long ReturnToLong(object val) } else { + var stringVal = val.ToString(); //Console.WriteLine(val); - return (long)Double.Parse(val.ToString()); + return stringVal != null ? (long)Double.Parse(stringVal) : Int64.MinValue; } } - internal DateTime[] ReturnToDateArray(object val) + internal DateTime[] ReturnToDateArray(object? val) { if (val == null) { - return null; + return Array.Empty(); } val = ConvertReturnValue(val); if (val == null) { - return null; + return Array.Empty(); } try { - var arr = JsonSerializer.Deserialize((string)val.ToString(), SerializerContext.ObjectArray); + var stringVal = val.ToString(); + if (stringVal == null) + { + return Array.Empty(); + } + var arr = JsonSerializer.Deserialize(stringVal, SerializerContext.ObjectArray); + if (arr == null) + { + return Array.Empty(); + } DateTime[] ret = new DateTime[arr.Length]; for (int i = 0; i < arr.Length; i++) { @@ -2304,11 +2360,11 @@ internal DateTime[] ReturnToDateArray(object val) } catch (Exception e) { - return null; + return Array.Empty(); } } - internal DateTime ReturnToDate(object val, bool tryConvertValue = true) + internal DateTime ReturnToDate(object? val, bool tryConvertValue = true) { if (val == null) { @@ -2329,11 +2385,11 @@ internal DateTime ReturnToDate(object val, bool tryConvertValue = true) switch (RoundTripDateConversion) { case RoundTripDateConversion.UTC: - return DateTime.Parse((String)val.ToString(), CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind); + return DateTime.Parse((string)val, CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind); case RoundTripDateConversion.Auto: case RoundTripDateConversion.Local: default: - return DateTime.Parse((String)val.ToString(), CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind).ToLocalTime(); + return DateTime.Parse((string)val, CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind).ToLocalTime(); } } else if (val is IConvertible) @@ -2344,25 +2400,35 @@ internal DateTime ReturnToDate(object val, bool tryConvertValue = true) else { //Console.WriteLine(val); + var dateString = val.ToString(); + if (dateString == null) + { + return DateTime.MinValue; + } + switch (RoundTripDateConversion) { case RoundTripDateConversion.UTC: - return DateTime.Parse((String)val.ToString(), CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind); + return DateTime.Parse(dateString, CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind); case RoundTripDateConversion.Auto: case RoundTripDateConversion.Local: default: - return DateTime.Parse((String)val.ToString(), CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind).ToLocalTime(); + return DateTime.Parse(dateString, CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind).ToLocalTime(); } } } - internal bool ReturnToBoolean(object val) + internal bool ReturnToBoolean(object? val) { if (val == null) { return false; } val = ConvertReturnValue(val); + if (val == null) + { + return false; + } if (val is bool) { return (bool)val; @@ -2373,11 +2439,12 @@ internal bool ReturnToBoolean(object val) } else { - return Boolean.Parse(val.ToString()); + var stringVal = val.ToString(); + return stringVal != null ? Boolean.Parse(stringVal) : false; } } - internal string ComponentToJson(object val, int index) + internal string? ComponentToJson(object val, int index) { if (val is BaseRendererControl || val is BaseRendererElement) { @@ -2408,7 +2475,7 @@ internal String BooleanToString(bool val) return ((bool)val).ToString().ToLower(); } - internal string ObjectToParam(object val) + internal string ObjectToParam(object? val) { using (MemoryStream ms = new MemoryStream()) { @@ -2422,7 +2489,7 @@ internal string ObjectToParam(object val) } } - internal string ObjectToParam(object val, Type type) + internal string ObjectToParam(object? val, Type type) { using (MemoryStream ms = new MemoryStream()) { @@ -2436,15 +2503,16 @@ internal string ObjectToParam(object val, Type type) } } - internal void ObjectToParam(SerializationContext context, object val) + internal void ObjectToParam(SerializationContext? context, object? val) { + ArgumentNullException.ThrowIfNull(context); if (val == null) { context.Writer.WriteNullValue(); return; } var w = context.Writer; - Guid id = _dataSourceManager.FindItemId(val); + Guid id = _dataSourceManager?.FindItemId(val) ?? Guid.Empty; var typeName = ""; @@ -2519,7 +2587,7 @@ internal void ObjectToParam(SerializationContext context, object val) w.WriteStringValue(val.ToString()); } } - internal void ObjectToParam(SerializationContext c, string propertyName, object val) + internal void ObjectToParam(SerializationContext c, string propertyName, object? val) { var w = c.Writer; if (val == null) @@ -2527,7 +2595,7 @@ internal void ObjectToParam(SerializationContext c, string propertyName, object w.WriteNull(propertyName); return; } - Guid id = _dataSourceManager.FindItemId(val); + Guid id = _dataSourceManager?.FindItemId(val) ?? Guid.Empty; string typeName = ""; if (val is JsonSerializable) @@ -2535,7 +2603,7 @@ internal void ObjectToParam(SerializationContext c, string propertyName, object if (val is BaseRendererControl) { - typeName = ((BaseRendererControl)val).Type; + typeName = ((BaseRendererControl)val).Type ?? ""; } else if (val is BaseRendererElement) { @@ -2601,7 +2669,7 @@ internal void ObjectToParam(SerializationContext c, string propertyName, object w.WriteString(propertyName, val.ToString()); } } - internal void ObjectToParam(SerializationContext c, Type type, object val) + internal void ObjectToParam(SerializationContext c, Type type, object? val) { if (type.IsEnum) { @@ -2630,24 +2698,15 @@ internal void ObjectToParam(SerializationContext c, Type type, object val) ObjectToParam(c, val); } - internal string ReturnToString(object val) + internal string ReturnToString(object? val) { - if (val == null) - { - return null; - } val = ConvertReturnValue(val); - - if (val == null) - { - return null; - } - return val.ToString(); + return val?.ToString() ?? String.Empty; } - internal string StringToString(object val) + internal string? StringToString(object? val) { - return val == null ? null : JsonSerializer.Serialize(val.ToString(), SerializerContext.String); + return val == null ? null : JsonSerializer.Serialize(val.ToString() ?? string.Empty, SerializerContext.String); //return val == null ? null : val.ToString(); } @@ -2659,16 +2718,16 @@ protected virtual bool UseCamelEnumValues } } - protected string Camelize(string value) + protected string Camelize(string? value) { if (value == null || value.Length == 0) { - return value; + return value ?? string.Empty; } return value.Substring(0, 1).ToLower() + value.Substring(1); } - protected string ToPascal(string value) + protected string? ToPascal(string? value) { if (value == null || value.Length == 0) { @@ -2677,7 +2736,7 @@ protected string ToPascal(string value) return value.Substring(0, 1).ToUpper() + value.Substring(1); } - internal string EnumToString(T val) where T : struct + internal string? EnumToString(T val) where T : struct { if (UseCamelEnumValues) { @@ -2687,12 +2746,8 @@ internal string EnumToString(T val) where T : struct return val.ToString(); } - internal T StringToEnum(Object val) where T : struct + internal T StringToEnum(Object? val) where T : struct { - if (val == null) - { - return default(T); - } val = ConvertReturnValue(val); if (val == null) { @@ -2707,7 +2762,7 @@ internal T StringToEnum(Object val) where T : struct return default(T); } - internal string ObjectArrayToParam(object[] arr) + internal string? ObjectArrayToParam(object[]? arr) { if (arr == null) { @@ -2748,7 +2803,7 @@ internal string ObjectArrayToParam(object[] arr) // } } - internal string StringArrayToString(string[] arr) + internal string? StringArrayToString(string[]? arr) { // object jarr = new JSONArray(); // try { @@ -2761,7 +2816,7 @@ internal string StringArrayToString(string[] arr) // return jarr.toString(); try { - return JsonSerializer.Serialize(arr, SerializerContext.StringArray); + return JsonSerializer.Serialize(arr!, SerializerContext.StringArray); } catch (Exception e) { @@ -2769,7 +2824,7 @@ internal string StringArrayToString(string[] arr) } } - internal string IntArrayToString(int[] arr) + internal string? IntArrayToString(int[]? arr) { // object jarr = new JSONArray(); // try { @@ -2782,7 +2837,7 @@ internal string IntArrayToString(int[] arr) // return jarr.toString(); try { - return JsonSerializer.Serialize(arr, SerializerContext.Int32Array); + return JsonSerializer.Serialize(arr!, SerializerContext.Int32Array); } catch (Exception e) { @@ -2790,7 +2845,7 @@ internal string IntArrayToString(int[] arr) } } - internal string DoubleArrayToString(double[] arr) + internal string? DoubleArrayToString(double[]? arr) { // object jarr = new JSONArray(); // try { @@ -2803,7 +2858,7 @@ internal string DoubleArrayToString(double[] arr) // return jarr.toString(); try { - return JsonSerializer.Serialize(arr, SerializerContext.DoubleArray); + return JsonSerializer.Serialize(arr!, SerializerContext.DoubleArray); } catch (Exception e) { @@ -2811,58 +2866,74 @@ internal string DoubleArrayToString(double[] arr) } } - internal object[] ReturnToObjectArray(object val) + internal object[] ReturnToObjectArray(object? val) { - if (val == null) - { - return null; - } val = ConvertReturnValue(val); if (val == null) { - return null; + return Array.Empty(); } try { - var arr = JsonSerializer.Deserialize((string)val.ToString(), SerializerContext.ObjectArray); + var arr = JsonSerializer.Deserialize(val.ToString() ?? "", SerializerContext.ObjectArray); + if (arr == null) + { + return Array.Empty(); + } Object[] ret = new Object[arr.Length]; for (int i = 0; i < arr.Length; i++) { - Object ele = arr[i]; + Object? ele = arr[i]; ele = ConvertReturnValue(ele); - ret[i] = ele; + if (ele != null) + { + ret[i] = ele; + } } return ret; } catch (Exception e) { - return null; + return Array.Empty(); } } - internal T[] ReturnToObjectArray(object val) + internal T[]? ReturnToObjectArray(object? val) { return ReturnToObjectArray(val, null); } - internal T[] ReturnToObjectArray(object val, string typeGuess) + internal T[]? ReturnToObjectArray(object? val, string? typeGuess) { + val = ConvertReturnValue(val); + if (val == null) { return null; } - val = ConvertReturnValue(val); try { - var arr = JsonSerializer.Deserialize((string)val.ToString(), SerializerContext.DictionaryStringObjectArray); + var stringVal = val.ToString(); + if (stringVal == null) + { + return null; + } + var arr = JsonSerializer.Deserialize(stringVal, SerializerContext.DictionaryStringObjectArray); + if (arr == null) + { + return null; + } T[] ret = new T[arr.Length]; for (int i = 0; i < arr.Length; i++) { - Object ele = arr[i]; + Object? ele = arr[i]; //Console.WriteLine("converting obj"); //Console.WriteLine(ele); ele = ConvertReturnValue(ele, false, typeGuess); - ret[i] = (T)ele; + if (ele != null) + { + ret[i] = (T)ele; + } } return ret; } @@ -2872,12 +2943,8 @@ internal T[] ReturnToObjectArray(object val, string typeGuess) } } - internal string[] ReturnToStringArray(object val) + internal string[]? ReturnToStringArray(object? val) { - if (val == null) - { - return null; - } val = ConvertReturnValue(val); if (val == null) { @@ -2886,12 +2953,20 @@ internal string[] ReturnToStringArray(object val) try { var valStr = val.ToString(); - var arr = JsonSerializer.Deserialize((string)valStr, SerializerContext.StringArray); + if (valStr == null) + { + return null; + } + var arr = JsonSerializer.Deserialize(valStr, SerializerContext.StringArray); + if (arr == null) + { + return null; + } string[] ret = new string[arr.Length]; for (int i = 0; i < arr.Length; i++) { - string ele = arr[i] != null ? arr[i].ToString() : null; - ret[i] = ele; + // Elements can be JSON nulls; keep them in place. + ret[i] = arr[i]; } return ret; } @@ -2901,16 +2976,25 @@ internal string[] ReturnToStringArray(object val) } } - internal double[] ReturnToDoubleArray(object val) + internal double[]? ReturnToDoubleArray(object? val) { + val = ConvertReturnValue(val); if (val == null) { return null; } - val = ConvertReturnValue(val); try { - var arr = JsonSerializer.Deserialize((string)val.ToString(), SerializerContext.ObjectArray); + var stringVal = val.ToString(); + if (stringVal == null) + { + return null; + } + var arr = JsonSerializer.Deserialize(stringVal, SerializerContext.ObjectArray); + if (arr == null) + { + return null; + } double[] ret = new double[arr.Length]; for (int i = 0; i < arr.Length; i++) { @@ -2925,16 +3009,20 @@ internal double[] ReturnToDoubleArray(object val) } } - internal int[] ReturnToIntArray(object val) + internal int[]? ReturnToIntArray(object? val) { + val = ConvertReturnValue(val); if (val == null) { return null; } - val = ConvertReturnValue(val); try { - var arr = JsonSerializer.Deserialize((string)val.ToString(), SerializerContext.ObjectArray); + var arr = JsonSerializer.Deserialize(val.ToString() ?? "[]", SerializerContext.ObjectArray); + if (arr == null) + { + return null; + } int[] ret = new int[arr.Length]; for (int i = 0; i < arr.Length; i++) { @@ -2982,7 +3070,7 @@ protected internal void OnElementNameChanged(BaseRendererElement element, string } } - internal void SetHandler(string name, string propertyName, EventCallback? handler, Action onArgs = null) where T : BaseRendererElement, new() + internal void SetHandler(string name, string propertyName, EventCallback? handler, Action? onArgs = null) where T : BaseRendererElement, new() { if (!handler.HasValue) { @@ -2990,23 +3078,34 @@ protected internal void OnElementNameChanged(BaseRendererElement element, string _handlers.Remove(name + "/" + propertyName); return; } - Action inner = (sender, args) => + Action inner = (sender, args) => { + // Native void events (e.g. focus/blur) legitimately deliver null args, + // so only bail out when a non-null payload is not the expected dictionary. + if (args is not null and not Dictionary) + { + return; + } + var eventArgs = args as Dictionary; + T a = new T(); BaseRendererElement ele = (BaseRendererElement)a; ele.Parent = this; - ele.FromEventJson(this, (Dictionary)args); + ele.FromEventJson(this, eventArgs); //Console.WriteLine("invoking async"); if (onArgs != null) { onArgs(a); } var task = handler?.InvokeAsync(a); - if (task.Exception != null) + if (task?.Exception != null) { throw task.Exception; } - ele.ToEventJson(this, (Dictionary)args); + if (eventArgs != null) + { + ele.ToEventJson(this, eventArgs); + } ele.Parent = (null); }; @@ -3014,7 +3113,7 @@ protected internal void OnElementNameChanged(BaseRendererElement element, string _handlers[name + "/" + propertyName] = inner; } - internal void SetHandlerSimple(string name, string propertyName, EventCallback? handler, Func getReturn, Action onArgs = null) + internal void SetHandlerSimple(string name, string propertyName, EventCallback? handler, Func getReturn, Action? onArgs = null) { if (!handler.HasValue) { @@ -3022,16 +3121,16 @@ internal void SetHandlerSimple(string name, string propertyName, EventCallbac _handlers.Remove(name + "/" + propertyName); return; } - Action inner = (sender, args) => + Action inner = (sender, args) => { - T a = getReturn(args); + T a = getReturn(args!); //Console.WriteLine("invoking async"); if (onArgs != null) { onArgs(a); } var task = handler?.InvokeAsync(a); - if (task.Exception != null) + if (task?.Exception != null) { throw task.Exception; } @@ -3041,7 +3140,7 @@ internal void SetHandlerSimple(string name, string propertyName, EventCallbac _handlers[name + "/" + propertyName] = inner; } - internal void SetActionHandler(string name, string propertyName, Action handler, Action onArgs = null) where T : BaseRendererElement, new() + internal void SetActionHandler(string name, string propertyName, Action handler, Action? onArgs = null) where T : BaseRendererElement, new() { if (handler == null) { @@ -3049,19 +3148,30 @@ internal void SetHandlerSimple(string name, string propertyName, EventCallbac _handlers.Remove(name + "/" + propertyName); return; } - Action inner = (sender, args) => + Action inner = (sender, args) => { + // Native void events (e.g. focus/blur) legitimately deliver null args, + // so only bail out when a non-null payload is not the expected dictionary. + if (args is not null and not Dictionary) + { + return; + } + var eventArgs = args as Dictionary; + T a = new T(); BaseRendererElement ele = (BaseRendererElement)a; ele.Parent = this; - ele.FromEventJson(this, (Dictionary)args); + ele.FromEventJson(this, eventArgs); //Console.WriteLine("invoking async"); if (onArgs != null) { onArgs(a); } handler(a); - ele.ToEventJson(this, (Dictionary)args); + if (eventArgs != null) + { + ele.ToEventJson(this, eventArgs); + } ele.Parent = (null); }; @@ -3069,7 +3179,7 @@ internal void SetHandlerSimple(string name, string propertyName, EventCallbac _handlers[name + "/" + propertyName] = inner; } - internal void SetActionHandlerSimple(string name, string propertyName, Action handler, Func getReturn, Action onArgs = null) + internal void SetActionHandlerSimple(string name, string propertyName, Action handler, Func getReturn, Action? onArgs = null) { if (handler == null) { @@ -3077,9 +3187,9 @@ internal void SetActionHandlerSimple(string name, string propertyName, Action _handlers.Remove(name + "/" + propertyName); return; } - Action inner = (sender, args) => + Action inner = (sender, args) => { - T a = getReturn(args); + T a = getReturn(args!); //Console.WriteLine("invoking async"); if (onArgs != null) @@ -3102,16 +3212,25 @@ internal void OnRaiseEvent(string name, string propertyName, string args) { //Console.WriteLine("got handler"); bool usedTempParent = false; - Object senderObj = null; + Object? senderObj = null; try { var obj = JsonSerializer.Deserialize((string)args.ToString(), SerializerContext.DictionaryStringObject); + if (obj == null) + { + return; + } //Console.WriteLine(args.ToString()); - object sender = obj["sender"]; + object? sender = obj["sender"]; if (sender is JsonElement && ((JsonElement)sender).ValueKind == JsonValueKind.String) { - sender = JsonSerializer.Deserialize(((JsonElement)sender).GetString(), SerializerContext.DictionaryStringObject); + var stringVal = ((JsonElement)sender).GetString(); + if (stringVal == null) + { + return; + } + sender = JsonSerializer.Deserialize(stringVal, SerializerContext.DictionaryStringObject); } senderObj = ConvertReturnValue(sender); @@ -3125,7 +3244,7 @@ internal void OnRaiseEvent(string name, string propertyName, string args) } var argsString = obj["args"] != null ? obj["args"].ToString() : null; - object val = null; + object? val = null; if (argsString != null) { @@ -3141,7 +3260,7 @@ internal void OnRaiseEvent(string name, string propertyName, string args) // Avoid double unwrapping primitive value types. This primarily only applies to events with primitive types for event args which // there are not many of. bool needsConversion = true; - if (dict.ContainsKey("retType")) + if (dict != null && dict.ContainsKey("retType")) { var retType = ((JsonElement)dict["retType"]).ToString(); if ("string".Equals(retType) || @@ -3218,7 +3337,7 @@ private async Task TrySendCleanupAsync() { try { - if (IgBlazor == null || !IgBlazor.IsRuntimeValid(_shouldReevaluateRuntime)) + if (_igBlazor == null || !_igBlazor.IsRuntimeValid(_shouldReevaluateRuntime)) { return; } @@ -3257,6 +3376,13 @@ private async Task TrySendCleanupAsync() // (double-dispose race or host-driven teardown). Nothing left to release. Debug.WriteLine($"[IgniteUI.Blazor] TrySendCleanupAsync: target already disposed; cleanup skipped. {ex.Message}"); } + catch (InvalidOperationException ex) + { + // Ordered after ObjectDisposedException, which derives from this type. Reached when + // the component is disposed before dependency injection assigned IgBlazor: there is + // no runtime to send a cleanup message to. + Debug.WriteLine($"[IgniteUI.Blazor] TrySendCleanupAsync: component never received IgBlazor; cleanup skipped. {ex.Message}"); + } catch (JSException ex) { // The JS side rejected or errored during cleanup. There is no meaningful @@ -3274,18 +3400,18 @@ private async Task TrySendCleanupAsync() } } - public async Task SetResourceStringAsync(string grouping, string id, string value) + public async Task SetResourceStringAsync(string grouping, string id, string value) { - if (!IgBlazor.IsRuntimeValid(_shouldReevaluateRuntime)) + if (!IgBlazor.IsRuntimeValid(_shouldReevaluateRuntime) || JsRuntime == null) { return null; } return await JsRuntime.InvokeAsync("igSetResourceString", new object[] { "set", grouping, id, value }); } - public async Task SetResourceStringAsync(string grouping, string json) + public async Task SetResourceStringAsync(string grouping, string json) { - if (!IgBlazor.IsRuntimeValid(_shouldReevaluateRuntime)) + if (!IgBlazor.IsRuntimeValid(_shouldReevaluateRuntime) || JsRuntime == null) { return null; } @@ -3294,7 +3420,7 @@ public async Task SetResourceStringAsync(string grouping, string json) protected void SetPropertyValue(object item, System.Reflection.PropertyInfo property, JsonElement jsonElement) { - System.Type type = Nullable.GetUnderlyingType(property.PropertyType); + System.Type? type = Nullable.GetUnderlyingType(property.PropertyType); if (type == null) { type = property.PropertyType; @@ -3347,7 +3473,7 @@ protected void SetPropertyValue(object item, System.Reflection.PropertyInfo prop } protected void SetPropertyValue(object item, System.Reflection.PropertyInfo property, object value) { - System.Type type = Nullable.GetUnderlyingType(property.PropertyType); + System.Type? type = Nullable.GetUnderlyingType(property.PropertyType); if (type == null) { type = property.PropertyType; @@ -3363,7 +3489,8 @@ protected void SetPropertyValue(object item, System.Reflection.PropertyInfo prop if (type.IsArray) { var src = (Array)value; - var dest = Array.CreateInstance(type.GetElementType(), src.Length); + var elementType = type.GetElementType() ?? typeof(object); + var dest = Array.CreateInstance(elementType, src.Length); Array.Copy(src, dest, src.Length); property.SetValue(item, dest); return; @@ -3447,7 +3574,7 @@ public interface IIgniteUIBlazorSettings { bool ForceJsonDataMarshalling { get; } IgniteUIJsonSerializerOptions JsonSerializerOptions { get; } - ReadOnlyCollection ModulesToLoad { get; } + ReadOnlyCollection? ModulesToLoad { get; } } public class IgniteUIBlazorSettings @@ -3455,7 +3582,7 @@ public class IgniteUIBlazorSettings { public bool ForceJsonDataMarshalling { get; private set; } public IgniteUIJsonSerializerOptions JsonSerializerOptions { get; private set; } - public ReadOnlyCollection ModulesToLoad { get; private set; } + public ReadOnlyCollection? ModulesToLoad { get; private set; } public IgniteUIBlazorSettings() { @@ -3490,7 +3617,7 @@ public IgniteUIBlazorSettings WithJsonSerializerOptions(IgniteUIJsonSerializerOp return newSettings; } - public IgniteUIBlazorSettings WithModulesToLoad(ReadOnlyCollection modulesToLoad) + public IgniteUIBlazorSettings WithModulesToLoad(ReadOnlyCollection? modulesToLoad) { var newSettings = new IgniteUIBlazorSettings(this); newSettings.ModulesToLoad = modulesToLoad; @@ -3508,7 +3635,7 @@ internal IgniteUIBlazorSettings(IIgniteUIBlazorSettings settings) public interface IIgniteUIBlazor { IJSRuntime JsRuntime { get; } - IIgniteUIBlazorSettings Settings { get; } + IIgniteUIBlazorSettings? Settings { get; } WebCallback WebCallback { get; } void RequestLoad(string moduleName); bool IsLoadRequested(string moduleName); @@ -3521,7 +3648,7 @@ public class IgniteUIBlazor : IIgniteUIBlazor private bool _isRuntimeValid = false; private bool _isRuntimeChecked = false; private bool _isRemoteRuntime = false; - private System.Reflection.PropertyInfo _remoteRuntimeProp; + private System.Reflection.PropertyInfo? _remoteRuntimeProp; [UnconditionalSuppressMessage("Trimming", "IL2075", Justification = "Library module types carry [IgbModule], preserving Register whenever the type is kept; third-party module types must be preserved by the app — see docs/TRIMMING.md.")] public IgniteUIBlazor(IJSRuntime runtime, IIgniteUIBlazorSettings settings) @@ -3561,7 +3688,7 @@ public IgniteUIBlazor(IJSRuntime runtime) } public IJSRuntime JsRuntime { get; private set; } - public IIgniteUIBlazorSettings Settings { get; private set; } + public IIgniteUIBlazorSettings? Settings { get; private set; } public WebCallback WebCallback { get; private set; } private ConcurrentDictionary _loadedCache = new ConcurrentDictionary(); @@ -3608,7 +3735,7 @@ public bool IsRuntimeValid(bool reevaluate = false) } else if (_remoteRuntimeProp != null) { - _isRuntimeValid = (bool)_remoteRuntimeProp.GetValue(JsRuntime); + _isRuntimeValid = (bool)(_remoteRuntimeProp.GetValue(JsRuntime) ?? false); _isRemoteRuntime = true; } else @@ -3622,7 +3749,7 @@ public bool IsRuntimeValid(bool reevaluate = false) { if (reevaluate && _isRemoteRuntime) { - _isRuntimeValid = (bool)_remoteRuntimeProp.GetValue(JsRuntime); + _isRuntimeValid = (bool)(_remoteRuntimeProp?.GetValue(JsRuntime) ?? false); } } return _isRuntimeValid; @@ -3631,7 +3758,7 @@ public bool IsRuntimeValid(bool reevaluate = false) public class SequenceInfo { - private ReadOnlyCollection _attributeKeys = null; + private ReadOnlyCollection? _attributeKeys = null; public ReadOnlyCollection AttributeKeys { get @@ -3657,27 +3784,27 @@ internal SequenceInfo(int startSequence) SequenceMap = new Dictionary(); } - internal string TransformKey(string attributeKey) + internal string TransformKey(string? attributeKey) { - if (_transforms.ContainsKey(attributeKey)) + if (attributeKey != null && _transforms.ContainsKey(attributeKey)) { return _transforms[attributeKey]; } - return attributeKey; + return attributeKey ?? ""; } - internal bool IsTransformedEnum(string attributeKey) + internal bool IsTransformedEnum(string? attributeKey) { - if (_enumTransforms.ContainsKey(attributeKey)) + if (attributeKey != null && _enumTransforms.ContainsKey(attributeKey)) { return true; } return false; } - internal string TransformEnumValue(string attributeKey, string fieldName) + internal string TransformEnumValue(string? attributeKey, string? fieldName) { - if (_enumTransforms.ContainsKey(attributeKey)) + if (attributeKey != null && fieldName != null && _enumTransforms.ContainsKey(attributeKey)) { var d = _enumTransforms[attributeKey]; if (d.ContainsKey(fieldName.ToLower())) @@ -3685,12 +3812,12 @@ internal string TransformEnumValue(string attributeKey, string fieldName) return d[fieldName.ToLower()]; } } - return fieldName; + return fieldName ?? ""; } - internal void AddSequence(string attributeKey, string wcName = null, Dictionary wcEnumTransform = null) + internal void AddSequence(string? attributeKey, string? wcName = null, Dictionary? wcEnumTransform = null) { - if (!_keysSet.Contains(attributeKey)) + if (attributeKey != null && !_keysSet.Contains(attributeKey)) { _dirty = true; _keysSet.Add(attributeKey); diff --git a/src/componentsBase/BaseRendererElement.cs b/src/componentsBase/BaseRendererElement.cs index f6c2af87..d535b66c 100644 --- a/src/componentsBase/BaseRendererElement.cs +++ b/src/componentsBase/BaseRendererElement.cs @@ -11,13 +11,13 @@ public partial class BaseRendererElement : ComponentBase, JsonSerializable // Console.WriteLine("constructing: " + this.GetType().Name); // } - private IIgniteUIBlazor _igBlazor; + private IIgniteUIBlazor? _igBlazor; [Inject] protected IIgniteUIBlazor IgBlazor { get { - return _igBlazor; + return _igBlazor ?? throw new InvalidOperationException("IgBlazor accessed before dependency injection completed."); } set { @@ -81,7 +81,7 @@ internal void DetachChild(BaseRendererElement child) } } - protected virtual string ParentTypeName + protected virtual string? ParentTypeName { get { @@ -97,7 +97,7 @@ protected virtual bool UseDirectRender } } - [Parameter] public RenderFragment ChildContent { get; set; } + [Parameter] public RenderFragment? ChildContent { get; set; } protected virtual bool SupportsVisualChildren { @@ -186,7 +186,7 @@ protected void OnElementNameChanged(BaseRendererElement element, string oldName, { ((BaseRendererElement)CurrParent).OnElementNameChanged(element, oldName, newName); } - else + else if (CurrParent is BaseRendererControl) { ((BaseRendererControl)CurrParent).OnElementNameChanged(element, oldName, newName); } @@ -199,7 +199,7 @@ protected void OnElementNameChanged(BaseRendererElement element, string oldName, { ((BaseRendererElement)CurrParent).OnElementNameChanged(element, oldName, newName); } - else + else if (CurrParent is BaseRendererControl) { ((BaseRendererControl)CurrParent).OnElementNameChanged(element, oldName, newName); } @@ -207,8 +207,8 @@ protected void OnElementNameChanged(BaseRendererElement element, string oldName, } } - private object _tempParent = null; - internal object TempParent + private object? _tempParent = null; + internal object? TempParent { get { @@ -220,14 +220,14 @@ internal object TempParent } } - private Object _parent = null; + private Object? _parent = null; private class RefChange { - public String propertyName; - public Object oldValue; - public Object newValue; - public Action refChanged; + public String propertyName = string.Empty; + public Object? oldValue; + public Object? newValue; + public Action? refChanged = null; public bool isScript; public bool isElement; } @@ -235,7 +235,7 @@ private class RefChange private List _queuedTemplateUpdates = new List(); private List _deferredNameChanges = new List(); - private void QueueRefChange(String propertyName, Object oldValue, Object newValue, bool isScript, bool isElement, Action refChanged) + private void QueueRefChange(String propertyName, Object? oldValue, Object? newValue, bool isScript, bool isElement, Action refChanged) { RefChange c = new RefChange(); c.propertyName = propertyName; @@ -249,15 +249,18 @@ private void QueueRefChange(String propertyName, Object oldValue, Object newValu private void FlushRefs() { - while (_queuedChanges.Count > 0) + while (_queuedChanges != null && _queuedChanges.Count > 0) { - RefChange c = _queuedChanges.First.Value; + RefChange? c = _queuedChanges.First?.Value; _queuedChanges.RemoveFirst(); - OnRefChanged(c.propertyName, c.oldValue, c.newValue, c.isScript, c.isElement, c.refChanged); + if (c != null && c.refChanged != null) + { + OnRefChanged(c.propertyName, c.oldValue, c.newValue, c.isScript, c.isElement, c.refChanged); + } } } - public object Parent + public object? Parent { get { @@ -265,7 +268,7 @@ public object Parent } internal set { - Object oldParent = _parent; + Object? oldParent = _parent; _parent = value; _serializeDirty = true; if (_parent != null) @@ -327,17 +330,17 @@ protected virtual string MethodTarget } } - protected async Task InvokeMethod(string methodName, object[] arguments, string[] types, ElementReference[] nativeElements = null) + protected async Task InvokeMethod(string methodName, object[] arguments, string[] types, ElementReference[]? nativeElements = null) { return await InvokeMethodHelper(MethodTarget, methodName, arguments, types, nativeElements); } - protected object InvokeMethodSync(string methodName, object[] arguments, string[] types, ElementReference[] nativeElements = null) + protected object? InvokeMethodSync(string methodName, object[] arguments, string[] types, ElementReference[]? nativeElements = null) { return InvokeMethodHelperSync(MethodTarget, methodName, arguments, types, nativeElements); } - protected async Task InvokeMethodHelper(string target, string methodName, object[] arguments, string[] types, ElementReference[] nativeElements) + protected async Task InvokeMethodHelper(string target, string methodName, object[] arguments, string[] types, ElementReference[]? nativeElements) { if (CurrParent == null) { @@ -353,7 +356,7 @@ protected async Task InvokeMethodHelper(string target, string methodName } } - protected object InvokeMethodHelperSync(string target, string methodName, object[] arguments, string[] types, ElementReference[] nativeElements) + protected object? InvokeMethodHelperSync(string target, string methodName, object[] arguments, string[] types, ElementReference[]? nativeElements) { if (CurrParent == null) { @@ -385,7 +388,7 @@ internal void OnPropertyPropagatedOut(string name, string propertyName) } } - internal void UpdateTemplate(string contentType, object template, Type type) + internal void UpdateTemplate(string contentType, object? template, Type type) { Action templateUpdate = () => { @@ -394,7 +397,7 @@ internal void UpdateTemplate(string contentType, object template, Type type) ((BaseRendererControl)_parent).ChildDirty(this); ((BaseRendererControl)_parent).UpdateTemplate(contentType, template, type); } - else + else if (_parent is BaseRendererElement) { ((BaseRendererElement)_parent).ChildDirty(this); ((BaseRendererElement)_parent).UpdateTemplate(contentType, template, type); @@ -410,7 +413,7 @@ internal void UpdateTemplate(string contentType, object template, Type type) } } - internal void OnRefChanged(string propertyName, object oldValue, object newValue, bool isScript, bool isElement, Action refChanged) + internal void OnRefChanged(string propertyName, object? oldValue, object? newValue, bool isScript, bool isElement, Action refChanged) { _isDirtyRef[propertyName] = true; _isDirty[propertyName] = true; @@ -452,8 +455,12 @@ internal bool SuppressParentNotify } } - internal void MarkPropDirty(String propertyName) + internal void MarkPropDirty(String? propertyName) { + if (propertyName == null) + { + return; + } _isDirty[propertyName] = true; _hasDirty = true; _serializeDirty = true; @@ -523,7 +530,7 @@ public virtual string Type } } - public void Serialize(SerializationContext context, string propertyName = null) + public void Serialize(SerializationContext context, string? propertyName = null) { RendererSerializer ser = new RendererSerializer(context, this, Name); ser.Type = Type; @@ -559,7 +566,7 @@ protected void EnsureValid() } } - protected object CurrParent + protected object? CurrParent { get { @@ -571,48 +578,51 @@ protected object CurrParent } } - internal T ReturnToObject(Object val) + internal T? ReturnToObject(Object val) { return ReturnToObject(val, null); } - internal T ReturnToObject(Object val, string? typeGuess) + internal T? ReturnToObject(Object val, string? typeGuess) { EnsureValid(); if (CurrParent is BaseRendererElement) { return ((BaseRendererElement)CurrParent).ReturnToObject(val, typeGuess); } - else + else if (CurrParent is BaseRendererControl) { return ((BaseRendererControl)CurrParent).ReturnToObject(val, typeGuess); } + return default(T); } - internal int ReturnToInt(Object val) + internal int ReturnToInt(Object? val) { EnsureValid(); if (CurrParent is BaseRendererElement) { return ((BaseRendererElement)CurrParent).ReturnToInt(val); } - else + else if (CurrParent is BaseRendererControl) { return ((BaseRendererControl)CurrParent).ReturnToInt(val); } + return default(int); } - internal double ReturnToDouble(Object val) + internal double ReturnToDouble(Object? val) { EnsureValid(); if (CurrParent is BaseRendererElement) { return ((BaseRendererElement)CurrParent).ReturnToDouble(val); } - else + else if (CurrParent is BaseRendererControl) { return ((BaseRendererControl)CurrParent).ReturnToDouble(val); } + return default(double); } internal long ReturnToLong(Object val) @@ -622,36 +632,39 @@ internal long ReturnToLong(Object val) { return ((BaseRendererElement)CurrParent).ReturnToLong(val); } - else + else if (CurrParent is BaseRendererControl) { return ((BaseRendererControl)CurrParent).ReturnToLong(val); } + return default(long); } - internal DateTime ReturnToDate(Object val) + internal DateTime ReturnToDate(Object? val) { EnsureValid(); if (CurrParent is BaseRendererElement) { return ((BaseRendererElement)CurrParent).ReturnToDate(val); } - else + else if (CurrParent is BaseRendererControl) { return ((BaseRendererControl)CurrParent).ReturnToDate(val); } + return default(DateTime); } - internal String ComponentToJson(object val, int index) + internal String? ComponentToJson(object val, int index) { EnsureValid(); if (CurrParent is BaseRendererElement) { return ((BaseRendererElement)CurrParent).ComponentToJson(val, index); } - else + else if (CurrParent is BaseRendererControl) { return ((BaseRendererControl)CurrParent).ComponentToJson(val, index); } + return default(string); } internal string DateToString(DateTime val) @@ -661,10 +674,11 @@ internal string DateToString(DateTime val) { return ((BaseRendererElement)CurrParent).DateToString(val); } - else + else if (CurrParent is BaseRendererControl) { return ((BaseRendererControl)CurrParent).DateToString(val); } + return String.Empty; } internal string BooleanToString(bool val) @@ -674,240 +688,256 @@ internal string BooleanToString(bool val) { return ((BaseRendererElement)CurrParent).BooleanToString(val); } - else + else if (CurrParent is BaseRendererControl) { return ((BaseRendererControl)CurrParent).BooleanToString(val); } + return String.Empty; } - internal string EnumToString(T val) where T : struct + internal string? EnumToString(T val) where T : struct { EnsureValid(); if (CurrParent is BaseRendererElement) { return ((BaseRendererElement)CurrParent).EnumToString(val); } - else + else if (CurrParent is BaseRendererControl) { return ((BaseRendererControl)CurrParent).EnumToString(val); } + return default(string); } - internal T StringToEnum(Object val) where T : struct + internal T StringToEnum(Object? val) where T : struct { EnsureValid(); if (CurrParent is BaseRendererElement) { return ((BaseRendererElement)CurrParent).StringToEnum(val); } - else + else if (CurrParent is BaseRendererControl) { return ((BaseRendererControl)CurrParent).StringToEnum(val); } + return default(T); } - internal string ObjectArrayToParam(object[] arr) + internal string? ObjectArrayToParam(object[]? arr) { EnsureValid(); if (CurrParent is BaseRendererElement) { return ((BaseRendererElement)CurrParent).ObjectArrayToParam(arr); } - else + else if (CurrParent is BaseRendererControl) { return ((BaseRendererControl)CurrParent).ObjectArrayToParam(arr); } + return default(string); } - internal object[] ReturnToObjectArray(Object val) + internal object[] ReturnToObjectArray(Object? val) { EnsureValid(); if (CurrParent is BaseRendererElement) { return ((BaseRendererElement)CurrParent).ReturnToObjectArray(val); } - else + else if (CurrParent is BaseRendererControl) { return ((BaseRendererControl)CurrParent).ReturnToObjectArray(val); } + return Array.Empty(); } - internal T[] ReturnToObjectArray(Object val) + internal T[]? ReturnToObjectArray(Object? val) { return ReturnToObjectArray(val, null); } - internal T[] ReturnToObjectArray(Object val, string typeGuess) + internal T[]? ReturnToObjectArray(Object? val, string? typeGuess) { EnsureValid(); if (CurrParent is BaseRendererElement) { return ((BaseRendererElement)CurrParent).ReturnToObjectArray(val, typeGuess); } - else + else if (CurrParent is BaseRendererControl) { return ((BaseRendererControl)CurrParent).ReturnToObjectArray(val, typeGuess); } + return default; } - internal string[] ReturnToStringArray(Object val) + internal string[]? ReturnToStringArray(Object? val) { EnsureValid(); if (CurrParent is BaseRendererElement) { return ((BaseRendererElement)CurrParent).ReturnToStringArray(val); } - else + else if (CurrParent is BaseRendererControl) { return ((BaseRendererControl)CurrParent).ReturnToStringArray(val); } + return default; } - internal int[] ReturnToIntArray(Object val) + internal int[]? ReturnToIntArray(Object val) { EnsureValid(); if (CurrParent is BaseRendererElement) { return ((BaseRendererElement)CurrParent).ReturnToIntArray(val); } - else + else if (CurrParent is BaseRendererControl) { return ((BaseRendererControl)CurrParent).ReturnToIntArray(val); } + return default; } - internal double[] ReturnToDoubleArray(Object val) + internal double[]? ReturnToDoubleArray(Object? val) { EnsureValid(); if (CurrParent is BaseRendererElement) { return ((BaseRendererElement)CurrParent).ReturnToDoubleArray(val); } - else + else if (CurrParent is BaseRendererControl) { return ((BaseRendererControl)CurrParent).ReturnToDoubleArray(val); } + return default; } - internal string ObjectToParam(object val) + internal string ObjectToParam(object? val) { EnsureValid(); if (CurrParent is BaseRendererElement) { return ((BaseRendererElement)CurrParent).ObjectToParam(val); } - else + else if (CurrParent is BaseRendererControl) { return ((BaseRendererControl)CurrParent).ObjectToParam(val); } + return String.Empty; } - internal string ObjectToParam(object val, Type type) + internal string ObjectToParam(object? val, Type type) { EnsureValid(); if (CurrParent is BaseRendererElement) { return ((BaseRendererElement)CurrParent).ObjectToParam(val, type); } - else + else if (CurrParent is BaseRendererControl) { return ((BaseRendererControl)CurrParent).ObjectToParam(val, type); } + return String.Empty; } - internal void ObjectToParam(SerializationContext c, string propertyName, object val) + internal void ObjectToParam(SerializationContext c, string propertyName, object? val) { EnsureValid(); if (CurrParent is BaseRendererElement) { ((BaseRendererElement)CurrParent).ObjectToParam(c, propertyName, val); } - else + else if (CurrParent is BaseRendererControl) { ((BaseRendererControl)CurrParent).ObjectToParam(c, propertyName, val); } } - internal void ObjectToParam(SerializationContext c, object val) + internal void ObjectToParam(SerializationContext? c, object? val) { EnsureValid(); if (CurrParent is BaseRendererElement) { ((BaseRendererElement)CurrParent).ObjectToParam(c, val); } - else + else if (CurrParent is BaseRendererControl) { ((BaseRendererControl)CurrParent).ObjectToParam(c, val); } } - internal string ReturnToString(object val) + internal string ReturnToString(object? val) { EnsureValid(); if (CurrParent is BaseRendererElement) { return ((BaseRendererElement)CurrParent).ReturnToString(val); } - else + else if (CurrParent is BaseRendererControl) { return ((BaseRendererControl)CurrParent).ReturnToString(val); } + return String.Empty; } - internal bool ReturnToBoolean(object val) + internal bool ReturnToBoolean(object? val) { EnsureValid(); if (CurrParent is BaseRendererElement) { return ((BaseRendererElement)CurrParent).ReturnToBoolean(val); } - else + else if (CurrParent is BaseRendererControl) { return ((BaseRendererControl)CurrParent).ReturnToBoolean(val); } + return default; } - internal object ConvertReturnValue(object val, string typeGuess = null, bool acceptsNullIfMarshalDoesNotExist = false) + internal object? ConvertReturnValue(object? val, string? typeGuess = null, bool acceptsNullIfMarshalDoesNotExist = false) { EnsureValid(); if (CurrParent is BaseRendererElement) { return ((BaseRendererElement)CurrParent).ConvertReturnValue(val, typeGuess, acceptsNullIfMarshalDoesNotExist); } - else + else if (CurrParent is BaseRendererControl) { return ((BaseRendererControl)CurrParent).ConvertReturnValue(val, false, typeGuess, acceptsNullIfMarshalDoesNotExist); } + return null; } - internal object ReturnToPrimitive(object val) + internal object? ReturnToPrimitive(object? val) { EnsureValid(); if (CurrParent is BaseRendererElement) { return ((BaseRendererElement)CurrParent).ReturnToPrimitive(val); } - else + else if (CurrParent is BaseRendererControl) { return ((BaseRendererControl)CurrParent).ReturnToPrimitive(val); } + return null; } - internal T[] DowncastArray(object val) + internal T[]? DowncastArray(object val) { EnsureValid(); if (CurrParent is BaseRendererElement) { return ((BaseRendererElement)CurrParent).DowncastArray(val); } - else + else if (CurrParent is BaseRendererControl) { return ((BaseRendererControl)CurrParent).DowncastArray(val); } + return default; } private List _deferredHandlers = new List(); - internal void SetHandler(string name, string propertyName, EventCallback? handler, Action onArgs = null) where T : BaseRendererElement, new() + internal void SetHandler(string name, string propertyName, EventCallback? handler, Action? onArgs = null) where T : BaseRendererElement, new() { Action add = () => { @@ -915,7 +945,7 @@ internal T[] DowncastArray(object val) { ((BaseRendererElement)CurrParent).SetHandler(name, propertyName, handler, onArgs); } - else + else if (CurrParent is BaseRendererControl) { ((BaseRendererControl)CurrParent).SetHandler(name, propertyName, handler, onArgs); } @@ -929,7 +959,7 @@ internal T[] DowncastArray(object val) add(); } - internal void SetHandlerSimple(string name, string propertyName, EventCallback? handler, Func getReturn, Action onArgs = null) + internal void SetHandlerSimple(string name, string propertyName, EventCallback? handler, Func getReturn, Action? onArgs = null) { Action add = () => { @@ -937,7 +967,7 @@ internal void SetHandlerSimple(string name, string propertyName, EventCallbac { ((BaseRendererElement)CurrParent).SetHandlerSimple(name, propertyName, handler, getReturn, onArgs); } - else + else if (CurrParent is BaseRendererControl) { ((BaseRendererControl)CurrParent).SetHandlerSimple(name, propertyName, handler, getReturn, onArgs); } @@ -951,7 +981,7 @@ internal void SetHandlerSimple(string name, string propertyName, EventCallbac add(); } - internal void SetActionHandler(string name, string propertyName, Action handler, Action onArgs = null) where T : BaseRendererElement, new() + internal void SetActionHandler(string name, string propertyName, Action handler, Action? onArgs = null) where T : BaseRendererElement, new() { Action add = () => { @@ -959,7 +989,7 @@ internal void SetHandlerSimple(string name, string propertyName, EventCallbac { ((BaseRendererElement)CurrParent).SetActionHandler(name, propertyName, handler, onArgs); } - else + else if (CurrParent is BaseRendererControl) { ((BaseRendererControl)CurrParent).SetActionHandler(name, propertyName, handler, onArgs); } @@ -974,7 +1004,7 @@ internal void SetHandlerSimple(string name, string propertyName, EventCallbac } - internal void SetActionHandlerSimple(string name, string propertyName, Action handler, Func getReturn, Action onArgs = null) + internal void SetActionHandlerSimple(string name, string propertyName, Action handler, Func getReturn, Action? onArgs = null) { Action add = () => { @@ -982,7 +1012,7 @@ internal void SetActionHandlerSimple(string name, string propertyName, Action { ((BaseRendererElement)CurrParent).SetActionHandlerSimple(name, propertyName, handler, getReturn, onArgs); } - else + else if (CurrParent is BaseRendererControl) { ((BaseRendererControl)CurrParent).SetActionHandlerSimple(name, propertyName, handler, getReturn, onArgs); } @@ -996,74 +1026,78 @@ internal void SetActionHandlerSimple(string name, string propertyName, Action add(); } - internal string StringToString(object val) + internal string? StringToString(object? val) { EnsureValid(); if (CurrParent is BaseRendererElement) { return ((BaseRendererElement)CurrParent).StringToString(val); } - else + else if (CurrParent is BaseRendererControl) { return ((BaseRendererControl)CurrParent).StringToString(val); } + return default; } - internal string StringArrayToString(string[] val) + internal string? StringArrayToString(string[]? val) { EnsureValid(); if (CurrParent is BaseRendererElement) { return ((BaseRendererElement)CurrParent).StringArrayToString(val); } - else + else if (CurrParent is BaseRendererControl) { return ((BaseRendererControl)CurrParent).StringArrayToString(val); } + return default; } - internal string IntArrayToString(int[] val) + internal string? IntArrayToString(int[]? val) { EnsureValid(); if (CurrParent is BaseRendererElement) { return ((BaseRendererElement)CurrParent).IntArrayToString(val); } - else + else if (CurrParent is BaseRendererControl) { return ((BaseRendererControl)CurrParent).IntArrayToString(val); } + return default; } - internal string DoubleArrayToString(double[] val) + internal string? DoubleArrayToString(double[]? val) { EnsureValid(); if (CurrParent is BaseRendererElement) { return ((BaseRendererElement)CurrParent).DoubleArrayToString(val); } - else + else if (CurrParent is BaseRendererControl) { return ((BaseRendererControl)CurrParent).DoubleArrayToString(val); } + return default; } - protected internal virtual void FromEventJson(BaseRendererControl control, Dictionary args) + protected internal virtual void FromEventJson(BaseRendererControl control, Dictionary? args) { } - protected internal virtual void ToEventJson(BaseRendererControl control, Dictionary args) + protected internal virtual void ToEventJson(BaseRendererControl control, Dictionary args) { } - public virtual object FindByName(string name) + public virtual object? FindByName(string name) { return null; } - protected async Task SetResourceStringAsync(string grouping, string id, string value) + protected async Task SetResourceStringAsync(string grouping, string id, string value) { if (CurrParent == null) { @@ -1078,7 +1112,7 @@ protected async Task SetResourceStringAsync(string grouping, string id, return await ((BaseRendererControl)CurrParent).SetResourceStringAsync(grouping, id, value); } } - protected async Task SetResourceStringAsync(string grouping, string json) + protected async Task SetResourceStringAsync(string grouping, string json) { if (CurrParent == null) { diff --git a/src/componentsBase/CollectionAdapter.cs b/src/componentsBase/CollectionAdapter.cs index e6720be8..d83646e4 100644 --- a/src/componentsBase/CollectionAdapter.cs +++ b/src/componentsBase/CollectionAdapter.cs @@ -6,19 +6,19 @@ internal class CollectionAdapter where T : class where J : class { - private IList _queryItems; + private IList? _queryItems; private IList _manualItems = new List(); - private IList _allList; + private IList? _allList; private IList _target; - private IList _query; + private IList? _query; private Func _toTarget; private Action _onItemAdded; private Action _onItemRemoved; private bool _hasShiftedOnceAlready; - public CollectionAdapter(IList query, IList target, IList allList, Func toTarget, Action onItemAdded, Action onItemRemoved, Func collisionChecker = null) + public CollectionAdapter(IList query, IList target, IList allList, Func toTarget, Action onItemAdded, Action onItemRemoved, Func? collisionChecker = null) { if (collisionChecker != null) { @@ -40,9 +40,9 @@ public CollectionAdapter(IList query, IList target, IList allList, Func } } - private Func _collisionChecker = null; + private Func? _collisionChecker = null; - public Func CollisionChecker + public Func? CollisionChecker { get { @@ -80,20 +80,29 @@ public void UpdateTarget(IList target) _target = target; } - private void OnManualChanged(object sender, NotifyCollectionChangedEventArgs args) + private void OnManualChanged(object? sender, NotifyCollectionChangedEventArgs args) { switch (args.Action) { case NotifyCollectionChangedAction.Add: - this.InsertManualItem(args.NewStartingIndex, (T)args.NewItems[0]); + if (args.NewItems is { Count: > 0 } && args.NewItems[0] is T addedItem) + { + this.InsertManualItem(args.NewStartingIndex, addedItem); + } break; + case NotifyCollectionChangedAction.Remove: this.RemoveManualItemAt(args.OldStartingIndex); break; + case NotifyCollectionChangedAction.Replace: this.RemoveManualItemAt(args.OldStartingIndex); - this.InsertManualItem(args.NewStartingIndex, (T)args.NewItems[0]); + if (args.NewItems is { Count: > 0 } && args.NewItems[0] is T replacedItem) + { + this.InsertManualItem(args.NewStartingIndex, replacedItem); + } break; + case NotifyCollectionChangedAction.Reset: this.ClearManualItems(); break; @@ -102,7 +111,7 @@ private void OnManualChanged(object sender, NotifyCollectionChangedEventArgs arg public void ShiftContentToManual(IList manualCollection, Action onMoving) { - T item = default(T); + T? item = default(T); var manualSet = new HashSet(); if (this.CollisionChecker != null) @@ -115,16 +124,18 @@ public void ShiftContentToManual(IList manualCollection, Action onMoving) var key = this.CollisionChecker(item); if (key != null) { - if (!manualSet.Contains(key)) - { - manualSet.Add(key); - } + manualSet.Add(key); } } } } var mapWasEmpty = manualSet.Count == 0; + if (this._query == null) + { + // no collection to shift + return; + } for (var i = 0; i < this._query.Count; i++) { item = this._query[i]; @@ -137,7 +148,7 @@ public void ShiftContentToManual(IList manualCollection, Action onMoving) } else { - var key = this.CollisionChecker(item); + var key = this.CollisionChecker?.Invoke(item); if (key == null) { this._manualItems.Insert(i, item); @@ -168,14 +179,18 @@ private void SyncItems() Dictionary queryMap = new Dictionary(); Dictionary manualMap = new Dictionary(); - T item = default(T); + T? item = default(T); + if (this._allList == null) + { + return; + } for (var i = 0; i < this._allList.Count; i++) { item = this._allList[i]; targetMap[item] = true; } - var queryArray = new List(this._query); + var queryArray = new List(this._query ?? Enumerable.Empty()); this.actualContent = queryArray; if (this.CollisionChecker != null) @@ -197,6 +212,11 @@ private void SyncItems() } } } + if (this._query == null) + { + // no collection to sync + return; + } for (var i = this._query.Count - 1; i >= 0; i--) { item = queryArray[i]; @@ -239,7 +259,7 @@ private void SyncItems() int ind = 0; int ins = 0; - T insItem = default(T); + T? insItem = default(T); int maxLen = queryArray.Count + this._manualItems.Count; while (ind < maxLen) { diff --git a/src/componentsBase/DataAdapters.cs b/src/componentsBase/DataAdapters.cs index 4b9196f8..89d275cb 100644 --- a/src/componentsBase/DataAdapters.cs +++ b/src/componentsBase/DataAdapters.cs @@ -38,8 +38,8 @@ public static RemoteJson From(string uri) return new RemoteJson(uri); } - private string _uri; - public string Uri { get { return _uri; } } + private string? _uri; + public string? Uri { get { return _uri; } } internal string ToRef() { diff --git a/src/componentsBase/DataSourceManager.cs b/src/componentsBase/DataSourceManager.cs index 6e4e42dc..ab3203f9 100644 --- a/src/componentsBase/DataSourceManager.cs +++ b/src/componentsBase/DataSourceManager.cs @@ -10,35 +10,35 @@ public DataSourceManager(RefSink sink, RuntimeHelper helper) _refSink = sink; } - private RuntimeHelper _helper; + private RuntimeHelper? _helper; // public int ChunkAmount { get; set; } // public int ChunkSlicingWait { get; set; } - private RefSink _refSink; + private RefSink? _refSink; private Dictionary _refs = new Dictionary(); private Dictionary _refsById = new Dictionary(); - private Dictionary _dataSources = new Dictionary(); + private Dictionary _dataSources = new Dictionary(); private Dictionary _idLookup = new Dictionary(); private Dictionary _suspensionLookup = new Dictionary(); - public object FindItem(Guid id) + public object? FindItem(Guid id) { foreach (var data in _dataSources.Values) { - if (data.HasId(id)) + if (data != null && data.HasId(id)) { return data.LookupOriginal(id); } } return null; } - public object FindItem(string id) + public object? FindItem(string id) { foreach (var data in _dataSources.Values) { - if (data.HasId(id)) + if (data != null && data.HasId(id)) { return data.LookupOriginal(id); } @@ -70,9 +70,9 @@ public Guid FindItemId(object item) return Guid.Empty; } - public string OnRefChanged(string path, object data) + public string? OnRefChanged(string path, object? data) { - string id = null; + string? id = null; if (_refs.ContainsKey(path)) { object obj = _refs[path]; @@ -101,7 +101,7 @@ public string OnRefChanged(string path, object data) IncrementRef(id); if (!_dataSources.ContainsKey(id)) { - if (_helper.IsInproc && !_helper.IsForcedJsonDataMarshalling) + if (_helper?.IsInproc == true && !_helper.IsForcedJsonDataMarshalling) { //Console.WriteLine("unmarshalled datasource"); _dataSources[id] = UnmarshalledDataSource.Create(data, this, _helper); @@ -113,7 +113,7 @@ public string OnRefChanged(string path, object data) } } _idLookup[data] = id; - _refSink.OnRefChanged(id, _dataSources[id]); + _refSink?.OnRefChanged(id, _dataSources[id]); } if (data == null) @@ -153,7 +153,7 @@ void DecrementRef(string id) _refCount.Remove(id); if (_dataSources.ContainsKey(id)) { - Object data = _dataSources[id]; + Object? data = _dataSources[id]; if (data != null && _idLookup.ContainsKey(data)) { _idLookup.Remove(data); @@ -164,12 +164,12 @@ void DecrementRef(string id) } _dataSources.Remove(id); _refsById.Remove(id); - _refSink.OnRefChanged(id, null); + _refSink?.OnRefChanged(id, null); } } } - public void NotifyInsertItem(string refName, int index, object refItem) + public void NotifyInsertItem(string refName, int index, object? refItem) { if (_suspensionLookup.ContainsKey(refName) && _suspensionLookup[refName]) { @@ -181,12 +181,17 @@ public void NotifyInsertItem(string refName, int index, object refItem) { //Console.WriteLine("found by id"); object data = _refsById[refName]; - IJSDataSource dataSource = _dataSources[refName]; - IJSDataSourceItem newItem = dataSource.NotifyInsertItem(data, index, refItem); - _refSink.OnRefNotifyInsertItem(dataSource, refName, index, newItem); + IJSDataSource? dataSource = _dataSources[refName]; + if (dataSource == null) + { + return; + } + + IJSDataSourceItem? newItem = dataSource.NotifyInsertItem(data, index, refItem); + _refSink?.OnRefNotifyInsertItem(dataSource, refName, index, newItem); } } - public void NotifyRemoveItem(String refName, int index, Object oldItem) + public void NotifyRemoveItem(String refName, int index, Object? oldItem) { if (_suspensionLookup.ContainsKey(refName) && _suspensionLookup[refName]) { @@ -196,9 +201,14 @@ public void NotifyRemoveItem(String refName, int index, Object oldItem) if (_refsById.ContainsKey(refName)) { Object data = _refsById[refName]; - IJSDataSource dataSource = _dataSources[refName]; - IJSDataSourceItem oldItemJson = dataSource.NotifyRemoveItem(data, index, oldItem); - _refSink.OnRefNotifyRemoveItem(dataSource, refName, index, oldItemJson); + IJSDataSource? dataSource = _dataSources[refName]; + if (dataSource == null) + { + return; + } + + IJSDataSourceItem? oldItemJson = dataSource.NotifyRemoveItem(data, index, oldItem); + _refSink?.OnRefNotifyRemoveItem(dataSource, refName, index, oldItemJson); } } public void NotifyClearItems(string refName) @@ -211,9 +221,14 @@ public void NotifyClearItems(string refName) if (_refsById.ContainsKey(refName)) { Object data = _refsById[refName]; - IJSDataSource dataSource = _dataSources[refName]; + IJSDataSource? dataSource = _dataSources[refName]; + if (dataSource == null) + { + return; + } + dataSource.NotifyClearItems(data); - _refSink.OnRefNotifyClearItems(dataSource, refName, dataSource); + _refSink?.OnRefNotifyClearItems(dataSource, refName, dataSource); } } public void NotifySetItem(string refName, int index, object oldItem, object newItem) @@ -225,10 +240,15 @@ public void NotifySetItem(string refName, int index, object oldItem, object newI if (_refsById.ContainsKey(refName)) { object data = _refsById[refName]; - IJSDataSource dataSource = _dataSources[refName]; - IJSDataSourceItem oldItemJson = dataSource.DataSourceType == JSDataSourceType.Json ? ((JsonDataSource)dataSource)[index] : null; - IJSDataSourceItem newItemJson = dataSource.NotifySetItem(data, index, oldItem, newItem); - _refSink.OnRefNotifySetItem(dataSource, refName, index, oldItemJson, newItemJson); + IJSDataSource? dataSource = _dataSources[refName]; + if (dataSource == null) + { + return; + } + + IJSDataSourceItem? oldItemJson = dataSource.DataSourceType == JSDataSourceType.Json ? ((JsonDataSource)dataSource)[index] : null; + IJSDataSourceItem? newItemJson = dataSource.NotifySetItem(data, index, oldItem, newItem); + _refSink?.OnRefNotifySetItem(dataSource, refName, index, oldItemJson, newItemJson); } } public void NotifyUpdateItem(string refName, int index, object refItem, bool syncDataOnly) @@ -240,9 +260,14 @@ public void NotifyUpdateItem(string refName, int index, object refItem, bool syn if (_refsById.ContainsKey(refName)) { object data = _refsById[refName]; - IJSDataSource dataSource = _dataSources[refName]; - IJSDataSourceItem newItemJson = dataSource.NotifyUpdateItem(data, index, refItem); - _refSink.OnRefNotifyUpdateItem(dataSource, refName, index, newItemJson, syncDataOnly); + IJSDataSource? dataSource = _dataSources[refName]; + if (dataSource == null) + { + return; + } + + IJSDataSourceItem? newItemJson = dataSource.NotifyUpdateItem(data, index, refItem); + _refSink?.OnRefNotifyUpdateItem(dataSource, refName, index, newItemJson, syncDataOnly); } } @@ -293,7 +318,7 @@ public void ResumeNotifications(object dataSource, bool notify = true) } } - public IJSDataSource GetDataSource(string id) + public IJSDataSource? GetDataSource(string id) { if (_dataSources.ContainsKey(id)) { diff --git a/src/componentsBase/DynamicContentHolder.cs b/src/componentsBase/DynamicContentHolder.cs index 22ebc8f3..567a891e 100644 --- a/src/componentsBase/DynamicContentHolder.cs +++ b/src/componentsBase/DynamicContentHolder.cs @@ -7,6 +7,10 @@ namespace IgniteUI.Blazor.Controls public class DynamicContentHolder : ComponentBase { + public DynamicContentHolder() + { + DynamicContentInfo = new LinkedList(); + } protected LinkedList DynamicContentInfo { get; @@ -17,7 +21,6 @@ protected LinkedList DynamicContentInfo protected override void OnInitialized() { base.OnInitialized(); - DynamicContentInfo = new LinkedList(); } private bool _isDirty = false; @@ -29,6 +32,7 @@ protected override void OnInitialized() public void AddDynamicContent(DynamicContentInfo content) { + DynamicContentInfo ??= new LinkedList(); _contentInfos[content.RefName] = content; _contentInfoNode[content.RefName] = DynamicContentInfo.AddLast(content); _isDirty = true; @@ -106,7 +110,7 @@ protected override void BuildRenderTree(RenderTreeBuilder builder) public abstract class DynamicContentInfo { [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] - public Type ControlType { get; set; } + public required Type ControlType { get; set; } public DynamicContentInfo() { RefName = Guid.NewGuid().ToString(); @@ -121,8 +125,8 @@ public string RefDivName } } - private object _component = null; - public object Component + private object? _component = null; + public object? Component { get { @@ -136,19 +140,19 @@ public object Component } } - public BaseRendererControl Owner { get; internal set; } + public BaseRendererControl? Owner { get; internal set; } - protected virtual void OnComponentChanged(object oldValue, object component) + protected virtual void OnComponentChanged(object? oldValue, object? component) { } - public virtual void UpdateTemplate(object template) + public virtual void UpdateTemplate(object? template) { } - public virtual void UpdateContext(object context) + public virtual void UpdateContext(object? context) { } @@ -163,7 +167,7 @@ public TypedDynamicContent([DynamicallyAccessedMembers(DynamicallyAccessedMember } /// - protected override void OnComponentChanged(object oldValue, object component) + protected override void OnComponentChanged(object? oldValue, object? component) { //if (component != null) { @@ -182,7 +186,14 @@ protected override void OnComponentChanged(object oldValue, object component) foreach (var item in toSignal) { - item.SetResult(Component); + if (component != null) + { + item.SetResult(component); + } + else + { + item.SetException(new InvalidOperationException("Component is null.")); + } } } @@ -191,8 +202,8 @@ protected override void OnComponentChanged(object oldValue, object component) public Task GetInstanceAsync() { TaskCompletionSource tcs = new TaskCompletionSource(); - object component = null; - List> toSignal = null; + object? component = null; + List>? toSignal = null; lock (_lock) { @@ -206,26 +217,33 @@ public Task GetInstanceAsync() } } - if (component != null) + if (toSignal != null) { foreach (var item in toSignal) { - item.SetResult(Component); + if (component != null) + { + item.SetResult(component); + } + else + { + item.SetException(new InvalidOperationException("Component is null.")); + } } } return tcs.Task; } - public event DynamicComponentChangingEventHandler OnComponentChanging; + public event DynamicComponentChangingEventHandler? OnComponentChanging; } public delegate void DynamicComponentChangingEventHandler(object sender, DynamicComponentChangingEventArgs e); public class DynamicComponentChangingEventArgs { - public object OldComponent { get; internal set; } - public object NewComponent { get; internal set; } + public object? OldComponent { get; internal set; } + public object? NewComponent { get; internal set; } } public class DynamicContentInfo @@ -236,12 +254,12 @@ public DynamicContentInfo() ControlType = typeof(IgbTemplateContent); } - private RenderFragment _template; - private T _context; + private RenderFragment? _template; + private T? _context; private bool _hasPopulatedContext = false; - public RenderFragment Template + public RenderFragment? Template { get { @@ -252,7 +270,7 @@ public RenderFragment Template _template = value; } } - public T Context + public T? Context { get { @@ -268,23 +286,23 @@ public T Context } /// - protected override void OnComponentChanged(object oldValue, object component) + protected override void OnComponentChanged(object? oldValue, object? component) { if (component is IgbTemplateContent) { - OnContextChanged((T)Context, (T)Context); + OnContextChanged((T?)Context, (T?)Context); } } - private void OnContextChanged(T oldValue, T newValue) + private void OnContextChanged(T? oldValue, T? newValue) { if (Component is IgbTemplateContent) { var template = (IgbTemplateContent)Component; - if (_hasPopulatedContext) + if (_hasPopulatedContext && Context != null) { - template.Context = (T)Context; + template.Context = Context; } template.Template = Template; template.Update(); @@ -292,15 +310,15 @@ private void OnContextChanged(T oldValue, T newValue) } /// - public override void UpdateTemplate(object template) + public override void UpdateTemplate(object? template) { - Template = (RenderFragment)template; + Template = (RenderFragment?)template; } /// - public override void UpdateContext(object context) + public override void UpdateContext(object? context) { - Context = (T)context; + Context = (T?)context; } } diff --git a/src/componentsBase/EventCallbackExtensions.cs b/src/componentsBase/EventCallbackExtensions.cs index c173687c..36822745 100644 --- a/src/componentsBase/EventCallbackExtensions.cs +++ b/src/componentsBase/EventCallbackExtensions.cs @@ -36,10 +36,10 @@ internal static bool EqualsCompat(this EventCallback left, Event } // Mirrors .NET 10's EventCallback.Equals, need the internal fields for the checks: - MulticastDelegate leftDelegate = (MulticastDelegate)CallbackFields.Delegate.GetValue(left); - MulticastDelegate rightDelegate = (MulticastDelegate)CallbackFields.Delegate.GetValue(other); + MulticastDelegate? leftDelegate = (MulticastDelegate?)CallbackFields.Delegate?.GetValue(left); + MulticastDelegate? rightDelegate = (MulticastDelegate?)CallbackFields.Delegate?.GetValue(other); - return ReferenceEquals(CallbackFields.Receiver.GetValue(left), CallbackFields.Receiver.GetValue(other)) + return ReferenceEquals(CallbackFields.Receiver?.GetValue(left), CallbackFields.Receiver?.GetValue(other)) && (leftDelegate?.Equals(rightDelegate) ?? (rightDelegate == null)); #endif } @@ -48,13 +48,13 @@ internal static bool EqualsCompat(this EventCallback left, Event /// Resolved once per closed callback type, rather than per component instance. private static class CallbackFields { - internal static readonly FieldInfo Delegate = Field("Delegate"); - internal static readonly FieldInfo Receiver = Field("Receiver"); + internal static readonly FieldInfo? Delegate = Field("Delegate"); + internal static readonly FieldInfo? Receiver = Field("Receiver"); /// Use as guard against (unlikely) fields rename in old versions that won't resolve. internal static readonly bool Resolved = Delegate != null && Receiver != null; - private static FieldInfo Field(string name) => + private static FieldInfo? Field(string name) => typeof(EventCallback).GetField(name, BindingFlags.NonPublic | BindingFlags.Instance); } #endif diff --git a/src/componentsBase/IgbComponentRendererContainer.cs b/src/componentsBase/IgbComponentRendererContainer.cs index d38cfbb3..3ede4557 100644 --- a/src/componentsBase/IgbComponentRendererContainer.cs +++ b/src/componentsBase/IgbComponentRendererContainer.cs @@ -7,11 +7,11 @@ namespace IgniteUI.Blazor.Controls public class IgbComponentRendererContainer : ComponentBase { - private Type _componentType; + private Type? _componentType; [Parameter] [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] [UnconditionalSuppressMessage("Trimming", "IL2078", Justification = "The backing field is only assigned through this annotated property; annotating the field would surface IL2110 in consuming apps.")] - public Type ComponentType + public Type? ComponentType { get { @@ -28,8 +28,8 @@ public Type ComponentType } } - private object _rootComponent = null; - public object RootComponent + private object? _rootComponent = null; + public object? RootComponent { get { @@ -46,7 +46,7 @@ public object RootComponent } } - private void OnRootComponentChanged(object oldComponent, object newComponent) + private void OnRootComponentChanged(object? oldComponent, object? newComponent) { if (ComponentChanged != null) { @@ -73,15 +73,15 @@ protected override void BuildRenderTree(RenderTreeBuilder builder) } } - public event ComponentRendererComponentChangedEventHandler ComponentChanged; + public event ComponentRendererComponentChangedEventHandler? ComponentChanged; } public delegate void ComponentRendererComponentChangedEventHandler(object sender, ComponentRendererComponentChangedEventArgs args); public class ComponentRendererComponentChangedEventArgs { - public object OldComponent { get; internal set; } - public object NewComponent { get; internal set; } + public object? OldComponent { get; internal set; } + public object? NewComponent { get; internal set; } } } diff --git a/src/componentsBase/IgbTemplateContent.razor b/src/componentsBase/IgbTemplateContent.razor index ae2d5b92..e224a9f0 100644 --- a/src/componentsBase/IgbTemplateContent.razor +++ b/src/componentsBase/IgbTemplateContent.razor @@ -11,10 +11,10 @@ @code { [Parameter] - public RenderFragment Template { get; set; } + public RenderFragment? Template { get; set; } private bool _hasPopulatedContext = false; - private T _context; + private T _context = default!; [Parameter] public T Context { @@ -32,4 +32,4 @@ { StateHasChanged(); } -} \ No newline at end of file +} diff --git a/src/componentsBase/JsonDataSource.cs b/src/componentsBase/JsonDataSource.cs index 36641103..f2a44e5b 100644 --- a/src/componentsBase/JsonDataSource.cs +++ b/src/componentsBase/JsonDataSource.cs @@ -10,22 +10,22 @@ internal interface IJSDataSourceItem internal interface IJSDataSource { - string GetDataIntentsAsJson(); + string? GetDataIntentsAsJson(); bool SuppressModifications { get; set; } JSDataSourceType DataSourceType { get; } bool IsSent { get; set; } bool HasId(Guid id); bool HasId(string id); //IJSDataSourceItem LookupById(Guid id); - object LookupOriginal(Guid id); - object LookupOriginal(string id); + object? LookupOriginal(Guid id); + object? LookupOriginal(string id); bool HasOriginal(object item); Guid IdFromOriginal(object item); - IJSDataSourceItem NotifyInsertItem(object data, int index, Object item); - IJSDataSourceItem NotifyRemoveItem(object data, int index, object oldItem); + IJSDataSourceItem? NotifyInsertItem(object data, int index, Object? item); + IJSDataSourceItem? NotifyRemoveItem(object data, int index, object? oldItem); void NotifyClearItems(Object data); - IJSDataSourceItem NotifySetItem(Object data, int index, Object oldItem, Object newItem); - IJSDataSourceItem NotifyUpdateItem(object data, int index, object item); + IJSDataSourceItem? NotifySetItem(Object data, int index, Object oldItem, Object newItem); + IJSDataSourceItem? NotifyUpdateItem(object data, int index, object item); void InsertItemWithId(string id, int index, Object item); } @@ -48,9 +48,9 @@ public JSDataSourceType DataSourceType } public bool IsSent { get; set; } - private object _originalData; + private object? _originalData; - public string GetDataIntentsAsJson() + public string? GetDataIntentsAsJson() { if (_schema != null) { @@ -63,22 +63,27 @@ public string GetDataIntentsAsJson() private Dictionary _uuidToItem = new Dictionary(); private Dictionary _itemToOriginal = new Dictionary(); private Dictionary _originalToItem = new Dictionary(); - private JSDataSourceSchema _parentSchema = null; - private DataSourceManager _manager = null; - private string _parentId = null; + private JSDataSourceSchema? _parentSchema = null; + private DataSourceManager? _manager = null; + private string? _parentId = null; private bool _dateCacheReady = false; private Dictionary> _subDataSources = new Dictionary>(); public bool DateCacheReady { get { return _dateCacheReady; } } - public static IJSDataSource CreateWithSchema(Object data, JSDataSourceSchema schema, DataSourceManager manager, string parentId) + public static IJSDataSource? CreateWithSchema(Object data, JSDataSourceSchema schema, DataSourceManager? manager, string? parentId) { if (data == null) { return null; } + if (manager == null) + { + return null; + } + if (data.GetType().IsArray) { return JsonDataSource.CreateFromArray((Object[])data, schema, manager, parentId); @@ -104,9 +109,9 @@ private void Listen(object data) } } - private void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) + private void OnCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e) { - if (SuppressModifications) + if (SuppressModifications || _manager == null || _originalData == null) { return; } @@ -121,10 +126,6 @@ private void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs { var item = e.NewItems[i]; var refName = _manager.GetRefId(_originalData); - if (refName == null) - { - return; - } _manager.NotifyInsertItem(refName, e.NewStartingIndex + i, item); } } @@ -138,10 +139,6 @@ private void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs { var item = e.OldItems[i]; var refName = _manager.GetRefId(_originalData); - if (refName == null) - { - return; - } _manager.NotifyRemoveItem(refName, e.OldStartingIndex, item); } } @@ -155,10 +152,6 @@ private void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs { var item = e.OldItems[i]; var refName = _manager.GetRefId(_originalData); - if (refName == null) - { - return; - } _manager.NotifyRemoveItem(refName, e.OldStartingIndex, item); } } @@ -168,10 +161,6 @@ private void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs { var item = e.NewItems[i]; var refName = _manager.GetRefId(_originalData); - if (refName == null) - { - return; - } _manager.NotifyInsertItem(refName, e.NewStartingIndex + i, item); } } @@ -180,10 +169,6 @@ private void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs case NotifyCollectionChangedAction.Reset: { var refName = _manager.GetRefId(_originalData); - if (refName == null) - { - return; - } _manager.NotifyClearItems(refName); break; } @@ -217,7 +202,7 @@ public bool HasId(string id) } } - public IJSDataSourceItem LookupById(Guid id) + public IJSDataSourceItem? LookupById(Guid id) { if (_uuidToItem.ContainsKey(id)) { @@ -226,11 +211,11 @@ public IJSDataSourceItem LookupById(Guid id) return null; } - public object LookupOriginal(Guid id) + public object? LookupOriginal(Guid id) { return ToOriginal(LookupById(id)); } - public object LookupOriginal(string id) + public object? LookupOriginal(string id) { if (id.Contains("/")) { @@ -262,14 +247,14 @@ public bool HasOriginal(object item) public Guid IdFromOriginal(object item) { var itm = FromOriginal(item); - if (item == null) + if (itm == null) { return Guid.Empty; } return itm.Id; } - public IJSDataSourceItem FromOriginal(object item) + public IJSDataSourceItem? FromOriginal(object item) { if (_originalToItem.ContainsKey(item)) { @@ -279,7 +264,7 @@ public IJSDataSourceItem FromOriginal(object item) return null; } - public Object ToOriginal(IJSDataSourceItem item) + public Object? ToOriginal(IJSDataSourceItem? item) { if (item == null) { @@ -294,7 +279,7 @@ public Object ToOriginal(IJSDataSourceItem item) return null; } - public static IJSDataSource Create(Object data, DataSourceManager manager) + public static IJSDataSource? Create(Object data, DataSourceManager manager) { if (data == null) { @@ -316,7 +301,7 @@ public static IJSDataSource Create(Object data, DataSourceManager manager) return null; } - private static IJSDataSource CreateFromIEnumerable(IEnumerable data, JSDataSourceSchema schema, DataSourceManager manager, string parentId) + private static IJSDataSource CreateFromIEnumerable(IEnumerable data, JSDataSourceSchema? schema, DataSourceManager manager, string? parentId) { JsonDataSource newData = new JsonDataSource(); newData._manager = manager; @@ -330,7 +315,7 @@ private static IJSDataSource CreateFromIEnumerable(IEnumerable data, JSDataSourc return newData; } - private static IJSDataSource CreateFromIList(IList data, JSDataSourceSchema schema, DataSourceManager manager, string parentId) + private static IJSDataSource CreateFromIList(IList data, JSDataSourceSchema? schema, DataSourceManager manager, string? parentId) { //Console.WriteLine("test json"); //DateTime testTime = DateTime.Now; @@ -353,7 +338,7 @@ private static IJSDataSource CreateFromIList(IList data, JSDataSourceSchema sche return newData; } - private static IJSDataSource CreateFromArray(object[] data, JSDataSourceSchema schema, DataSourceManager manager, string parentId) + private static IJSDataSource CreateFromArray(object[] data, JSDataSourceSchema? schema, DataSourceManager manager, string? parentId) { JsonDataSource newData = new JsonDataSource(); newData._parentSchema = schema; @@ -367,9 +352,9 @@ private static IJSDataSource CreateFromArray(object[] data, JSDataSourceSchema s return newData; } - private JSDataSourceSchema _schema = null; + private JSDataSourceSchema? _schema = null; - private void Add(object item) + private void Add(object? item) { if (_schema == null) { @@ -386,7 +371,7 @@ private void Add(object item) OnAddItem(itemJson, item); _data.Add(itemJson); - if (schema != null) + if (schema != null && schema.PropertyNames != null && schema.PropertyTypes != null) { for (int i = 0; i < schema.PropertyNames.Length; i++) { @@ -397,8 +382,8 @@ private void Add(object item) var subSchema = schema.GetSubSchema(propertyName); if (subSchema != null) { - var propValue = (JsonDataSourceItem)itemJson.GetValue(propertyName); - if (propValue.Source != null) + var propValue = (JsonDataSourceItem?)itemJson.GetValue(propertyName); + if (propValue?.Source != null) { if (!_subDataSources.ContainsKey(itemJson.Id)) { @@ -412,7 +397,7 @@ private void Add(object item) } } - private void OnAddItem(IJSDataSourceItem itemJson, Object item) + private void OnAddItem(IJSDataSourceItem itemJson, Object? item) { _uuidToItem[itemJson.Id] = itemJson; if (item != null) @@ -422,7 +407,7 @@ private void OnAddItem(IJSDataSourceItem itemJson, Object item) } } - private void EnsureSchema(object item) + private void EnsureSchema(object? item) { if (item != null && _schema == null) { @@ -445,7 +430,7 @@ private void EnsureSchema(object item) } } - public IJSDataSourceItem NotifyInsertItem(object data, int index, Object item) + public IJSDataSourceItem NotifyInsertItem(object data, int index, Object? item) { EnsureSchema(item); IJSDataSourceItem itemJson = JsonDataSourceItem.Create(item, _schema, _manager); @@ -454,7 +439,7 @@ public IJSDataSourceItem NotifyInsertItem(object data, int index, Object item) return itemJson; } - public IJSDataSourceItem NotifyRemoveItem(object data, int index, object oldItem) + public IJSDataSourceItem NotifyRemoveItem(object data, int index, object? oldItem) { EnsureSchema(oldItem); IJSDataSourceItem itemJson = _data[index]; @@ -463,7 +448,7 @@ public IJSDataSourceItem NotifyRemoveItem(object data, int index, object oldItem return itemJson; } - private void OnRemove(IJSDataSourceItem itemJson, object item) + private void OnRemove(IJSDataSourceItem itemJson, object? item) { if (_uuidToItem.ContainsKey(itemJson.Id)) { @@ -539,7 +524,7 @@ public IJSDataSourceItem this[int i] public IJSDataSourceItem NotifyUpdateItem(object data, int index, object item) { EnsureSchema(item); - JsonDataSourceItem itemJson = null; + JsonDataSourceItem? itemJson = null; if (HasOriginal(item)) { itemJson = (JsonDataSourceItem)_originalToItem[item]; @@ -586,8 +571,8 @@ private void GetDateCacheAsJson(System.Text.Json.Utf8JsonWriter writer) for (int i = 0; i < _data.Count; i++) { item = (JsonDataSourceItem)_data[0]; - JsonDataSource ds = (JsonDataSource)item.Source; - ds.GetDateCacheAsJson(writer); + JsonDataSource? ds = item.Source as JsonDataSource; + ds?.GetDateCacheAsJson(writer); } } else diff --git a/src/componentsBase/JsonDataSourceItem.cs b/src/componentsBase/JsonDataSourceItem.cs index 2895feef..ae959af4 100644 --- a/src/componentsBase/JsonDataSourceItem.cs +++ b/src/componentsBase/JsonDataSourceItem.cs @@ -9,9 +9,9 @@ internal class JsonDataSourceItem private Guid _id; private bool _isNull = false; private bool _isDataSource = true; - private IJSDataSource _source = null; - private string _parentId = null; - private Dictionary _values = new Dictionary(); + private IJSDataSource? _source = null; + private string? _parentId = null; + private Dictionary _values = new Dictionary(); private Dictionary _valueTypes = new Dictionary(); public bool IsNull @@ -39,12 +39,12 @@ public Guid Id } } - public IJSDataSource Source + public IJSDataSource? Source { get { return _source; } } - public string ParentId + public string? ParentId { get { @@ -52,7 +52,7 @@ public string ParentId } } - public object GetValue(string key) + public object? GetValue(string key) { if (_values.ContainsKey(key)) return _values[key]; @@ -60,7 +60,7 @@ public object GetValue(string key) return null; } - public static JSDataSourceSchema ExtractSchema(object item) + public static JSDataSourceSchema? ExtractSchema(object? item) { if (item == null) { @@ -106,20 +106,20 @@ public static JSDataSourceSchema ExtractSchema(object item) return JSDataSourceSchema.Create(c); } - public static JsonDataSourceItem Create(object item, JSDataSourceSchema schema, DataSourceManager manager) + public static JsonDataSourceItem Create(object? item, JSDataSourceSchema? schema, DataSourceManager? manager) { JsonDataSourceItem newItem = new JsonDataSourceItem(); newItem.Read(item, schema, manager); return newItem; } - public static JsonDataSourceItem Create(object item, JSDataSourceSchema schema, DataSourceManager manager, JsonDataSourceItem parentItem) + public static JsonDataSourceItem Create(object? item, JSDataSourceSchema? schema, DataSourceManager? manager, JsonDataSourceItem parentItem) { JsonDataSourceItem newItem = new JsonDataSourceItem(); newItem._parentId = parentItem.ParentId != null ? parentItem.ParentId + "/" + parentItem.Id.ToString() : parentItem.Id.ToString(); newItem.Read(item, schema, manager); return newItem; } - public static JsonDataSourceItem Create(object item, JSDataSourceSchema schema, DataSourceManager manager, string parentId) + public static JsonDataSourceItem Create(object? item, JSDataSourceSchema? schema, DataSourceManager? manager, string? parentId) { JsonDataSourceItem newItem = new JsonDataSourceItem(); newItem._parentId = parentId; @@ -127,20 +127,20 @@ public static JsonDataSourceItem Create(object item, JSDataSourceSchema schema, return newItem; } - public static JsonDataSourceItem CreateWithId(object item, Guid id, JSDataSourceSchema schema, DataSourceManager manager) + public static JsonDataSourceItem CreateWithId(object? item, Guid id, JSDataSourceSchema? schema, DataSourceManager? manager) { JsonDataSourceItem newItem = new JsonDataSourceItem(id); newItem.Read(item, schema, manager); return newItem; } - public void Refresh(object item, JSDataSourceSchema schema, DataSourceManager manager) + public void Refresh(object? item, JSDataSourceSchema? schema, DataSourceManager? manager) { Read(item, schema, manager); } - private JSDataSourceSchema _schema = null; - private void Read(Object item, JSDataSourceSchema schema, DataSourceManager manager) + private JSDataSourceSchema? _schema = null; + private void Read(Object? item, JSDataSourceSchema? schema, DataSourceManager? manager) { if (schema == null || item == null) { @@ -151,7 +151,7 @@ private void Read(Object item, JSDataSourceSchema schema, DataSourceManager mana if (_schema.IsDataSource) { //Console.WriteLine("in read"); - IJSDataSource source = JsonDataSource.CreateWithSchema(item, _schema, manager, _parentId); + IJSDataSource? source = JsonDataSource.CreateWithSchema(item, _schema, manager, _parentId); _source = source; return; } @@ -160,25 +160,34 @@ private void Read(Object item, JSDataSourceSchema schema, DataSourceManager mana _values["value"] = item; _valueTypes["value"] = schema.PrimitiveType; } - for (int i = 0; i < schema.PropertyNames.Length; i++) + var propertyGetters = schema.PropertyGetters; + if (propertyGetters != null) { - String name = schema.PropertyNames[i]; - Func propGetter = schema.PropertyGetters[i]; - JSDataSourceSchemaType type = schema.PropertyTypes[i]; - Object val = schema.ResolveValue(name, item, propGetter, this, type, manager); + for (int i = 0; i < schema.PropertyNames.Length; i++) + { + String name = schema.PropertyNames[i]; + Func propGetter = propertyGetters[i]; + JSDataSourceSchemaType type = schema.PropertyTypes[i]; + object? val = schema.ResolveValue(name, item, propGetter, this, type, manager); - _values[name] = val; - _valueTypes[name] = type; + _values[name] = val; + _valueTypes[name] = type; + } } - for (int i = 0; i < schema.Fields.Length; i++) + + var fieldGetters = schema.FieldGetters; + if (fieldGetters != null) { - String name = schema.Fields[i].Name; - Func fieldGetter = schema.FieldGetters[i]; - JSDataSourceSchemaType type = schema.FieldTypes[i]; - Object val = schema.ResolveFieldValue(name, item, fieldGetter, this, type, manager); + for (int i = 0; i < schema.Fields.Length; i++) + { + String name = schema.Fields[i].Name; + Func fieldGetter = fieldGetters[i]; + JSDataSourceSchemaType type = schema.FieldTypes[i]; + object? val = schema.ResolveFieldValue(name, item, fieldGetter, this, type, manager); - _values[name] = val; - _valueTypes[name] = type; + _values[name] = val; + _valueTypes[name] = type; + } } } @@ -198,14 +207,14 @@ public string ToJson() } - public void GetDateCacheAsJson(System.Text.Json.Utf8JsonWriter writer, string parentKey = null) + public void GetDateCacheAsJson(System.Text.Json.Utf8JsonWriter writer, string? parentKey = null) { if (_isNull) { return; } - if (_schema.IsDataSource) + if (_schema?.IsDataSource == true) { var itemSchema = _schema.GetSubSchema("Items"); GetDateCacheAsJson(itemSchema, writer, parentKey + "[]"); @@ -215,7 +224,7 @@ public void GetDateCacheAsJson(System.Text.Json.Utf8JsonWriter writer, string pa GetDateCacheAsJson(_schema, writer, parentKey); } } - public void GetDateCacheAsJson(JSDataSourceSchema schema, System.Text.Json.Utf8JsonWriter writer, string parentKey = null) + public void GetDateCacheAsJson(JSDataSourceSchema? schema, System.Text.Json.Utf8JsonWriter writer, string? parentKey = null) { if (schema == null) { @@ -223,25 +232,37 @@ public void GetDateCacheAsJson(JSDataSourceSchema schema, System.Text.Json.Utf8J } parentKey = parentKey != null ? parentKey + "." : ""; - for (int i = 0; i < schema.PropertyTypes.Length; i++) + + var propertyTypes = schema.PropertyTypes; + var propertyNames = schema.PropertyNames; + if (propertyTypes == null || propertyNames == null) + { + return; + } + + var propertyLength = Math.Min(propertyTypes.Length, propertyNames.Length); + for (var i = 0; i < propertyLength; i++) { - if (schema.PropertyTypes[i] == JSDataSourceSchemaType.DateTimeValue || - schema.PropertyTypes[i] == JSDataSourceSchemaType.NullableDateTimeValue) + var propertyType = propertyTypes[i]; + var propertyName = propertyNames[i]; + + if (propertyType == JSDataSourceSchemaType.DateTimeValue || + propertyType == JSDataSourceSchemaType.NullableDateTimeValue) { - writer.WriteStringValue(parentKey + schema.PropertyNames[i]); + writer.WriteStringValue(parentKey + propertyName); } - if (schema.PropertyTypes[i] == JSDataSourceSchemaType.ObjectValue) + if (propertyType == JSDataSourceSchemaType.ObjectValue) { - var subSchema = schema.GetSubSchema(schema.PropertyNames[i]); + var subSchema = schema.GetSubSchema(propertyName); if (subSchema != null) { if (subSchema.IsDataSource) { - GetDateCacheAsJson(subSchema.GetSubSchema("Items"), writer, parentKey + schema.PropertyNames[i] + "[]"); + GetDateCacheAsJson(subSchema.GetSubSchema("Items"), writer, parentKey + propertyName + "[]"); } else { - GetDateCacheAsJson(subSchema, writer, parentKey + schema.PropertyNames[i]); + GetDateCacheAsJson(subSchema, writer, parentKey + propertyName); //((JsonDataSourceItem)_values[schema.PropertyNames[i]]).GetDateCacheAsJson(writer, parentKey + schema.PropertyNames[i]); } } @@ -261,6 +282,10 @@ public void ToJson(System.Text.Json.Utf8JsonWriter writer) ((JsonDataSource)_source).ToJson(writer); return; } + if (_schema == null) + { + return; + } if (_schema.IsPrimitive) { ValueToJson("value", new System.Text.Json.JsonEncodedText(), writer); @@ -304,12 +329,15 @@ public void ToJson(System.Text.Json.Utf8JsonWriter writer, System.Text.Json.Json writer.WriteStartObject(propertyName); - var propertyNames = _schema.PropertyNames; - var jsonPropertyNames = _schema.JsonPropertyNames; - var len = propertyNames.Length; + var propertyNames = _schema?.PropertyNames; + var jsonPropertyNames = _schema?.JsonPropertyNames; + var len = propertyNames?.Length ?? 0; for (var i = 0; i < len; i++) { - ValueToJson(propertyNames[i], jsonPropertyNames[i], writer); + if (propertyNames?[i] != null && jsonPropertyNames?[i] != null) + { + ValueToJson(propertyNames[i], jsonPropertyNames[i], writer); + } } writer.WriteString("___id", _id); @@ -319,7 +347,7 @@ public void ToJson(System.Text.Json.Utf8JsonWriter writer, System.Text.Json.Json private void ValueToJson(String key, System.Text.Json.JsonEncodedText prop, System.Text.Json.Utf8JsonWriter writer) { - Object value = _values[key]; + Object? value = _values[key]; if (value == null) { if (prop.Equals(default)) diff --git a/src/componentsBase/JsonDataSourceSchema.cs b/src/componentsBase/JsonDataSourceSchema.cs index 1cb88475..8c1d9c1a 100644 --- a/src/componentsBase/JsonDataSourceSchema.cs +++ b/src/componentsBase/JsonDataSourceSchema.cs @@ -12,7 +12,7 @@ internal class JSDataSourceSchema private Dictionary _checkedArray = new Dictionary(); - public Action NotifyModified { get; set; } + public Action? NotifyModified { get; set; } private bool HasDataIntents() { @@ -24,13 +24,13 @@ private bool HasDataIntents() //Console.WriteLine("has item schema"); return ItemSchema.HasDataIntents(); } - if (_subSchemas.ContainsKey("___self")) + if (_subSchemas.TryGetValue("___self", out var selfSchema)) { //Console.WriteLine("checking self intents"); - if (_subSchemas["___self"] != null) + if (selfSchema != null) { //Console.WriteLine("has item schema"); - return _subSchemas["___self"].HasDataIntents(); + return selfSchema.HasDataIntents(); } } } @@ -80,7 +80,7 @@ private bool HasDataIntents() return false; } - private void WriteDataIntentsAsJson(string propertyName, System.Text.Json.Utf8JsonWriter uw) + private void WriteDataIntentsAsJson(string? propertyName, System.Text.Json.Utf8JsonWriter uw) { if (propertyName != null) { @@ -109,7 +109,7 @@ private void WriteDataIntentsAsJson(string propertyName, System.Text.Json.Utf8Js { //Console.WriteLine("has item schema"); uw.WriteBoolean("subProps", true); - _subSchemas["___self"].WriteDataIntentsAsJson("subIntents", uw); + _subSchemas["___self"]?.WriteDataIntentsAsJson("subIntents", uw); } } } @@ -122,9 +122,9 @@ private void WriteDataIntentsAsJson(string propertyName, System.Text.Json.Utf8Js if (_subSchemas.ContainsKey(currProp)) { - if (_subSchemas[currProp].HasDataIntents()) + var sub = _subSchemas[currProp]; + if (sub != null && sub.HasDataIntents()) { - var sub = _subSchemas[currProp]; if (sub.IsDataSource) { uw.WriteStartObject(currProp); @@ -159,9 +159,9 @@ private void WriteDataIntentsAsJson(string propertyName, System.Text.Json.Utf8Js if (_subSchemas.ContainsKey(currProp)) { - if (_subSchemas[currProp].HasDataIntents()) + var sub = _subSchemas[currProp]; + if (sub != null && sub.HasDataIntents()) { - var sub = _subSchemas[currProp]; if (sub.IsDataSource) { uw.WriteStartObject(currProp); @@ -193,7 +193,7 @@ private void WriteDataIntentsAsJson(string propertyName, System.Text.Json.Utf8Js uw.WriteEndObject(); } - public string GetDataIntentsAsJson() + public string? GetDataIntentsAsJson() { if (!HasDataIntents()) { @@ -261,16 +261,15 @@ public static JSDataSourceSchema CreateFromDictionary(IDictionary item) { if (key is string) { - if (item[key] == null) + var keyValue = item[key]; + if (keyValue == null) { continue; } - - List dataIntents = null; names.Add((string)key); s._buildingPropertiesDataIntents.Add(null); - Type ret = item[key].GetType(); + var ret = keyValue.GetType(); types.Add(ret); JSDataSourceSchemaType type = s.ResolveSchemaType(ret); @@ -285,10 +284,10 @@ public static JSDataSourceSchema CreateFromDictionary(IDictionary item) s.PropertyTypes = s._buildingPropertiesTypes.ToArray(); s.PropertyDataIntents = s._buildingPropertiesDataIntents.ToArray(); s.PropertyNames = names.ToArray(); - s.PropertyGetters = new Func[names.Count]; + s.PropertyGetters = new Func[names.Count]; s.TypedPropertyGetters = new Delegate[names.Count]; - var itemProp = item.GetType().GetProperty("Item"); + var itemProp = item.GetType().GetProperty("Item") ?? throw new InvalidOperationException("The 'Item' property was not found on the dictionary type."); for (int i = 0; i < names.Count; i++) { @@ -363,7 +362,7 @@ public static JSDataSourceSchema Create(Type c) return s; } - public object ResolveValue(String name, Object item, Func propGetter, JsonDataSourceItem jsonItem, JSDataSourceSchemaType type, DataSourceManager manager) + public object? ResolveValue(String name, Object item, Func propGetter, JsonDataSourceItem jsonItem, JSDataSourceSchemaType type, DataSourceManager? manager) { if (item == null) { @@ -372,7 +371,7 @@ public object ResolveValue(String name, Object item, Func propGe try { - object value = propGetter(item); + object? value = propGetter(item); if (type == JSDataSourceSchemaType.ObjectValue) { return GetSubObject(name, value, jsonItem, manager); @@ -385,7 +384,7 @@ public object ResolveValue(String name, Object item, Func propGe } } - private object GetSubObject(String name, Object value, JsonDataSourceItem rootItem, DataSourceManager manager) + private object GetSubObject(String name, Object? value, JsonDataSourceItem rootItem, DataSourceManager? manager) { bool checkedArray = _checkedArray.ContainsKey(name); if (!checkedArray && value != null) @@ -413,12 +412,12 @@ private object GetSubObject(String name, Object value, JsonDataSourceItem rootIt NotifyModified(); } } - JSDataSourceSchema subSchema = _subSchemas[name]; + JSDataSourceSchema? subSchema = _subSchemas[name]; return JsonDataSourceItem.Create(value, subSchema, manager, rootItem); } - public JSDataSourceSchema BuildSubObjectSchema(object subObject) + public JSDataSourceSchema? BuildSubObjectSchema(object? subObject) { if (subObject == null) { @@ -426,10 +425,9 @@ public JSDataSourceSchema BuildSubObjectSchema(object subObject) } var schema = JsonDataSourceItem.ExtractSchema(subObject); - JSDataSourceSchema itemSchema = null; - if (subObject is IEnumerable) + JSDataSourceSchema? itemSchema = null; + if (subObject is IEnumerable collection) { - var collection = subObject as IEnumerable; foreach (var item in collection) { if (item != null) @@ -439,7 +437,7 @@ public JSDataSourceSchema BuildSubObjectSchema(object subObject) break; } } - if (itemSchema != null) + if (schema != null && itemSchema != null) { schema.SetSubSchema("Items", itemSchema); } @@ -451,19 +449,23 @@ public JSDataSourceSchema BuildSubObjectSchema(object subObject) if (itemSchema != null) { - for (int i = 0; i < itemSchema.PropertyTypes.Length; i++) + var propertyGetters = itemSchema.PropertyGetters; + if (propertyGetters != null) { - if (itemSchema.PropertyTypes[i] == JSDataSourceSchemaType.ObjectValue) + for (int i = 0; i < itemSchema.PropertyTypes.Length; i++) { - var obj = itemSchema.PropertyGetters[i](subObject); - itemSchema.SetSubSchema(itemSchema.PropertyNames[i], BuildSubObjectSchema(obj)); + if (itemSchema.PropertyTypes[i] == JSDataSourceSchemaType.ObjectValue) + { + var obj = propertyGetters[i](subObject); + itemSchema.SetSubSchema(itemSchema.PropertyNames[i], BuildSubObjectSchema(obj)); + } } } } return schema; } - public object ResolveFieldValue(String name, Object item, Func fieldGetter, JsonDataSourceItem rootItem, JSDataSourceSchemaType type, DataSourceManager manager) + public object? ResolveFieldValue(String name, Object item, Func fieldGetter, JsonDataSourceItem rootItem, JSDataSourceSchemaType type, DataSourceManager? manager) { try { @@ -490,9 +492,9 @@ public String RenderDate(object value) return "null"; } - private JSDataSourceSchema _itemSchema = null; + private JSDataSourceSchema? _itemSchema = null; - public JSDataSourceSchema ItemSchema + public JSDataSourceSchema? ItemSchema { get { @@ -509,12 +511,12 @@ public JSDataSourceSchema ItemSchema private List _buildingProperties = new List(); private List _buildingPropertiesTypes = new List(); - private List _buildingPropertiesDataIntents = new List(); + private List _buildingPropertiesDataIntents = new List(); private List _buildingFields = new List(); private List _buildingFieldsTypes = new List(); - private List _buildingFieldsDataIntents = new List(); + private List _buildingFieldsDataIntents = new List(); - private Dictionary _subSchemas = new Dictionary(); + private Dictionary _subSchemas = new Dictionary(); public bool IsNullable(string propertyName) { @@ -537,21 +539,30 @@ public bool IsNullable(Type propertyType) return propertyType.IsGenericType && propertyType.GetGenericTypeDefinition() == typeof(Nullable<>); } - public JSDataSourceSchema GetSubSchema(string propertyName) + public JSDataSourceSchema? GetSubSchema(string? propertyName) { - if (_subSchemas.ContainsKey(propertyName)) + if (propertyName == null || !_subSchemas.ContainsKey(propertyName)) { - return _subSchemas[propertyName]; + return null; } - return null; + return _subSchemas[propertyName]; } - public void SetSubSchema(string propertyName, JSDataSourceSchema schema) + public void SetSubSchema(string? propertyName, JSDataSourceSchema? schema) { + if (propertyName == null) + { + return; + } _subSchemas[propertyName] = schema; } - public JSDataSourceSchemaType ResolveSchemaType(Type type) + public JSDataSourceSchemaType ResolveSchemaType(Type? type) { + if (type == null) + { + return JSDataSourceSchemaType.ObjectValue; + } + if (type == typeof(double)) { return JSDataSourceSchemaType.DoubleValue; @@ -627,7 +638,7 @@ public JSDataSourceSchemaType ResolveSchemaType(Type type) } if (typeof(IEnumerable).IsAssignableFrom(type)) { - Type enumerableType = null; + Type? enumerableType = null; if (type.IsArray) { enumerableType = type.GetElementType(); @@ -674,7 +685,7 @@ public void AddProperty(PropertyInfo prop) { _buildingProperties.Add(prop); - List dataIntents = null; + List? dataIntents = null; var attrs = prop.GetCustomAttributes(); if (attrs != null) { @@ -707,7 +718,7 @@ public void AddField(FieldInfo curr) Type ret = curr.FieldType; JSDataSourceSchemaType type = ResolveSchemaType(ret); - List dataIntents = null; + List? dataIntents = null; var attrs = curr.GetCustomAttributes(); if (attrs != null) { @@ -730,23 +741,24 @@ public void AddField(FieldInfo curr) _buildingFieldsTypes.Add(type); } - public PropertyInfo[] Properties; - public Func[] PropertyGetters; - public Func[] FieldGetters; - public Delegate[] TypedPropertyGetters; - public Delegate[] TypedFieldGetters; - public JSDataSourceSchemaType[] PropertyTypes; - public IDataIntentAttribute[][] PropertyDataIntents; - public System.Text.Json.JsonEncodedText[] JsonPropertyNames; - public System.Text.Json.JsonEncodedText[] JsonFieldNames; - public String[] PropertyNames; - public String[] FieldNames; - public FieldInfo[] Fields; - public JSDataSourceSchemaType[] FieldTypes; - public IDataIntentAttribute[][] FieldDataIntents; - - private System.Linq.Expressions.UnaryExpression GetConversion(Type type, System.Linq.Expressions.Expression expression) + public PropertyInfo[] Properties = Array.Empty(); + public Func[]? PropertyGetters; + public Func[]? FieldGetters; + public Delegate[]? TypedPropertyGetters; + public Delegate[]? TypedFieldGetters; + public JSDataSourceSchemaType[] PropertyTypes = Array.Empty(); + public IDataIntentAttribute[]?[] PropertyDataIntents = Array.Empty(); + public System.Text.Json.JsonEncodedText[] JsonPropertyNames = Array.Empty(); + public System.Text.Json.JsonEncodedText[] JsonFieldNames = Array.Empty(); + public String[] PropertyNames = Array.Empty(); + public String[] FieldNames = Array.Empty(); + public FieldInfo[] Fields = Array.Empty(); + public JSDataSourceSchemaType[] FieldTypes = Array.Empty(); + public IDataIntentAttribute[]?[] FieldDataIntents = Array.Empty(); + + private System.Linq.Expressions.UnaryExpression GetConversion(Type? type, System.Linq.Expressions.Expression expression) { + ArgumentNullException.ThrowIfNull(type); var isValueType = type.IsValueType; var isGenericType = type.IsGenericType; var isNullable = isGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>); @@ -761,7 +773,7 @@ private System.Linq.Expressions.UnaryExpression GetConversion(Type type, System. } } - private Func GetPropertyValueGetter(Type type, PropertyInfo propertyInfo) + private Func GetPropertyValueGetter(Type? type, PropertyInfo propertyInfo) { //var propertyInfo = type.GetProperty(propertyName); @@ -777,7 +789,7 @@ private Func GetPropertyValueGetter(Type type, PropertyInfo prop } } - private Delegate GetTypedPropertyValueGetter(Type type, PropertyInfo propertyInfo) + private Delegate GetTypedPropertyValueGetter(Type? type, PropertyInfo propertyInfo) { //var propertyInfo = type.GetProperty(propertyName); @@ -822,7 +834,7 @@ private Delegate GetTypedDictionaryValueGetter(Type dictType, Type valueType, Pr } } - private Func GetFieldValueGetter(Type type, FieldInfo fieldInfo) + private Func GetFieldValueGetter(Type? type, FieldInfo fieldInfo) { //var propertyInfo = type.GetProperty(propertyName); @@ -838,7 +850,7 @@ private Func GetFieldValueGetter(Type type, FieldInfo fieldInfo) } } - private Delegate GetTypedFieldValueGetter(Type type, FieldInfo fieldInfo) + private Delegate GetTypedFieldValueGetter(Type? type, FieldInfo fieldInfo) { //var propertyInfo = type.GetProperty(propertyName); @@ -866,7 +878,7 @@ public void Commit() PropertyTypes = _buildingPropertiesTypes.ToArray(); PropertyDataIntents = _buildingPropertiesDataIntents.ToArray(); PropertyNames = new String[_buildingProperties.Count]; - PropertyGetters = new Func[_buildingProperties.Count]; + PropertyGetters = new Func[_buildingProperties.Count]; TypedPropertyGetters = new Delegate[_buildingProperties.Count]; for (int i = 0; i < _buildingProperties.Count; i++) { diff --git a/src/componentsBase/JsonSerializable.cs b/src/componentsBase/JsonSerializable.cs index 4e041a7f..aa61f550 100644 --- a/src/componentsBase/JsonSerializable.cs +++ b/src/componentsBase/JsonSerializable.cs @@ -1,13 +1,13 @@ namespace IgniteUI.Blazor.Controls { - public delegate bool SerializationFilter(string name, string property); + public delegate bool SerializationFilter(string? name, string? property); public class SerializationContext { public System.Text.Json.Utf8JsonWriter Writer { get; set; } - public SerializationFilter Filter { get; set; } + public SerializationFilter? Filter { get; set; } - public SerializationContext(System.Text.Json.Utf8JsonWriter writer, SerializationFilter filter) + public SerializationContext(System.Text.Json.Utf8JsonWriter writer, SerializationFilter? filter) { Writer = writer; Filter = filter; @@ -16,7 +16,7 @@ public SerializationContext(System.Text.Json.Utf8JsonWriter writer, Serializatio public interface JsonSerializable { - void Serialize(SerializationContext writer, string propertyName = null); + void Serialize(SerializationContext writer, string? propertyName = null); } } diff --git a/src/componentsBase/MarshalByValueFactory.cs b/src/componentsBase/MarshalByValueFactory.cs index 58f7aeee..09bd91e4 100644 --- a/src/componentsBase/MarshalByValueFactory.cs +++ b/src/componentsBase/MarshalByValueFactory.cs @@ -2,7 +2,7 @@ namespace IgniteUI.Blazor.Controls { public class MarshalByValueFactory { - internal static bool MustMarshalByValue(string typeName) + internal static bool MustMarshalByValue(string? typeName) { switch (typeName) { @@ -135,7 +135,7 @@ internal static bool MustMarshalByValue(string typeName) return false; } - internal static object CreateInstance(string typeName) + internal static object? CreateInstance(string typeName) { switch (typeName) { diff --git a/src/componentsBase/RefSink.cs b/src/componentsBase/RefSink.cs index 9fd674d2..eceaa460 100644 --- a/src/componentsBase/RefSink.cs +++ b/src/componentsBase/RefSink.cs @@ -3,11 +3,11 @@ namespace IgniteUI.Blazor.Controls internal interface RefSink { - void OnRefChanged(String refName, Object refValue); - void OnRefNotifyInsertItem(IJSDataSource dataSource, String refName, int index, Object refItem); - void OnRefNotifyRemoveItem(IJSDataSource dataSource, String refName, int index, Object oldItem); - void OnRefNotifyClearItems(IJSDataSource dataSource, String refName, Object refValue); - void OnRefNotifySetItem(IJSDataSource dataSource, String refName, int index, Object oldItem, Object newItem); - void OnRefNotifyUpdateItem(IJSDataSource dataSource, String refName, int index, Object refItem, bool syncDataOnly); + void OnRefChanged(String refName, Object? refValue); + void OnRefNotifyInsertItem(IJSDataSource dataSource, String refName, int index, Object? refItem); + void OnRefNotifyRemoveItem(IJSDataSource dataSource, String refName, int index, Object? oldItem); + void OnRefNotifyClearItems(IJSDataSource dataSource, String refName, Object? refValue); + void OnRefNotifySetItem(IJSDataSource dataSource, String refName, int index, Object? oldItem, Object? newItem); + void OnRefNotifyUpdateItem(IJSDataSource dataSource, String refName, int index, Object? refItem, bool syncDataOnly); } } diff --git a/src/componentsBase/RendererMessage.cs b/src/componentsBase/RendererMessage.cs index 06297815..d2934f48 100644 --- a/src/componentsBase/RendererMessage.cs +++ b/src/componentsBase/RendererMessage.cs @@ -4,9 +4,9 @@ namespace IgniteUI.Blazor.Controls { internal class RendererMessage { - private Dictionary _data = new Dictionary(); - private String _type = null; - public string Type + private Dictionary _data = new Dictionary(); + private String? _type = null; + public string? Type { get { @@ -17,7 +17,7 @@ public string Type _type = value; } } - public void SetData(string key, string data) + public void SetData(string key, string? data) { _data[key] = data; } @@ -35,7 +35,7 @@ public string ToJson() return "{" + string.Join(",\n", props) + "}"; } - public ElementReference[] NativeElements { get; set; } + public ElementReference[]? NativeElements { get; set; } } } diff --git a/src/componentsBase/RendererSerializer.cs b/src/componentsBase/RendererSerializer.cs index cfa25a68..40018510 100644 --- a/src/componentsBase/RendererSerializer.cs +++ b/src/componentsBase/RendererSerializer.cs @@ -15,15 +15,15 @@ public RendererSerializer(SerializationContext context, ComponentBase component, _component = component; } - private string _name; - private ComponentBase _component; + private string? _name; + private ComponentBase? _component; private SerializationContext _context; //private List _properties = new List(); - private string _type = null; + private string? _type = null; - public string Type + public string? Type { get { @@ -48,7 +48,7 @@ public void AddBooleanProp(string propertyName, bool value) //_properties.Add("\"" + propertyName + "\"" + ": " + value.ToString(CultureInfo.InvariantCulture).ToLower()); } - public void AddStringProp(string propertyName, string value) + public void AddStringProp(string propertyName, string? value) { if (_context.Filter != null) { @@ -64,7 +64,7 @@ public void AddStringProp(string propertyName, string value) //_properties.Add("\"" + propertyName + "\"" + ": \"" + (value == null ? "null" : value) + "\""); } - public void AddPrimitiveProp(object val) + public void AddPrimitiveProp(object? val) { if (val is Array) { @@ -110,16 +110,16 @@ public void AddPrimitiveProp(object val) // ObjectToParam this thing if (_component is BaseRendererElement) { - (_component as BaseRendererElement).ObjectToParam(_context, val); + (_component as BaseRendererElement)?.ObjectToParam(_context, val); } else if (_component is BaseRendererControl) { - (_component as BaseRendererControl).ObjectToParam(_context, val); + (_component as BaseRendererControl)?.ObjectToParam(_context, val); } } } - public void AddPrimitiveProp(string propertyName, object val) + public void AddPrimitiveProp(string propertyName, object? val) { if (_context.Filter != null) { @@ -173,16 +173,16 @@ public void AddPrimitiveProp(string propertyName, object val) // ObjectToParam this thing if (_component is BaseRendererElement) { - (_component as BaseRendererElement).ObjectToParam(_context, propertyName, val); + (_component as BaseRendererElement)?.ObjectToParam(_context, propertyName, val); } else if (_component is BaseRendererControl) { - (_component as BaseRendererControl).ObjectToParam(_context, propertyName, val); + (_component as BaseRendererControl)?.ObjectToParam(_context, propertyName, val); } } } - public void AddArrayProp(string propertyName, IEnumerable values) + public void AddArrayProp(string propertyName, IEnumerable? values) { var items = values == null ? null : values as IList ?? values.ToList(); bool containsSub = false; @@ -217,7 +217,7 @@ public void AddArrayProp(string propertyName, IEnumerable values) } //string[] strValues = new string[values.Length]; context.Writer.WriteStartArray(propertyName); - foreach (object val in items) + foreach (object? val in items) { if (val is String) { @@ -262,11 +262,11 @@ public void AddArrayProp(string propertyName, IEnumerable values) { if (_component is BaseRendererElement) { - (_component as BaseRendererElement).ObjectToParam(context, val); + (_component as BaseRendererElement)?.ObjectToParam(context, val); } else if (_component is BaseRendererControl) { - (_component as BaseRendererControl).ObjectToParam(context, val); + (_component as BaseRendererControl)?.ObjectToParam(context, val); } } } @@ -275,7 +275,7 @@ public void AddArrayProp(string propertyName, IEnumerable values) //_properties.Add("\"" + propertyName + "\"" + ": [" + String.Join(", ", strValues) + " ]"); } - protected string Camelize(string value) + protected string? Camelize(string? value) { if (value == null || value.Length == 0) { @@ -311,7 +311,7 @@ public void AddEnumProp(string propertyName, Enum value) // return TextUtils.join("", parts); // } - public void AddNumberProp(String propertyName, Object value) + public void AddNumberProp(String propertyName, Object? value) { if (_context.Filter != null) { @@ -356,7 +356,7 @@ public void AddDateTimeProp(String propertyName, DateTime? value) //_properties.Add("\"" + propertyName + "\"" + ": \"" + value.ToString("o") + "\""); } - public void Start(string propertyName = null) + public void Start(string? propertyName = null) { if (propertyName != null) { @@ -374,7 +374,7 @@ public void End() _context.Writer.WriteEndObject(); } - public void AddSerializableProp(String propertyName, JsonSerializable value) + public void AddSerializableProp(String propertyName, JsonSerializable? value) { var context = _context; @@ -411,7 +411,7 @@ public void AddSerializableProp(String propertyName, JsonSerializable value) //_properties.Add("\"" + propertyName + "\"" + ": " + value.Serialize()); } - public void AddStringArrayProp(String propertyName, string[] values) + public void AddStringArrayProp(String propertyName, string[]? values) { if (_context.Filter != null) { @@ -453,7 +453,7 @@ public void AddStringArrayProp(String propertyName, string[] values) // _properties.Add("\"" + propertyName + "\"" + ": [" + arrayParts + " ]"); } - public void AddDateArrayProp(String propertyName, DateTime[] values) + public void AddDateArrayProp(String propertyName, DateTime[]? values) { if (_context.Filter != null) { @@ -499,7 +499,7 @@ public void AddDateArrayProp(String propertyName, DateTime[] values) } private Regex _colorSplitRegex = new Regex("[\\s,]+(?![^(]*\\))"); - public void AddStringArrayProp(String propertyName, string values) + public void AddStringArrayProp(String propertyName, string? values) { if (_context.Filter != null) { @@ -541,7 +541,7 @@ public void AddStringArrayProp(String propertyName, string values) // _properties.Add("\"" + propertyName + "\"" + ": [" + arrayParts + " ]"); } - public void AddEnumArrayProp(String propertyName, object values) + public void AddEnumArrayProp(String propertyName, object? values) { if (_context.Filter != null) { @@ -562,15 +562,23 @@ public void AddEnumArrayProp(String propertyName, object values) _context.Writer.WriteStartArray(propertyName); for (int i = 0; i < vals.Count; i++) { - Enum val = (Enum)vals[i]; - _context.Writer.WriteStringValue(Camelize(val.ToString())); + Enum? val = (Enum?)vals[i]; + if (val == null) + { + // Keep the element positions aligned with the source collection. + _context.Writer.WriteNullValue(); + } + else + { + _context.Writer.WriteStringValue(Camelize(val.ToString())); + } //strValues[i] = "\"" + val.ToString() + "\""; } _context.Writer.WriteEndArray(); //_properties.Add("\"" + propertyName + "\"" + ": [" + string.Join(", ", strValues) + " ]"); } - public void AddIntArrayProp(String propertyName, int[] values) + public void AddIntArrayProp(String propertyName, int[]? values) { if (_context.Filter != null) { @@ -598,7 +606,7 @@ public void AddIntArrayProp(String propertyName, int[] values) //_properties.Add("\"" + propertyName + "\"" + ": [" + string.Join(", ", strValues) + " ]"); } - public void AddDoubleArrayProp(string propertyName, double[] numbers) + public void AddDoubleArrayProp(string propertyName, double[]? numbers) { if (_context.Filter != null) { @@ -627,7 +635,7 @@ public void AddDoubleArrayProp(string propertyName, double[] numbers) //_properties.Add("\"" + propertyName + "\": " + "[" + string.Join(", ", items) + "]"); } - public void AddSerializableArrayProp(string propertyName, T[] array) where T : JsonSerializable + public void AddSerializableArrayProp(string propertyName, T[]? array) where T : JsonSerializable { if (array == null) { diff --git a/src/componentsBase/RuntimeHelper.cs b/src/componentsBase/RuntimeHelper.cs index bc0b0d46..85b26349 100644 --- a/src/componentsBase/RuntimeHelper.cs +++ b/src/componentsBase/RuntimeHelper.cs @@ -8,13 +8,13 @@ namespace IgniteUI.Blazor.Controls internal class RuntimeHelper { #if NET5_0 - private IJSUnmarshalledRuntime _unmarshalledRuntime; + private IJSUnmarshalledRuntime? _unmarshalledRuntime; #else - private Func _callSendUnmarshalledColumnMessage; - private Func _callSendUnmarshalledColumnDataIntentMessage; + private Func? _callSendUnmarshalledColumnMessage; + private Func? _callSendUnmarshalledColumnDataIntentMessage; #endif - private IJSInProcessRuntime _inprocRuntime; - private IIgniteUIBlazor _igBlazor; + private IJSInProcessRuntime? _inprocRuntime; + private IIgniteUIBlazor? _igBlazor; #if !NETSTANDARD [DynamicDependency( @@ -26,7 +26,7 @@ internal class RuntimeHelper [UnconditionalSuppressMessage("Trimming", "IL2075", Justification = "Probes the net8-only InvokeUnmarshalled methods (removed in net9+), preserved via the DynamicDependency above; absence falls back to the raw-pointer InvokeVoid path.")] [UnconditionalSuppressMessage("Trimming", "IL2060", Justification = "The generic arguments are statically referenced framework/library types, and the InvokeUnmarshalled generic parameters carry no DynamicallyAccessedMembers requirements.")] [UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "The DynamicDependency above marks the runtime's RequiresUnreferencedCode members (Invoke, GetValue, SetValue, ...); the probe filters by name and never invokes them.")] - public RuntimeHelper(IJSRuntime runtime, IIgniteUIBlazor igBlazor) + public RuntimeHelper(IJSRuntime? runtime, IIgniteUIBlazor igBlazor) { _igBlazor = igBlazor; //Console.WriteLine("initializing runtime helper"); @@ -41,7 +41,7 @@ public RuntimeHelper(IJSRuntime runtime, IIgniteUIBlazor igBlazor) IsInproc = true; //Console.WriteLine("is inproc"); } - if (IsInproc) + if (IsInproc && inprocRuntime != null) { #if NET5_0 _unmarshalledRuntime = _inprocRuntime as IJSUnmarshalledRuntime; @@ -75,7 +75,7 @@ public RuntimeHelper(IJSRuntime runtime, IIgniteUIBlazor igBlazor) indexParam, columnsParam); _callSendUnmarshalledColumnMessage = - (Func)Expression.Lambda( + (Func)Expression.Lambda( call, jsRuntimeParam, methodNameParam, refNameParam, indexParam, columnsParam).Compile(); } @@ -108,26 +108,29 @@ public RuntimeHelper(IJSRuntime runtime, IIgniteUIBlazor igBlazor) } } - public unsafe string SendUnmarshalledColumnMessage(string methodName, string refName, int index, UnmarshalledColumn[] columns) + public unsafe string? SendUnmarshalledColumnMessage(string methodName, string refName, int index, UnmarshalledColumn[]? columns) { #if NET5_0 if (_unmarshalledRuntime != null) { - return _unmarshalledRuntime.InvokeUnmarshalled(methodName, refName, index, columns); + return _unmarshalledRuntime.InvokeUnmarshalled(methodName, refName, index, columns); } #else - if (_callSendUnmarshalledColumnMessage != null) + if (_callSendUnmarshalledColumnMessage != null && _inprocRuntime != null) { return _callSendUnmarshalledColumnMessage(_inprocRuntime, methodName, refName, index, columns); } #endif var intptr = Unsafe.AsPointer(ref columns); - _inprocRuntime.InvokeVoid(methodName, new object[] { refName, index, (int)intptr }); + if (_inprocRuntime != null) + { + _inprocRuntime.InvokeVoid(methodName, new object[] { refName, index, (int)intptr }); + } return null; } - public string SendUnmarshalledColumnDataIntentsMessage(string methodName, string refName, string dataIntents) + public string? SendUnmarshalledColumnDataIntentsMessage(string methodName, string refName, string dataIntents) { #if NET5_0 if (_unmarshalledRuntime != null) @@ -136,18 +139,21 @@ public string SendUnmarshalledColumnDataIntentsMessage(string methodName, string return _unmarshalledRuntime.InvokeUnmarshalled(methodName, refName, dataIntents); } #else - if (_callSendUnmarshalledColumnMessage != null) + if (_callSendUnmarshalledColumnDataIntentMessage != null && _inprocRuntime != null) { //Console.WriteLine("invoking sadness"); return _callSendUnmarshalledColumnDataIntentMessage(_inprocRuntime, methodName, refName, dataIntents); } #endif - _inprocRuntime.InvokeVoid(methodName, new object[] { refName, dataIntents }); + if (_inprocRuntime != null) + { + _inprocRuntime.InvokeVoid(methodName, new object[] { refName, dataIntents }); + } return null; } public bool IsInproc { get; private set; } - public bool IsForcedJsonDataMarshalling { get { return _igBlazor.Settings.ForceJsonDataMarshalling; } } + public bool IsForcedJsonDataMarshalling { get { return _igBlazor?.Settings?.ForceJsonDataMarshalling ?? false; } } } } diff --git a/src/componentsBase/UnmarshalledDataSource.cs b/src/componentsBase/UnmarshalledDataSource.cs index 5d7b14b8..f4c70312 100644 --- a/src/componentsBase/UnmarshalledDataSource.cs +++ b/src/componentsBase/UnmarshalledDataSource.cs @@ -19,30 +19,30 @@ public UnmarshalledColumnData() SubSchema = null; } - public string PropertyPath { get; set; } + public string? PropertyPath { get; set; } public JSDataSourceSchemaType Type { get; set; } - public int[] IntValues { get; set; } - public long[] LongValues { get; set; } - public double[] DoubleValues { get; set; } - public string[] StringValues { get; set; } - public bool[] NullValues { get; set; } - public Guid[] IDValues { get; set; } - public UnmarshalledColumn[][] SubDataSourceValues; + public int[]? IntValues { get; set; } + public long[]? LongValues { get; set; } + public double[]? DoubleValues { get; set; } + public string?[]? StringValues { get; set; } + public bool[]? NullValues { get; set; } + public Guid[]? IDValues { get; set; } + public UnmarshalledColumn[]?[]? SubDataSourceValues; public UnmarshalledColumn Column { get; set; } public bool IsObjectColumn { get; set; } - public UnmarshalledColumnData[] SubColumns { get; set; } - public JSDataSourceSchema SubSchema { get; set; } - public Action Insert { get; internal set; } - public Action Update { get; internal set; } - public Action Remove { get; internal set; } + public UnmarshalledColumnData?[]? SubColumns { get; set; } + public JSDataSourceSchema? SubSchema { get; set; } + public Action? Insert { get; internal set; } + public Action? Update { get; internal set; } + public Action? Remove { get; internal set; } public bool IsIDColumn { get; internal set; } - public Action Clear { get; internal set; } - public string PropertyName { get; internal set; } + public Action? Clear { get; internal set; } + public string? PropertyName { get; internal set; } public bool IsSubDataSource { get; internal set; } - public Delegate Getter { get; internal set; } + public Delegate? Getter { get; internal set; } } [StructLayout(LayoutKind.Explicit, Size = 56)] @@ -67,7 +67,7 @@ internal struct UnmarshalledColumn [FieldOffset(40)] public string[] StringValues; [FieldOffset(40)] - public UnmarshalledColumn[][] SubDataSourceValues; + public UnmarshalledColumn[]?[]? SubDataSourceValues; [FieldOffset(48)] public bool[] NullValues; } @@ -84,21 +84,21 @@ public JSDataSourceType DataSourceType } } public bool IsSent { get; set; } - private object _originalData; + private object? _originalData; private Dictionary _uuidToOriginal = new Dictionary(); private Dictionary _originalToUuid = new Dictionary(); //private Dictionary _stringToUuid = new Dictionary(); - private RuntimeHelper _helper; - private JSDataSourceSchema _parentSchema = null; - private string _parentId; - private DataSourceManager _manager = null; + private RuntimeHelper? _helper; + private JSDataSourceSchema? _parentSchema = null; + private string? _parentId; + private DataSourceManager? _manager = null; - private UnmarshalledColumnData[] _columns = null; + private UnmarshalledColumnData?[]? _columns = null; private Dictionary> _subDataSources = new Dictionary>(); - private Func _idGetter; + private Func? _idGetter; private int _size = 0; private int _capacity = 0; @@ -142,15 +142,14 @@ public UnmarshalledDataSource() }; } - private UnmarshalledColumnData[] AdjustCapacity(string parentPath, UnmarshalledColumnData[] columns, JSDataSourceSchema schema, int oldValue, int newValue) + private UnmarshalledColumnData?[]? AdjustCapacity(string? parentPath, UnmarshalledColumnData?[]? columns, JSDataSourceSchema? schema, int oldValue, int newValue) { //Console.WriteLine("adjusting capacity, oldValue: " + oldValue + ", newValue: " + newValue); DateTime start = DateTime.Now; - if (columns == null && schema == null) + if (schema == null) { - return null; + return columns; } - if (schema.IsDataSource) { if (columns == null) @@ -164,6 +163,15 @@ private UnmarshalledColumnData[] AdjustCapacity(string parentPath, UnmarshalledC } else { + var propertyNames = schema.PropertyNames ?? Array.Empty(); + var fieldNames = schema.FieldNames ?? Array.Empty(); + var propertyGetters = schema.PropertyGetters ?? Array.Empty>(); + var fieldGetters = schema.FieldGetters ?? Array.Empty>(); + var typedPropertyGetters = schema.TypedPropertyGetters ?? Array.Empty(); + var typedFieldGetters = schema.TypedFieldGetters ?? Array.Empty(); + var propertyTypes = schema.PropertyTypes ?? Array.Empty(); + var fieldTypes = schema.FieldTypes ?? Array.Empty(); + if (columns == null) { var extraCols = 1; @@ -171,21 +179,22 @@ private UnmarshalledColumnData[] AdjustCapacity(string parentPath, UnmarshalledC { extraCols = 0; } - columns = new UnmarshalledColumnData[schema.PropertyNames.Length + schema.FieldNames.Length + extraCols]; + columns = new UnmarshalledColumnData[propertyNames.Length + fieldNames.Length + extraCols]; for (var k = 0; k < columns.Length; k++) { columns[k] = null; } } + int i = 0; - for (i = 0; i < schema.PropertyNames.Length; i++) + for (i = 0; i < propertyNames.Length; i++) { - columns[i] = AdjustColumnCapacity(parentPath, columns[i], schema, schema.PropertyNames[i], schema.TypedPropertyGetters[i], schema.PropertyGetters[i], false, schema.PropertyTypes[i], oldValue, newValue); + columns[i] = AdjustColumnCapacity(parentPath, columns[i], schema, propertyNames[i], typedPropertyGetters[i], propertyGetters[i], false, propertyTypes[i], oldValue, newValue); } - for (int j = 0; j < _schema.FieldNames.Length; i++, j++) + for (int j = 0; j < fieldNames.Length; i++, j++) { - columns[i] = AdjustColumnCapacity(parentPath, columns[i], schema, schema.FieldNames[j], schema.TypedFieldGetters[j], schema.FieldGetters[j], false, schema.FieldTypes[j], oldValue, newValue); + columns[i] = AdjustColumnCapacity(parentPath, columns[i], schema, fieldNames[j], typedFieldGetters[j], fieldGetters[j], false, fieldTypes[j], oldValue, newValue); } } if (schema.IsPrimitive) @@ -220,8 +229,9 @@ private UnmarshalledColumnData[] AdjustCapacity(string parentPath, UnmarshalledC }; if (columns[columns.Length - 1] == null) { - columns[columns.Length - 1] = CreateColumn(parentPath, "___id", schema, JSDataSourceSchemaType.StringValue, idGetter, untypedIdGetter, true); - columns[columns.Length - 1].IsIDColumn = true; + var idColumn = CreateColumn(parentPath, "___id", schema, JSDataSourceSchemaType.StringValue, idGetter, untypedIdGetter, true); + idColumn.IsIDColumn = true; + columns[columns.Length - 1] = idColumn; } columns[columns.Length - 1] = AdjustColumnCapacity(parentPath, columns[columns.Length - 1], schema, "___id", idGetter, untypedIdGetter, true, JSDataSourceSchemaType.StringValue, oldValue, newValue); } @@ -230,7 +240,7 @@ private UnmarshalledColumnData[] AdjustCapacity(string parentPath, UnmarshalledC return columns; } - private UnmarshalledColumnData CreateColumn(string parentPath, string propertyName, JSDataSourceSchema schema, JSDataSourceSchemaType type, Delegate valueGetter, Func untypedGetter, bool isIDColumn) + private UnmarshalledColumnData CreateColumn(string? parentPath, string? propertyName, JSDataSourceSchema schema, JSDataSourceSchemaType type, Delegate? valueGetter, Func? untypedGetter, bool isIDColumn) { if (parentPath != null && parentPath.Length > 0) { @@ -262,86 +272,89 @@ private UnmarshalledColumnData CreateColumn(string parentPath, string propertyNa col.IsSubDataSource = newColumn.IsSubDataSource ? 1 : 0; newColumn.Column = col; - Func idGetter = null; - Func doubleGetter = null; - Func singleGetter = null; - Func boolGetter = null; - Func byteGetter = null; - Func decimalGetter = null; - Func shortGetter = null; - Func longGetter = null; - Func stringGetter = null; - Func dateTimeGetter = null; - Func objectGetter = null; - - Func floatingPointGetter = null; - Func integerGetter = null; - - Func nullableShortGetter = null; - Func nullableIntegerGetter = null; - Func nullableLongGetter = null; - Func nullableSingleGetter = null; - Func nullableDoubleGetter = null; - Func nullableDecimalGetter = null; - Func nullableBoolGetter = null; - Func nullableByteGetter = null; - Func nullableDateTimeGetter = null; - Func nullableFloatingPointGetter = null; + Func? idGetter = null; + Func? doubleGetter = null; + Func? singleGetter = null; + Func? boolGetter = null; + Func? byteGetter = null; + Func? decimalGetter = null; + Func? shortGetter = null; + Func? longGetter = null; + Func? stringGetter = null; + Func? dateTimeGetter = null; + Func? objectGetter = null; + + Func? floatingPointGetter = null; + Func? integerGetter = null; + + Func? nullableShortGetter = null; + Func? nullableIntegerGetter = null; + Func? nullableLongGetter = null; + Func? nullableSingleGetter = null; + Func? nullableDoubleGetter = null; + Func? nullableDecimalGetter = null; + Func? nullableBoolGetter = null; + Func? nullableByteGetter = null; + Func? nullableDateTimeGetter = null; + Func? nullableFloatingPointGetter = null; switch (newColumn.Type) { case JSDataSourceSchemaType.DoubleValue: - doubleGetter = (Func)valueGetter; + doubleGetter = (Func?)valueGetter; floatingPointGetter = doubleGetter; break; case JSDataSourceSchemaType.SingleValue: - singleGetter = (Func)valueGetter; - floatingPointGetter = (o) => (double)singleGetter(o); + singleGetter = (Func?)valueGetter; + floatingPointGetter = (o) => singleGetter == null ? double.NaN : (double)singleGetter(o); break; case JSDataSourceSchemaType.BooleanValue: - boolGetter = (Func)valueGetter; - integerGetter = (o) => boolGetter(o) ? 1 : 0; + boolGetter = (Func?)valueGetter; + integerGetter = (o) => (boolGetter != null && boolGetter(o)) ? 1 : 0; break; case JSDataSourceSchemaType.ByteValue: - byteGetter = (Func)valueGetter; - integerGetter = (o) => (int)byteGetter(o); + byteGetter = (Func?)valueGetter; + integerGetter = (o) => byteGetter == null ? 0 : (int)byteGetter(o); break; case JSDataSourceSchemaType.DecimalValue: - decimalGetter = (Func)valueGetter; - floatingPointGetter = (o) => (double)decimalGetter(o); + decimalGetter = (Func?)valueGetter; + floatingPointGetter = (o) => decimalGetter == null ? double.NaN : (double)decimalGetter(o); break; case JSDataSourceSchemaType.IntValue: - integerGetter = (Func)valueGetter; + integerGetter = (Func?)valueGetter; break; case JSDataSourceSchemaType.ShortValue: - shortGetter = (Func)valueGetter; - integerGetter = (o) => (int)shortGetter(o); + shortGetter = (Func?)valueGetter; + integerGetter = (o) => shortGetter == null ? 0 : (int)shortGetter(o); break; case JSDataSourceSchemaType.LongValue: - longGetter = (Func)valueGetter; + longGetter = (Func?)valueGetter; break; case JSDataSourceSchemaType.StringValue: if (isIDColumn) { - idGetter = (Func)valueGetter; - stringGetter = (o) => idGetter(o).ToString(); + idGetter = (Func?)valueGetter; + stringGetter = (o) => idGetter == null ? string.Empty : idGetter(o).ToString(); } else { - stringGetter = (Func)valueGetter; + stringGetter = (Func?)valueGetter; } break; case JSDataSourceSchemaType.CalendarValue: case JSDataSourceSchemaType.DateTimeValue: - if (typeof(Func).IsAssignableFrom(valueGetter.GetType())) + if (valueGetter != null && typeof(Func).IsAssignableFrom(valueGetter.GetType())) { dateTimeGetter = (Func)valueGetter; stringGetter = (o) => ((DateTime)dateTimeGetter(o)).ToString("o"); } else { - dateTimeGetter = (o) => (DateTime)untypedGetter(o); - stringGetter = (o) => ((DateTime)dateTimeGetter(o)).ToString("o"); + stringGetter = (o) => + { + var val = (DateTime?)untypedGetter?.Invoke(o); + return val == null ? null : val.Value.ToString("o"); + }; } break; case JSDataSourceSchemaType.ObjectValue: @@ -363,17 +376,21 @@ private UnmarshalledColumnData CreateColumn(string parentPath, string propertyNa break; case JSDataSourceSchemaType.NullableDoubleValue: - nullableDoubleGetter = (Func)valueGetter; + nullableDoubleGetter = (Func?)valueGetter; nullableFloatingPointGetter = nullableDoubleGetter; break; case JSDataSourceSchemaType.NullableSingleValue: - nullableSingleGetter = (Func)valueGetter; - nullableFloatingPointGetter = (o) => (double?)nullableSingleGetter(o); + nullableSingleGetter = (Func?)valueGetter; + nullableFloatingPointGetter = (o) => nullableSingleGetter == null ? null : (double?)nullableSingleGetter(o); break; case JSDataSourceSchemaType.NullableBooleanValue: - nullableBoolGetter = (Func)valueGetter; + nullableBoolGetter = (Func?)valueGetter; nullableIntegerGetter = (o) => { + if (nullableBoolGetter == null) + { + return null; + } var val = nullableBoolGetter(o); int? t = 1; int? f = 0; @@ -381,26 +398,26 @@ private UnmarshalledColumnData CreateColumn(string parentPath, string propertyNa }; break; case JSDataSourceSchemaType.NullableByteValue: - nullableByteGetter = (Func)valueGetter; - nullableIntegerGetter = (o) => (int?)nullableByteGetter(o); + nullableByteGetter = (Func?)valueGetter; + nullableIntegerGetter = (o) => nullableByteGetter == null ? null : (int?)nullableByteGetter(o); break; case JSDataSourceSchemaType.NullableDecimalValue: - nullableDecimalGetter = (Func)valueGetter; - nullableFloatingPointGetter = (o) => (double?)nullableDecimalGetter(o); + nullableDecimalGetter = (Func?)valueGetter; + nullableFloatingPointGetter = (o) => nullableDecimalGetter == null ? null : (double?)nullableDecimalGetter(o); break; case JSDataSourceSchemaType.NullableIntValue: - nullableIntegerGetter = (Func)valueGetter; + nullableIntegerGetter = (Func?)valueGetter; break; case JSDataSourceSchemaType.NullableShortValue: - nullableShortGetter = (Func)valueGetter; - nullableIntegerGetter = (o) => (int?)nullableShortGetter(o); + nullableShortGetter = (Func?)valueGetter; + nullableIntegerGetter = (o) => nullableShortGetter == null ? null : (int?)nullableShortGetter(o); break; case JSDataSourceSchemaType.NullableLongValue: - nullableLongGetter = (Func)valueGetter; + nullableLongGetter = (Func?)valueGetter; break; case JSDataSourceSchemaType.NullableCalendarValue: case JSDataSourceSchemaType.NullableDateTimeValue: - if (typeof(Func).IsAssignableFrom(valueGetter.GetType())) + if (valueGetter != null && typeof(Func).IsAssignableFrom(valueGetter.GetType())) { nullableDateTimeGetter = (Func)valueGetter; stringGetter = (o) => @@ -411,17 +428,16 @@ private UnmarshalledColumnData CreateColumn(string parentPath, string propertyNa } else { - nullableDateTimeGetter = (o) => (DateTime?)untypedGetter(o); stringGetter = (o) => { - var val = nullableDateTimeGetter(o); + var val = (DateTime?)untypedGetter?.Invoke(o); return val == null ? null : val.Value.ToString("o"); }; } break; } - Action insert = null; + Action? insert = null; switch (newColumn.Type) { case JSDataSourceSchemaType.DoubleValue: @@ -429,12 +445,19 @@ private UnmarshalledColumnData CreateColumn(string parentPath, string propertyNa case JSDataSourceSchemaType.DecimalValue: insert = (size, column, index, item) => { + if (column.DoubleValues == null) + { + return; + } double floatVal = double.NaN; if (item != null) { if (!schema.IsPrimitive) { - floatVal = floatingPointGetter(item); + if (floatingPointGetter != null) + { + floatVal = floatingPointGetter(item); + } } else { @@ -458,10 +481,17 @@ private UnmarshalledColumnData CreateColumn(string parentPath, string propertyNa case JSDataSourceSchemaType.NullableDecimalValue: insert = (size, column, index, item) => { + if (column.DoubleValues == null || column.NullValues == null) + { + return; + } double? floatVal = null; if (item != null) { - floatVal = nullableFloatingPointGetter(item); + if (nullableFloatingPointGetter != null) + { + floatVal = nullableFloatingPointGetter(item); + } } if (index == size) { @@ -484,12 +514,19 @@ private UnmarshalledColumnData CreateColumn(string parentPath, string propertyNa case JSDataSourceSchemaType.ShortValue: insert = (size, column, index, item) => { + if (column.IntValues == null) + { + return; + } int intVal = int.MinValue; if (item != null) { if (!schema.IsPrimitive) { - intVal = integerGetter(item); + if (integerGetter != null) + { + intVal = integerGetter(item); + } } else { @@ -514,10 +551,17 @@ private UnmarshalledColumnData CreateColumn(string parentPath, string propertyNa case JSDataSourceSchemaType.NullableShortValue: insert = (size, column, index, item) => { + if (column.IntValues == null || column.NullValues == null) + { + return; + } int? intVal = null; if (item != null) { - intVal = nullableIntegerGetter(item); + if (nullableIntegerGetter != null) + { + intVal = nullableIntegerGetter(item); + } } if (index == size) { @@ -537,12 +581,19 @@ private UnmarshalledColumnData CreateColumn(string parentPath, string propertyNa case JSDataSourceSchemaType.LongValue: insert = (size, column, index, item) => { + if (column.LongValues == null) + { + return; + } long longVal = long.MinValue; if (item != null) { if (!schema.IsPrimitive) { - longVal = longGetter(item); + if (longGetter != null) + { + longVal = longGetter(item); + } } else { @@ -564,10 +615,17 @@ private UnmarshalledColumnData CreateColumn(string parentPath, string propertyNa case JSDataSourceSchemaType.NullableLongValue: insert = (size, column, index, item) => { + if (column.LongValues == null || column.NullValues == null) + { + return; + } long? longVal = null; if (item != null) { - longVal = nullableLongGetter(item); + if (nullableLongGetter != null) + { + longVal = nullableLongGetter(item); + } } if (index == size) { @@ -589,20 +647,27 @@ private UnmarshalledColumnData CreateColumn(string parentPath, string propertyNa case JSDataSourceSchemaType.DateTimeValue: insert = (size, column, index, item) => { - string stringVal = null; + if (column.StringValues == null) + { + return; + } + string? stringVal = null; Guid idVal = Guid.Empty; if (item != null) { if (column.IsIDColumn) { - idVal = idGetter(item); + if (idGetter != null) + { + idVal = idGetter(item); + } stringVal = _parentId != null ? _parentId + "/" + idVal.ToString() : idVal.ToString(); } else if (!schema.IsPrimitive) { try { - stringVal = stringGetter(item); + stringVal = stringGetter != null ? stringGetter(item) : null; } catch { @@ -616,10 +681,6 @@ private UnmarshalledColumnData CreateColumn(string parentPath, string propertyNa } if (index == size) { - if (column.StringValues == null) - { - //Console.WriteLine("stringvalues null: " + column.PropertyName); - } column.StringValues[index] = stringVal; } else @@ -629,14 +690,10 @@ private UnmarshalledColumnData CreateColumn(string parentPath, string propertyNa column.StringValues[index] = stringVal; } - if (column.IsIDColumn) + if (column.IsIDColumn && column.IDValues != null) { if (index == size) { - if (column.IDValues == null) - { - //Console.WriteLine("stringvalues null: " + column.PropertyName); - } column.IDValues[index] = idVal; } else @@ -652,12 +709,16 @@ private UnmarshalledColumnData CreateColumn(string parentPath, string propertyNa case JSDataSourceSchemaType.NullableDateTimeValue: insert = (size, column, index, item) => { - string stringVal = null; + if (column.StringValues == null) + { + return; + } + string? stringVal = null; if (item != null) { try { - stringVal = stringGetter(item); + stringVal = stringGetter != null ? stringGetter(item) : null; } catch { @@ -666,10 +727,6 @@ private UnmarshalledColumnData CreateColumn(string parentPath, string propertyNa } if (index == size) { - if (column.StringValues == null) - { - //Console.WriteLine("stringvalues null: " + column.PropertyName); - } column.StringValues[index] = stringVal; } else @@ -684,8 +741,8 @@ private UnmarshalledColumnData CreateColumn(string parentPath, string propertyNa insert = (size, column, index, item) => { //Console.WriteLine("shouldn't be here"); - object objVal = null; - if (item != null) + object? objVal = null; + if (item != null && objectGetter != null) { objVal = objectGetter(item); } @@ -698,7 +755,7 @@ private UnmarshalledColumnData CreateColumn(string parentPath, string propertyNa schema.SetSubSchema(column.PropertyName, subSchema); column.SubSchema = subSchema; } - if (subSchema.IsDataSource && !column.IsSubDataSource) + if (subSchema != null && subSchema.IsDataSource && !column.IsSubDataSource) { column.IsSubDataSource = true; var c = column.Column; @@ -714,20 +771,27 @@ private UnmarshalledColumnData CreateColumn(string parentPath, string propertyNa if (column.IsSubDataSource) { - UnmarshalledColumn[] cols = null; + if (column.SubDataSourceValues == null) + { + return; + } + UnmarshalledColumn[]? cols = null; if (objVal != null) { - var id = _idGetter(item); + var id = _idGetter != null && item != null ? _idGetter(item) : Guid.Empty; var parentId = _parentId != null ? _parentId + "/" + id.ToString() : id.ToString(); - var sub = (UnmarshalledDataSource)UnmarshalledDataSource.CreateWithSchema(objVal, parentId, column.SubSchema, _manager, _helper); - cols = sub.GetColumns(""); + var sub = (UnmarshalledDataSource?)UnmarshalledDataSource.CreateWithSchema(objVal, parentId, column.SubSchema, _manager, _helper); + cols = sub?.GetColumns(""); if (!_subDataSources.ContainsKey(id)) { _subDataSources[id] = new Dictionary(); } - _subDataSources[id].Add(column.PropertyName, sub); + if (column.PropertyName != null && sub != null) + { + _subDataSources[id].Add(column.PropertyName, sub); + } } if (index == size) { @@ -747,7 +811,10 @@ private UnmarshalledColumnData CreateColumn(string parentPath, string propertyNa for (var i = 0; i < column.SubColumns.Length; i++) { var subColumn = column.SubColumns[i]; - subColumn.Insert(size, subColumn, index, objVal); + if (subColumn != null) + { + subColumn.Insert?.Invoke(size, subColumn, index, objVal); + } } } } @@ -766,8 +833,8 @@ private UnmarshalledColumnData CreateColumn(string parentPath, string propertyNa case JSDataSourceSchemaType.SingleArrayValue: insert = (size, column, index, item) => { - object objVal = null; - if (item != null) + object? objVal = null; + if (item != null && objectGetter != null) { objVal = objectGetter(item); } @@ -781,7 +848,7 @@ private UnmarshalledColumnData CreateColumn(string parentPath, string propertyNa schema.SetSubSchema(column.PropertyName, subSchema); column.SubSchema = subSchema; } - if (subSchema.IsDataSource && !column.IsSubDataSource) + if (subSchema != null && subSchema.IsDataSource && !column.IsSubDataSource) { column.IsSubDataSource = true; var c = column.Column; @@ -797,74 +864,81 @@ private UnmarshalledColumnData CreateColumn(string parentPath, string propertyNa if (column.IsSubDataSource) { - UnmarshalledColumn[] cols = null; + if (column.SubDataSourceValues == null) + { + return; + } + UnmarshalledColumn[]? cols = null; if (objVal != null) { - var sub = (UnmarshalledDataSource)UnmarshalledDataSource.CreateWithSchema(objVal, column.SubSchema, _manager, _helper); - var subcols = sub.GetColumns(""); - - UnmarshalledColumn primcol = new UnmarshalledColumn(); - primcol.ActualCount = subcols[0].ActualCount; - primcol.DataSourceID = subcols[0].DataSourceID; - primcol.PropertyPath = "___primitiveVal"; - primcol.Type = GetArrayType(newColumn.Type); - int i = 0; - switch (newColumn.Type) - { - case JSDataSourceSchemaType.StringArrayValue: - primcol.StringValues = new string[primcol.ActualCount]; - foreach (var v in (objVal as IEnumerable)) - { - primcol.StringValues[i] = (string)v; - i++; - } - break; - case JSDataSourceSchemaType.DateTimeArrayValue: - case JSDataSourceSchemaType.CalendarArrayValue: - primcol.StringValues = new string[primcol.ActualCount]; - foreach (var v in (objVal as IEnumerable)) - { - primcol.StringValues[i] = ((DateTime)v).ToString("o"); - i++; - } - break; - case JSDataSourceSchemaType.BooleanArrayValue: - case JSDataSourceSchemaType.ByteArrayValue: - case JSDataSourceSchemaType.IntArrayValue: - case JSDataSourceSchemaType.ShortArrayValue: - primcol.IntValues = new int[primcol.ActualCount]; - foreach (var v in (objVal as IEnumerable)) - { - primcol.IntValues[i] = Convert.ToInt32(v); - i++; - } - break; - case JSDataSourceSchemaType.DoubleArrayValue: - case JSDataSourceSchemaType.SingleArrayValue: - case JSDataSourceSchemaType.DecimalArrayValue: - primcol.DoubleValues = new double[primcol.ActualCount]; - foreach (var v in (objVal as IEnumerable)) - { - primcol.DoubleValues[i] = Convert.ToDouble(v); - i++; - } - break; - case JSDataSourceSchemaType.LongArrayValue: - primcol.LongValues = new long[primcol.ActualCount]; - foreach (var v in (objVal as IEnumerable)) - { - primcol.LongValues[i] = Convert.ToInt64(v); - i++; - } - break; - } - - cols = new UnmarshalledColumn[subcols.Length + 1]; - for (i = 0; i < subcols.Length; i++) + var sub = (UnmarshalledDataSource?)UnmarshalledDataSource.CreateWithSchema(objVal, column.SubSchema, _manager, _helper); + if (sub != null) { - cols[i] = subcols[i]; + var subcols = sub.GetColumns(""); + + UnmarshalledColumn primcol = new UnmarshalledColumn(); + primcol.ActualCount = subcols[0].ActualCount; + primcol.DataSourceID = subcols[0].DataSourceID; + primcol.PropertyPath = "___primitiveVal"; + primcol.Type = GetArrayType(newColumn.Type); + int i = 0; + switch (newColumn.Type) + { + case JSDataSourceSchemaType.StringArrayValue: + primcol.StringValues = new string[primcol.ActualCount]; + foreach (var v in ((IEnumerable)objVal)) + { + primcol.StringValues[i] = (string)v; + i++; + } + break; + case JSDataSourceSchemaType.DateTimeArrayValue: + case JSDataSourceSchemaType.CalendarArrayValue: + primcol.StringValues = new string[primcol.ActualCount]; + foreach (var v in ((IEnumerable)objVal)) + { + primcol.StringValues[i] = ((DateTime)v).ToString("o"); + i++; + } + break; + case JSDataSourceSchemaType.BooleanArrayValue: + case JSDataSourceSchemaType.ByteArrayValue: + case JSDataSourceSchemaType.IntArrayValue: + case JSDataSourceSchemaType.ShortArrayValue: + primcol.IntValues = new int[primcol.ActualCount]; + foreach (var v in ((IEnumerable)objVal)) + { + primcol.IntValues[i] = Convert.ToInt32(v); + i++; + } + break; + case JSDataSourceSchemaType.DoubleArrayValue: + case JSDataSourceSchemaType.SingleArrayValue: + case JSDataSourceSchemaType.DecimalArrayValue: + primcol.DoubleValues = new double[primcol.ActualCount]; + foreach (var v in ((IEnumerable)objVal)) + { + primcol.DoubleValues[i] = Convert.ToDouble(v); + i++; + } + break; + case JSDataSourceSchemaType.LongArrayValue: + primcol.LongValues = new long[primcol.ActualCount]; + foreach (var v in ((IEnumerable)objVal)) + { + primcol.LongValues[i] = Convert.ToInt64(v); + i++; + } + break; + } + + cols = new UnmarshalledColumn[subcols.Length + 1]; + for (i = 0; i < subcols.Length; i++) + { + cols[i] = subcols[i]; + } + cols[subcols.Length] = primcol; } - cols[subcols.Length] = primcol; } if (index == size) { @@ -884,7 +958,10 @@ private UnmarshalledColumnData CreateColumn(string parentPath, string propertyNa for (var i = 0; i < column.SubColumns.Length; i++) { var subColumn = column.SubColumns[i]; - subColumn.Insert(size, subColumn, index, objVal); + if (subColumn != null) + { + subColumn.Insert?.Invoke(size, subColumn, index, objVal); + } } } } @@ -892,7 +969,7 @@ private UnmarshalledColumnData CreateColumn(string parentPath, string propertyNa break; } - Action update = null; + Action? update = null; switch (newColumn.Type) { case JSDataSourceSchemaType.DoubleValue: @@ -900,8 +977,12 @@ private UnmarshalledColumnData CreateColumn(string parentPath, string propertyNa case JSDataSourceSchemaType.DecimalValue: update = (size, column, index, oldItem, newItem) => { + if (column.DoubleValues == null) + { + return; + } double floatVal = double.NaN; - if (newItem != null) + if (newItem != null && floatingPointGetter != null) { floatVal = floatingPointGetter(newItem); } @@ -913,8 +994,12 @@ private UnmarshalledColumnData CreateColumn(string parentPath, string propertyNa case JSDataSourceSchemaType.NullableDecimalValue: update = (size, column, index, oldItem, newItem) => { + if (column.DoubleValues == null || column.NullValues == null) + { + return; + } double? floatVal = null; - if (newItem != null) + if (newItem != null && nullableFloatingPointGetter != null) { floatVal = nullableFloatingPointGetter(newItem); } @@ -928,8 +1013,12 @@ private UnmarshalledColumnData CreateColumn(string parentPath, string propertyNa case JSDataSourceSchemaType.ShortValue: update = (size, column, index, oldItem, newItem) => { + if (column.IntValues == null) + { + return; + } int intVal = int.MinValue; - if (newItem != null) + if (newItem != null && integerGetter != null) { intVal = integerGetter(newItem); } @@ -942,8 +1031,12 @@ private UnmarshalledColumnData CreateColumn(string parentPath, string propertyNa case JSDataSourceSchemaType.NullableShortValue: update = (size, column, index, oldItem, newItem) => { + if (column.IntValues == null || column.NullValues == null) + { + return; + } int? intVal = null; - if (newItem != null) + if (newItem != null && nullableIntegerGetter != null) { intVal = nullableIntegerGetter(newItem); } @@ -954,8 +1047,12 @@ private UnmarshalledColumnData CreateColumn(string parentPath, string propertyNa case JSDataSourceSchemaType.LongValue: update = (size, column, index, oldItem, newItem) => { + if (column.LongValues == null) + { + return; + } long longVal = long.MinValue; - if (newItem != null) + if (newItem != null && longGetter != null) { longVal = longGetter(newItem); } @@ -965,8 +1062,12 @@ private UnmarshalledColumnData CreateColumn(string parentPath, string propertyNa case JSDataSourceSchemaType.NullableLongValue: update = (size, column, index, oldItem, newItem) => { + if (column.LongValues == null || column.NullValues == null) + { + return; + } long? longVal = null; - if (newItem != null) + if (newItem != null && nullableLongGetter != null) { longVal = nullableLongGetter(newItem); } @@ -979,9 +1080,13 @@ private UnmarshalledColumnData CreateColumn(string parentPath, string propertyNa case JSDataSourceSchemaType.DateTimeValue: update = (size, column, index, oldItem, newItem) => { - string stringVal = null; + if (column.StringValues == null) + { + return; + } + string? stringVal = null; Guid idVal = Guid.Empty; - if (column.IsIDColumn && oldItem != newItem) + if (column.IsIDColumn && oldItem != newItem && column.IDValues != null) { var oldId = column.IDValues[index]; OnRemoveId(oldId); @@ -990,17 +1095,20 @@ private UnmarshalledColumnData CreateColumn(string parentPath, string propertyNa { if (column.IsIDColumn) { - idVal = idGetter(newItem); + if (idGetter != null) + { + idVal = idGetter(newItem); + } stringVal = idVal.ToString(); } else { - stringVal = stringGetter(newItem); + stringVal = stringGetter != null ? stringGetter(newItem) : null; } } column.StringValues[index] = stringVal; - if (column.IsIDColumn) + if (column.IsIDColumn && column.IDValues != null) { column.IDValues[index] = idVal; } @@ -1010,8 +1118,12 @@ private UnmarshalledColumnData CreateColumn(string parentPath, string propertyNa case JSDataSourceSchemaType.NullableDateTimeValue: update = (size, column, index, oldItem, newItem) => { - string stringVal = null; - if (newItem != null) + if (column.StringValues == null) + { + return; + } + string? stringVal = null; + if (newItem != null && stringGetter != null) { stringVal = stringGetter(newItem); } @@ -1021,14 +1133,14 @@ private UnmarshalledColumnData CreateColumn(string parentPath, string propertyNa case JSDataSourceSchemaType.ObjectValue: update = (size, column, index, oldItem, newItem) => { - object objVal = null; - if (newItem != null) + object? objVal = null; + if (newItem != null && objectGetter != null) { objVal = objectGetter(newItem); } - object oldObjVal = null; - if (oldItem != null) + object? oldObjVal = null; + if (oldItem != null && objectGetter != null) { oldObjVal = objectGetter(oldItem); } @@ -1042,7 +1154,7 @@ private UnmarshalledColumnData CreateColumn(string parentPath, string propertyNa schema.SetSubSchema(column.PropertyName, subSchema); column.SubSchema = subSchema; } - if (subSchema.IsDataSource && !column.IsSubDataSource) + if (subSchema != null && subSchema.IsDataSource && !column.IsSubDataSource) { column.IsSubDataSource = true; var c = column.Column; @@ -1056,11 +1168,15 @@ private UnmarshalledColumnData CreateColumn(string parentPath, string propertyNa if (column.IsSubDataSource) { - UnmarshalledColumn[] cols = null; + if (column.SubDataSourceValues == null) + { + return; + } + UnmarshalledColumn[]? cols = null; if (objVal != null) { - var sub = (UnmarshalledDataSource)UnmarshalledDataSource.CreateWithSchema(objVal, column.SubSchema, _manager, _helper); - cols = sub.GetColumns(""); + var sub = (UnmarshalledDataSource?)UnmarshalledDataSource.CreateWithSchema(objVal, column.SubSchema, _manager, _helper); + cols = sub?.GetColumns(""); } column.SubDataSourceValues[index] = cols; } @@ -1071,7 +1187,10 @@ private UnmarshalledColumnData CreateColumn(string parentPath, string propertyNa for (var i = 0; i < column.SubColumns.Length; i++) { var subColumn = column.SubColumns[i]; - subColumn.Update(size, subColumn, index, oldObjVal, objVal); + if (subColumn != null) + { + subColumn.Update?.Invoke(size, subColumn, index, oldObjVal, objVal); + } } } } @@ -1090,88 +1209,95 @@ private UnmarshalledColumnData CreateColumn(string parentPath, string propertyNa case JSDataSourceSchemaType.SingleArrayValue: update = (size, column, index, oldItem, newItem) => { - object objVal = null; - if (newItem != null) + object? objVal = null; + if (newItem != null && objectGetter != null) { objVal = objectGetter(newItem); } - object oldObjVal = null; - if (oldItem != null) + object? oldObjVal = null; + if (oldItem != null && objectGetter != null) { oldObjVal = objectGetter(oldItem); } if (column.IsSubDataSource) { - UnmarshalledColumn[] cols = null; + if (column.SubDataSourceValues == null) + { + return; + } + UnmarshalledColumn[]? cols = null; if (objVal != null) { - var sub = (UnmarshalledDataSource)UnmarshalledDataSource.CreateWithSchema(objVal, column.SubSchema, _manager, _helper); - var subcols = sub.GetColumns(""); - - UnmarshalledColumn primcol = new UnmarshalledColumn(); - primcol.ActualCount = subcols[0].ActualCount; - primcol.DataSourceID = subcols[0].DataSourceID; - primcol.PropertyPath = "___primitiveVal"; - primcol.Type = GetArrayType(newColumn.Type); - int i = 0; - switch (newColumn.Type) + var sub = (UnmarshalledDataSource?)UnmarshalledDataSource.CreateWithSchema(objVal, column.SubSchema, _manager, _helper); + if (sub != null) { - case JSDataSourceSchemaType.StringArrayValue: - primcol.StringValues = new string[primcol.ActualCount]; - foreach (var v in (objVal as IEnumerable)) - { - primcol.StringValues[i] = (string)v; - i++; - } - break; - case JSDataSourceSchemaType.DateTimeArrayValue: - case JSDataSourceSchemaType.CalendarArrayValue: - primcol.StringValues = new string[primcol.ActualCount]; - foreach (var v in (objVal as IEnumerable)) - { - primcol.StringValues[i] = ((DateTime)v).ToString("o"); - i++; - } - break; - case JSDataSourceSchemaType.BooleanArrayValue: - case JSDataSourceSchemaType.ByteArrayValue: - case JSDataSourceSchemaType.IntArrayValue: - case JSDataSourceSchemaType.ShortArrayValue: - primcol.IntValues = new int[primcol.ActualCount]; - foreach (var v in (objVal as IEnumerable)) - { - primcol.IntValues[i] = Convert.ToInt32(v); - i++; - } - break; - case JSDataSourceSchemaType.DoubleArrayValue: - case JSDataSourceSchemaType.SingleArrayValue: - case JSDataSourceSchemaType.DecimalArrayValue: - primcol.DoubleValues = new double[primcol.ActualCount]; - foreach (var v in (objVal as IEnumerable)) - { - primcol.DoubleValues[i] = Convert.ToDouble(v); - i++; - } - break; - case JSDataSourceSchemaType.LongArrayValue: - primcol.LongValues = new long[primcol.ActualCount]; - foreach (var v in (objVal as IEnumerable)) - { - primcol.LongValues[i] = Convert.ToInt64(v); - i++; - } - break; + var subcols = sub.GetColumns(""); + + UnmarshalledColumn primcol = new UnmarshalledColumn(); + primcol.ActualCount = subcols[0].ActualCount; + primcol.DataSourceID = subcols[0].DataSourceID; + primcol.PropertyPath = "___primitiveVal"; + primcol.Type = GetArrayType(newColumn.Type); + int i = 0; + switch (newColumn.Type) + { + case JSDataSourceSchemaType.StringArrayValue: + primcol.StringValues = new string[primcol.ActualCount]; + foreach (var v in ((IEnumerable)objVal)) + { + primcol.StringValues[i] = (string)v; + i++; + } + break; + case JSDataSourceSchemaType.DateTimeArrayValue: + case JSDataSourceSchemaType.CalendarArrayValue: + primcol.StringValues = new string[primcol.ActualCount]; + foreach (var v in ((IEnumerable)objVal)) + { + primcol.StringValues[i] = ((DateTime)v).ToString("o"); + i++; + } + break; + case JSDataSourceSchemaType.BooleanArrayValue: + case JSDataSourceSchemaType.ByteArrayValue: + case JSDataSourceSchemaType.IntArrayValue: + case JSDataSourceSchemaType.ShortArrayValue: + primcol.IntValues = new int[primcol.ActualCount]; + foreach (var v in ((IEnumerable)objVal)) + { + primcol.IntValues[i] = Convert.ToInt32(v); + i++; + } + break; + case JSDataSourceSchemaType.DoubleArrayValue: + case JSDataSourceSchemaType.SingleArrayValue: + case JSDataSourceSchemaType.DecimalArrayValue: + primcol.DoubleValues = new double[primcol.ActualCount]; + foreach (var v in ((IEnumerable)objVal)) + { + primcol.DoubleValues[i] = Convert.ToDouble(v); + i++; + } + break; + case JSDataSourceSchemaType.LongArrayValue: + primcol.LongValues = new long[primcol.ActualCount]; + foreach (var v in ((IEnumerable)objVal)) + { + primcol.LongValues[i] = Convert.ToInt64(v); + i++; + } + break; + } + + cols = new UnmarshalledColumn[subcols.Length + 1]; + for (i = 0; i < subcols.Length; i++) + { + cols[i] = subcols[i]; + } + cols[subcols.Length] = primcol; } - - cols = new UnmarshalledColumn[subcols.Length + 1]; - for (i = 0; i < subcols.Length; i++) - { - cols[i] = subcols[i]; - } - cols[subcols.Length] = primcol; } column.SubDataSourceValues[index] = cols; @@ -1183,7 +1309,10 @@ private UnmarshalledColumnData CreateColumn(string parentPath, string propertyNa for (var i = 0; i < column.SubColumns.Length; i++) { var subColumn = column.SubColumns[i]; - subColumn.Update(size, subColumn, index, oldItem, newItem); + if (subColumn != null) + { + subColumn.Update?.Invoke(size, subColumn, index, oldItem, newItem); + } } } } @@ -1191,7 +1320,7 @@ private UnmarshalledColumnData CreateColumn(string parentPath, string propertyNa break; } - Action remove = null; + Action? remove = null; switch (newColumn.Type) { case JSDataSourceSchemaType.DoubleValue: @@ -1199,6 +1328,10 @@ private UnmarshalledColumnData CreateColumn(string parentPath, string propertyNa case JSDataSourceSchemaType.DecimalValue: remove = (size, column, index) => { + if (column.DoubleValues == null) + { + return; + } if (index == (size - 1)) { column.DoubleValues[index] = double.NaN; @@ -1215,6 +1348,10 @@ private UnmarshalledColumnData CreateColumn(string parentPath, string propertyNa case JSDataSourceSchemaType.NullableDecimalValue: remove = (size, column, index) => { + if (column.DoubleValues == null || column.NullValues == null) + { + return; + } if (index == (size - 1)) { column.DoubleValues[index] = double.NaN; @@ -1235,6 +1372,10 @@ private UnmarshalledColumnData CreateColumn(string parentPath, string propertyNa case JSDataSourceSchemaType.ShortValue: remove = (size, column, index) => { + if (column.IntValues == null) + { + return; + } if (index == (size - 1)) { column.IntValues[index] = 0; @@ -1252,6 +1393,10 @@ private UnmarshalledColumnData CreateColumn(string parentPath, string propertyNa case JSDataSourceSchemaType.NullableShortValue: remove = (size, column, index) => { + if (column.IntValues == null || column.NullValues == null) + { + return; + } if (index == (size - 1)) { column.IntValues[index] = 0; @@ -1269,6 +1414,10 @@ private UnmarshalledColumnData CreateColumn(string parentPath, string propertyNa case JSDataSourceSchemaType.LongValue: remove = (size, column, index) => { + if (column.LongValues == null) + { + return; + } if (index == (size - 1)) { column.LongValues[index] = 0; @@ -1283,6 +1432,10 @@ private UnmarshalledColumnData CreateColumn(string parentPath, string propertyNa case JSDataSourceSchemaType.NullableLongValue: remove = (size, column, index) => { + if (column.LongValues == null || column.NullValues == null) + { + return; + } if (index == (size - 1)) { column.LongValues[index] = 0; @@ -1302,7 +1455,11 @@ private UnmarshalledColumnData CreateColumn(string parentPath, string propertyNa case JSDataSourceSchemaType.DateTimeValue: remove = (size, column, index) => { - if (column.IsIDColumn) + if (column.StringValues == null) + { + return; + } + if (column.IsIDColumn && column.IDValues != null) { var oldId = column.IDValues[index]; OnRemoveId(oldId); @@ -1317,7 +1474,7 @@ private UnmarshalledColumnData CreateColumn(string parentPath, string propertyNa Array.Copy(column.StringValues, index + 1, column.StringValues, index, (size - 1) - index); column.StringValues[size - 1] = null; } - if (column.IsIDColumn) + if (column.IsIDColumn && column.IDValues != null) { if (index == (size - 1)) { @@ -1335,6 +1492,10 @@ private UnmarshalledColumnData CreateColumn(string parentPath, string propertyNa case JSDataSourceSchemaType.NullableDateTimeValue: remove = (size, column, index) => { + if (column.StringValues == null) + { + return; + } if (index == (size - 1)) { column.StringValues[index] = null; @@ -1362,6 +1523,10 @@ private UnmarshalledColumnData CreateColumn(string parentPath, string propertyNa { if (column.IsSubDataSource) { + if (column.SubDataSourceValues == null) + { + return; + } if (index == (size - 1)) { column.SubDataSourceValues[index] = null; @@ -1379,7 +1544,10 @@ private UnmarshalledColumnData CreateColumn(string parentPath, string propertyNa for (var i = 0; i < column.SubColumns.Length; i++) { var subColumn = column.SubColumns[i]; - subColumn.Remove(size, subColumn, index); + if (subColumn != null) + { + subColumn.Remove?.Invoke(size, subColumn, index); + } } } } @@ -1387,7 +1555,7 @@ private UnmarshalledColumnData CreateColumn(string parentPath, string propertyNa break; } - Action clear = null; + Action? clear = null; switch (newColumn.Type) { case JSDataSourceSchemaType.DoubleValue: @@ -1395,6 +1563,10 @@ private UnmarshalledColumnData CreateColumn(string parentPath, string propertyNa case JSDataSourceSchemaType.DecimalValue: clear = (size, column) => { + if (column.DoubleValues == null) + { + return; + } Array.Clear(column.DoubleValues, 0, size); }; break; @@ -1403,6 +1575,10 @@ private UnmarshalledColumnData CreateColumn(string parentPath, string propertyNa case JSDataSourceSchemaType.NullableDecimalValue: clear = (size, column) => { + if (column.DoubleValues == null || column.NullValues == null) + { + return; + } Array.Clear(column.DoubleValues, 0, size); Array.Clear(column.NullValues, 0, size); }; @@ -1413,6 +1589,10 @@ private UnmarshalledColumnData CreateColumn(string parentPath, string propertyNa case JSDataSourceSchemaType.ShortValue: clear = (size, column) => { + if (column.IntValues == null) + { + return; + } Array.Clear(column.IntValues, 0, size); }; break; @@ -1422,6 +1602,10 @@ private UnmarshalledColumnData CreateColumn(string parentPath, string propertyNa case JSDataSourceSchemaType.NullableShortValue: clear = (size, column) => { + if (column.IntValues == null || column.NullValues == null) + { + return; + } Array.Clear(column.IntValues, 0, size); Array.Clear(column.NullValues, 0, size); }; @@ -1429,12 +1613,20 @@ private UnmarshalledColumnData CreateColumn(string parentPath, string propertyNa case JSDataSourceSchemaType.LongValue: clear = (size, column) => { + if (column.LongValues == null) + { + return; + } Array.Clear(column.LongValues, 0, size); }; break; case JSDataSourceSchemaType.NullableLongValue: clear = (size, column) => { + if (column.LongValues == null || column.NullValues == null) + { + return; + } Array.Clear(column.LongValues, 0, size); Array.Clear(column.NullValues, 0, size); }; @@ -1444,7 +1636,11 @@ private UnmarshalledColumnData CreateColumn(string parentPath, string propertyNa case JSDataSourceSchemaType.DateTimeValue: clear = (size, column) => { - if (column.IsIDColumn) + if (column.StringValues == null) + { + return; + } + if (column.IsIDColumn && column.IDValues != null) { for (var i = 0; i < size; i++) { @@ -1453,7 +1649,7 @@ private UnmarshalledColumnData CreateColumn(string parentPath, string propertyNa } Array.Clear(column.StringValues, 0, size); - if (column.IsIDColumn) + if (column.IsIDColumn && column.IDValues != null) { Array.Clear(column.IDValues, 0, size); } @@ -1463,6 +1659,10 @@ private UnmarshalledColumnData CreateColumn(string parentPath, string propertyNa case JSDataSourceSchemaType.NullableDateTimeValue: clear = (size, column) => { + if (column.StringValues == null) + { + return; + } Array.Clear(column.StringValues, 0, size); }; break; @@ -1482,6 +1682,10 @@ private UnmarshalledColumnData CreateColumn(string parentPath, string propertyNa { if (column.IsSubDataSource) { + if (column.SubDataSourceValues == null) + { + return; + } Array.Clear(column.SubDataSourceValues, 0, size); } else @@ -1491,7 +1695,10 @@ private UnmarshalledColumnData CreateColumn(string parentPath, string propertyNa for (var i = 0; i < column.SubColumns.Length; i++) { var subColumn = column.SubColumns[i]; - subColumn.Clear(size, subColumn); + if (subColumn != null) + { + subColumn.Clear?.Invoke(size, subColumn); + } } } } @@ -1537,9 +1744,9 @@ private JSDataSourceSchemaType GetArrayType(JSDataSourceSchemaType arrayType) return JSDataSourceSchemaType.ObjectValue; } - private void GetColumns(string refName, UnmarshalledColumnData[] columns, List l) + private void GetColumns(string refName, UnmarshalledColumnData?[]? columns, List l) { - List toDrill = new List(); + List toDrill = new List(); if (columns == null) { @@ -1583,26 +1790,46 @@ internal UnmarshalledColumn[] GetColumns(string refName) public void SendClear(string containerId, string refName) { + if (_helper == null) + { + return; + } _helper.SendUnmarshalledColumnMessage("igUnmarshalledDataSourceClear", containerId + ":" + refName, -1, GetColumns(refName)); } public void SendRemove(string containerId, string refName, int index) { + if (_helper == null) + { + return; + } _helper.SendUnmarshalledColumnMessage("igUnmarshalledDataSourceRemove", containerId + ":" + refName, index, GetColumns(refName)); } public void SendInsert(string containerId, string refName, int index) { + if (_helper == null) + { + return; + } _helper.SendUnmarshalledColumnMessage("igUnmarshalledDataSourceInsert", containerId + ":" + refName, index, GetColumns(refName)); } public void SendUpdate(string containerId, string refName, int index, bool syncDataOnly) { + if (_helper == null) + { + return; + } _helper.SendUnmarshalledColumnMessage("igUnmarshalledDataSourceUpdate", containerId + ":" + refName + ":" + (syncDataOnly ? "true" : "false"), index, GetColumns(refName)); } - public void SendCreate(string containerId, string refName, string dataIntents) + public void SendCreate(string containerId, string refName, string? dataIntents) { + if (_helper == null) + { + return; + } if (dataIntents != null) { //Console.WriteLine("sending create data intents"); @@ -1629,7 +1856,7 @@ private void OnRemoveId(Guid oldId) } } - private UnmarshalledColumnData AdjustColumnCapacity(string parentPath, UnmarshalledColumnData column, JSDataSourceSchema schema, string propertyName, Delegate getter, Func untypedGetter, bool isIdColumn, JSDataSourceSchemaType type, int oldValue, int newValue) + private UnmarshalledColumnData AdjustColumnCapacity(string? parentPath, UnmarshalledColumnData? column, JSDataSourceSchema schema, string? propertyName, Delegate? getter, Func? untypedGetter, bool isIdColumn, JSDataSourceSchemaType type, int oldValue, int newValue) { if (column == null) { @@ -1699,7 +1926,7 @@ private UnmarshalledColumnData AdjustColumnCapacity(string parentPath, Unmarshal { var floatColumn = new double[newValue]; var nullColumn = new bool[newValue]; - if (existingColumn != null) + if (existingColumn != null && column.NullValues != null) { Array.Copy(existingColumn, floatColumn, _size); Array.Copy(column.NullValues, nullColumn, _size); @@ -1743,7 +1970,7 @@ private UnmarshalledColumnData AdjustColumnCapacity(string parentPath, Unmarshal { var intColumn = new int[newValue]; var nullColumn = new bool[newValue]; - if (existingColumn != null) + if (existingColumn != null && column.NullValues != null) { Array.Copy(existingColumn, intColumn, _size); Array.Copy(column.NullValues, nullColumn, _size); @@ -1781,7 +2008,7 @@ private UnmarshalledColumnData AdjustColumnCapacity(string parentPath, Unmarshal { var longColumn = new long[newValue]; var nullColumn = new bool[newValue]; - if (existingColumn != null) + if (existingColumn != null && column.NullValues != null) { Array.Copy(existingColumn, longColumn, _size); Array.Copy(column.NullValues, nullColumn, _size); @@ -1861,7 +2088,7 @@ private void EnsureCapacity(int required) } } - public static IJSDataSource CreateWithSchema(Object data, JSDataSourceSchema schema, DataSourceManager manager, RuntimeHelper helper) + public static IJSDataSource? CreateWithSchema(Object data, JSDataSourceSchema? schema, DataSourceManager? manager, RuntimeHelper? helper) { if (data == null) { @@ -1883,7 +2110,7 @@ public static IJSDataSource CreateWithSchema(Object data, JSDataSourceSchema sch } return null; } - public static IJSDataSource CreateWithSchema(Object data, string parentId, JSDataSourceSchema schema, DataSourceManager manager, RuntimeHelper helper) + public static IJSDataSource? CreateWithSchema(Object data, string? parentId, JSDataSourceSchema? schema, DataSourceManager? manager, RuntimeHelper? helper) { if (data == null) { @@ -1915,13 +2142,18 @@ private void Listen(object data) } } - private void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) + private void OnCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e) { if (SuppressModifications) { return; } + if (_manager == null || _originalData == null) + { + return; + } + switch (e.Action) { case NotifyCollectionChangedAction.Add: @@ -1932,10 +2164,6 @@ private void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs { var item = e.NewItems[i]; var refName = _manager.GetRefId(_originalData); - if (refName == null) - { - return; - } _manager.NotifyInsertItem(refName, e.NewStartingIndex + i, item); } } @@ -1949,10 +2177,6 @@ private void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs { var item = e.OldItems[i]; var refName = _manager.GetRefId(_originalData); - if (refName == null) - { - return; - } _manager.NotifyRemoveItem(refName, e.OldStartingIndex, item); } } @@ -1966,10 +2190,6 @@ private void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs { var item = e.OldItems[i]; var refName = _manager.GetRefId(_originalData); - if (refName == null) - { - return; - } _manager.NotifyRemoveItem(refName, e.OldStartingIndex, item); } } @@ -1979,10 +2199,6 @@ private void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs { var item = e.NewItems[i]; var refName = _manager.GetRefId(_originalData); - if (refName == null) - { - return; - } _manager.NotifyInsertItem(refName, e.NewStartingIndex + i, item); } } @@ -1991,10 +2207,6 @@ private void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs case NotifyCollectionChangedAction.Reset: { var refName = _manager.GetRefId(_originalData); - if (refName == null) - { - return; - } _manager.NotifyClearItems(refName); break; } @@ -2028,7 +2240,7 @@ public bool HasId(string id) } } - public object LookupOriginal(Guid id) + public object? LookupOriginal(Guid id) { if (_uuidToOriginal.ContainsKey(id)) { @@ -2036,7 +2248,7 @@ public object LookupOriginal(Guid id) } return null; } - public object LookupOriginal(string id) + public object? LookupOriginal(string id) { if (id.Contains("/")) { @@ -2074,7 +2286,7 @@ public bool HasOriginal(object item) return _originalToUuid.ContainsKey(item); } - public static IJSDataSource Create(Object data, DataSourceManager manager, RuntimeHelper helper) + public static IJSDataSource? Create(Object data, DataSourceManager manager, RuntimeHelper helper) { if (data == null) { @@ -2095,11 +2307,11 @@ public static IJSDataSource Create(Object data, DataSourceManager manager, Runti } return null; } - private static IJSDataSource CreateFromIEnumerable(IEnumerable data, JSDataSourceSchema schema, DataSourceManager manager, RuntimeHelper helper) + private static IJSDataSource CreateFromIEnumerable(IEnumerable data, JSDataSourceSchema? schema, DataSourceManager? manager, RuntimeHelper? helper) { return CreateFromIEnumerable(data, null, schema, manager, helper); } - private static IJSDataSource CreateFromIEnumerable(IEnumerable data, string parentId, JSDataSourceSchema schema, DataSourceManager manager, RuntimeHelper helper) + private static IJSDataSource CreateFromIEnumerable(IEnumerable data, string? parentId, JSDataSourceSchema? schema, DataSourceManager? manager, RuntimeHelper? helper) { UnmarshalledDataSource newData = new UnmarshalledDataSource(); newData._helper = helper; @@ -2120,11 +2332,11 @@ private static IJSDataSource CreateFromIEnumerable(IEnumerable data, string pare return newData; } - private static IJSDataSource CreateFromIList(IList data, JSDataSourceSchema schema, DataSourceManager manager, RuntimeHelper helper) + private static IJSDataSource CreateFromIList(IList data, JSDataSourceSchema? schema, DataSourceManager? manager, RuntimeHelper? helper) { return CreateFromIList(data, null, schema, manager, helper); } - private static IJSDataSource CreateFromIList(IList data, string parentId, JSDataSourceSchema schema, DataSourceManager manager, RuntimeHelper helper) + private static IJSDataSource CreateFromIList(IList data, string? parentId, JSDataSourceSchema? schema, DataSourceManager? manager, RuntimeHelper? helper) { //Console.WriteLine("test json"); //DateTime testTime = DateTime.Now; @@ -2169,11 +2381,11 @@ private static void EnsureParentSchema(UnmarshalledDataSource data) } } - private static IJSDataSource CreateFromArray(Array data, JSDataSourceSchema schema, DataSourceManager manager, RuntimeHelper helper) + private static IJSDataSource CreateFromArray(Array data, JSDataSourceSchema? schema, DataSourceManager? manager, RuntimeHelper? helper) { return CreateFromArray(data, null, schema, manager, helper); } - private static IJSDataSource CreateFromArray(Array data, string parentId, JSDataSourceSchema schema, DataSourceManager manager, RuntimeHelper helper) + private static IJSDataSource CreateFromArray(Array data, string? parentId, JSDataSourceSchema? schema, DataSourceManager? manager, RuntimeHelper? helper) { UnmarshalledDataSource newData = new UnmarshalledDataSource(); newData._helper = helper; @@ -2193,11 +2405,11 @@ private static IJSDataSource CreateFromArray(Array data, string parentId, JSData return newData; } - private JSDataSourceSchema _schema = null; + private JSDataSourceSchema? _schema = null; private int _leadingNullItems = 0; - private void Add(object item) + private void Add(object? item) { if (_schema == null) { @@ -2215,8 +2427,12 @@ private void Add(object item) //_data.Add(itemJson); } - private void EnsureLeadingNullsInserted(JSDataSourceSchema schema, UnmarshalledColumnData[] columns) + private void EnsureLeadingNullsInserted(JSDataSourceSchema? schema, UnmarshalledColumnData?[]? columns) { + if (schema == null || columns == null) + { + return; + } if (_leadingNullItems > 0) { //Console.WriteLine("dealing with leading nulls."); @@ -2231,10 +2447,14 @@ private void EnsureLeadingNullsInserted(JSDataSourceSchema schema, UnmarshalledC } } - private void InsertItemAt(object item, int index, JSDataSourceSchema schema, UnmarshalledColumnData[] columns) + private void InsertItemAt(object? item, int index, JSDataSourceSchema? schema, UnmarshalledColumnData?[]? columns) { EnsureLeadingNullsInserted(schema, columns); EnsureCapacity(_size + 1); + if (columns == null) + { + return; + } for (var i = 0; i < columns.Length; i++) { var column = columns[i]; @@ -2244,31 +2464,45 @@ private void InsertItemAt(object item, int index, JSDataSourceSchema schema, Unm continue; } //Console.WriteLine(column.PropertyName); - column.Insert(_size, column, index, item); + column.Insert?.Invoke(_size, column, index, item); } _size++; } - private void UpdateItemAt(object oldItem, object newItem, int index, JSDataSourceSchema schema, UnmarshalledColumnData[] columns) + private void UpdateItemAt(object? oldItem, object? newItem, int index, JSDataSourceSchema schema, UnmarshalledColumnData?[]? columns) { EnsureLeadingNullsInserted(schema, columns); + if (columns == null) + { + return; + } for (var i = 0; i < columns.Length; i++) { var column = columns[i]; - - column.Update(_size, column, index, oldItem, newItem); + if (column == null) + { + continue; + } + column.Update?.Invoke(_size, column, index, oldItem, newItem); } } - private void RemoveItemAt(int index, JSDataSourceSchema schema, UnmarshalledColumnData[] columns) + private void RemoveItemAt(int index, JSDataSourceSchema schema, UnmarshalledColumnData?[]? columns) { EnsureLeadingNullsInserted(schema, columns); + if (columns == null) + { + return; + } for (var i = 0; i < columns.Length; i++) { var column = columns[i]; - - column.Remove(_size, column, index); + var remove = column?.Remove; + if (column != null && remove != null) + { + remove(_size, column, index); + } } _size--; } @@ -2280,7 +2514,7 @@ private void RemoveItemAt(int index, JSDataSourceSchema schema, UnmarshalledColu // _itemToOriginal[itemJson] = item; // } // } - // private void OnRemove(IJSDataSourceItem itemJson, object item) + // private void OnRemove(IJSDataSourceItem itemJson, object item) // { // if (_uuidToItem.ContainsKey(itemJson.Id)) { // _uuidToItem.Remove(itemJson.Id); @@ -2299,7 +2533,7 @@ private void RemoveItemAt(int index, JSDataSourceSchema schema, UnmarshalledColu // } [UnconditionalSuppressMessage("Trimming", "IL2072", Justification = "Data item types are supplied by the application at runtime; trimmed apps must preserve their data item types — see docs/TRIMMING.md.")] - public static JSDataSourceSchema ExtractSchema(object item) + public static JSDataSourceSchema? ExtractSchema(object item) { if (item == null) { @@ -2315,7 +2549,10 @@ public static JSDataSourceSchema ExtractSchema(object item) if (isEmpty) { var eleType = c.GetElementType(); - s.ItemSchema = ExtractSchemaFromType(eleType); + if (eleType != null) + { + s.ItemSchema = ExtractSchemaFromType(eleType); + } } s.Commit(); return s; @@ -2325,10 +2562,13 @@ public static JSDataSourceSchema ExtractSchema(object item) JSDataSourceSchema s = new JSDataSourceSchema(); s.IsDataSource = true; var isEmpty = item != null && ((IList)item).Count == 0; - if (isEmpty && GetIListTypeArg(item.GetType()) != null) + if (isEmpty && item != null) { var eleType = GetIListTypeArg(item.GetType()); - s.ItemSchema = ExtractSchemaFromType(eleType); + if (eleType != null) + { + s.ItemSchema = ExtractSchemaFromType(eleType); + } } s.Commit(); return s; @@ -2346,10 +2586,13 @@ public static JSDataSourceSchema ExtractSchema(object item) { isEmpty = false; } - if (isEmpty && GetIEnumerableTypeArg(item.GetType()) != null) + if (isEmpty) { var eleType = GetIEnumerableTypeArg(item.GetType()); - s.ItemSchema = ExtractSchemaFromType(eleType); + if (eleType != null) + { + s.ItemSchema = ExtractSchemaFromType(eleType); + } } s.Commit(); return s; @@ -2366,7 +2609,7 @@ public static JSDataSourceSchema ExtractSchema(object item) return JSDataSourceSchema.Create(c); } - private static Type GetIListTypeArg([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)] Type itemType) + private static Type? GetIListTypeArg([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)] Type itemType) { foreach (var inter in itemType.GetInterfaces()) { @@ -2382,7 +2625,7 @@ private static Type GetIListTypeArg([DynamicallyAccessedMembers(DynamicallyAcces return null; } - private static Type GetIEnumerableTypeArg([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)] Type itemType) + private static Type? GetIEnumerableTypeArg([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)] Type itemType) { foreach (var inter in itemType.GetInterfaces()) { @@ -2408,7 +2651,10 @@ public static JSDataSourceSchema ExtractSchemaFromType(Type itemType) //if (isEmpty) { var eleType = itemType.GetElementType(); - s.ItemSchema = ExtractSchemaFromType(eleType); + if (eleType != null) + { + s.ItemSchema = ExtractSchemaFromType(eleType); + } } s.Commit(); return s; @@ -2417,9 +2663,9 @@ public static JSDataSourceSchema ExtractSchemaFromType(Type itemType) { JSDataSourceSchema s = new JSDataSourceSchema(); s.IsDataSource = true; - if (GetIListTypeArg(itemType) != null) + var eleType = GetIListTypeArg(itemType); + if (eleType != null) { - var eleType = GetIListTypeArg(itemType); s.ItemSchema = ExtractSchemaFromType(eleType); } s.Commit(); @@ -2430,9 +2676,9 @@ public static JSDataSourceSchema ExtractSchemaFromType(Type itemType) { JSDataSourceSchema s = new JSDataSourceSchema(); s.IsDataSource = true; - if (GetIEnumerableTypeArg(itemType) != null) + var eleType = GetIEnumerableTypeArg(itemType); + if (eleType != null) { - var eleType = GetIEnumerableTypeArg(itemType); s.ItemSchema = ExtractSchemaFromType(eleType); } s.Commit(); @@ -2458,7 +2704,7 @@ private static bool IsPrimitive(Type type) return false; } - public string GetDataIntentsAsJson() + public string? GetDataIntentsAsJson() { if (_schema != null) { @@ -2467,7 +2713,7 @@ public string GetDataIntentsAsJson() return null; } - private void EnsureSchema(object item) + private void EnsureSchema(object? item) { if (item != null && _schema == null) { @@ -2495,7 +2741,7 @@ private void EnsureSchema(object item) } } - public IJSDataSourceItem NotifyInsertItem(object data, int index, Object item) + public IJSDataSourceItem? NotifyInsertItem(object data, int index, Object? item) { EnsureSchema(item); if (_schema == null && item == null) @@ -2512,7 +2758,7 @@ public IJSDataSourceItem NotifyInsertItem(object data, int index, Object item) return null; } - public IJSDataSourceItem NotifyRemoveItem(object data, int index, object oldItem) + public IJSDataSourceItem? NotifyRemoveItem(object data, int index, object? oldItem) { EnsureSchema(oldItem); if (_schema == null) @@ -2538,7 +2784,12 @@ public void NotifyClearItems(Object data) { for (var i = 0; i < _columns.Length; i++) { - _columns[i].Clear(_size, _columns[i]); + var column = _columns[i]; + var clear = column?.Clear; + if (column != null && clear != null) + { + clear(_size, column); + } } } } @@ -2571,7 +2822,7 @@ public void NotifyClearItems(Object data) } } - public IJSDataSourceItem NotifySetItem(Object data, int index, Object oldItem, Object newItem) + public IJSDataSourceItem? NotifySetItem(Object data, int index, Object oldItem, Object newItem) { EnsureSchema(newItem); if (_schema == null) @@ -2584,7 +2835,7 @@ public IJSDataSourceItem NotifySetItem(Object data, int index, Object oldItem, O return null; } - public IJSDataSourceItem NotifyUpdateItem(object data, int index, object item) + public IJSDataSourceItem? NotifyUpdateItem(object data, int index, object item) { EnsureSchema(item); if (_schema == null) diff --git a/src/componentsBase/Utils.cs b/src/componentsBase/Utils.cs index d9e5c030..0da9db25 100644 --- a/src/componentsBase/Utils.cs +++ b/src/componentsBase/Utils.cs @@ -7,7 +7,7 @@ internal static class Utils // enumType intentionally unannotated: the requirement would propagate into ObjectToParam on the // component base classes, where DAM method parameters surface IL2111 in every consuming app. [UnconditionalSuppressMessage("Trimming", "IL2070", Justification = "The trimmer preserves all fields of enum types that are kept, and the enum types reaching here are statically referenced by their callers.")] - internal static bool TryGetWCEnumName(Type enumType, string enumMemberName, out string name) + internal static bool TryGetWCEnumName(Type enumType, string? enumMemberName, out string? name) { name = null; diff --git a/src/componentsBase/WebInputs/Accordion.cs b/src/componentsBase/WebInputs/Accordion.cs index 76d45082..49d19327 100644 --- a/src/componentsBase/WebInputs/Accordion.cs +++ b/src/componentsBase/WebInputs/Accordion.cs @@ -13,7 +13,7 @@ protected override string ParentTypeName } } - private BaseCollection _contentItems = null; + private BaseCollection? _contentItems = null; internal BaseCollection ContentItems { @@ -33,7 +33,7 @@ internal BaseCollection ContentItems public partial class IgbExpansionPanel { [CascadingParameter(Name = "AccordionParent")] - protected BaseRendererControl AccordionParent + protected BaseRendererControl? AccordionParent { get; set; } diff --git a/src/componentsBase/WebInputs/Chat.cs b/src/componentsBase/WebInputs/Chat.cs index 4d08fe52..c7a47d4c 100644 --- a/src/componentsBase/WebInputs/Chat.cs +++ b/src/componentsBase/WebInputs/Chat.cs @@ -6,15 +6,15 @@ namespace IgniteUI.Blazor.Controls /// public partial class IgbChat { - public IgbChatDraftMessage GetCurrentDraftMessage() + public IgbChatDraftMessage? GetCurrentDraftMessage() { - var iv = InvokeMethodSync("p:DraftMessage", new object[] { }, new string[] { }); + var iv = InvokeMethodSync("p:DraftMessage", new object?[] { }, new string[] { }); return ReturnToObject(iv, "ChatDraftMessage"); } - public async Task GetCurrentDraftMessageAsync() + public async Task GetCurrentDraftMessageAsync() { - var iv = await InvokeMethod("p:DraftMessage", new object[] { }, new string[] { }); + var iv = await InvokeMethod("p:DraftMessage", new object?[] { }, new string[] { }); return ReturnToObject(iv, "ChatDraftMessage"); } } diff --git a/src/componentsBase/WebInputs/DateTimeInput.cs b/src/componentsBase/WebInputs/DateTimeInput.cs index 548124aa..3889de08 100644 --- a/src/componentsBase/WebInputs/DateTimeInput.cs +++ b/src/componentsBase/WebInputs/DateTimeInput.cs @@ -1,39 +1,39 @@ -namespace IgniteUI.Blazor.Controls +namespace IgniteUI.Blazor.Controls { public partial class IgbDateTimeInput { public async Task StepUpAsync() { - await InvokeMethod("stepUp", new object[] { }, new string[] { }); + await InvokeMethod("stepUp", new object?[] { }, new string[] { }); } public void StepUp() { - InvokeMethodSync("stepUp", new object[] { }, new string[] { }); + InvokeMethodSync("stepUp", new object?[] { }, new string[] { }); } public async Task StepUpAsync(DatePart datePart) { - await InvokeMethod("stepUp", new object[] { ObjectToParam(datePart, typeof(DatePart)) }, new string[] { "Json" }); + await InvokeMethod("stepUp", new object?[] { ObjectToParam(datePart, typeof(DatePart)) }, new string[] { "Json" }); } public void StepUp(DatePart datePart) { - InvokeMethodSync("stepUp", new object[] { ObjectToParam(datePart, typeof(DatePart)) }, new string[] { "Json" }); + InvokeMethodSync("stepUp", new object?[] { ObjectToParam(datePart, typeof(DatePart)) }, new string[] { "Json" }); } public async Task StepDownAsync() { - await InvokeMethod("stepDown", new object[] { }, new string[] { }); + await InvokeMethod("stepDown", new object?[] { }, new string[] { }); } public void StepDown() { - InvokeMethodSync("stepDown", new object[] { }, new string[] { }); + InvokeMethodSync("stepDown", new object?[] { }, new string[] { }); } public async Task StepDownAsync(DatePart datePart) { - await InvokeMethod("stepDown", new object[] { ObjectToParam(datePart, typeof(DatePart)) }, new string[] { "Json" }); + await InvokeMethod("stepDown", new object?[] { ObjectToParam(datePart, typeof(DatePart)) }, new string[] { "Json" }); } public void StepDown(DatePart datePart) { - InvokeMethodSync("stepDown", new object[] { ObjectToParam(datePart, typeof(DatePart)) }, new string[] { "Json" }); + InvokeMethodSync("stepDown", new object?[] { ObjectToParam(datePart, typeof(DatePart)) }, new string[] { "Json" }); } } } diff --git a/src/componentsBase/WebInputs/Dropdown.cs b/src/componentsBase/WebInputs/Dropdown.cs index 983b8a35..0b6c62ee 100644 --- a/src/componentsBase/WebInputs/Dropdown.cs +++ b/src/componentsBase/WebInputs/Dropdown.cs @@ -20,7 +20,7 @@ public partial class IgbDropdown public async Task ShowAsync(Object target_) { //Console.WriteLine(ComponentToJson(target_)); - var iv = await InvokeMethod("show", new object[] { ComponentToJson(target_, 0) }, new string[] { "Component" }, + var iv = await InvokeMethod("show", new object?[] { ComponentToJson(target_, 0) }, new string[] { "Component" }, target_ is ElementReference ? new ElementReference[] { (ElementReference)target_ } : null); return ReturnToBoolean(iv); } @@ -38,7 +38,7 @@ public async Task ShowAsync(Object target_) /// or if it was already open. public bool Show(Object target_) { - var iv = InvokeMethodSync("show", new object[] { ComponentToJson(target_, 0) }, new string[] { "Component" }, + var iv = InvokeMethodSync("show", new object?[] { ComponentToJson(target_, 0) }, new string[] { "Component" }, target_ is ElementReference ? new ElementReference[] { (ElementReference)target_ } : null); return ReturnToBoolean(iv); } @@ -55,7 +55,7 @@ public bool Show(Object target_) /// when the open state was changed. public async Task ToggleAsync(Object target_) { - var iv = await InvokeMethod("toggle", new object[] { ComponentToJson(target_, 0) }, new string[] { "Component" }, + var iv = await InvokeMethod("toggle", new object?[] { ComponentToJson(target_, 0) }, new string[] { "Component" }, target_ is ElementReference ? new ElementReference[] { (ElementReference)target_ } : null); return ReturnToBoolean(iv); } @@ -72,7 +72,7 @@ public async Task ToggleAsync(Object target_) /// when the open state was changed. public bool Toggle(Object target_) { - var iv = InvokeMethodSync("toggle", new object[] { ComponentToJson(target_, 0) }, new string[] { "Component" }, + var iv = InvokeMethodSync("toggle", new object?[] { ComponentToJson(target_, 0) }, new string[] { "Component" }, target_ is ElementReference ? new ElementReference[] { (ElementReference)target_ } : null); return ReturnToBoolean(iv); } @@ -86,7 +86,7 @@ protected override string ParentTypeName } } - private IgbDropdownItemCollection _contentItems = null; + private IgbDropdownItemCollection? _contentItems = null; public IgbDropdownItemCollection ContentItems { diff --git a/src/componentsBase/WebInputs/DropdownItem.cs b/src/componentsBase/WebInputs/DropdownItem.cs index 712b75fd..7a1decab 100644 --- a/src/componentsBase/WebInputs/DropdownItem.cs +++ b/src/componentsBase/WebInputs/DropdownItem.cs @@ -5,7 +5,7 @@ namespace IgniteUI.Blazor.Controls public partial class IgbDropdownItem { [CascadingParameter(Name = "DropdownParent")] - protected BaseRendererControl DropdownParent + protected BaseRendererControl? DropdownParent { get; set; } diff --git a/src/componentsBase/WebInputs/Input.cs b/src/componentsBase/WebInputs/Input.cs index 2a221294..ada831af 100644 --- a/src/componentsBase/WebInputs/Input.cs +++ b/src/componentsBase/WebInputs/Input.cs @@ -9,7 +9,7 @@ namespace IgniteUI.Blazor.Controls public partial class IgbInputBase : BaseRendererControl { [Inject] - internal ILogger Logger { get; set; } = default; + internal ILogger? Logger { get; set; } private void EnsureInputOcurredHandled() { @@ -64,10 +64,10 @@ public override Task SetParametersAsync(ParameterView parameters) { // Params are case-insensitive & can't keep old name as deprecated, // so coerce value to avoid old code setting incorrect type errors: - parameters.TryGetValue("Readonly", out object result); + parameters.TryGetValue("Readonly", out object? result); if (result != null && result is string value) { - Logger.LogWarning("Readonly has been renamed, use ReadOnly instead"); + Logger?.LogWarning("Readonly has been renamed, use ReadOnly instead"); var updatedParams = parameters.ToDictionary().ToDictionary(kvp => kvp.Key, kvp => kvp.Value); bool.TryParse(value, out var coerced); updatedParams["Readonly"] = coerced; @@ -92,10 +92,10 @@ public override Task SetParametersAsync(ParameterView parameters) private ParameterView TryCoerceRenamedNumericProp(ParameterView parameters, string oldName, string newName) { - parameters.TryGetValue(oldName, out object result); + parameters.TryGetValue(oldName, out object? result); if (result != null && result is string value) { - Logger.LogWarning($"{oldName} has been renamed, use {newName} instead"); + Logger?.LogWarning($"{oldName} has been renamed, use {newName} instead"); var updatedParams = parameters.ToDictionary().ToDictionary(kvp => kvp.Key, kvp => kvp.Value); if (double.TryParse(value, out var coerced)) { diff --git a/src/componentsBase/WebInputs/Rating.cs b/src/componentsBase/WebInputs/Rating.cs index 6f4da14e..be110967 100644 --- a/src/componentsBase/WebInputs/Rating.cs +++ b/src/componentsBase/WebInputs/Rating.cs @@ -7,17 +7,17 @@ namespace IgniteUI.Blazor.Controls public partial class IgbRating { [Inject] - private ILogger Logger { get; set; } = default; + private ILogger? Logger { get; set; } /// public override Task SetParametersAsync(ParameterView parameters) { // Params are case-insensitive & can't keep old name as deprecated, // so coerce value to avoid old code setting incorrect type errors: - parameters.TryGetValue("Readonly", out object result); + parameters.TryGetValue("Readonly", out object? result); if (result != null && result is string value) { - Logger.LogWarning("Readonly has been renamed, use ReadOnly instead"); + Logger?.LogWarning("Readonly has been renamed, use ReadOnly instead"); var updatedParams = parameters.ToDictionary().ToDictionary(kvp => kvp.Key, kvp => kvp.Value); bool.TryParse(value, out var coerced); updatedParams["Readonly"] = coerced; diff --git a/src/componentsBase/WebInputs/Select.cs b/src/componentsBase/WebInputs/Select.cs index 7b4ed032..a3320e24 100644 --- a/src/componentsBase/WebInputs/Select.cs +++ b/src/componentsBase/WebInputs/Select.cs @@ -11,7 +11,7 @@ protected override string ParentTypeName } } - private BaseCollection _contentItems = null; + private BaseCollection? _contentItems = null; internal BaseCollection ContentItems { diff --git a/src/componentsBase/WebInputs/SelectItem.cs b/src/componentsBase/WebInputs/SelectItem.cs index 313525ff..2e773619 100644 --- a/src/componentsBase/WebInputs/SelectItem.cs +++ b/src/componentsBase/WebInputs/SelectItem.cs @@ -5,7 +5,7 @@ namespace IgniteUI.Blazor.Controls public partial class IgbSelectItem { [CascadingParameter(Name = "SelectParent")] - protected BaseRendererControl SelectParent + protected BaseRendererControl? SelectParent { get; set; } diff --git a/src/componentsBase/WebInputs/Tile.cs b/src/componentsBase/WebInputs/Tile.cs index 4cde9882..0d0fb344 100644 --- a/src/componentsBase/WebInputs/Tile.cs +++ b/src/componentsBase/WebInputs/Tile.cs @@ -5,7 +5,7 @@ namespace IgniteUI.Blazor.Controls public partial class IgbTile { [CascadingParameter(Name = "TileManagerParent")] - protected BaseRendererControl TileManagerParent + protected BaseRendererControl? TileManagerParent { get; set; } diff --git a/src/componentsBase/WebInputs/TileManager.cs b/src/componentsBase/WebInputs/TileManager.cs index f6e0afd3..016fc753 100644 --- a/src/componentsBase/WebInputs/TileManager.cs +++ b/src/componentsBase/WebInputs/TileManager.cs @@ -11,7 +11,7 @@ protected override string ParentTypeName } } - private BaseCollection _contentItems = null; + private BaseCollection? _contentItems = null; internal BaseCollection ContentItems { diff --git a/src/componentsBase/WebInputs/Tree.cs b/src/componentsBase/WebInputs/Tree.cs index bb8768fc..ef40159a 100644 --- a/src/componentsBase/WebInputs/Tree.cs +++ b/src/componentsBase/WebInputs/Tree.cs @@ -11,7 +11,7 @@ protected override string ParentTypeName } } - private IgbTreeItemCollection _contentItems = null; + private IgbTreeItemCollection? _contentItems = null; public IgbTreeItemCollection ContentItems { diff --git a/src/componentsBase/WebInputs/TreeItem.cs b/src/componentsBase/WebInputs/TreeItem.cs index 01cba2cb..dcb54264 100644 --- a/src/componentsBase/WebInputs/TreeItem.cs +++ b/src/componentsBase/WebInputs/TreeItem.cs @@ -5,7 +5,7 @@ namespace IgniteUI.Blazor.Controls public partial class IgbTreeItem { [CascadingParameter(Name = "TreeParent")] - protected BaseRendererControl TreeParent + protected BaseRendererControl? TreeParent { get; set; } diff --git a/src/componentsBase/WebViewCallback.cs b/src/componentsBase/WebViewCallback.cs index 4daad923..02a06558 100644 --- a/src/componentsBase/WebViewCallback.cs +++ b/src/componentsBase/WebViewCallback.cs @@ -41,11 +41,11 @@ public void OnReady() private void ForControls(Action act) { - List toRemove = null; + List? toRemove = null; foreach (var controlKey in _controlsMap.Keys) { var control = _controlsMap[controlKey]; - BaseRendererControl target; + BaseRendererControl? target; if (control.TryGetTarget(out target)) { target.OnReady(); @@ -69,12 +69,12 @@ private void ForControls(Action act) } } - private BaseRendererControl GetControl(string key) + private BaseRendererControl? GetControl(string key) { if (_controlsMap.ContainsKey(key)) { var control = _controlsMap[key]; - BaseRendererControl target; + BaseRendererControl? target; if (control.TryGetTarget(out target)) { return target; @@ -135,21 +135,24 @@ public void AdjustDynamicContentBatch(string containerId, string batch) if (control != null) { var arr = control.DeserializeDictionaryArray(batch); - for (var i = 0; i < arr.Length; i++) + if (arr != null) { - var item = arr[i]; - string currContainer = item.ContainsKey("containerId") ? (string)item["containerId"].ToString() : null; - string contentType = item.ContainsKey("contentType") ? (string)item["contentType"].ToString() : null; - string templateId = item.ContainsKey("templateId") ? (string)item["templateId"].ToString() : null; - string contentId = item.ContainsKey("contentId") ? (string)item["contentId"].ToString() : null; - string actionType = item.ContainsKey("actionType") ? (string)item["actionType"].ToString() : null; - string args = item.ContainsKey("args") ? (item["args"] != null ? item["args"].ToString() : null) : null; - //Console.WriteLine("raising event"); - if (currContainer != null) + for (var i = 0; i < arr.Length; i++) { - var currControl = GetControl(currContainer); - //Console.WriteLine("found target"); - currControl.AdjustDynamicContent(containerId, contentType, templateId, contentId, actionType, args); + var item = arr[i]; + string? currContainer = item.ContainsKey("containerId") ? item["containerId"].ToString() : null; + string? contentType = item.ContainsKey("contentType") ? item["contentType"].ToString() : null; + string? templateId = item.ContainsKey("templateId") ? item["templateId"].ToString() : null; + string? contentId = item.ContainsKey("contentId") ? item["contentId"].ToString() : null; + string? actionType = item.ContainsKey("actionType") ? item["actionType"].ToString() : null; + string? args = item.ContainsKey("args") ? (item["args"] != null ? item["args"].ToString() : null) : null; + //Console.WriteLine("raising event"); + if (currContainer != null) + { + var currControl = GetControl(currContainer); + //Console.WriteLine("found target"); + currControl?.AdjustDynamicContent(containerId, contentType, templateId, contentId, actionType, args); + } } } control.RefreshDynamicContent(); diff --git a/stories/Components/Stories/Chat.stories.razor b/stories/Components/Stories/Chat.stories.razor index 85c40a1c..4be12603 100644 --- a/stories/Components/Stories/Chat.stories.razor +++ b/stories/Components/Stories/Chat.stories.razor @@ -195,4 +195,4 @@ return "I can help with NuGet setup, theme registration, EventCallback wiring, and component usage in Ignite UI Blazor Lite."; } -} \ No newline at end of file +} diff --git a/tests/IgniteUI.Blazor.Lite.TestBed/Components/Common/ReflectionUtils.cs b/tests/IgniteUI.Blazor.Lite.TestBed/Components/Common/ReflectionUtils.cs index b866a222..e403bafb 100644 --- a/tests/IgniteUI.Blazor.Lite.TestBed/Components/Common/ReflectionUtils.cs +++ b/tests/IgniteUI.Blazor.Lite.TestBed/Components/Common/ReflectionUtils.cs @@ -1,4 +1,4 @@ -using System.Data; +using System.Data; using System.Reflection; using IgniteUI.Blazor.Controls; using Microsoft.AspNetCore.Components; @@ -185,7 +185,8 @@ public static object CreateRenderFragmentForType(Type propertyType, object value } // Invoke the generic method to create RenderFragment - return methodInfo.Invoke(null, new object[] { value })!; + var renderFragment = methodInfo.Invoke(null, new object[] { value }); + return renderFragment ?? throw new InvalidOperationException($"Cannot create RenderFragment for type '{propertyType.Name}'."); } private static RenderFragment CreateTypedRenderFragment(T value) diff --git a/tests/IgniteUI.Blazor.Lite.TestBed/Components/Common/TestUtil.cs b/tests/IgniteUI.Blazor.Lite.TestBed/Components/Common/TestUtil.cs index a56c4c0a..cd17c8df 100644 --- a/tests/IgniteUI.Blazor.Lite.TestBed/Components/Common/TestUtil.cs +++ b/tests/IgniteUI.Blazor.Lite.TestBed/Components/Common/TestUtil.cs @@ -1,4 +1,4 @@ -using System.Reflection; +using System.Reflection; using IgniteUI.Blazor.Controls; using Newtonsoft.Json; using Newtonsoft.Json.Linq; @@ -84,9 +84,9 @@ public static bool PropertyValuesAreEqual(object? serverValue, string? clientVal return false; } - DateTime[] serverDateArray = (DateTime[])serverDateRangeArray[i].DateRange; + DateTime[] serverDateArray = (DateTime[])serverDateRangeArray[i].DateRange!; string[] serverStringArray = serverDateArray.Select(x => x.ToShortDateString()).ToArray(); - var clientRangeArray = ((JArray)clientDateArray[i].DateRange).ToObject(); + var clientRangeArray = ((JArray)clientDateArray[i].DateRange!).ToObject(); if (clientRangeArray == null) { return false; diff --git a/tests/IgniteUI.Blazor.Tests/ChatTests.cs b/tests/IgniteUI.Blazor.Tests/ChatTests.cs index 2c9312b7..8d345022 100644 --- a/tests/IgniteUI.Blazor.Tests/ChatTests.cs +++ b/tests/IgniteUI.Blazor.Tests/ChatTests.cs @@ -12,7 +12,11 @@ public class ChatTests : ComponentWithContractTestBase .Getter(c => c.GetCurrentDraftMessageAsync(), c => c.GetCurrentDraftMessage(), "DraftMessage", arrange: _ => { }, returns: FromRender.Of((interop, cut) => InteropReturn.Object("", """{"text": "wip draft"}""")), - assert: (cut, result) => Assert.Equal("wip draft", result.Text)) + assert: (cut, result) => + { + Assert.NotNull(result); + Assert.Equal("wip draft", result.Text); + }) .Event(c => c.TypingChange, argsJson: """{"detail": true}""", assert: args => Assert.True(args.Detail)) diff --git a/tests/IgniteUI.Blazor.Tests/ComboTests.cs b/tests/IgniteUI.Blazor.Tests/ComboTests.cs index 6a8763a0..b69f20a8 100644 --- a/tests/IgniteUI.Blazor.Tests/ComboTests.cs +++ b/tests/IgniteUI.Blazor.Tests/ComboTests.cs @@ -20,8 +20,14 @@ public class ComboTests : ComponentWithContractTestBase> // JsonDataSourceItem.ToJson's "___id" marker), assigned once item is added to DS. internal static string DataItemId(InteropHarness interop, IRenderedComponent cut, int index) { - var items = interop.FindPropertyUpdate(interop.ContainerIdOf(cut), "data")!.Value.EnumerateArray().ToArray(); - return items[index].GetProperty("___id").GetString()!; + var dataUpdate = interop.FindPropertyUpdate(interop.ContainerIdOf(cut), "data"); + if (dataUpdate is not { } data) + { + return string.Empty; + } + + var items = data.EnumerateArray().ToArray(); + return items[index].GetProperty("___id").GetString() ?? string.Empty; } internal static string UuidRef(InteropHarness interop, IRenderedComponent cut, int index) => diff --git a/tests/IgniteUI.Blazor.Tests/DropdownTests.cs b/tests/IgniteUI.Blazor.Tests/DropdownTests.cs index ce8a7ae1..4bd35efd 100644 --- a/tests/IgniteUI.Blazor.Tests/DropdownTests.cs +++ b/tests/IgniteUI.Blazor.Tests/DropdownTests.cs @@ -91,9 +91,9 @@ sealed class Anchor elements: () => [anchor.Element]) .Method(c => c.ClearSelectionAsync(), c => c.ClearSelection(), "clearSelection") .Method(c => c.SelectAsync("item-1"), c => c.Select("item-1"), "select", - InteropReturn.Undefined, expect: null!, args: ["item-1"], types: ["Json"]) + InteropReturn.Undefined, expect: null, args: ["item-1"], types: ["Json"]) .Method(c => c.NavigateToAsync(2), c => c.NavigateTo(2), "navigateTo", - InteropReturn.Undefined, expect: null!, args: [2.0], types: ["Json"]) + InteropReturn.Undefined, expect: null, args: [2.0], types: ["Json"]) .Getter(c => c.GetItemsAsync(), c => c.GetItems(), "Items", itemsArrange, returns: FromRender.Of((interop, cut) => InteropReturn.Array($$$"""[{"refType": "name", "id": "{{{interop.ContainerIdOf(cut, "igc-dropdown-item:nth-of-type(1)")}}}"}, {"refType": "name", "id": "{{{interop.ContainerIdOf(cut, "igc-dropdown-item:nth-of-type(2)")}}}"}]""")), @@ -115,7 +115,7 @@ sealed class Anchor // Assert.Same(cut.FindComponents()[0].Instance, result[0]); // Assert.Same(cut.FindComponents()[1].Instance, result[1]); }) - .Getter(c => c.GetSelectedItemAsync(), c => c.GetSelectedItem(), "SelectedItem", InteropReturn.Undefined, expect: null!) + .Getter(c => c.GetSelectedItemAsync(), c => c.GetSelectedItem(), "SelectedItem", InteropReturn.Undefined, expect: null) .Getter(c => c.GetSelectedItemAsync(), c => c.GetSelectedItem(), "SelectedItem", itemsArrange, returns: FromRender.Of((interop, cut) => InteropReturn.Ref($$"""{"refType": "name", "id": "{{interop.ContainerIdOf(cut, "igc-dropdown-item:nth-of-type(1)")}}"}""")), diff --git a/tests/IgniteUI.Blazor.Tests/DynamicContentHolderTests.cs b/tests/IgniteUI.Blazor.Tests/DynamicContentHolderTests.cs new file mode 100644 index 00000000..d3a96d0f --- /dev/null +++ b/tests/IgniteUI.Blazor.Tests/DynamicContentHolderTests.cs @@ -0,0 +1,40 @@ +using IgniteUI.Blazor.Controls; + +namespace IgniteUI.Blazor.Tests; + +public class DynamicContentHolderTests +{ + [Fact] + public async Task TypedDynamicContent_WhenComponentIsSetAfterGetInstanceAsync_ReturnsCurrentComponent() + { + var content = new TypedDynamicContent(typeof(TestComponent)) + { + ControlType = typeof(TestComponent) + }; + var task = content.GetInstanceAsync(); + + var component = new TestComponent(); + content.Component = component; + + Assert.Same(component, await task); + } + + [Fact] + public async Task TypedDynamicContent_WhenComponentChangesToNull_FaultsPendingTask() + { + var content = new TypedDynamicContent(typeof(TestComponent)) + { + ControlType = typeof(TestComponent) + }; + var task = content.GetInstanceAsync(); + + content.Component = null; + + var exception = await Assert.ThrowsAsync(() => task); + Assert.Equal("Component is null.", exception.Message); + } + + private sealed class TestComponent + { + } +}