PrintsCharming / ObjectHydrator

This project allows you to pass custom POCO's to it, and have it return an instance of the class populated with randomly generated data. This random data can be overridden by convention.
Apache License 2.0
39 stars 19 forks source link

Going back to origins. #9

Open mikila85 opened 9 years ago

mikila85 commented 9 years ago

Hi, arriving to you from your original post at: http://stackoverflow.com/questions/1413342/are-there-any-tools-to-populate-class-properties-with-random-data

i tried todo the same thing and to create this project until i found yours, the problem is i still cant find the use of attributes(in class) in order to determine the type of the field.

am i missing it or it got neglected on the way?

p.s. What worked was calling the Name as "EmailAddress" .. but the name is Email .. i tried:

[Attribute("EmailAddress")] public string Email{ get; set; }

[EmailAddress] public string Email{ get; set; }

[Hydrator("EmailAddress")] public string Email{ get; set; }

please help.

mikila85 commented 9 years ago

Ok,

i managed to solve this (if anyone ever needs it) by creating an attribute:

[Hydrator(Kind="email")]
public string ElectronicMail { get; set; }
public class HydratorAttribute : Attribute
{
    public string Kind;
}

and changing the mapping to match:

Add(new Map<string>()
        .Matching(info =>
        {
            HydratorAttribute hydratorType = info.GetCustomAttributes(typeof(HydratorAttribute), false).Cast<HydratorAttribute>().FirstOrDefault();
            return hydratorType != null && hydratorType.Kind == "email";
        })
        .Using(new EmailAddressGenerator()));
PrintsCharming commented 9 years ago

I ended up not doing Attributes just due to the clutter they tend to gather on classes. I opted for configuring it in the Hyrdrator. It was just a personal choice really.