Minerals.AutoInterfaces 0.1.5

dotnet add package Minerals.AutoInterfaces --version 0.1.5                
NuGet\Install-Package Minerals.AutoInterfaces -Version 0.1.5                
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="Minerals.AutoInterfaces" Version="0.1.5" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Minerals.AutoInterfaces --version 0.1.5                
#r "nuget: Minerals.AutoInterfaces, 0.1.5"                
#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.
// Install Minerals.AutoInterfaces as a Cake Addin
#addin nuget:?package=Minerals.AutoInterfaces&version=0.1.5

// Install Minerals.AutoInterfaces as a Cake Tool
#tool nuget:?package=Minerals.AutoInterfaces&version=0.1.5                

Minerals.AutoInterfaces

This NuGet package provides a functionality to automatically generate interfaces for C# classes with a single attribute. This simplifies the creation of interfaces for classes with clearly defined public members, without having to manually write interface code.

Features

  • Automatic interface generation: Saves time and reduces the risk of errors when creating interfaces for classes.
  • Support for generic methods and constraints: Allows for generating interfaces for complex classes with generic methods.
  • Support for custom getters and setters: Generates interfaces for properties with custom getter and setter implementations.
  • Customizable interface name: Allows you to name the interface according to naming conventions or user preferences.
  • Compatible with .NET Standard 2.0 and C# 7.3+: Works on a wide range of platforms and development environments.

Installation

Add the Minerals.AutoInterfaces nuget package to your C# project using the following methods:

1. Project file definition

<PackageReference Include="Minerals.AutoInterfaces" Version="0.1.*" />

2. dotnet command

dotnet add package Minerals.AutoInterfaces

Usage

To use the package, add the [GenerateInterface] attribute to the selected class.

namespace Examples
{
    [Minerals.AutoInterfaces.GenerateInterface]
    public class ExampleClass
    {
        public int Property1 { get; set; } = 1;
        public int Property2 { get; private set; } = 2;
        public int Property3
        {
            get { return _field1; }
            set { _field1 = value; }
        }

        private int _field1 = 0;

        public int Method1(int arg0, int arg1)
        {
            return arg0 + arg1;
        }

        public void Method2<T>(T arg0) where T : class, new()
        {
            return $"{arg0}";
        }

        protected void Method3() { }
    }
}

The code above will generate the IExampleClass.g.cs file with the IExampleClass interface.

namespace Examples
{
    [global::System.Runtime.CompilerServices.CompilerGenerated]
    public interface IExampleClass
    {
        int Property1 { get; set; }
        int Property2 { get; }
        int Property3 { get; set; }
        int Method1(int arg0, int arg1);
        string Method2<T>(T arg0) where T : class, new();
    }
}

Package supports custom interface names

namespace Examples
{
    [Minerals.AutoInterfaces.GenerateInterface("ExampleInterface")]
    public class ExampleClass
    {
        public int Property1 { get; protected set; } = 1;
    }
}

The code above will generate the ExampleInterface.g.cs file with the ExampleInterface interface.

namespace Examples
{
    [global::System.Runtime.CompilerServices.CompilerGenerated]
    public interface ExampleInterface
    {
        int Property1 { get; }
    }
}

Versioning

We use SemVer for versioning. For the versions available, see the branches on this repository.

Authors

  • Szymon Hałucha - Maintainer

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE file for details.

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
0.1.5 113 5/1/2024
0.1.4 194 4/13/2024
0.1.3 166 4/11/2024
0.1.2 162 3/24/2024
0.1.1 202 3/24/2024
0.1.0 130 3/12/2024

Fixed bug with the CodeBuilder enumeration methods