Skip to content

Commit

Permalink
Updating readmes & updating actions
Browse files Browse the repository at this point in the history
  • Loading branch information
safalin1 committed Dec 1, 2023
1 parent b86304b commit 76b25a0
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 42 deletions.
27 changes: 13 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI
name: ci

on:
push:
Expand All @@ -8,22 +8,21 @@ on:

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
dotnet: [ '6.x', '7.x', '8.x' ]

steps:
- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ matrix.dotnet }}
- name: Restore dependencies
run: dotnet restore src/BuilderGenerator.sln
- name: Build
run: dotnet build --no-restore src/BuilderGenerator.sln
- name: Test
run: dotnet test --no-build --verbosity normal src/BuilderGenerator.sln
- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ matrix.dotnet }}
- name: Restore dependencies
run: dotnet restore src/BuilderGenerator.sln
- name: Build
run: dotnet build --no-restore src/BuilderGenerator.sln
- name: Test
run: dotnet test --no-build --verbosity normal src/BuilderGenerator.sln
21 changes: 21 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,27 @@ on:
jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
dotnet: [ '6.x', '7.x', '8.x' ]

steps:
- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ matrix.dotnet }}
- name: Restore dependencies
run: dotnet restore src/BuilderGenerator.sln
- name: Build
run: dotnet build --no-restore src/BuilderGenerator.sln
- name: Test
run: dotnet test --no-build --verbosity normal src/BuilderGenerator.sln

publish:
needs: build
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
Expand Down
1 change: 1 addition & 0 deletions GitVersion.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ increment: Minor
ignore:
sha: []
update-build-number: true
next-version: 2.0.0
branches:
master:
regex: ^main$
Expand Down
59 changes: 33 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,43 +29,50 @@ new MyBuilder().WithValuesFrom(anotherObject)

## Installation ##

BuilderGenerator2 is installed as an analyzer via a NuGet package - for more info on how to install/add this package to your solution: [am4u.BuilderGenerator](https://www.nuget.org/packages/am4u.BuilderGenerator/)
BuilderGenerator2 is installed as an analyzer via a NuGet package.

For more info on how to install/add this package to your solution, visit nuget.org: [Safalin.BuilderGenerator](https://www.nuget.org/packages/Safalin.BuilderGenerator/)
## Usage ##

After the package has been installed into your project:

1. Create a new partial class that will hold your builder methods.
2. Decorate it with the ```BuilderFor``` attribute, specifying the type of class that the builder is meant to build. For example:
```csharp
[BuilderFor(typeof(Foo))]
public partial class FooBuilder
{
}
```
```csharp
[BuilderFor(typeof(Foo))]
public partial class FooBuilder
{
}
```
3. Rebuild your project. The source generator will run and autogenerate methods in a separate partial class file, for each property in the type you specified in Step 2.

You can also add factory methods to your partial class which can craft specific data scenarios:

```csharp
[BuilderFor(typeof(Foo))]
public partial class FooBuilder
{
public static FooBuilder Bar()
{
return new FooBuilder()
.WithBar(true);
}

public static FooBuilder NotBar()
{
return new FooBuilder()
.WithBar(false);
}
}
```
You can also add factory methods to your partial class which can craft specific data scenarios:

```csharp
[BuilderFor(typeof(Foo))]
public partial class FooBuilder
{
public static FooBuilder Bar()
{
return new FooBuilder()
.WithBar(true);
}
public static FooBuilder NotBar()
{
return new FooBuilder()
.WithBar(false);
}
}
```

## Version History ##
- v2.0
- Rewrote internal source generation logic
- Added XML comments for auto-generated With methods
- Renamed from am4u.BuilderGenerator to Safalin.BuilderGenerator

- v1.1
- Added `WithValuesFrom` fluent method to builders

Expand Down
56 changes: 54 additions & 2 deletions src/BuilderGenerator/ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,57 @@ A fork of BuilderGenerator, a .NET Source Generator that is designed to add flue
## What are Builders?
[Builders](https://en.wikipedia.org/wiki/Builder_pattern) are an object creation pattern, similar to the [Object Mother](https://martinfowler.com/bliki/ObjectMother.html) pattern. Object Mothers and Builders are most commonly used to create objects for testing, but they can be used anywhere you want "canned" objects.

## Examples and Documentation
For documentation, please see the [GitHub repository](https://github.com/am4u/BuilderGenerator2).
## Example Usage ##

1. Create a new partial class that will hold your builder methods - for this example, we'll call it ```FooBuilder```, as the class we want to work with is called `Foo`.
2. Decorate it with the ```BuilderFor``` attribute, specifying the type of class that the builder is meant to build. For example:
```csharp
[BuilderFor(typeof(Foo))]
public partial class FooBuilder
{
}
```
3. Rebuild your project. The source generator will run and autogenerate methods in a separate partial class file, for each property in the type you specified in Step 2.

You can also add factory methods to your partial class which can craft specific data scenarios:

```csharp
[BuilderFor(typeof(Foo))]
public partial class FooBuilder
{
public static FooBuilder Bar()
{
return new FooBuilder()
.WithBar(true);
}

public static FooBuilder NotBar()
{
return new FooBuilder()
.WithBar(false);
}
}
```

## Features
### Record types
With this fork, you can use the `[BuilderFor]` attribute on C# record types:
```csharp
public record MyRecord(bool Hello);

[BuilderFor(typeof(MyRecord)]
public partial class MyRecordBuilder
{
}

var builder = new MyRecordBuilder().WithHello(true).Build();
```

### WithValuesFrom
The new `WithValuesFrom` method allows you to copy values from an existing instance into your builder:
```csharp
new MyBuilder().WithValuesFrom(anotherObject)
```

## Documentation & Source Code
For more information, please visit the [GitHub repository](https://github.com/safalin1/BuilderGenerator2).

0 comments on commit 76b25a0

Please sign in to comment.