Minerals.AutoInterfaces 0.2.0

dotnet add package Minerals.AutoInterfaces --version 0.2.0
                    
NuGet\Install-Package Minerals.AutoInterfaces -Version 0.2.0
                    
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.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Minerals.AutoInterfaces" Version="0.2.0" />
                    
Directory.Packages.props
<PackageReference Include="Minerals.AutoInterfaces" />
                    
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 Minerals.AutoInterfaces --version 0.2.0
                    
#r "nuget: Minerals.AutoInterfaces, 0.2.0"
                    
#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 Minerals.AutoInterfaces@0.2.0
                    
#: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=Minerals.AutoInterfaces&version=0.2.0
                    
Install as a Cake Addin
#tool nuget:?package=Minerals.AutoInterfaces&version=0.2.0
                    
Install as a Cake Tool

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.2.0" />

2. dotnet command

dotnet add package Minerals.AutoInterfaces

Changes in 0.2.0 version

The new name for the marker attribute is Minerals.AutoInterfaces.AutoInterface

// OLD MARKER ATTRIBUTE NAME - v0.1.6
[Minerals.AutoInterfaces.GenerateInterface]
public class TestClass
{
    public int Property1 { get; set; }
}

// NEW MARKER ATTRIBUTE NAME - v0.2.0
[Minerals.AutoInterfaces.AutoInterface]
public class TestClass
{
    public int Property1 { get; set; }
}

Usage

To use the package, add the [AutoInterface] marker attribute to the selected class or struct.

using System;

namespace TestNamespace
{
    [Minerals.AutoInterfaces.AutoInterface]
    public class TestClass
    {
        public int Property1 { get; set; }
        public int Property2 { get; private set; }
        protected int Property3 { get; set; }
        public event Action? Event1;

        public void Method1()
        {
            Console.WriteLine("Hello World");
        }

        public void Method2(int arg)
        {
            Console.WriteLine(arg);
        }

        public bool Method3<T0, T1>(T0 arg0, T1 arg1) where T0 : IEquatable<T1> where T1 : IEquatable<T0>
        {
            return arg0.Equals(arg1);
        }
    }
}

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

namespace global::TestNamespace
{
    [global::System.Runtime.CompilerServices.CompilerGenerated]
    public interface ITestClass
    {
        int Property1 { get; set; }
        int Property2 { get; }
        event Action? Event1;
        void Method1();
        void Method2(int arg);
        bool Method3<T0, T1>(T0 arg0, T1 arg1) where T0 : global::System.IEquatable<T1> where T1 : global::System.IEquatable<T0>;
    }
}

Package supports custom interface names

namespace TestNamespace
{
    [Minerals.AutoInterfaces.AutoInterface("ITestInterface")]
    public class TestClass
    {
        public int Property1 { get; protected set; } = 1;
    }
}

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

namespace global::TestNamespace
{
    [global::System.Runtime.CompilerServices.CompilerGenerated]
    public interface ITestInterface
    {
        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.2.0 157 5/26/2025
0.1.6 107 5/23/2025
0.1.5 142 5/1/2024
0.1.4 212 4/13/2024
0.1.3 184 4/11/2024
0.1.2 184 3/24/2024
0.1.1 222 3/24/2024
0.1.0 148 3/12/2024

Refactorization