This project is read-only.

Types of Generators

Sep 13, 2009 at 9:17 PM

Anybody have any ideas for any other generators for this first spike?

Sep 15, 2009 at 1:33 PM

How about if I pass in an enum and it spits back a randomly selected one?

Sep 15, 2009 at 4:42 PM

I'll take a look at it.

It might depend on if I can use Enums in attributes...not sure...I'll try it out tonight.

Sep 15, 2009 at 5:51 PM

I added a simple Enum returns the string value...having some trouble making it return EnumName.VALUE....but I'll keep looking to see what (if anything) I can do.

Sep 15, 2009 at 8:07 PM

I think I figured it out.

    public class EnumGenerator : IEnumGenerator
        public Enum Generate(Random random, Type myenum)
            int totalcount = Enum.GetValues(myenum).Length - 1;
            int itemnum = random.Next(1, totalcount);

            return (Enum)Enum.GetValues(myenum).GetValue(itemnum);

    public class EnumGen:Attribute
        public Type MyEnum { get; set; }
        public EnumGen(Type myEnum)
            MyEnum = myEnum;

/* Fillme.cs */

        if (att is EnumGen)
            EnumGen enumgenatt = (EnumGen)att;
            PropertyInfo propx = instance.GetType().GetProperty(prop.Name, BindingFlags.Public | BindingFlags.Instance); if (null != prop && prop.CanWrite) { prop.SetValue(instance, enumgenerator.Generate(random,enumgenatt.MyEnum), null); }

/*Customer.cs */

        public Days CustomerDay { get; set; }


Sep 15, 2009 at 8:23 PM

Looks good...putting it in now.


Sep 16, 2009 at 4:44 AM

This looks like a very interesting project, thanks for kicking things off.

What about these ideas?

A generator to return a string of specified length or a specified # of words.  The generator method could use a large block of Lorem Ipsum text to retrieve a passed length or # of words.  This could be used in situations where you wnat to illustrate what random Notes or Comments might look like.

A generator to return a randomly selected entry in a generic List.  Say you want to emulate a lookup table, you could pass in a List of KeyValuePair<int, string> that would be chosen against to populate a lookup Id (CustomerTypeId for example).

A generator to return a boolean.  Could be used to populate an IsActive field or other boolean property.

A generator to return a byte array or Version.  I think of this in the context of concurrency control within a database using a timestamp field.

A generator to return a Business Name.  Could be a combination of several businessy names (Acme | Crocket | Spacely | Smith) + (Blocks | Bags | Flocks | Widgets | Sprockets) (Company | Inc. | International | Coop | LLC) so you can end up with Acme Bags Inc. or Spacely Sprockets International.

A generator to return an email address.  This could leverage the FirstName, LastName and my proposal for Business Name along with (.com | .org | .net) to come up with or

A generator to return a URL.  This again could leverage the Business Name to come up with or

A generator to return a Guid.

A generator to return Gender (Male | Female).

A generator to return a Credit Card Type (Amex | Visa | Mastercard | Diners | ...)

A generator to return a valid Credit Card #, maybe for a specified Credit Card Type since they have different rules.

A generator to return a Credit Card CCV value for a specified Credit Card Type.

A generator to return a valid ISO Country Code.

A generator to return a FedEx or UPS tracking code.

A generator to return a random IP Address.  This might have the ability to pass in acceptable ranges or parts such as 192, 168, 1-100, 1-256.


I would be interested in participating if you like some of these ideas.



Sep 16, 2009 at 4:42 PM

Some great ideas in there...I'll turn them into tasks.

There is a boolean one already.

Feel free to submit any one of them.  I think for this stage keep them simple like the existing ones...the reason I'm suggesting that, is because I really want to focus on the core part of the project first...cuz if that's not right, the rest is just an exercise.

I was debating GUID since it can already be easily randomized in the object initialization, but I think there are scenarios where would be helpful.

After I put these in as tasks, I'll be working on implementing the default values.  I was thinking these would be great so I could fake a return of all customers with the last name 'Jones' for instance.

Jul 20, 2010 at 6:15 PM

There should me a mechanism for creating custom generators, maybe by inheriting a class.

Very useful to create dummies. Great job!