Skip to content

Commit 2779e77

Browse files
committed
Update README.md
1 parent 543266a commit 2779e77

File tree

1 file changed

+44
-4
lines changed

1 file changed

+44
-4
lines changed

README.md

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ The **.NET ObjectFiller** also supports IEnumerable<T> (and all derivations) and
1616
- [Let's use the fluent setup API](#lets-use-the-fluent-setup-api)
1717
- [Ignore Properties](#ignore-properties)
1818
- [Setup Subtypes](#setup-subtypes)
19+
- [Fill objects with IEnumerable](#fill-enumerable)
1920
- [Fill objects with constructor arguments](#fill-objects-with-constructor-arguments)
2021
- [Fill Interface-Properties](#fill-interface-properties)
2122
- [Fill Lists and Dictionaries](#fill-lists-and-dictionaries)
@@ -45,10 +46,11 @@ I will show you some examples how you can work with it.
4546
* ...fill the public writable properties of your objects
4647
* ...fills also all subobjects
4748
* ...has a nice FluentAPI
48-
* ...can handle constructor with parameters
49-
* ...can handle IEnumerable<T> and all derivations
50-
* ...can handle Interfaces
51-
* ...cas handle Dictionaries
49+
* ...handles constructors with parameters
50+
* ...handles IEnumerable<T> and all derivations
51+
* ...handles Interfaces
52+
* ...handles Dictionaries
53+
* ...handles Enumerations
5254
* ...is highly customizable
5355
* ...has many nice plugins
5456
* ...is very easy to extend
@@ -245,6 +247,44 @@ The same method **```.IgnoreIt()```** is also available after you call **```.OnT
245247

246248
With **```SetupFor<T>```** you start a setup for another type. In the example above we define that the ```Name``` of the ```Person``` will be "John" and the ```City``` of an ```Address``` object will be "Dresden". **```SetupFor<T>```** takes an ```bool``` parameter. If this is set to **```true```** then all the settings which were made on the parent type will be set back to default. When a property is not set up, then the filler will take the setup of the parent type, except the settings which are made specially for this actual type.
247249

250+
###Fill objects with the IEnumerable interface
251+
252+
With ObjectFiller.NET you can use the IEnumerable interface to fill objects. Use it for example when you want to fill a property in a specific order with include and exclude and all the other cool stuff which IEnumerable and LINQ supports.
253+
254+
```csharp
255+
public class Person
256+
{
257+
public string Name { get; set; }
258+
public string LastName { get; set; }
259+
public int Age { get; set; }
260+
public DateTime Birthday { get; set; }
261+
262+
public List<Address> Addresses { get; set; }
263+
}
264+
265+
public class Address
266+
{
267+
public int Id { get; set; }
268+
269+
public string Street { get; set; }
270+
}
271+
272+
public class HelloFiller
273+
{
274+
public void FillPerson()
275+
{
276+
Filler<Person> pFiller = new Filler<Person>();
277+
pFiller.Setup()
278+
.SetupFor<Address>()
279+
.OnProperty(x => x.Id).Use(Enumerable.Range(1, 100).Where(x => x % 2 == 0));
280+
281+
Person filledPerson = pFiller.Create();
282+
}
283+
}
284+
```
285+
In this example the ID of an Address item will be an even number between 1 and 100 in ascending order.
286+
This means, the first Address will have the Id 2, the second the Id 4, the fourth Id 6 and so...
287+
248288
###Fill objects with constructor arguments
249289

250290
```csharp

0 commit comments

Comments
 (0)