|
| 1 | +// Licensed to the .NET Foundation under one or more agreements. |
| 2 | +// The .NET Foundation licenses this file to you under the MIT license. |
| 3 | +// See the LICENSE file in the project root for more information. |
| 4 | + |
| 5 | +using System; |
| 6 | +using System.Diagnostics; |
| 7 | + |
| 8 | +namespace CommunityToolkit.Mvvm.ComponentModel; |
| 9 | + |
| 10 | +/// <summary> |
| 11 | +/// An attribute that can be used to support <see cref="ObservablePropertyAttribute"/> in generated properties, when applied to fields |
| 12 | +/// contained in a type that is either inheriting from <see cref="ObservableRecipient"/>, or annotated with <see cref="ObservableRecipientAttribute"/>. |
| 13 | +/// When this attribute is used, the generated property setter will also call <see cref="ObservableRecipient.Broadcast{T}(T, T, string?)"/>. |
| 14 | +/// This allows generated properties to opt-in into broadcasting behavior without having to fallback into a full explicit observable property. |
| 15 | +/// <para> |
| 16 | +/// This attribute can be used as follows: |
| 17 | +/// <code> |
| 18 | +/// partial class MyViewModel : ObservableRecipient |
| 19 | +/// { |
| 20 | +/// [ObservableProperty] |
| 21 | +/// [AlsoBroadcastChange] |
| 22 | +/// private string username; |
| 23 | +/// } |
| 24 | +/// </code> |
| 25 | +/// </para> |
| 26 | +/// And with this, code analogous to this will be generated: |
| 27 | +/// <code> |
| 28 | +/// partial class MyViewModel |
| 29 | +/// { |
| 30 | +/// public string Username |
| 31 | +/// { |
| 32 | +/// get => username; |
| 33 | +/// set => SetProperty(ref username, value, broadcast: true); |
| 34 | +/// } |
| 35 | +/// } |
| 36 | +/// </code> |
| 37 | +/// </summary> |
| 38 | +[AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = false)] |
| 39 | +[Conditional("MVVMTOOLKIT_KEEP_SOURCE_GENERATOR_ATTRIBUTES")] |
| 40 | +public sealed class AlsoBroadcastChangeAttribute : Attribute |
| 41 | +{ |
| 42 | +} |
0 commit comments