CommunityToolkit / CommunityToolkit/dotnet
newValue argument as Ref for *Changing() generated methods
- Dominant language
- C#
- Stars
- 3.8k
- Forks
- 400
- PR merge metrics
- No merged PRs in 30d
Description
### Overview
Hi, I'm migrating some old C# ViewModel code to use the [ObservableProperty] attribute on all the properties.
I'd like to convert the following code:
```csharp
private string _windowTitle;
public string WindowTitle {
get {
return _windowTitle;
}
set {
_windowTitle = $ "Window title prefix: {value}";
OnPropertyChanged(nameof(WindowTitle));
}
}
```
...but I couldn't find any "simple" or "standard" method to accomplish the same behavior using the MVVM Toolkit.
I discovered that recently the methods *Changing(string? newValue) or *Changing(string? oldValue, string newValue) got added, but the newValue isn't passed as `ref string`, so I can't intercept and change the value.
Could this prototype be implemented for those methods? Thanks!
### API breakdown
```csharp
partial void OnWindowTitleChanging(ref string value);
partial void OnWindowTitleChanging(string? oldValue, ref string newValue);
```
### Usage example
```csharp
partial void OnWindowTitleChanging(string? oldValue, ref string newValue)
{
newValue = "Window title prefix: " + newValue;
}
```
### Breaking change?
I'm not sure
### Alternatives
-
### Additional context
_No response_
### Help us help you
No, just wanted to propose this
Contributor guide
Assessment
This issue has not been assessed yet.