https://github.com/bepost/begenerate
Code generation for ease of coding in C#
https://github.com/bepost/begenerate
codegenerator dotnet
Last synced: about 1 year ago
JSON representation
Code generation for ease of coding in C#
- Host: GitHub
- URL: https://github.com/bepost/begenerate
- Owner: bepost
- License: mit
- Created: 2025-02-01T18:56:11.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-03-07T17:32:37.000Z (over 1 year ago)
- Last Synced: 2025-03-07T18:28:08.540Z (over 1 year ago)
- Topics: codegenerator, dotnet
- Language: C#
- Homepage:
- Size: 75.2 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# BeGenerate
[](LICENSE)
[](https://github.com/bepost/BeGenerate/actions)
[](https://www.nuget.org/packages/BeGenerate)
This repo is the home for BeGenerate, a .NET Code Generator that simplifies the process of creating boilerplate code.
The current feature set is still limited as we're at a pre-release stage, but we're working hard to add more features
and
improve the existing ones.
## Usage
Add the BeGenerate package to your project:
```bash
dotnet add package BeGenerate
```
This will add the BeGenerate code generator to your project, and will add the required abstractions to your project.
### AutoInterface
The AutoInterface feature allows you to automatically generate interfaces for your classes. This is useful when you have
a class that you want to extract an interface from, but you don't want to do it manually.
To use the AutoInterface feature, you need to add the `AutoInterface` attribute to your class:
```csharp
using BeGenerate.AutoInterface;
[AutoInterface]
internal sealed class MyService : IMyService
{
public void MyMethod()
{
// Do something
}
void IMyService.MyExplicitMethod()
{
// Do something
}
}
```
When you build your project, the code generator will automatically generate an interface for your class:
```csharp
public partial interface IMyService
{
void MyMethod();
void MyExplicitMethod();
}
```
You can leave out methods and properties by adding the `ExcludeFromInterface` attribute to them:
```csharp
using BeGenerate.AutoInterface;
[AutoInterface]
internal sealed class MyService : IMyService
{
public void MyMethod()
{
// Do something
}
[ExcludeFromInterface]
public void MyMethodToExclude()
{
// Do something
}
}
```
If the generated interface should implement another interface, you can specify it using the `Implements` attribute:
```csharp
[AutoInterface]
[Implements]
internal sealed class MyService : IMyService
...
```
When you build your project, the code generator will automatically generate an interface for your class:
```csharp
public partial interface IMyService : IOtherInterface
...
```
You can give your interface a custom name by specifying it in the `Name` argument of the `AutoInterface` attribute:
```csharp
[AutoInterface(Name = "IMyCustomService")]
internal sealed class MyService : IMyCustomService
...
```
If you don't want your interface to be public, you can also alter the visibility of the generated interface:
```csharp
[AutoInterface(Accessibility = InterfaceAccessibility.Internal)]
internal sealed class MyService : IMyCustomService
...
```
Or even remove th access modifier entirely, so you can define it yourself using the partial keyword:
```csharp
[AutoInterface(Accessibility = InterfaceAccessibility.None)]
internal sealed class MyService : IMyCustomService;
public partial interface IMyCustomService;
...
```
## Contributing
BeGenerate is a community project. We invite your participation through issues and pull requests!
## License
All assets and code are under the MIT LICENSE and in the public domain unless specified otherwise.