-
Notifications
You must be signed in to change notification settings - Fork 351
Description
Describe the bug
When using MVVM Toolkit with ObservableValidator, I noticed that the source generator does not generate the validation code for abstract classes as part of the generated method static void ValidateAllProperties(object obj)
.
Example
Here is a sample abstract class with validator properties:
public partial abstract class BaseMyViewModel: ObservableValidator
{
[Required]
private string MyProperty;
}
Here is a concrete class that inherits from the abstract class:
public class MyViewModel : BaseMyViewModel
{
}
Here is the generated source file C:\Users\sam\AppData\Local\Temp\VSGeneratedDocuments\ef8d18dd-b51e-be83-e0c9-e148364b22d7\MyNamespace.MyViewModel.g.cs
:
// <auto-generated/>
#pragma warning disable
namespace CommunityToolkit.Mvvm.ComponentModel.__Internals
{
partial class __ObservableValidatorExtensions
{
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
[global::System.Obsolete("This method is not intended to be called directly by user code")]
public static global::System.Action<object> CreateAllPropertiesValidator(global::MyNamespace.MyViewModel _)
{
static void ValidateAllProperties(object obj)
{
var instance = (global::MyNamespace.MyViewModel)obj;
}
return ValidateAllProperties;
}
}
}
Here is what I would instead expect as the implementation of ValidateAllProperties
:
static void ValidateAllProperties(object obj)
{
var instance = (global::MyNamespace.MyViewModel)obj;
__ObservableValidatorHelper.ValidateProperty(instance, instance.MyProperty, nameof(instance.MyProperty));
}
Steps to reproduce
- Create an abstract class that inherits from ObservableValidator.
- Add properties with validation attributes.
- Create a concrete class that inherits the abstract class.
- Build the project.
- Look at sources generated in namespace
CommunityToolkit.Mvvm.ComponentModel.__Internals
.
Expected behavior
The generated code for the concrete class should contain the validation logic for properties in the abstract class.
Visual Studio Version
2022
Nuget packages
CommunityToolkit.Mvvm v8.1.0
Help us help you
Yes, but only if others can assist.