Skip to content

Commit 48daad9

Browse files
AnastassiaPMrJul
authored andcommitted
Add XML doc comments to RegisterDirect warning about unsetValue and defaultValue (#18719)
Refine XML doc comments for defaultValue/unsetValue
1 parent ca07bda commit 48daad9

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

src/Avalonia.Base/AvaloniaProperty.cs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,12 @@ public void Unregister(Type type)
238238
/// <typeparam name="TValue">The type of the property's value.</typeparam>
239239
/// <param name="name">The name of the property.</param>
240240
/// <param name="defaultValue">The default value of the property.</param>
241+
/// <remarks>
242+
/// <b>⚠️ Be cautious:</b> if <c>defaultValue</c> is a reference type (like a list), this same instance
243+
/// will be shared across all controls using this property.<br/>
244+
/// Use value types (like <c>int</c>, <c>bool</c>) or immutable objects only.<br/>
245+
/// For collections or mutable types, use a factory pattern instead.
246+
/// </remarks>
241247
/// <param name="inherits">Whether the property inherits its value.</param>
242248
/// <param name="defaultBindingMode">The default binding mode for the property.</param>
243249
/// <param name="validate">A value validation callback.</param>
@@ -280,6 +286,12 @@ public static StyledProperty<TValue> Register<TOwner, TValue>(
280286
/// <typeparam name="TValue">The type of the property's value.</typeparam>
281287
/// <param name="name">The name of the property.</param>
282288
/// <param name="defaultValue">The default value of the property.</param>
289+
/// <remarks>
290+
/// <b>⚠️ Be cautious:</b> if <c>defaultValue</c> is a reference type (like a list), this same instance
291+
/// will be shared across all controls using this property.<br/>
292+
/// Use value types (like <c>int</c>, <c>bool</c>) or immutable objects only.<br/>
293+
/// For collections or mutable types, use a factory pattern instead.
294+
/// </remarks>
283295
/// <param name="inherits">Whether the property inherits its value.</param>
284296
/// <param name="defaultBindingMode">The default binding mode for the property.</param>
285297
/// <param name="validate">A value validation callback.</param>
@@ -329,6 +341,12 @@ internal static StyledProperty<TValue> Register<TOwner, TValue>(
329341
/// <typeparam name="TValue">The type of the property's value.</typeparam>
330342
/// <param name="name">The name of the property.</param>
331343
/// <param name="defaultValue">The default value of the property.</param>
344+
/// <remarks>
345+
/// <b>⚠️ Be cautious:</b> if <c>defaultValue</c> is a reference type (like a list), this same instance
346+
/// will be shared across all controls using this property.<br/>
347+
/// Use value types (like <c>int</c>, <c>bool</c>) or immutable objects only.<br/>
348+
/// For collections or mutable types, use a factory pattern instead.
349+
/// </remarks>
332350
/// <param name="inherits">Whether the property inherits its value.</param>
333351
/// <param name="defaultBindingMode">The default binding mode for the property.</param>
334352
/// <param name="validate">A value validation callback.</param>
@@ -365,6 +383,12 @@ public static AttachedProperty<TValue> RegisterAttached<TOwner, THost, TValue>(
365383
/// <param name="name">The name of the property.</param>
366384
/// <param name="ownerType">The type of the class that is registering the property.</param>
367385
/// <param name="defaultValue">The default value of the property.</param>
386+
/// <remarks>
387+
/// <b>⚠️ Be cautious:</b> if <c>defaultValue</c> is a reference type (like a list), this same instance
388+
/// will be shared across all controls using this property.<br/>
389+
/// Use value types (like <c>int</c>, <c>bool</c>) or immutable objects only.<br/>
390+
/// For collections or mutable types, use a factory pattern instead.
391+
/// </remarks>
368392
/// <param name="inherits">Whether the property inherits its value.</param>
369393
/// <param name="defaultBindingMode">The default binding mode for the property.</param>
370394
/// <param name="validate">A value validation callback.</param>
@@ -402,7 +426,11 @@ public static AttachedProperty<TValue> RegisterAttached<THost, TValue>(
402426
/// <param name="name">The name of the property.</param>
403427
/// <param name="getter">Gets the current value of the property.</param>
404428
/// <param name="setter">Sets the value of the property.</param>
405-
/// <param name="unsetValue">The value to use when the property is cleared.</param>
429+
/// <param name="unsetValue">
430+
/// The value to use when the property is cleared.
431+
/// ⚠️ Be careful with reference types: if you pass a mutable object (like a list),
432+
/// it will be shared across all instances using this property. Use value types or immutable objects.
433+
/// </param>
406434
/// <param name="defaultBindingMode">The default binding mode for the property.</param>
407435
/// <param name="enableDataValidation">
408436
/// Whether the property is interested in data validation.

0 commit comments

Comments
 (0)