Skip to content

Instantly share code, notes, and snippets.

@jeffreyschultz
Last active January 17, 2019 19:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffreyschultz/2133001951d081e7a7e6ecc661752fc2 to your computer and use it in GitHub Desktop.
Save jeffreyschultz/2133001951d081e7a7e6ecc661752fc2 to your computer and use it in GitHub Desktop.
public class Builder<T>
{
public Builder()
{
Controller = new BuilderStep<Controller>(this);
}
public BuilderStep<ListingSearchController> Controller { get; }
public T Build()
{
return default(T);
}
public class BuilderStep<TValueType>
{
public BuilderStep(Builder<T> builder)
{
Builder = builder ?? throw new ArgumentNullException(nameof(builder));
}
public Builder<T> Set(TValueType value)
{
Value = value;
return Builder;
}
protected TValueType Value { get; set; }
protected Builder<T> Builder { get; }
}
}
@jeffreyschultz
Copy link
Author

The BuilderStep class should be extended to add a lambda that will be used to handle the actual assigned, and also accept a boolean that determines whether the value is required or not. This way the builder base classes can be generalized to support assignment and validation of the values without having to use reflection.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment