Use ReactiveUI
MODIFY
WalletWasabi.Fluent.Generators/AutoNotifyGenerator.cs
WalletWasabi.Fluent.Generators/AutoNotifyGenerator.cs
@@ -50,7 +50,7 @@ namespace WalletWasabi.Fluent
return;
}
- var notifySymbol = compilation.GetTypeByMetadataName("System.ComponentModel.INotifyPropertyChanged");
+ var notifySymbol = compilation.GetTypeByMetadataName("ReactiveUI.ReactiveObject");
if (notifySymbol is null)
{
return;
@@ -109,7 +109,7 @@ namespace WalletWasabi.Fluent
break;
}
- if (baseType.Interfaces.Contains(notifySymbol))
+ if (SymbolEqualityComparer.Default.Equals(baseType, notifySymbol))
{
addNotifyInterface = false;
break;
@@ -123,22 +123,22 @@ namespace WalletWasabi.Fluent
if (addNotifyInterface)
{
source.Append($@"// <auto-generated />
+using ReactiveUI;
+
namespace {namespaceName}
{{
public partial class {classSymbol.Name} : {notifySymbol.ToDisplayString()}
- {{
-");
- source.Append(
- " public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;");
+ {{");
}
else
{
source.Append($@"// <auto-generated />
+using ReactiveUI;
+
namespace {namespaceName}
{{
public partial class {classSymbol.Name}
- {{
-");
+ {{");
}
foreach (IFieldSymbol fieldSymbol in fields)
@@ -171,14 +171,7 @@ namespace {namespaceName}
public {fieldType} {propertyName}
{{
get => {fieldName};
- set
- {{
- if (Equals({fieldName}, value))
- {{
- {fieldName} = value;
- PropertyChanged?.Invoke(this, new System.ComponentModel.PropertyChangedEventArgs(nameof({propertyName})));
- }}
- }}
+ set => this.RaiseAndSetIfChanged(ref {fieldName}, value);
}}");
static string? ChooseName(string fieldName, TypedConstant overridenNameOpt)

MODIFY
WalletWasabi.Fluent.Generators/PropertyGenerator.cs
WalletWasabi.Fluent.Generators/PropertyGenerator.cs
@@ -17,11 +17,13 @@ namespace WalletWasabi.Fluent
{
public enum PropertyModifier
{
- Public = 0,
- Protected = 1,
- Internal = 2,
- Private = 3
+ None = 0,
+ Public = 1,
+ Protected = 2,
+ Private = 3,
+ Internal = 4
}
+
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = true)]
public sealed class PropertyAttribute : Attribute
{
@@ -29,8 +31,8 @@ namespace WalletWasabi.Fluent
string propertyName,
Type propertyType,
bool isReadOnly = false,
- PropertyModifier getterModifier = PropertyModifier.Public,
- PropertyModifier setterModifier = PropertyModifier.Public)
+ PropertyModifier getterModifier = PropertyModifier.None,
+ PropertyModifier setterModifier = PropertyModifier.None)
{
PropertyName = propertyName;
PropertyType = propertyType;
@@ -70,7 +72,7 @@ namespace WalletWasabi.Fluent
return;
}
- var notifySymbol = compilation.GetTypeByMetadataName("System.ComponentModel.INotifyPropertyChanged");
+ var notifySymbol = compilation.GetTypeByMetadataName("ReactiveUI.ReactiveObject");
if (notifySymbol is null)
{
return;
@@ -122,7 +124,7 @@ namespace WalletWasabi.Fluent
break;
}
- if (baseType.Interfaces.Contains(notifySymbol))
+ if (SymbolEqualityComparer.Default.Equals(baseType, notifySymbol))
{
addNotifyInterface = false;
break;
@@ -136,22 +138,23 @@ namespace WalletWasabi.Fluent
if (addNotifyInterface)
{
source.Append($@"// <auto-generated />
+using ReactiveUI;
+
namespace {namespaceName}
{{
public partial class {classSymbol.Name} : {notifySymbol.ToDisplayString()}
- {{
-");
- source.Append(
- " public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;");
+ {{");
+
}
else
{
source.Append($@"// <auto-generated />
+using ReactiveUI;
+
namespace {namespaceName}
{{
public partial class {classSymbol.Name}
- {{
-");
+ {{");
}
var attributes = classSymbol
@@ -162,14 +165,16 @@ namespace {namespaceName}
{
return value switch
{
- // Public
+ // None
0 => "",
+ // Public
+ 1 => "public",
// Protected
- 1 => "protected ",
- // Internal
- 2 => "internal ",
+ 2 => "protected ",
// Private
3 => "private ",
+ // Internal
+ 4 => "internal ",
// Default
_ => ""
};
@@ -201,27 +206,16 @@ private {propertyType} {fieldName};");
source.Append($@"
public {propertyType} {propertyName}
{{
- {ToModifier(getterModifier.Value)}get
- {{
- return this.{fieldName};
- }}");
+ {ToModifier(getterModifier.Value)}get => this.{fieldName};");
if (!isReadOnly.Value)
{
source.Append($@"
- {ToModifier(setterModifier.Value)}set
- {{
- if (!Equals({fieldName}, value))
- {{
- {fieldName} = value;
- PropertyChanged?.Invoke(this, new System.ComponentModel.PropertyChangedEventArgs(nameof({propertyName})));
- }}
- }}");
+ {ToModifier(setterModifier.Value)}set => this.RaiseAndSetIfChanged(ref {fieldName}, value);");
}
source.Append($@"
-}}
-");
+ }}");
}
source.Append($@"

MODIFY
WalletWasabi.Fluent/ViewModels/TestViewModel.cs
WalletWasabi.Fluent/ViewModels/TestViewModel.cs
@@ -5,19 +5,10 @@ namespace WalletWasabi.Fluent.ViewModels
{
// TODO: For testing only.
[Property("IsVisible", typeof(bool))]
- [Property("Title", typeof(string), false, PropertyModifier.Public, PropertyModifier.Internal)]
- [Property("Items", typeof(List<string>), false, PropertyModifier.Public, PropertyModifier.Private)]
+ [Property("Title", typeof(string), false, PropertyModifier.None, PropertyModifier.Internal)]
+ [Property("Items", typeof(List<string>), false, PropertyModifier.None, PropertyModifier.Private)]
[Property("Count", typeof(int), isReadOnly: true)]
- [NavigationMetaData(
- Searchable = true,
- Title = "Test",
- Caption = "Test caption",
- IconName = "info_regular",
- Order = 0,
- Category = "General",
- Keywords = new[] { "Test", "ViewModel" },
- NavBarPosition = NavBarPosition.None)]
- public partial class TestViewModel : RoutableViewModel
+ public partial class TestViewModel
{
// [AutoNotify] private bool _test;
}

Use ReactiveUI