### Install BuilderGenerator NuGet Package
Source: https://github.com/melgrubb/buildergenerator/blob/main/docs/index.md
This snippet shows the command to install the BuilderGenerator NuGet package using the .NET CLI or Package Manager Console.
```powershell
Install-Package BuilderGenerator
```
--------------------------------
### Install BuilderGenerator via NuGet
Source: https://github.com/melgrubb/buildergenerator/blob/main/README.md
This command installs the BuilderGenerator NuGet package, which is required to use the source generator in your .NET project.
```powershell
Install-Package BuilderGenerator
```
--------------------------------
### Fluent Builder Usage Example
Source: https://github.com/melgrubb/buildergenerator/blob/main/docs/index.md
Illustrates how to use a generated builder class with a fluent syntax to create an instance of the User class, setting specific properties.
```csharp
var testUser = new UserBuilder()
.WithId(Guid.NewGuid)
.WithFirstName("Hiro")
.WithLastName("Protagonist")
.Build();
```
--------------------------------
### Typical User Builder Example
Source: https://github.com/melgrubb/buildergenerator/blob/main/docs/index.md
Demonstrates how to use the UserBuilder to create a typical user and set specific properties like the first name. It highlights the importance of only depending on documented behavior.
```csharp
var user = UserBuilder.Typical()
.WithFirstName("Hiro")
.Build()
var result = SomeMethod(user);
```
--------------------------------
### PersonBuilder InternalString Property
Source: https://github.com/melgrubb/buildergenerator/blob/main/src/BuilderGenerator.Tests.Unit/Verify/When_generating_a_Builder_with_internal_properties.Test.verified.txt
Documentation for the 'InternalString' property, noted as having internal accessibility for testing specific attributes.
```C#
/// A string with internal accessibility to test the "includeInternals" attribute parameter.
```
--------------------------------
### PersonBuilder Core Functionality
Source: https://github.com/melgrubb/buildergenerator/blob/main/src/BuilderGenerator.Tests.Unit/Verify/When_generating_a_Builder_with_internal_properties.Test.verified.txt
Demonstrates the core methods for initializing and configuring a PersonBuilder. Includes setting the main Person object, defining a post-build action, and populating values from an existing Person object.
```C#
/// Sets the object to be returned by this instance.
/// The object to be returned.
/// A reference to this builder instance.
public PersonBuilder WithPerson(BuilderGenerator.Tests.Unit.Examples.Person value)
{
Person = new System.Lazy(() => value);
WithValuesFrom(value);
return this;
}
public PersonBuilder WithPostBuildAction(System.Action action)
{
PostBuildAction = action;
return this;
}
/// Populates this instance with values from the provided example.
/// This is a shallow clone, and does not traverse the example object creating builders for its properties.
public PersonBuilder WithValuesFrom(BuilderGenerator.Tests.Unit.Examples.Person example)
{
WithCreatedAt(example.CreatedAt);
WithCreatedBy(example.CreatedBy);
WithFirstName(example.FirstName);
WithId(example.Id);
WithInternalString(example.InternalString);
WithLastName(example.LastName);
WithMiddleName(example.MiddleName);
WithUpdatedAt(example.UpdatedAt);
WithUpdatedBy(example.UpdatedBy);
return this;
}
```
--------------------------------
### PersonBuilder WithUpdatedAt Methods
Source: https://github.com/melgrubb/buildergenerator/blob/main/src/BuilderGenerator.Tests.Unit/Verify/When_generating_a_Builder_with_internal_properties.Test.verified.txt
Provides methods to set the updated at timestamp of a PersonBuilder. It includes overloads for setting the value directly or via a function.
```csharp
public PersonBuilder WithUpdatedAt(System.DateTime value)
{
return WithUpdatedAt(() => value);
}
public PersonBuilder WithUpdatedAt(System.Func func)
{
UpdatedAt = new System.Lazy(func);
return this;
}
public PersonBuilder WithoutUpdatedAt()
{
UpdatedAt = new System.Lazy(() => default(System.DateTime));
return this;
}
```
--------------------------------
### PersonBuilder CreatedAt Property
Source: https://github.com/melgrubb/buildergenerator/blob/main/src/BuilderGenerator.Tests.Unit/Verify/When_generating_a_Builder_with_internal_properties.Test.verified.txt
Methods for setting, updating, and clearing the 'CreatedAt' property of the PersonBuilder. Supports direct value assignment or using a function for lazy initialization.
```C#
/// When this instance was created.
public PersonBuilder WithCreatedAt(System.DateTime value)
{
return WithCreatedAt(() => value);
}
/// When this instance was created.
public PersonBuilder WithCreatedAt(System.Func func)
{
CreatedAt = new System.Lazy(func);
return this;
}
/// When this instance was created.
public PersonBuilder WithoutCreatedAt()
{
CreatedAt = new System.Lazy(() => default(System.DateTime));
return this;
}
```
--------------------------------
### PersonBuilder Methods for UpdatedAt
Source: https://github.com/melgrubb/buildergenerator/blob/main/src/BuilderGenerator.Tests.Unit/Verify/When_generating_a_Builder.Test.verified.txt
Methods to manage the UpdatedAt timestamp for a Person object. Allows setting the timestamp directly or through a function, with System.Lazy ensuring the value is computed only when needed.
```C#
public PersonBuilder WithoutUpdatedAt()
{
UpdatedAt = new System.Lazy(() => default(System.DateTime));
return this;
}
```
```C#
public PersonBuilder WithUpdatedAt(System.DateTime value)
{
return WithUpdatedAt(() => value);
}
public PersonBuilder WithUpdatedAt(System.Func func)
{
UpdatedAt = new System.Lazy(func);
return this;
}
```
--------------------------------
### PersonBuilder Methods for UpdatedAt
Source: https://github.com/melgrubb/buildergenerator/blob/main/src/BuilderGenerator.Tests.Unit/Verify/When_generating_a_Builder_sealed.Test.verified.txt
Methods to manage the UpdatedAt timestamp for a Person object. Allows setting the timestamp directly or through a function, with System.Lazy ensuring the value is computed only when needed.
```C#
public PersonBuilder WithoutUpdatedAt()
{
UpdatedAt = new System.Lazy(() => default(System.DateTime));
return this;
}
```
```C#
public PersonBuilder WithUpdatedAt(System.DateTime value)
{
return WithUpdatedAt(() => value);
}
public PersonBuilder WithUpdatedAt(System.Func func)
{
UpdatedAt = new System.Lazy(func);
return this;
}
```
--------------------------------
### PersonBuilder FirstName Property
Source: https://github.com/melgrubb/buildergenerator/blob/main/src/BuilderGenerator.Tests.Unit/Verify/When_generating_a_Builder_with_internal_properties.Test.verified.txt
Methods for setting, updating, and clearing the 'FirstName' property of the PersonBuilder. Supports direct value assignment or using a function for lazy initialization, with detailed remarks on the summary.
```C#
///
/// The Person's first name.
///
/// This was a multi-line, indented summary in the original source code.
public PersonBuilder WithFirstName(string value)
{
return WithFirstName(() => value);
}
///
/// The Person's first name.
///
/// This was a multi-line, indented summary in the original source code.
public PersonBuilder WithFirstName(System.Func func)
{
FirstName = new System.Lazy(func);
return this;
}
///
/// The Person's first name.
///
/// This was a multi-line, indented summary in the original source code.
public PersonBuilder WithoutFirstName()
{
FirstName = new System.Lazy(() => default(string));
return this;
}
```
--------------------------------
### PersonBuilder WithLastName Methods
Source: https://github.com/melgrubb/buildergenerator/blob/main/src/BuilderGenerator.Tests.Unit/Verify/When_generating_a_Builder_with_internal_properties.Test.verified.txt
Provides methods to set the last name property of a PersonBuilder. It includes overloads for setting the value directly or via a function, and a method to unset the value.
```csharp
public PersonBuilder WithLastName(string value)
{
return WithLastName(() => value);
}
public PersonBuilder WithLastName(System.Func func)
{
LastName = new System.Lazy(func);
return this;
}
public PersonBuilder WithoutLastName()
{
LastName = new System.Lazy(() => default(string));
return this;
}
```
--------------------------------
### PersonBuilder Methods for LastName
Source: https://github.com/melgrubb/buildergenerator/blob/main/src/BuilderGenerator.Tests.Unit/Verify/When_generating_a_Builder.Test.verified.txt
Provides methods to set or unset the LastName property of a Person object using System.Lazy for deferred initialization. Includes overloads for direct value assignment and function-based assignment.
```C#
public PersonBuilder WithoutLastName()
{
LastName = new System.Lazy(() => default(string));
return this;
}
```
```C#
public PersonBuilder WithLastName(string value)
{
return WithLastName(() => value);
}
public PersonBuilder WithLastName(System.Func func)
{
LastName = new System.Lazy(func);
return this;
}
```
--------------------------------
### PersonBuilder WithUpdatedBy Methods
Source: https://github.com/melgrubb/buildergenerator/blob/main/src/BuilderGenerator.Tests.Unit/Verify/When_generating_a_Builder_with_internal_properties.Test.verified.txt
Provides methods to set the updated by user property of a PersonBuilder. It includes overloads for setting the value directly or via a function, and a method to unset the value.
```csharp
public PersonBuilder WithUpdatedBy(string value)
{
return WithUpdatedBy(() => value);
}
public PersonBuilder WithUpdatedBy(System.Func func)
{
UpdatedBy = new System.Lazy(func);
return this;
}
public PersonBuilder WithoutUpdatedBy()
{
UpdatedBy = new System.Lazy(() => default(string));
return this;
}
```
--------------------------------
### PersonBuilder Methods for LastName
Source: https://github.com/melgrubb/buildergenerator/blob/main/src/BuilderGenerator.Tests.Unit/Verify/When_generating_a_Builder_sealed.Test.verified.txt
Provides methods to set or unset the LastName property of a Person object using System.Lazy for deferred initialization. Includes overloads for direct value assignment and function-based assignment.
```C#
public PersonBuilder WithoutLastName()
{
LastName = new System.Lazy(() => default(string));
return this;
}
```
```C#
public PersonBuilder WithLastName(string value)
{
return WithLastName(() => value);
}
public PersonBuilder WithLastName(System.Func func)
{
LastName = new System.Lazy(func);
return this;
}
```
--------------------------------
### PersonBuilder WithMiddleName Methods
Source: https://github.com/melgrubb/buildergenerator/blob/main/src/BuilderGenerator.Tests.Unit/Verify/When_generating_a_Builder_with_internal_properties.Test.verified.txt
Provides methods to set the middle name property of a PersonBuilder. It includes overloads for setting the value directly or via a function, and a method to unset the value. This property is marked as obsolete.
```csharp
public PersonBuilder WithMiddleName(string value)
{
return WithMiddleName(() => value);
}
public PersonBuilder WithMiddleName(System.Func func)
{
MiddleName = new System.Lazy(func);
return this;
}
public PersonBuilder WithoutMiddleName()
{
MiddleName = new System.Lazy(() => default(string));
return this;
}
```
--------------------------------
### PersonBuilderWithObsolete: WithoutLastName
Source: https://github.com/melgrubb/buildergenerator/blob/main/src/BuilderGenerator.Tests.Unit/Verify/When_generating_a_Builder_with_obsolete_properties.Test.verified.txt
Resets the LastName property of the PersonBuilderWithObsolete to its default value. This method is part of the builder pattern for creating Person objects.
```csharp
/// The Person's last name.
/// This was a single-line summary in the original source code.
public PersonBuilderWithObsolete WithoutLastName()
{
LastName = new System.Lazy(() => default(string));
return this;
}
```
--------------------------------
### PersonBuilderWithObsolete: WithoutId
Source: https://github.com/melgrubb/buildergenerator/blob/main/src/BuilderGenerator.Tests.Unit/Verify/When_generating_a_Builder_with_obsolete_properties.Test.verified.txt
Resets the Id property of the PersonBuilderWithObsolete to its default value. This method is part of the builder pattern for creating Person objects.
```csharp
public PersonBuilderWithObsolete WithoutId()
{
Id = new System.Lazy(() => default(System.Guid));
return this;
}
```
--------------------------------
### Factory Method: Typical (Derived)
Source: https://github.com/melgrubb/buildergenerator/blob/main/docs/index.md
Shows how to derive a 'Typical' factory method from the 'Simple' method to create a builder with additional fields populated, such as a list of orders.
```csharp
public static UserBuilder Typical()
{
var builder = Simple()
.WithOrders(new List
{
OrderBuilder.Simple().Build()
});
return builder;
}
```
--------------------------------
### PersonBuilderWithObsolete: WithoutUpdatedBy
Source: https://github.com/melgrubb/buildergenerator/blob/main/src/BuilderGenerator.Tests.Unit/Verify/When_generating_a_Builder_with_obsolete_properties.Test.verified.txt
Resets the UpdatedBy property of the PersonBuilderWithObsolete to its default value. This method is part of the builder pattern for creating Person objects.
```csharp
/// Who last updated this instance.
public PersonBuilderWithObsolete WithoutUpdatedBy()
{
UpdatedBy = new System.Lazy(() => default(string));
return this;
}
```
--------------------------------
### Builder Pattern for Object Creation
Source: https://github.com/melgrubb/buildergenerator/blob/main/docs/index.md
Illustrates the use of the Builder pattern to create an object with a fluent interface. This approach allows for concise customization of specific properties and improves test clarity.
```csharp
var user = UserBuilder.Typical()
.WithFirstName("Hiro")
.Build()
var result = SomeMethod(user);
...
```
--------------------------------
### PersonBuilderWithObsolete: WithoutUpdatedAt
Source: https://github.com/melgrubb/buildergenerator/blob/main/src/BuilderGenerator.Tests.Unit/Verify/When_generating_a_Builder_with_obsolete_properties.Test.verified.txt
Resets the UpdatedAt property of the PersonBuilderWithObsolete to its default value. This method is part of the builder pattern for creating Person objects.
```csharp
/// When this instance was last updated.
public PersonBuilderWithObsolete WithoutUpdatedAt()
{
UpdatedAt = new System.Lazy(() => default(System.DateTime));
return this;
}
```
--------------------------------
### Basic Builder Generation with BuilderFor Attribute
Source: https://github.com/melgrubb/buildergenerator/blob/main/README.md
Demonstrates the fundamental usage of BuilderGenerator. A partial class is defined and decorated with the `BuilderFor` attribute, specifying the target type for which a builder should be generated. The generator then creates the necessary builder implementation.
```cs
using BuilderGenerator;
[BuilderFor(typeof(Foo))]
public partial class FooBuilder
{
// Factory and helper methods can be defined here
}
// The generated code will contain the builder implementation for Foo.
```
--------------------------------
### PersonBuilderWithObsolete: WithoutObsoleteString
Source: https://github.com/melgrubb/buildergenerator/blob/main/src/BuilderGenerator.Tests.Unit/Verify/When_generating_a_Builder_with_obsolete_properties.Test.verified.txt
Resets the ObsoleteString property of the PersonBuilderWithObsolete to its default value. This method is part of the builder pattern for creating Person objects and is marked as obsolete.
```csharp
/// A string with internal accessibility to test the "includeInternals" attribute parameter.
/// This was a single-line summary in the original source code.
public PersonBuilderWithObsolete WithoutObsoleteString()
{
ObsoleteString = new System.Lazy(() => default(string));
return this;
}
```
--------------------------------
### Factory Method: Simple
Source: https://github.com/melgrubb/buildergenerator/blob/main/docs/index.md
Demonstrates creating a 'Simple' factory method within the handwritten partial class to generate a builder with minimal required fields populated.
```csharp
namespace MyTests.Builders
{
[BuilderFor(typeof(User))]
public partial class UserBuilder
{
public static UserBuilder Simple()
{
var builder = new UserBuilder()
.WithId(Guid.NewGuid)
.WithFirstName(Guid.NewGuid().ToString());
.WithLastName(Guid.NewGuid().ToString());
return builder;
}
}
}
```
--------------------------------
### PersonBuilder Methods
Source: https://github.com/melgrubb/buildergenerator/blob/main/src/BuilderGenerator.Tests.Unit/Verify/When_generating_a_Builder.Test.verified.txt
This section covers various methods within the PersonBuilder class. These methods allow for setting specific properties of a Person object, such as their ID, name, creation/update timestamps, and the person object itself. It also includes methods for setting a post-build action and populating values from an existing Person object.
```csharp
/// The object to be returned.
/// A reference to this builder instance.
public PersonBuilder WithPerson(BuilderGenerator.Tests.Unit.Examples.Person value)
{
Person = new System.Lazy(() => value);
WithValuesFrom(value);
return this;
}
public PersonBuilder WithPostBuildAction(System.Action action)
{
PostBuildAction = action;
return this;
}
/// Populates this instance with values from the provided example.
/// This is a shallow clone, and does not traverse the example object creating builders for its properties.
public PersonBuilder WithValuesFrom(BuilderGenerator.Tests.Unit.Examples.Person example)
{
WithCreatedAt(example.CreatedAt);
WithCreatedBy(example.CreatedBy);
WithFirstName(example.FirstName);
WithId(example.Id);
WithLastName(example.LastName);
WithMiddleName(example.MiddleName);
WithUpdatedAt(example.UpdatedAt);
WithUpdatedBy(example.UpdatedBy);
return this;
}
/// When this instance was created.
public PersonBuilder WithCreatedAt(System.DateTime value)
{
return WithCreatedAt(() => value);
}
/// When this instance was created.
public PersonBuilder WithCreatedAt(System.Func func)
{
CreatedAt = new System.Lazy(func);
return this;
}
/// When this instance was created.
public PersonBuilder WithoutCreatedAt()
{
CreatedAt = new System.Lazy(() => default(System.DateTime));
return this;
}
/// Who created this instance.
public PersonBuilder WithCreatedBy(string value)
{
return WithCreatedBy(() => value);
}
/// Who created this instance.
public PersonBuilder WithCreatedBy(System.Func func)
{
CreatedBy = new System.Lazy(func);
return this;
}
/// Who created this instance.
public PersonBuilder WithoutCreatedBy()
{
CreatedBy = new System.Lazy(() => default(string));
return this;
}
///
/// The Person's first name.
///
/// This was a multi-line, indented summary in the original source code.
public PersonBuilder WithFirstName(string value)
{
return WithFirstName(() => value);
}
///
/// The Person's first name.
///
/// This was a multi-line, indented summary in the original source code.
public PersonBuilder WithFirstName(System.Func func)
{
FirstName = new System.Lazy(func);
return this;
}
///
/// The Person's first name.
///
/// This was a multi-line, indented summary in the original source code.
public PersonBuilder WithoutFirstName()
{
FirstName = new System.Lazy(() => default(string));
return this;
}
/// Uniquely identifies a instance.
public PersonBuilder WithId(System.Guid value)
{
return WithId(() => value);
}
/// Uniquely identifies a instance.
public PersonBuilder WithId(System.Func func)
{
Id = new System.Lazy(func);
return this;
}
/// Uniquely identifies a instance.
public PersonBuilder WithoutId()
{
Id = new System.Lazy(() => default(System.Guid));
return this;
}
/// The Person's last name.
/// This was a single-line summary in the original source code.
public PersonBuilder WithLastName(string value)
{
return WithLastName(() => value);
}
/// The Person's last name.
/// This was a single-line summary in the original source code.
public PersonBuilder WithLastName(System.Func func)
{
LastName = new System.Lazy(func);
return this;
}
```
--------------------------------
### PersonBuilder Methods
Source: https://github.com/melgrubb/buildergenerator/blob/main/src/BuilderGenerator.Tests.Unit/Verify/When_generating_a_Builder_sealed.Test.verified.txt
This section covers various methods within the PersonBuilder class. These methods allow for setting specific properties of a Person object, such as their ID, name, creation/update timestamps, and the person object itself. It also includes methods for setting a post-build action and populating values from an existing Person object.
```csharp
/// The object to be returned.
/// A reference to this builder instance.
public PersonBuilder WithPerson(BuilderGenerator.Tests.Unit.Examples.Person value)
{
Person = new System.Lazy(() => value);
WithValuesFrom(value);
return this;
}
public PersonBuilder WithPostBuildAction(System.Action action)
{
PostBuildAction = action;
return this;
}
/// Populates this instance with values from the provided example.
/// This is a shallow clone, and does not traverse the example object creating builders for its properties.
public PersonBuilder WithValuesFrom(BuilderGenerator.Tests.Unit.Examples.Person example)
{
WithCreatedAt(example.CreatedAt);
WithCreatedBy(example.CreatedBy);
WithFirstName(example.FirstName);
WithId(example.Id);
WithLastName(example.LastName);
WithMiddleName(example.MiddleName);
WithUpdatedAt(example.UpdatedAt);
WithUpdatedBy(example.UpdatedBy);
return this;
}
/// When this instance was created.
public PersonBuilder WithCreatedAt(System.DateTime value)
{
return WithCreatedAt(() => value);
}
/// When this instance was created.
public PersonBuilder WithCreatedAt(System.Func func)
{
CreatedAt = new System.Lazy(func);
return this;
}
/// When this instance was created.
public PersonBuilder WithoutCreatedAt()
{
CreatedAt = new System.Lazy(() => default(System.DateTime));
return this;
}
/// Who created this instance.
public PersonBuilder WithCreatedBy(string value)
{
return WithCreatedBy(() => value);
}
/// Who created this instance.
public PersonBuilder WithCreatedBy(System.Func func)
{
CreatedBy = new System.Lazy(func);
return this;
}
/// Who created this instance.
public PersonBuilder WithoutCreatedBy()
{
CreatedBy = new System.Lazy(() => default(string));
return this;
}
///
/// The Person's first name.
///
/// This was a multi-line, indented summary in the original source code.
public PersonBuilder WithFirstName(string value)
{
return WithFirstName(() => value);
}
///
/// The Person's first name.
///
/// This was a multi-line, indented summary in the original source code.
public PersonBuilder WithFirstName(System.Func func)
{
FirstName = new System.Lazy(func);
return this;
}
///
/// The Person's first name.
///
/// This was a multi-line, indented summary in the original source code.
public PersonBuilder WithoutFirstName()
{
FirstName = new System.Lazy(() => default(string));
return this;
}
/// Uniquely identifies a instance.
public PersonBuilder WithId(System.Guid value)
{
return WithId(() => value);
}
/// Uniquely identifies a instance.
public PersonBuilder WithId(System.Func func)
{
Id = new System.Lazy(func);
return this;
}
/// Uniquely identifies a instance.
public PersonBuilder WithoutId()
{
Id = new System.Lazy(() => default(System.Guid));
return this;
}
/// The Person's last name.
/// This was a single-line summary in the original source code.
public PersonBuilder WithLastName(string value)
{
return WithLastName(() => value);
}
/// The Person's last name.
/// This was a single-line summary in the original source code.
public PersonBuilder WithLastName(System.Func func)
{
LastName = new System.Lazy(func);
return this;
}
```
--------------------------------
### PersonBuilderWithObsolete Methods
Source: https://github.com/melgrubb/buildergenerator/blob/main/src/BuilderGenerator.Tests.Unit/Verify/When_generating_a_Builder_with_obsolete_properties.Test.verified.txt
This section details the various methods available in the PersonBuilderWithObsolete class. These methods allow for setting individual properties of a Person object, providing functions for lazy initialization, and defining post-build actions.
```C#
/// Sets the object to be returned by this instance.
/// The object to be returned.
/// A reference to this builder instance.
public PersonBuilderWithObsolete WithPerson(BuilderGenerator.Tests.Unit.Examples.Person value)
{
Person = new System.Lazy(() => value);
WithValuesFrom(value);
return this;
}
```
```C#
public PersonBuilderWithObsolete WithPostBuildAction(System.Action action)
{
PostBuildAction = action;
return this;
}
```
```C#
/// Populates this instance with values from the provided example.
/// This is a shallow clone, and does not traverse the example object creating builders for its properties.
public PersonBuilderWithObsolete WithValuesFrom(BuilderGenerator.Tests.Unit.Examples.Person example)
{
WithCreatedAt(example.CreatedAt);
WithCreatedBy(example.CreatedBy);
WithFirstName(example.FirstName);
WithId(example.Id);
WithLastName(example.LastName);
WithMiddleName(example.MiddleName);
WithObsoleteString(example.ObsoleteString);
WithUpdatedAt(example.UpdatedAt);
WithUpdatedBy(example.UpdatedBy);
return this;
}
```
```C#
/// When this instance was created.
public PersonBuilderWithObsolete WithCreatedAt(System.DateTime value)
{
return WithCreatedAt(() => value);
}
/// When this instance was created.
public PersonBuilderWithObsolete WithCreatedAt(System.Func func)
{
CreatedAt = new System.Lazy(func);
return this;
}
/// When this instance was created.
public PersonBuilderWithObsolete WithoutCreatedAt()
{
CreatedAt = new System.Lazy(() => default(System.DateTime));
return this;
}
```
```C#
/// Who created this instance.
public PersonBuilderWithObsolete WithCreatedBy(string value)
{
return WithCreatedBy(() => value);
}
/// Who created this instance.
public PersonBuilderWithObsolete WithCreatedBy(System.Func func)
{
CreatedBy = new System.Lazy(func);
return this;
}
/// Who created this instance.
public PersonBuilderWithObsolete WithoutCreatedBy()
{
CreatedBy = new System.Lazy(() => default(string));
return this;
}
```
```C#
///
/// The Person's first name.
///
/// This was a multi-line, indented summary in the original source code.
public PersonBuilderWithObsolete WithFirstName(string value)
{
return WithFirstName(() => value);
}
///
/// The Person's first name.
///
/// This was a multi-line, indented summary in the original source code.
public PersonBuilderWithObsolete WithFirstName(System.Func func)
{
FirstName = new System.Lazy(func);
return this;
}
///
/// The Person's first name.
///
/// This was a multi-line, indented summary in the original source code.
public PersonBuilderWithObsolete WithoutFirstName()
{
FirstName = new System.Lazy(() => default(string));
return this;
}
```
```C#
/// Uniquely identifies a instance.
public PersonBuilderWithObsolete WithId(System.Guid value)
{
return WithId(() => value);
}
/// Uniquely identifies a instance.
public PersonBuilderWithObsolete WithId(System.Func func)
{
Id = new System.Lazy(func);
return this;
}
/// Uniquely identifies a instance.
```
--------------------------------
### PersonBuilderWithObsolete: WithoutMiddleName
Source: https://github.com/melgrubb/buildergenerator/blob/main/src/BuilderGenerator.Tests.Unit/Verify/When_generating_a_Builder_with_obsolete_properties.Test.verified.txt
Resets the MiddleName property of the PersonBuilderWithObsolete to its default value. This method is part of the builder pattern for creating Person objects and is marked as obsolete.
```csharp
/// A string property marked as obsolete to test the "includeObsolete" attribute parameter.
/// This was a single-line summary in the original source code.
public PersonBuilderWithObsolete WithoutMiddleName()
{
MiddleName = new System.Lazy(() => default(string));
return this;
}
```
--------------------------------
### PersonBuilder CreatedBy Property
Source: https://github.com/melgrubb/buildergenerator/blob/main/src/BuilderGenerator.Tests.Unit/Verify/When_generating_a_Builder_with_internal_properties.Test.verified.txt
Methods for setting, updating, and clearing the 'CreatedBy' property of the PersonBuilder. Supports direct value assignment or using a function for lazy initialization.
```C#
/// Who created this instance.
public PersonBuilder WithCreatedBy(string value)
{
return WithCreatedBy(() => value);
}
/// Who created this instance.
public PersonBuilder WithCreatedBy(System.Func func)
{
CreatedBy = new System.Lazy(func);
return this;
}
/// Who created this instance.
public PersonBuilder WithoutCreatedBy()
{
CreatedBy = new System.Lazy(() => default(string));
return this;
}
```
--------------------------------
### Basic Builder Generation
Source: https://github.com/melgrubb/buildergenerator/blob/main/docs/index.md
Demonstrates how to generate a builder for a given class by creating a partial class decorated with the [BuilderFor] attribute. The BuilderGenerator automatically creates the other half of the builder class.
```csharp
namespace MyTests.Builders
{
[BuilderFor(typeof(User))]
public partial class UserBuilder
{
}
}
```
--------------------------------
### Traditional Object Instantiation
Source: https://github.com/melgrubb/buildergenerator/blob/main/docs/index.md
Demonstrates the traditional way of creating a complex object with multiple properties and nested collections. This method can obscure which properties are relevant to a specific test.
```csharp
var user = new User
{
Id = Guid.NewGuid,
FirstName = "Hiro",
LastName = "Protagonist",
Orders = new List
{
new Order
{
Id = Guid.NewGuid,
Status = OrderStatus.Processing,
OrderDate = DateTime.Today
}
}
}
var result = SomeMethod(user);
...
```