Skip to content

Commit be14d5e

Browse files
committed
fix: prevent KVO key path double-prefixing for bool properties already starting with "Is"
1 parent 1a96569 commit be14d5e

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

src/ReactiveUI.Binding.SourceGenerators/Plugins/Observation/KVOObservationPlugin.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,15 +283,16 @@ public void EmitInlineObservationVariable(
283283

284284
/// <summary>
285285
/// Converts a .NET property name to a KVO key path using the standard naming convention.
286-
/// Boolean properties get an "Is" prefix (e.g., <c>Enabled</c> → <c>"isEnabled"</c>).
286+
/// Boolean properties get an "Is" prefix unless they already start with "Is"
287+
/// (e.g., <c>Enabled</c> → <c>"isEnabled"</c>, but <c>IsEnabled</c> → <c>"isEnabled"</c>).
287288
/// All others: lowercase first character (e.g., <c>Text</c> → <c>"text"</c>).
288289
/// </summary>
289290
/// <param name="propertyName">The .NET property name.</param>
290291
/// <param name="propertyTypeFullName">The fully qualified property type (e.g., "bool", "string").</param>
291292
/// <returns>The KVO key path string.</returns>
292293
private static string ToKvoKeyPath(string propertyName, string propertyTypeFullName)
293294
{
294-
if (propertyTypeFullName == "bool")
295+
if (propertyTypeFullName == "bool" && !propertyName.StartsWith("Is", StringComparison.Ordinal))
295296
{
296297
propertyName = "Is" + propertyName;
297298
}

src/tests/ReactiveUI.Binding.SourceGenerators.Tests/Plugins/ObservationPluginTests.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,22 @@ public async Task KVOPlugin_BooleanProperty_UsesIsPrefix()
666666
await Assert.That(sb.ToString()).Contains("\"isEnabled\"");
667667
}
668668

669+
/// <summary>
670+
/// Verifies KVO key path for boolean property already starting with "Is" does not double-prefix.
671+
/// </summary>
672+
/// <returns>A task representing the asynchronous test operation.</returns>
673+
[Test]
674+
public async Task KVOPlugin_BooleanPropertyAlreadyStartingWithIs_DoesNotDoublePrefix()
675+
{
676+
var plugin = new KVOObservationPlugin();
677+
var sb = new StringBuilder();
678+
var segment = ModelFactory.CreatePropertyPathSegment("IsEnabled", "bool");
679+
680+
plugin.EmitShallowObservation(sb, "obj", segment, "global::TestApp.MyView", isBeforeChange: false, includeStartWith: true);
681+
682+
await Assert.That(sb.ToString()).Contains("\"isEnabled\"");
683+
}
684+
669685
/// <summary>
670686
/// Verifies KVO key path for empty property name returns empty string.
671687
/// </summary>

0 commit comments

Comments
 (0)