Rules

Overview

The Rules collection that governs data generation is highly customizable. You can easily add your own rules, remove rules, replace a Rule with your own version, or even wipe out all the Rules and start over. Consult the source code on GitHub for examples to base your own custom Rules on.

As the collection is public, it is alway possible to output a list of all the currently loaded rules. Each rule displays name, description (if available), type it matches, and property name it matches (if specified). This list is the default for the MultiDataSource. Keep in mind that order does matter as rules are always applied last to first.

Debugging is turned ON by default and writes useful information to the debug Output window in Visual Studio. For each type that is run, the name of each public property, property type, and the name of the Rule that matched it is shown.

Basic Rules Set

This set of Rules is one of the choices for the default MultiGenerator, is deterministic, and covers basic default data types. For instance, for a string type, the "String" rule just returns the name of the property that it is running for with the rownumber appended onto the end. Nullable types act in a similar way, but with 1 in 6 null. The nulls will always be in the same position unless the BaseRandom or the number of elements called is changed.

Name Description If Type Is... If Property Name Is...
String Returns propertyName + RowNumber. System.String Any
Bool Returns alternating true & false. System.Boolean Any
Int Returns RowNumber System.Int32 Any
Long Returns RowNumber System.Int64 Any
Double Returns RowNumber System.Double Any
Decimal Returns RowNumber System.Decimal Any
DateTime Returns BaseDateTime System.DateTime Any
Guid Returns a Guid System.Guid Any
Bool? Returns alternating true & false (1 in 6 NULL) System.Nullable`1[System.Boolean] Any
Int? Returns RowNumber (1 in 6 NULL) System.Nullable`1[System.Int32] Any
Long? Returns RowNumber (1 in 6 NULL) System.Nullable`1[System.Int64] Any
Double? Returns RowNumber (1 in 6 NULL) System.Nullable`1[System.Double] Any
Decimal? Returns RowNumber (1 in 6 NULL) System.Nullable`1[System.Decimal] Any
DateTime? Returns BaseDateTime (1 in 6 NULL) System.Nullable`1[System.DateTime] Any

Common Rules Set

The Common Rules Set loads the Basic Rules Set and then these additional, more specific, rules are loaded after.

Name Description If Type Is... If Propery Name Matches...
String Random string from data or default System.String Any
FirstName Random firstName System.String %firstname%,%givenname%
LastName Random lastname System.String %lastname%,%surname%
User Random username System.String %user%
Address Random address System.String %address%
City Random city System.String %city%
County Random county System.String %county%
State Random state System.String %state%
StateName Random state name System.String %statename%
Country Random country System.String %country%
Zip Random zip System.String %zip%
Fee/Tax Random fee/tax System.Decimal %fee%,%tax%
Cost/Price Random cost/price System.Decimal %cost%,%price%,%worth%
Company/Business Random company/business System.String %company%,%business%,%account%
Product/Item Random product/item System.String %product%,%item%
Email Random email System.String %email%
RowRandomNumber Random number System.Int32 %random%
Phone/Cell/Mobile/Fax Random phone/cell/mobile/fax System.String %phone%,%cell%,%mobile%,%fax%
DateTime Random DateTime base +/- 2yr by hour System.DateTime Any
DateTime? Random DateTime? base +/- 2yr by hour System.Nullable`1[System.DateTime] Any
Text/Note/Lorem Random lorem text paragraph System.String %text%,%note%,%lorem%
RandomBodyCopy Random copy list System.Collections.Generic.IList`1[System.String] %body%,%copy%

Creating Custom Rules

The ability to create new, customized versions of a Rule to create data that fits your requirements, is one of the main strengths of SeedPacket. For more information on the Rule class, consult the Documentation.


© 2018 Will Crowther - SeedPacket