You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CommunityToolkit.Mvvm.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs
+19-3Lines changed: 19 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -319,17 +319,17 @@ internal static class DiagnosticDescriptors
319
319
/// <summary>
320
320
/// Gets a <see cref="DiagnosticDescriptor"/> indicating when <c>[ObservableProperty]</c> is applied to a field in an invalid type.
321
321
/// <para>
322
-
/// Format: <c>"The field {0}.{1} needs to be annotated with [ObservableProperty] in order to enable using [AlsoNotifyChangeFor]and [AlsoNotifyCanExecuteFor]"</c>.
322
+
/// Format: <c>"The field {0}.{1} needs to be annotated with [ObservableProperty] in order to enable using [AlsoNotifyChangeFor], [AlsoNotifyCanExecuteFor] and [AlsoBroadcastChange]"</c>.
title:"Invalid use of attributes dependent on [ObservableProperty]",
328
-
messageFormat:"The field {0}.{1} needs to be annotated with [ObservableProperty] in order to enable using [AlsoNotifyChangeFor]and [AlsoNotifyCanExecuteFor]",
328
+
messageFormat:"The field {0}.{1} needs to be annotated with [ObservableProperty] in order to enable using [AlsoNotifyChangeFor], [AlsoNotifyCanExecuteFor] and [AlsoBroadcastChange]",
description:"Fields not annotated with [ObservableProperty] cannot use [AlsoNotifyChangeFor]and [AlsoNotifyCanExecuteFor].",
332
+
description:"Fields not annotated with [ObservableProperty] cannot use [AlsoNotifyChangeFor], [AlsoNotifyCanExecuteFor] and [AlsoBroadcastChange].",
333
333
helpLinkUri:"https://aka.ms/mvvmtoolkit");
334
334
335
335
/// <summary>
@@ -347,4 +347,20 @@ internal static class DiagnosticDescriptors
347
347
isEnabledByDefault:true,
348
348
description:"Cannot apply [ObservableRecipient] to a type that already inherits this attribute from a base type.",
349
349
helpLinkUri:"https://aka.ms/mvvmtoolkit");
350
+
351
+
/// <summary>
352
+
/// Gets a <see cref="DiagnosticDescriptor"/> indicating when <c>[AlsoBroadcastChange]</c> is applied to a field in an invalid type.
353
+
/// <para>
354
+
/// Format: <c>"The field {0}.{1} cannot be annotated with [AlsoBroadcastChange], as its containing type doesn't inherit from ObservableRecipient, nor does it use [ObservableRecipient]"</c>.
title:"Invalid containing type for [ObservableProperty] field",
360
+
messageFormat:"The field {0}.{1} cannot be annotated with [AlsoBroadcastChange], as its containing type doesn't inherit from ObservableRecipient, nor does it use [ObservableRecipient]",
description:"Fields annotated with [AlsoBroadcastChange] must be contained in a type that inherits from ObservableRecipient or that is annotated with [ObservableRecipient] (including base types).",
// 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
+
usingSystem;
6
+
usingSystem.Diagnostics;
7
+
8
+
namespaceCommunityToolkit.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);
0 commit comments