Skip to content

[Bug]: Reactive property from partial property with default value #244

@IvanJosipovic

Description

@IvanJosipovic

Describe the bug 🐞

Partial properties with default values appear to be broken. Example Class below is from the readme.

Error: Class1.cs(9,27): error CS8050: Only auto-implemented properties, or properties that use the 'field' keyword, can have initializers.

Step to reproduce

Create project as follows:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net9.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <LangVersion>preview</LangVersion>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="ReactiveUI" Version="20.2.45" />
    <PackageReference Include="ReactiveUI.SourceGenerators" Version="2.1.27">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
  </ItemGroup>

</Project>
using ReactiveUI;
using ReactiveUI.SourceGenerators;

namespace ClassLibrary1;

public partial class MyReactiveClass : ReactiveObject
{
    [Reactive]
    public partial string MyProperty { get; set; } = "Default Value";
}

Expected behavior

This should work as per readme

IDE

Visual Studio 2022

Operating system

Windows

Version

11

ReactiveUI Version

20.2.45

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions