Getting Started
This page will help you get started with ObjectFiller.NET. You'll be up and running in a jiffy!
First you need to add the ObjectFiller.NET package to your project using NuGet.
- Do that by running the following command in the Package Manager Console:
Install-Package Tynamix.ObjectFiller
Now you can start using ObjectFiller.NET in your application. With Filler<Person>
you define which object you want to create/fill. With the method .Create()
we create a new instance of Person
and fill it with random values.
public class Person
{
public string Name { get; set; }
public string LastName { get; set; }
public int Age { get; set; }
public DateTime Birthday { get; set; }
}
public class HelloFiller
{
public void CreatePerson()
{
Filler<Person> pFiller = new Filler<Person>();
Person p = pFiller.Create();
}
}
It is also possible to fill an already existing instance of an object. In the second example we first create a person and then call Fill(...) instead of Create(). This is great for stuff like DesignViewModels in WPF or whereever you need to fill the object in the constructor with Fill(this)
for example.
public class Person
{
public string Name { get; set; }
public string LastName { get; set; }
public int Age { get; set; }
public DateTime Birthday { get; set; }
}
public class HelloFiller
{
public void FillPerson()
{
Person person = new Person();
Filler<Person> pFiller = new Filler<Person>();
Person p = pFiller.Fill(person);
}
}
In VB.NET a simple example looks like this.
Imports Tynamix.ObjectFiller
Class Person
Property Name() As String
Property Age() As Integer
End Class
Module Module1
Sub Main()
Dim filler = New Filler(Of Person)()
filler.Setup() _
.OnType(Of String).Use(New MnemonicString(2)) _
.OnProperty(Function(x) x.Age).Use(New IntRange(18, 88))
Dim person As Person = filler.Create()
Console.WriteLine(person.Name)
Console.WriteLine(person.Age)
Console.ReadLine()
End Sub
End Module
Updated less than a minute ago