Buildenator
Buildenator copied to clipboard
Sophisticated domain subentities creation methods
The golden sample
the source generator should have possibility to generate as follows: Source:
public class Aggregate
{
public Entity Entity { get; set; }
public IEnumerable<Entity> Entities { get; set; }
}
public class Entity
{
/* */
}
[MakeBuilder(typeof(Aggregate), <NewOption?>)]
[<NewAttribute?>]
public partial class AggregateBuilder
{
}
Output:
public partial class AggregateBuilder
{
private Entity _entity;
public AggregateBuilder WithEntity(Func<EntityBuilder, EntityBuilder> configureEntity)
{
_entity = configureEntity(new EntityBuilder());
return this;
}
private IEnumerable<Entity> _entities;
public AggregateBuilder WithEntities(params Func<EntityBuilder, EntityBuilder>[] configureEntities)
{
_entities = configureEntities.Select(x => x(new EntityBuilder()));
return this;
}
}
Detecting entities to generate methods
Namespace rule
To prevent generating wrongly builders for build-in types, or types from external libraries, the buildenator will detect subentities by the same root namespace of the parent entity.
e.x. this is correct:
NameSpaceRoot.Aggregate
NameSpaceRoot.SubNamespace.Entity
this is not correct:
NameSpaceRoot.Aggregate
SubNamespace.Entity
Filtering out value types
By default if the subentity has only one not sophisticated property/contr. parameter, it will be treated as a value type, so default methods will be created.
Configurability
- UseSubentityBuilders[True/False]: whether using subentity builders [False by default]
- Should have possibility to set up a global config
The problem is with the subentities builders naming, how the aggregateRoot builder generator would know the names to generate? Probably this feature will require to implement #18 first.