Basilisque.AutoImplementer.CodeAnalysis.Fasteroid 1.0.0-Alpha

This is a prerelease version of Basilisque.AutoImplementer.CodeAnalysis.Fasteroid.
There is a newer prerelease version of this package available.
See the version list below for details.
The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package Basilisque.AutoImplementer.CodeAnalysis.Fasteroid --version 1.0.0-Alpha
                    
NuGet\Install-Package Basilisque.AutoImplementer.CodeAnalysis.Fasteroid -Version 1.0.0-Alpha
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Basilisque.AutoImplementer.CodeAnalysis.Fasteroid" Version="1.0.0-Alpha" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Basilisque.AutoImplementer.CodeAnalysis.Fasteroid" Version="1.0.0-Alpha" />
                    
Directory.Packages.props
<PackageReference Include="Basilisque.AutoImplementer.CodeAnalysis.Fasteroid" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Basilisque.AutoImplementer.CodeAnalysis.Fasteroid --version 1.0.0-Alpha
                    
#r "nuget: Basilisque.AutoImplementer.CodeAnalysis.Fasteroid, 1.0.0-Alpha"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Basilisque.AutoImplementer.CodeAnalysis.Fasteroid@1.0.0-Alpha
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Basilisque.AutoImplementer.CodeAnalysis.Fasteroid&version=1.0.0-Alpha&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Basilisque.AutoImplementer.CodeAnalysis.Fasteroid&version=1.0.0-Alpha&prerelease
                    
Install as a Cake Tool

Basilisque - Auto Implementer - Fasteroid's Fork

Overview

This project provides functionality to automatically implement interfaces.

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.Fasteroid.
Installing the package will add the source generator to your project.

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

Features

General

  • Automatic implementation of interfaces on classes

  • Classes have to be marked with the [AutoImplementInterfaces] attribute

    • Then all interfaces marked with the [AutoImplementInterface] attribute will be implemented
      [AutoImplementInterface]
      public interface ITitle
      {
        string Title { get; set; }
      }
      
      public interface ISummary
      {
        string Summary { get; set; }
      }
      
      [AutoImplementInterfaces]
      public partial class Book : ITitle, ISummary
      { /* will have the property 'Title' only. 'ISummary' is not marked with an attribute */ }
      
    • By specifying the interfaces explicitly within the attribute on the class, the interfaces dont't have to be marked
      ([AutoImplementInterfaces<IInterface>()] or [AutoImplementInterfaces(typeof(IInterface))])
      public interface ITitle
      {
        string Title { get; set; }
      }
      
      public interface ISummary
      {
        string Summary { get; set; }
      }
      
      [AutoImplementInterfaces<ITitle, ISummary>()]
      //[AutoImplementInterfaces(typeof(ITitle), typeof(ISummary))] <- alternative syntax
      public partial class Book : ITitle, ISummary
      { /* will have the properties 'Title' and 'Summary' */ }
      
  • When the interfaces are explicitly stated, they don't have to be stated as base type a second time. This is valid:

    public interface ITitle
    {
      string Title { get; set; }
    }
    
    [AutoImplementInterfaces<ITitle>()]
    //[AutoImplementInterfaces(typeof(ITitle))] <- alternative syntax
    public partial class Book // ': ITitle' <- this is optional because 'ITitle' was specified in the attribute
    { }
    

Property Implementation

  • By default, all non-nullable properties are implemented with the 'required' modifier
    public interface IBook
    {
      string Title { get; set; }          // required
    
      DateOnly? PublishDate { get; set; } // not required
    
      string Publisher { get; set; }      // required
    }
    
  • This can be disabled by setting the 'Strict' property to 'false' in the [AutoImplementInterface] attribute, but it's not recommended.
    [AutoImplementInterface(Strict = false)]
    public interface IMovie
    {
      [Required] string Title { get; set; } // required
    
      [AutoImplement(AsRequired = true)]    // required
      TimeSpan Runtime { get; set; }
    
      string Summary { get; set; } // not required (unsafe!)
    }
    
  • Properties can also be skipped. Then they have to be implemented manually.
    public interface IPublish
    {
      DateOnly PublishDate { get; set; }
    
      [AutoImplement(Implement = false)] // skips the 'Publisher' property
      string? Publisher { get; set; }
    }
    

Examples

Create the interfaces:

[AutoImplementInterface]
public interface ITitle
{
  [Required] string Title { get; set; }
}

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

Create some classes implementing the interfaces:

[AutoImplementInterfaces()] // <- no interfaces were stated explicitly. 'ITitle' will be implemented because it is marked with the 'AutoImplementInterface' attribute
public partial class Book : ITitle, IDetails
{ /* will have the properties Title only */ }

[AutoImplementInterfaces<IDetails>()] // <- 'IDetails' was stated explicitly; only this interface will be implemented
public partial class Movie : ITitle, IDetails
{ /* will have the properties Image and Summary */ }

[AutoImplementInterfaces<IDetails>()] // <- will implement 'IDetails'
[AutoImplementInterfaces()]           // <- will find 'ITitle' because it is marked with the 'AutoImplementInterface' attribute
public partial class Game : ITitle, IDetails
{ /* will have the properties Title, Image and Summary */ }

[AutoImplementInterfaces(typeof(ITitle), typeof(IDetails))]
public partial class Event
{ /* will have the properties Title, Image and Summary */ }

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.

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

  • .NETStandard 2.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.0-F 127 12/5/2024