Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/daver32/InterfaceGenerator
A simple source generator that creates interfaces by implementations.
https://github.com/daver32/InterfaceGenerator
csharp-sourcegenerator dotnet5 dotnet6 dotnet7
Last synced: 3 months ago
JSON representation
A simple source generator that creates interfaces by implementations.
- Host: GitHub
- URL: https://github.com/daver32/InterfaceGenerator
- Owner: daver32
- License: mit
- Created: 2021-04-09T22:46:42.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2024-03-27T14:35:25.000Z (7 months ago)
- Last Synced: 2024-05-12T12:41:50.216Z (6 months ago)
- Topics: csharp-sourcegenerator, dotnet5, dotnet6, dotnet7
- Language: C#
- Homepage:
- Size: 58.6 KB
- Stars: 30
- Watchers: 2
- Forks: 11
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- RSCG_Examples - InterfaceGenerator
- csharp-source-generators - InterfaceGenerator - ![stars](https://img.shields.io/github/stars/daver32/InterfaceGenerator?style=flat-square&cacheSeconds=604800) ![last commit](https://img.shields.io/github/last-commit/daver32/InterfaceGenerator?style=flat-square&cacheSeconds=86400) - Auto generate interface definition by implementation, for when you need an abstraction for the sake of mocking. (Source Generators / Testing)
README
# InterfaceGenerator [![NuGet Version](http://img.shields.io/nuget/v/InterfaceGenerator.svg?style=flat)](https://www.nuget.org/packages/InterfaceGenerator/)
A simple source generator that creates interfaces by implementations. Useful for when you need an interface purely for the sake of mocking, or maybe you're not sure if you'll need the abstraction later on.
Inspired by [net_automatic_interface](https://github.com/codecentric/net_automatic_interface)
Example user implementation:
```cs
[GenerateAutoInterface]
public class SampleService : ISampleService
{
public double Multiply(double x, double y)
{
return x * y;
}public int NiceNumber => 69;
}
```Auto generated interface:
```cs
public partial interface ISampleService
{
double Multiply(double x, double y);
int NiceNumber { get; }
}
```
Supports:
- Methods, properties, indexers.
- Default arguments, `params` arguments.
- Generic types and methods.
- XML docs.
- Explicit interface names (using the `Name` property on `GenerateAutoInterface`).
- Explicit interface visibility (using the `VisibilityModifier` property on `GenerateAutoInterface`).
- Explicitly excluding a member from the interface (using `[AutoInterfaceIgnore]`).
Missing:
- Events.
- Nested types.
- Probably a bunch of edge cases I forgot about.