Skip to content

Nina is a library for fluent generic construction of objects of any type.

License

Notifications You must be signed in to change notification settings

IseduardoRezende/Nina

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Nina

Nina is a library for fluent generic construction of objects of any type.

Icon

Implementation Example(s):


//Defining the class:
public class Person
{
    public string Name { get; set; }

    public bool Married { get; set; }

    public Person Partner { get; set; }

    public ICollection<Person> Friends { get; set; }

    public ICollection<ICollection<Person>> FriendsOfFriends { get; set; }

    public Gender Gender { get; set; }

    public DateTime BirthDate { get; set; }

    public int Age { get { return DateTime.Now.Year - BirthDate.Year; } }

    private string Secret {  get; set; } 
}

public enum Gender
{
    Male,
    Female
}

/*---------------------------------------------------------------------------- */

//Starting using the SetBuilder<T> class:
var person = new SetBuilder<Person>()
    .WithProperty(p => p.Name, s => "Edu")      //Can handle with any type
    .WithProperty(p => p.Married, m => true)
    .WithProperty(p => p.BirthDate, b => new DateTime(2005, 9, 22))
    .WithProperty(p => p.Partner, p =>
    {
        return new SetBuilder<Person>()
            .WithProperty(p => p.Name, n => "Livia")      
            .WithProperty(p => p.Married, m => true)
            .WithProperty(p => p.Gender, Gender.Female)     //Can pass a value directly  
            .Build();
    })
    .WithProperty(p => p.Friends, bf =>      //Can handle with Collections
    {
        bf.Add(f =>
        {
            return new SetBuilder<Person>()
                .WithProperty(p => p.Name, n => "Guilherme")
                .Build();
        });

        bf.Add(f =>
        {
            return new SetBuilder<Person>()
                .WithProperty(p => p.Name, n => "Alan")
                .WithProperty(p => p.Married, m => true)
                .Build();
        });
    })
    .WithProperty(p => p.FriendsOfFriends, bfof =>      //Can handle with nested Collections   
    {
        bfof.Add(bf =>
        {
            return
            [
                 new SetBuilder<Person>()
                .WithProperty(p => p.Name, n => "João")
                .Build(),

                 new SetBuilder<Person>()
                .WithProperty(p => p.Name, n => "Paulo")
                .Build()
            ];
        });

        bfof.Add(bf =>
        {
            return
            [
                 new SetBuilder<Person>()
                .WithProperty(p => p.Name, n => "Pedro")
                .WithProperty(p => p.Married, m => true)
                .Build()
            ];
        });
    })
    .Build();

About

Nina is a library for fluent generic construction of objects of any type.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages