BizHawk
BizHawk copied to clipboard
Source Generator for null-safe `[RequiredService]` boilerplate
Applying the new attribute one or more times, such as: https://github.com/TASEmulators/BizHawk/blob/e34e199e551303b1b1d28435396a0f582e440c17/src/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.cs#L24-L27 results in:
public partial class RamSearch
{
[RequiredService]
public IEmulator? _maybeEmu
{
[Obsolete("use Emu")] get;
[Obsolete("only service provider should be writing to this")] private set;
} = null;
private IEmulator Emu => _maybeEmu!;
[OptionalService]
public IInputPollable? InputPollableCore
{
get;
[Obsolete("only service provider should be writing to this")] private set;
} = null;
[RequiredService]
public IMemoryDomains? _maybeMemoryDomains
{
[Obsolete("use MemoryDomains")] get;
[Obsolete("only service provider should be writing to this")] private set;
} = null;
private IMemoryDomains MemoryDomains => _maybeMemoryDomains!;
}
This boilerplate uses nullity annotations and gives build warnings if the props are used incorrectly. But rather than copy it across the whole codebase, I thought codegen would be more suitable. What do people think? If it's well-recieved I can do the same for [RequiredApi]
.