Skip to content

refactor(DisplayBase): optimize nullable data types#8091

Merged
ArgoZhang merged 1 commit into
mainfrom
refactor-null
Jun 7, 2026
Merged

refactor(DisplayBase): optimize nullable data types#8091
ArgoZhang merged 1 commit into
mainfrom
refactor-null

Conversation

@ArgoZhang

@ArgoZhang ArgoZhang commented Jun 7, 2026

Copy link
Copy Markdown
Member

Link issues

fixes #8090

Summary By Copilot

Regression?

  • Yes
  • No

Risk

  • High
  • Medium
  • Low

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • Merge the latest code from the main branch

Summary by Sourcery

Cache the nullable underlying type for generic display components and reuse the computed value type across consumers to avoid repeated reflection.

Enhancements:

  • Reuse the computed non-nullable value type in radio lists, generic radio lists, input numbers, and multi-select components instead of recomputing it from nullable metadata.
  • Improve XML documentation for nullable type handling and type extension helpers to clarify behavior and usage.

Copilot AI review requested due to automatic review settings June 7, 2026 06:37
@bb-auto bb-auto Bot added the enhancement New feature or request label Jun 7, 2026
@bb-auto bb-auto Bot added this to the v10.7.0 milestone Jun 7, 2026
@sourcery-ai

sourcery-ai Bot commented Jun 7, 2026

Copy link
Copy Markdown
Contributor
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Refactors nullable type handling in DisplayBase and dependent components by caching the nullable underlying type per closed generic and consistently using the computed ValueType, plus minor documentation cleanups in TypeExtensions.

File-Level Changes

Change Details Files
Cache nullable underlying type per closed generic and remove per-instance recalculation.
  • Change NullableUnderlyingType from an instance property to a static readonly field initialized via Nullable.GetUnderlyingType(typeof(TValue)).
  • Update XML docs to clarify this now-readonly cached behavior and its purpose (avoiding repeated reflection on hot paths).
  • Remove per-call assignment to NullableUnderlyingType in SetParametersAsync and rely on the static cached field.
src/BootstrapBlazor/Components/Display/DisplayBase.cs
Standardize use of ValueType in generic components instead of recomputing the underlying type locally.
  • Replace usages of NullableUnderlyingType ?? typeof(TValue) with ValueType in RadioList, RadioListGeneric, BootstrapInputNumber, and MultiSelect.
  • Keep NullableUnderlyingType only where needed for decisions (e.g., whether to add null items) while ensuring logic that depends on the effective runtime type uses ValueType.
  • Ensure ValueType is initialized once using the new cached NullableUnderlyingType or typeof(TValue) in DisplayBase.
src/BootstrapBlazor/Components/Radio/RadioList.razor.cs
src/BootstrapBlazor/Components/InputNumber/BootstrapInputNumber.razor.cs
src/BootstrapBlazor/Components/Radio/RadioListGeneric.razor.cs
src/BootstrapBlazor/Components/Select/MultiSelect.razor.cs
src/BootstrapBlazor/Components/Display/DisplayBase.cs
Tighten and clarify English XML documentation in TypeExtensions.
  • Refine GetUniqueTypeName summary to clearly state it returns a unique type name.
  • Clarify GetSafeType summary to explicitly state it safely obtains a Type from a type name string.
src/BootstrapBlazor/Extensions/TypeExtensions.cs

Assessment against linked issues

