From fa438e70cb4945e35db483e676115c1fe42a2865 Mon Sep 17 00:00:00 2001 From: TekH Date: Thu, 26 Mar 2026 15:32:00 +0100 Subject: [PATCH] Allow ReplacePlaceholders to handle null objects safely Updated ReplacePlaceholders to accept nullable objects and skip nulls during placeholder resolution, preventing NullReferenceExceptions when nulls are passed in the objects array. --- .../Common/Behaviors/Action/PlaceholderExtensions.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/ReC.Application/Common/Behaviors/Action/PlaceholderExtensions.cs b/src/ReC.Application/Common/Behaviors/Action/PlaceholderExtensions.cs index 4607664..2433dfb 100644 --- a/src/ReC.Application/Common/Behaviors/Action/PlaceholderExtensions.cs +++ b/src/ReC.Application/Common/Behaviors/Action/PlaceholderExtensions.cs @@ -18,7 +18,7 @@ public static partial class PlaceholderExtensions /// /// Thrown when a placeholder's column name cannot be resolved from any of the provided objects. /// - public static string ReplacePlaceholders(this string str, params object[] objects) + public static string ReplacePlaceholders(this string str, params object?[] objects) { return PlaceholderRegex().Replace(str, match => { @@ -29,6 +29,9 @@ public static partial class PlaceholderExtensions foreach (var obj in objects) { + if (obj is null) + continue; + var value = obj.GetValueByColumnName(columnName); if (value is not null) return ToSqlLiteral(value);