diff --git a/docs/mvvm/generators/errors/MVVMTK0035.md b/docs/mvvm/generators/errors/MVVMTK0035.md index a0c8b644e..bd49a12f5 100644 --- a/docs/mvvm/generators/errors/MVVMTK0035.md +++ b/docs/mvvm/generators/errors/MVVMTK0035.md @@ -9,7 +9,7 @@ dev_langs: # MVVM Toolkit error MVVMTK0035 -All attributes targeting the generated property for a field annotated with [ObservableProperty] must correctly be resolved to valid types. This error is shown when a given `property:` attribute over a field with `[ObservableProperty]` is not correctly resolved to a type, which helps identifying issues at compile time as soon as possible. A common example where this can happen is if a `using` directive for the attribute is missing. +All attributes targeting the generated property for a field annotated with `[ObservableProperty]` must correctly be resolved to valid types. This error is shown when a given `property:` attribute over a field with `[ObservableProperty]` is not correctly resolved to a type, which helps identifying issues at compile time as soon as possible. A common example where this can happen is if a `using` directive for the attribute is missing. The following sample generates MVVMTK0035: diff --git a/docs/mvvm/generators/errors/MVVMTK0036.md b/docs/mvvm/generators/errors/MVVMTK0036.md new file mode 100644 index 000000000..7384faa43 --- /dev/null +++ b/docs/mvvm/generators/errors/MVVMTK0036.md @@ -0,0 +1,61 @@ +--- +title: MVVM Toolkit error MVVMTK0036 +author: Sergio0694 +description: MVVM Toolkit error MVVMTK0036 +keywords: community toolkit, dotnet, csharp, mvvm, net core, net standard, source generators +dev_langs: + - csharp +--- + +# MVVM Toolkit error MVVMTK0036 + +All attributes targeting the generated field or property for a method annotated with `[RelayCommand]` must correctly be resolved to valid types. This error is shown when a given `field:` or `property:` attribute over a method with `[RelayCommand]` is not correctly resolved to a type, which helps identifying issues at compile time as soon as possible. A common example where this can happen is if a `using` directive for the attribute is missing. + +The following sample generates MVVMTK0036: + +```csharp +using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.Input; + +namespace MyApp; + +public partial class SampleViewModel : ObservableObject +{ + [ObservableProperty] + private int counter; + + [RelayCommand] + [property: JsonIgnore] + private void IncrementCounter() + { + Counter++; + } +} +``` + +You can see that `JsonIgnore` has no `using` directive here, and as such is not resolved correctly. You can fix this by updating the code as follows: + +```csharp +using System.Text.Json.Serialization; +using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.Input; + +namespace MyApp; + +public partial class SampleViewModel : ObservableObject +{ + [ObservableProperty] + private int counter; + + [RelayCommand] + [property: JsonIgnore] + private void IncrementCounter() + { + Counter++; + } +} +``` + +## Additional resources + +- You can find more examples in the [unit tests](https://github.com/CommunityToolkit/dotnet/tree/main/tests/CommunityToolkit.Mvvm.SourceGenerators.UnitTests). diff --git a/docs/mvvm/generators/errors/TOC.yml b/docs/mvvm/generators/errors/TOC.yml index c06487ef0..c0ef4bb4d 100644 --- a/docs/mvvm/generators/errors/TOC.yml +++ b/docs/mvvm/generators/errors/TOC.yml @@ -69,3 +69,5 @@ items: href: MVVMTK0034.md - name: MVVMTK0035 href: MVVMTK0035.md +- name: MVVMTK0036 + href: MVVMTK0036.md