Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dasMulli/data-builder-generator
Code generator to easily create data builder patterns for your model classes
https://github.com/dasMulli/data-builder-generator
builder-patterns csharp-sourcegenerator
Last synced: about 1 month ago
JSON representation
Code generator to easily create data builder patterns for your model classes
- Host: GitHub
- URL: https://github.com/dasMulli/data-builder-generator
- Owner: dasMulli
- License: mit
- Created: 2020-06-23T12:10:01.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-09-03T21:18:48.000Z (3 months ago)
- Last Synced: 2024-11-08T04:20:49.645Z (about 1 month ago)
- Topics: builder-patterns, csharp-sourcegenerator
- Language: C#
- Homepage:
- Size: 45.9 KB
- Stars: 116
- Watchers: 5
- Forks: 11
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- RSCG_Examples - Data - builder-generator (Do not want to test 112 ( old ISourceGenerator ) / 1. [ThisAssembly](https://ignatandrei.github.io/RSCG_Examples/v2/docs/ThisAssembly) , in the [EnhancementProject](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#enhancementproject) category)
- csharp-source-generators - Data Builder Generator - ![stars](https://img.shields.io/github/stars/dasMulli/data-builder-generator?style=flat-square&cacheSeconds=604800) ![last commit](https://img.shields.io/github/last-commit/dasMulli/data-builder-generator?style=flat-square&cacheSeconds=86400) Generate data builder patterns for your model classes. (Source Generators / Patterns)
README
# Data Builder Generator
Allows to generate data builder patterns for your model classes.
Reference using Visual Studio 2019 16.6 or .NET CLI 3.1.500 / 5.0.100 or higher and opt into preview language features in your project file:
```xml
Preview
```
## Usage
Use the `GenerateDataBuilder` attribute to annotate the classes you wish to generate builder patterns for. If your class has constructors, be sure that the parameter names can be resolved to the name of a property:
```c#
using DasMulli.DataBuilderGenerator;[GenerateDataBuilder]
public class Person
{
public string FirstName { get; set; }
public string? MiddleNames { get; set; }
public string LastName { get; set; }public Person(string firstName, string? middleNames, string lastName)
{
FirstName = firstName;
MiddleNames = middleNames;
LastName = lastName;
}
}
```Then you can use the generated builder class:
```c#
var martinBuilder = new PersonBuilder()
.WithFirstName("Martin")
.WithMiddleNames("Andreas")
.WithLastName("Ullrich");var martin = martinBuilder.Build();
var otherMartin = martinBuilder.WithoutMiddleNames().WithLastName("Foo").Build();
```## Notes
Special thanks to [Mayr-Melnhof Karton AG](https://www.mayr-melnhof.com/) for supporting the development of this project.