/// <summary> /// Configures the builder to set a property with the informed value. /// </summary> public FluentBuilder <T> With <TProperty>(Expression <Func <T, TProperty> > expression, TProperty newValue) { var propertyName = GetMemberQuery.GetMemberNameFor(expression); _commands[propertyName] = new SetPropertyCommand(_newObject, propertyName, newValue); return(this); }
/// <summary> /// Configures the builder to add an element to a collection one by one. /// </summary> public FluentBuilder <T> AddingTo <TCollectionProperty, TElement>(Expression <Func <T, TCollectionProperty> > expression, TElement newElement) where TCollectionProperty : IEnumerable <TElement> { var fieldName = GetMemberQuery.GetMemberNameFor(expression); var setFieldCollectionCommand = GetCommandFor(fieldName); setFieldCollectionCommand.Add(newElement); return(this); }
/// <summary> /// Configures the builder to set a collection passing all elements at once /// </summary> public FluentBuilder <T> WithCollection <TCollectionProperty, TElement>(Expression <Func <T, TCollectionProperty> > expression, params TElement[] newElements) where TCollectionProperty : IEnumerable <TElement> { var fieldName = GetMemberQuery.GetMemberNameFor(expression); var cmd = new SetFieldCollectionCommand(_newObject, fieldName); foreach (var element in newElements) { cmd.Add(element); } _commands[fieldName] = cmd; return(this); }
public void Should_get_property_name_for_expression() { var propertyName = GetMemberQuery.GetMemberNameFor <SampleTypeWithFieldAndProperties, int>(sampleType => sampleType.ReadOnlyPropertyWithUnderLyingField); Assert.AreEqual("ReadOnlyPropertyWithUnderLyingField", propertyName); }