PublicInterfaceGenerator 0.0.1-preview.14

This is a prerelease version of PublicInterfaceGenerator.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package PublicInterfaceGenerator --version 0.0.1-preview.14                
NuGet\Install-Package PublicInterfaceGenerator -Version 0.0.1-preview.14                
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="PublicInterfaceGenerator" Version="0.0.1-preview.14" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add PublicInterfaceGenerator --version 0.0.1-preview.14                
#r "nuget: PublicInterfaceGenerator, 0.0.1-preview.14"                
#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 PublicInterfaceGenerator as a Cake Addin
#addin nuget:?package=PublicInterfaceGenerator&version=0.0.1-preview.14&prerelease

// Install PublicInterfaceGenerator as a Cake Tool
#tool nuget:?package=PublicInterfaceGenerator&version=0.0.1-preview.14&prerelease                

interface-generator

The purpose of this project is to make a C# Source Generator to create Interfaces at compile time. The Source Generator will inspect all classes with the provided [GenerateInterfaceAttribute] attribute and generate an Interface of all public Methods, Properties, and Events.

The default naming convention is to generate an interface of the same name as the class with 'I' prepended to it. For example, MyClass would generate an interface called IMyClass.

The GenerateInterfaceAttribute attribute has 2 properties.

  • InterfaceName - This will override the default name for the interface that is generated. The name will be the string provided.
  • Namespace - This will override the default namespace the interface is generated in. The default is to use the same namespace the class is in.

Why does this exist?

A common pattern in C# applications is to create a class and an underlying interface with a similar name. Usually this is done for for unit testing purposes. The interface can be mocked in a unit test to simplify test setup. The interface is

So the purpose of this project is to save a bit of time on some manual work.

public interface IUserManager
{
    Task UpdateUserName(string name);
    Task UpdateUserAddress(string address);
}

public class UserManager : IUserManager
{
    public async Task UpdateUserName(string name)
    {
        await Task.Completed;
    }

    public async Task UpdateUserAddress(string address)
    {
        await Task.Completed;
    }
}

//Register the interface to the .NET IoC Container
builder.Services.AddScoped<IUserManager, UserManager>();
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.0-preview.28 57 9/24/2024
0.1.0-preview.24 56 9/9/2024
0.0.1-preview.14 50 9/9/2024