Change ReplacePlaceholders to return NULL for unresolved
Previously, ReplacePlaceholders threw PlaceholderResolutionException when a placeholder could not be resolved. Now, unresolved placeholders are replaced with "NULL" instead. All exception references and related tests have been updated to reflect this new behavior. Documentation has also been revised accordingly.
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Reflection;
|
||||
using System.Text.RegularExpressions;
|
||||
using ReC.Application.Common.Exceptions;
|
||||
|
||||
namespace ReC.Application.Common.Dto;
|
||||
|
||||
@@ -14,10 +13,8 @@ public static partial class PlaceholderExtensions
|
||||
/// Replaces placeholders in the format <c>{#ANY_STRING#COLUMN_NAME}</c> with the corresponding
|
||||
/// property value resolved via <see cref="GetValueByColumnName{T}"/> from the provided objects.
|
||||
/// Values are converted to SQL-compatible string representations.
|
||||
/// If a placeholder cannot be resolved, it is replaced with <c>NULL</c>.
|
||||
/// </summary>
|
||||
/// <exception cref="PlaceholderResolutionException">
|
||||
/// Thrown when a placeholder's column name cannot be resolved from any of the provided objects.
|
||||
/// </exception>
|
||||
public static string ReplacePlaceholders(this string str, params object?[] objects)
|
||||
{
|
||||
return PlaceholderRegex().Replace(str, match =>
|
||||
@@ -37,7 +34,7 @@ public static partial class PlaceholderExtensions
|
||||
return ToSqlLiteral(value);
|
||||
}
|
||||
|
||||
throw new PlaceholderResolutionException(placeholder, columnName, str);
|
||||
return "NULL";
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user