Skip to content

Commit d085b67

Browse files
Copilotjeromelaban
andcommitted
fix: Handle value types (structs) in BindableTypeProviders generator
Co-authored-by: jeromelaban <5839577+jeromelaban@users.noreply.github.com>
1 parent 12d31b5 commit d085b67

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/SourceGenerators/Uno.UI.SourceGenerators/BindableTypeProviders/BindableTypeProvidersGenerationTask.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,10 +364,15 @@ where field.IsStatic
364364
continue;
365365
}
366366

367+
// For value types (structs), we cannot generate setters because modifying an unboxed value type
368+
// creates a temporary copy that is immediately discarded. Only generate getters for structs.
369+
var isValueType = ownerType.TypeKind == TypeKind.Struct;
370+
367371
if (
368372
property.SetMethod != null
369373
&& !property.SetMethod.IsInitOnly
370374
&& property.SetMethod.IsLocallyPublic(_currentModule!)
375+
&& !isValueType
371376
)
372377
{
373378
writer.AppendLineIndented($@"bindableType.AddProperty(""{propertyName}"", typeof({propertyTypeName}), Get{propertyName}, Set{propertyName});");

0 commit comments

Comments
 (0)