Skip to content

Umbraco Helper: Align GetDictionaryValue nullability with behaviour (closes #21145)#21372

Merged
AndyButland merged 1 commit into
v18/devfrom
v18/improvement/align-nullability-for-get-dictionary-value-with-behaviour
Jan 13, 2026
Merged

Umbraco Helper: Align GetDictionaryValue nullability with behaviour (closes #21145)#21372
AndyButland merged 1 commit into
v18/devfrom
v18/improvement/align-nullability-for-get-dictionary-value-with-behaviour

Conversation

@AndyButland

@AndyButland AndyButland commented Jan 12, 2026

Copy link
Copy Markdown
Contributor

Description

#21145 raised a concern about a change in behaviour of the GetDictionaryValue method, retuning empty string instead of null. This doesn't seem to be the case and it's consistent going back to Umbraco 13. However the signature suggests null can be returned, even though the implementation will never return null.

So to align behaviour with the signature I've changed the nullability such that it's clear a null string will never be returned.

Change Summary

  • Aligns the return type nullability of ICultureDictionary indexer and UmbracoHelper.GetDictionaryValue methods with actual behaviour
  • The implementation already returns an empty string (never null) when no dictionary item is found, but the interface incorrectly declared string?
  • Updated XML documentation to clarify the return behaviour

Testing

Visual inspection should suffice here, but you can verify the method still works as expected using an existing and non-existing key:

<div>Exists: @Umbraco.GetDictionaryValue("exists")</div>
<div>Not Exists: @(Umbraco.GetDictionaryValue("notExists") == string.Empty ? "Empty String" : "Something else")</div>

…ring when no dictionary item is found for the provided key).
Copilot AI review requested due to automatic review settings January 12, 2026 11:15

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 pull request corrects the return type nullability annotations for dictionary value methods to match their actual implementation behavior. The methods have always returned empty strings instead of null when dictionary items are not found, but the type signatures incorrectly declared nullable return types.

Changes:

  • Changed ICultureDictionary indexer return type from string? to string
  • Changed UmbracoHelper.GetDictionaryValue method return types from string? to string
  • Updated XML documentation to explicitly state that empty strings are returned instead of null

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/Umbraco.Core/Dictionary/ICultureDictionary.cs Updated interface indexer return type to non-nullable string and improved XML documentation
src/Umbraco.Web.Common/UmbracoHelper.cs Updated GetDictionaryValue method return types to non-nullable string and clarified documentation
Comments suppressed due to low confidence (1)

src/Umbraco.Web.Common/UmbracoHelper.cs:113

  • The XML documentation summary is incorrect. This method returns the dictionary value for the specified key, not the dictionary value with a default fallback. The summary should match the behavior described in the returns tag. Consider: "Returns the dictionary value for the key specified".
    /// <summary>
    ///     Returns the dictionary value for the key specified, and if empty returns the specified default fall back value

@AndyButland AndyButland changed the title Dictionary: Align GetDictionaryValue nullability with behaviour Dictionary: Align GetDictionaryValue nullability with behaviour Jan 12, 2026
@AndyButland AndyButland changed the title Dictionary: Align GetDictionaryValue nullability with behaviour Umbraco Helper: Align GetDictionaryValue nullability with behaviour Jan 12, 2026

@Zeegaan Zeegaan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good to me 🙆‍♂️

@AndyButland AndyButland merged commit 58a0b16 into v18/dev Jan 13, 2026
32 of 33 checks passed
@AndyButland AndyButland deleted the v18/improvement/align-nullability-for-get-dictionary-value-with-behaviour branch January 13, 2026 05:42
@AndyButland AndyButland changed the title Umbraco Helper: Align GetDictionaryValue nullability with behaviour Umbraco Helper: Align GetDictionaryValue nullability with behaviour (closes #21145) Jun 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants