How to migrate from [SynonymousTo]

Goal

The [SynonymousTo] attribute was deprecated in 2.3.2 and removed in Starcounter 2.4. This page explains how to migrate from [SynonymousTo] to standard C# features.

We only use properties in this guide since that's what recommended as described in Database classes.

Migrate synonymous fields with same type

Before.cs
[Database]
public class Foo
{
public string Bar;
[SynonymousTo("Bar")]
public string Fubar;
}
After.cs
[Database]
public class Foo
{
public string Bar { get; set; }
public string Fubar
{
get => Bar;
set => Bar = value;
}
}

Migrate synonymous fields with narrowed type

Before.cs
[Database]
public class Foo
{
public Foo Bar;
[SynonymousTo("Bar")]
public Narrowed Fubar;
}
[Database]
public class Narrowed : Foo {}
After.cs
[Database]
public class Foo
{
public Foo Bar { get; set; }
public Narrowed Fubar
{
get => (Narrowed)Bar;
set => Bar = value;
}
}
[Database]
public class Narrowed : Foo {}

Migrate read-only synonym pattern

Before.cs
[Database]
public class Foo
{
public string Bar;
[SynonymousTo("Bar")]
public readonly string Fubar;
}
After.cs
[Database]
public class Foo
{
public string Bar { get; set; }
public string Fubar => Bar;
}

Summary

After these changes, the database schema will still be compatible, so no unload/reload is needed. We hope that these changes makes the code easier to read and more familiar to C# developers.