Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> MyPropertyObservable() => Observable.Return("Test Value");
}
```

Expand Down
5 changes: 3 additions & 2 deletions src/ReactiveUI.SourceGenerators.Execute/TestViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public partial class TestViewModel : ReactiveObject
[JsonInclude]
[DataMember]
[ObservableAsProperty]
private double _test2Property;
private double _test2Property = 1.1d;

[JsonInclude]
[Reactive]
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ public class PropertyToReactiveFieldAnalyzer : DiagnosticAnalyzer
/// <param name="context">The context.</param>
public override void Initialize(AnalysisContext context)
{
if (context == null)
if (context is null)
{
return;
throw new System.ArgumentNullException(nameof(context));
}

context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>.",
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");

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ internal static ImmutableArray<MemberDeclarationSyntax> 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 =
Expand Down