basilisque-framework / AutoImplementer

Automatically implements interfaces
Apache License 2.0
1 stars 1 forks source link

Basilisque - Auto Implementer

Overview

This project provides functionality to automatically implement interfaces.

NuGet Basilisque.AutoImplementer.CodeAnalysis License

Description

This project contains a source generator that automatically implements interface members in classes implementing the interfaces.
The goal is to provide a workaround for C# not supporting multiple inheritance for some basic use cases.

Getting Started

Install the NuGet package Basilisque.AutoImplementer.
Installing the package will add the source generator to your project.

Now you're ready to start implementing your interfaces automatically.

Features

Examples

Create the interfaces:

[AutoImplementInterface()]
public interface ITitle
{
  [Required] string Title { get; set; } // implements 'Title' as 'required' in .NET 7.0+
}

[AutoImplementInterface()]
public interface IDetails
{
  byte[]? Image { get; set; }
  string Summary { get; set; }
}

Create some classes implementing the interfaces:

public partial class Book : ITitle, IDetails
{ /* will have the properties Title, Image and Summary */ }

public partial class Movie : ITitle, IDetails
{ /* will have the properties Title, Image and Summary */ }

public partial class Song: ITitle
{ /* will have the property Title */ }

The source generator now adds the members to the corresponding classes without you having to do this on your own every time.

For details see the wiki.

License

The Basilisque framework (including this repository) is licensed under the Apache License, Version 2.0.