Code Generator Hints and Tips
Payments and Donations
Some of the generated source code is supplied free of charge for personal use, however,
if the source code is to be used in a commercial project we request that you make
a donation to help us to cover the cost of developing and testing the source code
and the cost of providing the online code generator service. You may also make a
donation even if the source code is for personal use. Although we do not expect
you to donate for personal use we would appreciate the gesture.
Blayd Software accept payments and donations in British Pound (GBP), Euro (EUR)
and US Dollar (USD). The price for chargeable source code is displayed under each
currency, to the left of the relevant "Buy Now" button. There is no minimum amount
for donations, we trust you to make an appropriate donation based on the time saved
by generating, rather than developing and testing the code.
For chargeable source code, we guarantee that you will get the source code that
you have paid for. In the unlikely but possible event that the transfer back to
this site from our payment processor fails, we will reactivate the source code generator
transaction so that you can complete the process and generate your source code.
To reactivate a paid for but failed source code generator transaction:
- Direct your browser back to the Blayd Software website
- Follow the "Contact Us" link in the footer of any of the site's pages or go directly
to the Support Section, where you will find the Contact Us links
- Use the "Code Generator Enquiry" link to email your order reference and a brief
description of the problem to us
We will then email a reactivation link to you so that you can complete the generation
process and get your source code.
Copying Your Source Code
Important
The generated source code is displayed in a, read only, text area control on the
generator page. You must copy your source code before navigating away from the page.
Chargeable source code i.e. source code that you have already paid for, is only
generated once, you will not be able to regenerate it and return to the generator
page. You may be able to get back to the generator page for free of charge source
code but you should not rely on it.
Common Generator Properties
Collected Class Name
The Type or Class name of the objects that are to be stored in the collection. For
example, you may have a Customer class for which you are generating a collection
class. In this situation you would specify "Customer" as the Collected Class Name.
You can also specify .Net Framework types for the Collected Class Name property.
For example, to create a collection of String objects you would specify
"String" as the Collected Class Name.
You can also specify a value type for the Collected Class Name property. For example,
to create a collection of integers you would specify "Int32" as the Collected Class
Name property. You can also use language specific values e.g. "int" for CSharp or
"Integer" for Visual Basic.
Important
If you are generating a collection for a value type e.g. "Int32" or a custom struct
(Structure in Visual Basic) you should check the "Allow Null Items" checkbox on
the Collected Class page in the Code Generator Properties Wizard. Although this
may seem counterintuitive, checking this option prevents the generated source code
from testing a collected item for null as it is added to the collection and (this
is the intuitive bit!) checking a value type for null would lead to a compile time
error.
Collection Class Name
The Type or Class name of the collection. The Code Generator Properties Wizard generates
a Collection Class Name based on the value of the Collected Class Name. For example,
if you enter "Customer" for the Collected Class Name property, the wizard will generate
a value of "CustomerCollection" for the Collection Class Name. You can, however,
change the "suggested" Collection Class Name to your preferred value, however, by
convention, collection classes should follow the "<item>Collection" naming
pattern.
Namespace
The collection class namespace (CSharp only). This property is not required when
generating Visual Basic source code as it is assumed that the collection class will
be in the project's default namespace. If this is not the case i.e. the collection
class is in a sub-namespace, an Imports statement will need to be, manually, added
to generated Visual Basic source code.
DictionaryBase Generator Properties
Key Class Name
The Type or Class name of the objects that are to be used as the dictionary keys.
DictionaryBase provides a key/object pair collection. The Key Class Name generator
property specifies the class or type of the key. For example, if the Collected Class
Name is "Customer" which represents the Customer class and the key is "CustomerId"
which represents the CustomerId class, you would specify "CustomerId" as the Key
Class Name. The key can be a reference or a value type, however, it is assumed to
be a reference type and is, therefore, checked for null. If a value type is specified
as the key, the single check for a null key needs to removed from the generated
source code.
NameObjectCollectionBase Generic API Support Generator Properties
Name Member
The name of the collected class string property that represents the collection name
entry for an item. The Name Member property is required to support the
ICollection<T>.Add method, which only takes the collected item as a parameter.
For example, if the Collected Class Name is "Customer" and the Customer class
has a Name property that represents the key used when adding items to the collection
conventionally e.g. collection.Add("Bloggs and Co.", Customer) then you would
specify "Name" as the Name Member. The generated source code for the ICollection<T>.Add
method would then add the item to the collection with code similar to the following:
this.Add(item.Name, item).
Collection<T> Generator Properties
Find Property Name
The name of the collected class property to use when searching the collection. Source
code generated from the Collection<T> base class includes an overloaded
Find method that searches the collection for the specified value of a specified
collected class property. The Find Property Name property represents the name of the collected
class property to use in the search. For example, if the Collected Class Name is "Customer"
and the Customer class has a Name property that is to be used to
search the collection, you would specify "Name" as the Find Property Name. The
Find method would then iterate through the collection checking each item's
Name property value against the value being searched for.
Collection<T> and BindingList<T> Generator Properties
String Comparison
The string comparison to use when searching the collection using the value of a
string property. Source code generated from the Collection<T> and
BindingList<T> base classes provides search and in some cases binary
search and sorting functionality that uses the value of a specified collected class property
when searching and sorting. If the specified search or sort property is typed as String the
String Comparison generator property specifies the StringComparison enumerated
value to use when comparing collected item (String) properties. The required
String Comparison generator property can be selected from a drop down list.
Collection<T> Sort/Search Generator Properties
Default Sort Property
The name of the default sort property. The Collection<T> Sort/Search
generated source provides binary search and sorting functionality and
requires a default sort property to be specified. The Default Sort Property generator
property specifies the collected class property that is to be used as the binary
search property and the default sort property (the sort property can also be specified
by calling code). For example, if the Collected Class Name is "Customer" and the
Customer class has a Name property that is to be the default sort
property, you would specify "Name" as the Default Sort Property.
KeyedCollection<TKey, TItem> Generator Properties
Key Class Name
The Type or Class name of the collection key, this value is used as the generic
constructed type TKey. The value of the Collected Class Name generator property
is used as the generic constructed type TItem. The value specified for Key Class
Name should be the type of the property specified in the Key Property Name generator
property. For example, if the type of the property that is to supply the key is
integer and the property is named Id, you should specify “Int32” as the Key Class
Name and “Id” as the Key Property Name.
Key Property Name
The name of the TItem property that is to supply the key value. Internally, the
KeyedCollection<TKey, TItem> base class calls the abstract
GetKeyForItem method to retrieve the key value as each item is added to or
inserted into the collection. The generated derived class overrides this method and returns the
value of the property specified in the Key Property Name generator property. Therefore, the
type specified for TKey in the Key Class Name generator property must be the same
type as the property specified in the Key Property Name generator property as the TKey
type is generated as the return type of the GetKeyForItem method.
You can change the generated GetKeyForItem method, therefore, you do not have to
return a property value directly you can, for example, calculate the value in some
way, use an arbitrary value or concatenate the value of two properties, however,
the resulting key value must be the same type as TKey specified in the Key Class
Name generator property.
Important
You cannot add a null key to a KeyedCollection<TKkey, TItem>
derived collection, therefore, the protected GetKeyForItem method override should
not return null. The source code generated for a KeyedCollection<TKey, TItem>
derived class assumes that TItem is a reference type and as the collected item cannot
have a null key the collection does not allow null items to be added or inserted.
Both the protected InsertItem and SetItem method overrides check that the item to
be added or inserted is not null. If TItem is a value type,
the check for null in the InsertItem and SetItem
methods should be removed, otherwise the generated source code will not compile.
Encoding and Reserved Key Words
Important
Property values that are entered, rather than selected, in the Code Generator Properties
Wizard are HTML encoded on the server before use. Therefore, we recommend that you
do not use characters such as "&", "#", etc. in property
values such as class names, namespace, etc. We also recommend that you do not use
language specific escaped reserved words, e.g. "@File" in CSharp
or "[File]" in Visual Basic, for property values such as class names,
namespace, etc. Using escaped reserved words is likely to result in generated source
code that will not compile.