Skip to content

Commit 1727770

Browse files
committed
Revert initializer-setter changes (not needed). Refactor getter-initializer implementation.
1 parent 825adf8 commit 1727770

File tree

2 files changed

+11
-26
lines changed

2 files changed

+11
-26
lines changed

src/CommunityToolkit.Maui.SourceGenerators.Internal.UnitTests/BindablePropertyAttributeSourceGeneratorTests/CommonUsageTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,7 @@ static object __createDefaultText(global::Microsoft.Maui.Controls.BindableObject
701701
return defaultValue;
702702
}
703703
704-
public partial string Text { get => __initializingText ? field : (string)GetValue(TextProperty); set => SetValue(TextProperty, field = value); }
704+
public partial string Text { get => __initializingText ? field : (string)GetValue(TextProperty); set => SetValue(TextProperty, value); }
705705
706706
/// <summary>
707707
/// Backing BindableProperty for the <see cref = "CustomDuration"/> property.
@@ -716,7 +716,7 @@ static object __createDefaultCustomDuration(global::Microsoft.Maui.Controls.Bind
716716
return defaultValue;
717717
}
718718
719-
public partial System.TimeSpan CustomDuration { get => __initializingCustomDuration ? field : (System.TimeSpan)GetValue(CustomDurationProperty); set => SetValue(CustomDurationProperty, field = value); }
719+
public partial System.TimeSpan CustomDuration { get => __initializingCustomDuration ? field : (System.TimeSpan)GetValue(CustomDurationProperty); set => SetValue(CustomDurationProperty, value); }
720720
}
721721
""";
722722

src/CommunityToolkit.Maui.SourceGenerators.Internal/Generators/BindablePropertyAttributeSourceGenerator.cs

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -322,36 +322,21 @@ static void GenerateProperty(StringBuilder sb, in BindablePropertyModel info)
322322
{
323323
sb.Append("__initializing")
324324
.Append(info.PropertyName)
325-
.Append(" ? field : ")
326-
.Append("(")
327-
.Append(formattedReturnType)
328-
.Append(")GetValue(")
329-
.Append(info.BindablePropertyName)
330-
.Append(");\n");
331-
}
332-
else
333-
{
334-
sb.Append("(")
335-
.Append(formattedReturnType)
336-
.Append(")GetValue(")
337-
.Append(info.BindablePropertyName)
338-
.Append(");\n");
325+
.Append(" ? field : ");
339326
}
340327

328+
sb.Append("(")
329+
.Append(formattedReturnType)
330+
.Append(")GetValue(")
331+
.Append(info.BindablePropertyName)
332+
.Append(");\n");
333+
341334
if (info.SetterAccessibility is not null)
342335
{
343336
sb.Append(info.SetterAccessibility)
344337
.Append("set => SetValue(")
345-
.Append(info.IsReadOnlyBindableProperty ? info.BindablePropertyKeyName : info.BindablePropertyName);
346-
347-
if (info.HasInitializer)
348-
{
349-
sb.Append(", field = value);\n");
350-
}
351-
else
352-
{
353-
sb.Append(", value);\n");
354-
}
338+
.Append(info.IsReadOnlyBindableProperty ? info.BindablePropertyKeyName : info.BindablePropertyName)
339+
.Append(", value);\n");
355340
}
356341
// else Do not create a Setter because the property is read-only
357342

0 commit comments

Comments
 (0)