diff --git a/README.md b/README.md index b4e6cc7..0c5fb3a 100644 --- a/README.md +++ b/README.md @@ -81,7 +81,15 @@ using ReactiveUI.SourceGenerators; public partial class MyReactiveClass : ReactiveObject { [ObservableAsProperty] - private string _myProperty; + private string _myProperty = "Default Value"; + + public MyReactiveClass() + { + _myPrpertyHelper = MyPropertyObservable() + .ToProperty(this, x => x.MyProperty); + } + + IObservable MyPropertyObservable() => Observable.Return("Test Value"); } ``` diff --git a/src/ReactiveUI.SourceGenerators.Execute/TestViewModel.cs b/src/ReactiveUI.SourceGenerators.Execute/TestViewModel.cs index c0dffbe..2a40ab4 100644 --- a/src/ReactiveUI.SourceGenerators.Execute/TestViewModel.cs +++ b/src/ReactiveUI.SourceGenerators.Execute/TestViewModel.cs @@ -21,7 +21,7 @@ public partial class TestViewModel : ReactiveObject [JsonInclude] [DataMember] [ObservableAsProperty] - private double _test2Property; + private double _test2Property = 1.1d; [JsonInclude] [Reactive] @@ -53,10 +53,11 @@ public TestViewModel() Test6ArgOnlyCommand?.Execute("Hello World").Subscribe(); Test7ObservableCommand?.Execute().Subscribe(); + Console.Out.WriteLine($"Test2Property default Value: {Test2Property}"); _test2PropertyHelper = Test8ObservableCommand!.ToProperty(this, x => x.Test2Property); Test8ObservableCommand?.Execute(100).Subscribe(Console.Out.WriteLine); - Console.Out.WriteLine($"Test2Property Value: {Test2}"); + Console.Out.WriteLine($"Test2Property Value: {Test2Property}"); Console.Out.WriteLine($"Test2Property underlying Value: {_test2Property}"); Test9AsyncCommand?.ThrownExceptions.Subscribe(Console.Out.WriteLine); diff --git a/src/ReactiveUI.SourceGenerators/CodeAnalyzers/PropertyToReactiveFieldAnalyzer.cs b/src/ReactiveUI.SourceGenerators/CodeAnalyzers/PropertyToReactiveFieldAnalyzer.cs index de51119..c6fb054 100644 --- a/src/ReactiveUI.SourceGenerators/CodeAnalyzers/PropertyToReactiveFieldAnalyzer.cs +++ b/src/ReactiveUI.SourceGenerators/CodeAnalyzers/PropertyToReactiveFieldAnalyzer.cs @@ -34,9 +34,9 @@ public class PropertyToReactiveFieldAnalyzer : DiagnosticAnalyzer /// The context. public override void Initialize(AnalysisContext context) { - if (context == null) + if (context is null) { - return; + throw new System.ArgumentNullException(nameof(context)); } context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None); diff --git a/src/ReactiveUI.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs b/src/ReactiveUI.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs index b82e720..9930a67 100644 --- a/src/ReactiveUI.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs +++ b/src/ReactiveUI.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs @@ -137,7 +137,7 @@ internal static class DiagnosticDescriptors category: typeof(ReactiveCommandGenerator).FullName, defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true, - description: "All asynchronous methods annotated with [ReactiveCommand] should return a Task type, to benefit from the additional support provided by ReactiveCommand and ReactiveCommand.", + description: "All asynchronous methods annotated with [ReactiveCommand] should return a Task type, to benefit from the additional support provided by ReactiveCommand.FromTask.", helpLinkUri: "https://www.reactiveui.net/errors/RXUISG0008"); /// diff --git a/src/ReactiveUI.SourceGenerators/ObservableAsProperty/ObservableAsPropertyGenerator.Execute.cs b/src/ReactiveUI.SourceGenerators/ObservableAsProperty/ObservableAsPropertyGenerator.Execute.cs index c4ea3fb..89505ff 100644 --- a/src/ReactiveUI.SourceGenerators/ObservableAsProperty/ObservableAsPropertyGenerator.Execute.cs +++ b/src/ReactiveUI.SourceGenerators/ObservableAsProperty/ObservableAsPropertyGenerator.Execute.cs @@ -64,7 +64,7 @@ internal static ImmutableArray GetPropertySyntax(Proper getterFieldIdentifierName = propertyInfo.FieldName; } - var getterArrowExpression = ArrowExpressionClause(ParseExpression($"{getterFieldIdentifierName} = {getterFieldIdentifierName + "Helper"}.Value")); + var getterArrowExpression = ArrowExpressionClause(ParseExpression($"{getterFieldIdentifierName} = ({getterFieldIdentifierName}Helper?.Value ?? {getterFieldIdentifierName})")); // Prepare the forwarded attributes, if any var forwardedAttributes =