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: 3 months 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: 2023-03-31T12:00:41.000Z (over 1 year ago)
- Last Synced: 2024-05-12T12:41:52.688Z (6 months ago)
- Topics: builder-patterns, csharp-sourcegenerator
- Language: C#
- Homepage:
- Size: 43.9 KB
- Stars: 111
- Watchers: 4
- Forks: 11
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- RSCG_Examples - Data - builder-generator (Do not want to test 114 ( 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.