![]() |
VOOZH | about |
dotnet add package MakeInterface.Generator --version 1.0.4
NuGet\Install-Package MakeInterface.Generator -Version 1.0.4
<PackageReference Include="MakeInterface.Generator" Version="1.0.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageVersion Include="MakeInterface.Generator" Version="1.0.4" />Directory.Packages.props
<PackageReference Include="MakeInterface.Generator"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>Project file
paket add MakeInterface.Generator --version 1.0.4
#r "nuget: MakeInterface.Generator, 1.0.4"
#:package MakeInterface.Generator@1.0.4
#addin nuget:?package=MakeInterface.Generator&version=1.0.4Install as a Cake Addin
#tool nuget:?package=MakeInterface.Generator&version=1.0.4Install as a Cake Tool
Generate interfaces for your classes at compile time using a simple attribute. Generate interfaces for your classes at compile time using a simple attribute.
MakeInterface is a C# source generator that produces an I{ClassName} interface for any class marked with GenerateInterface. The generator analyses the public members of the class and writes the matching interface into your project's build output.
This is particularly useful when you simply need an interface to facilitate unit testing or dependency injection.
MakeInterface is a C# source generator that produces an I{ClassName} interface for any class marked with GenerateInterface. The generator analyses the public members of the class and writes the matching interface into your project's build output.
This is particularly useful when you simply need an interface to facilitate unit testing or dependency injection.
obj folder and be part of the compilation.obj folder and be part of the compilation.[GenerateInterface]
public class MyClass
{
public string MyProperty { get; set; }
public void MyMethod() { }
}
Need to omit a member? Use the Exclude property to provide a list of member names:
[GenerateInterface(Exclude = new[] { nameof(MyMethod) })]
public class MyClass
{
public string MyProperty { get; set; }
public void MyMethod() { }
}
Need to omit a member? Use the Exclude property to provide a list of member names:
[GenerateInterface(Exclude = new[] { nameof(MyMethod) })]
public class MyClass
{
public string MyProperty { get; set; }
public void MyMethod() { }
public string MyProperty { get; set; }
public void MyMethod() { }
}
The generated interface will then be generated as IMyClass.g.cs
public interface IMyClass
{
string MyProperty { get; set; }
void MyMethod();
}
You can then implement the interface in your class
public class MyClass : IMyClass
{
public string MyProperty { get; set; }
public void MyMethod() { }
public string MyProperty { get; set; }
public void MyMethod() { }
}
[GenerateInterface]
public partial class MailService
{
[InterfaceInclude] // will appear in IMailService
public Task SendAsync() { /*...*/ }
public void Flush() { } // will NOT appear because opt-in is active
}
If a class has no [InterfaceInclude] attributes, the generator keeps its original
"include everything" behaviour.
Generating interfaces works well when you only need an interface so the class can be mocked in unit tests or injected into other components. In that scenario your class is typically the single implementation and keeping the interface in sync manually becomes boilerplate. Let the generator do the work for you.
If you maintain many implementations of the same interface or the interface needs to diverge from the class surface, consider writing the interface yourself. Manually created interfaces give you more control over its shape and versioning.
Install the NuGet package MakeInterface:
dotnet add package MakeInterface.Generator
The GenerateInterface attribute is included in the package and will be available after the build without adding any extra references.
This repository uses GitVersion in Continuous Deployment mode. Every build calculates a deterministic SemVer 2.0 version from the Git history. Local builds and CI therefore produce identical package and assembly versions.
MIT
master publish prerelease packages to GitHub Packages using the version calculated by GitVersion.NUGET_API_KEY is configured.Learn more about Target Frameworks and .NET Standard.
This package has no dependencies.
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.4 | 2,485 | 6/10/2025 |
| 1.0.1 | 204 | 6/7/2025 |
| 1.0.0 | 217 | 6/7/2025 |
| 1.0.0-preview2 | 170 | 6/6/2025 |
| 1.0.0-preview1 | 168 | 6/6/2025 |
| 0.4.1 | 904 | 1/25/2024 |
| 0.4.0 | 325 | 1/17/2024 |
| 0.3.3 | 622 | 12/23/2022 |
| 0.3.2 | 422 | 12/22/2022 |
| 0.3.1 | 467 | 12/22/2022 |
| 0.3.0 | 434 | 12/21/2022 |
| 0.2.3 | 437 | 12/21/2022 |
| 0.2.2 | 436 | 12/21/2022 |
| 0.2.1 | 423 | 12/21/2022 |
| 0.2.0 | 436 | 12/19/2022 |
| 0.1.2 | 434 | 12/19/2022 |
| 0.1.1 | 452 | 12/19/2022 |
| 0.1.0 | 427 | 12/18/2022 |
| 0.0.3 | 474 | 12/16/2022 |
| 0.0.2 | 444 | 12/16/2022 |