Issue Objective Addressed Explanation
#8090 Refactor DisplayBase to optimize retrieval of the nullable underlying type for TValue (e.g., by caching it instead of recomputing via reflection on each parameter set).
#8090 Update components that depend on nullable type handling (e.g., RadioList, RadioListGeneric, BootstrapInputNumber, MultiSelect) to use the optimized nullable type/value type logic without changing their behavior.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • Changing NullableUnderlyingType from an instance property to a protected static readonly field is a breaking change for any subclasses that were setting it; consider either keeping a (possibly obsolete) setter or clearly routing all subclass customization through ValueType instead so derivations aren’t silently broken.
  • Now that ValueType is the canonical non-nullable type for TValue, it may be worth tightening remaining call sites that still manually combine NullableUnderlyingType ?? typeof(TValue) to use ValueType consistently, to avoid future divergence or misuse of the two concepts.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Changing `NullableUnderlyingType` from an instance property to a `protected static readonly` field is a breaking change for any subclasses that were setting it; consider either keeping a (possibly obsolete) setter or clearly routing all subclass customization through `ValueType` instead so derivations aren’t silently broken.
- Now that `ValueType` is the canonical non-nullable type for `TValue`, it may be worth tightening remaining call sites that still manually combine `NullableUnderlyingType ?? typeof(TValue)` to use `ValueType` consistently, to avoid future divergence or misuse of the two concepts.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@ArgoZhang ArgoZhang merged commit 5c410ce into main Jun 7, 2026
6 checks passed
@ArgoZhang ArgoZhang deleted the refactor-null branch June 7, 2026 06:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors DisplayBase<TValue> and related generic components to avoid repeated reflection when working with nullable generic value types by caching the nullable underlying type and reusing the computed effective value type.

Changes:

  • Cache Nullable.GetUnderlyingType(typeof(TValue)) once per closed generic DisplayBase<TValue> via a static field.
  • Reuse ValueType in RadioList*, BootstrapInputNumber, and MultiSelect instead of recomputing NullableUnderlyingType ?? typeof(TValue).
  • Improve English XML documentation in TypeExtensions.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/BootstrapBlazor/Extensions/TypeExtensions.cs Improves English XML doc strings for type helper methods.
src/BootstrapBlazor/Components/Select/MultiSelect.razor.cs Uses cached ValueType when resolving the inner type for enum item generation.
src/BootstrapBlazor/Components/Radio/RadioListGeneric.razor.cs Reuses ValueType for enum detection/item generation.
src/BootstrapBlazor/Components/Radio/RadioList.razor.cs Reuses ValueType for enum detection and parsing logic.
src/BootstrapBlazor/Components/InputNumber/BootstrapInputNumber.razor.cs Uses ValueType for decimal-type detection.
src/BootstrapBlazor/Components/Display/DisplayBase.cs Caches nullable underlying type statically and updates nullable-type handling documentation.
Comments suppressed due to low confidence (1)

src/BootstrapBlazor/Components/Display/DisplayBase.cs:42

  • The XML doc for ValueType still says it represents the "nullable type" of TValue, but ValueType is used throughout as the effective value type (i.e., NullableUnderlyingType ?? typeof(TValue)). Updating the doc would make the new refactor (reusing ValueType instead of recomputing) clearer.
    /// <summary>
    /// <para lang="zh">获得/设置 泛型参数 TValue 可为空类型 Type 实例</para>
    /// <para lang="en">Gets or sets Generic Parameter TValue Nullable Type Instance</para>
    /// </summary>

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 29 to 32
/// <summary>
/// <para lang="zh">获得/设置 泛型参数 TValue 可为空类型 Type 实例,为空时表示类型不可为空</para>
/// <para lang="en">Gets or sets Generic Parameter TValue Nullable Type Instance. Null means type is not nullable</para>
/// <para lang="zh">获得 泛型参数 TValue 可为空类型 Type 实例,为空时表示类型不可为空</para>
/// <para lang="en">Gets the underlying type of <typeparamref name="TValue"/> when it is <see cref="Nullable{T}"/>; otherwise <see langword="null"/>.</para>
/// </summary>
@codecov

codecov Bot commented Jun 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (d246fb7) to head (ef47153).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #8091   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          766       766           
  Lines        34207     34206    -1     
  Branches      4702      4697    -5     
=========================================
- Hits         34207     34206    -1     
Flag Coverage Δ
BB 100.00% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor(DisplayBase): optimize nullable data types

2 participants