ObjectHydrator icon indicating copy to clipboard operation
ObjectHydrator copied to clipboard

Going back to origins.

Open mikila85 opened this issue 9 years ago • 2 comments

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 avatar Aug 19 '15 13:08 mikila85

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()));

mikila85 avatar Aug 19 '15 14:08 mikila85

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.

PrintsCharming avatar Aug 20 '15 14:08 PrintsCharming