Field

The field managed element is used when declaring fields (list or web scoped). The base class that is used when declaring a field element is the SPGENField class inside the SPGenensis.Core assembly and namespace.

The syntax is:

[SPGENField(
        ID = "{EC23CA6E-BA90-443F-9F3A-6D54889298F4}", 
        DisplayName = "My field 1", 
        Type = SPFieldType.Text, 
        Group = "SPGenesis demo")]
    public class MyField1 : SPGENField<MyField1, SPFieldText, string>
    {
    }


The first part is the class attribute SPGENFieldAttribute that acts like a declaration of well known and defined properties for the field element. The ID attribute is required because this is used to bind the field with one that is used in lists or web scoped fields in SharePoint, or the ID to be used when the field is provisioned (created).

The class declaration holds the reference in code so the field can be used like a type when it's being referenced in code. All functionality is inherited from the base class SPGENField which exposes the Definition properties etc. All methods are exposed through the singleton instance property named Instance.

Head declaration

...
public class MyField1 : SPGENField<MyField1, SPFieldText, string>
...

Definition property

The Definition property exposed by the SPGENField base class holds the properties for this field definition. All properties that are declared by the SPGENFieldAttribute and in the overrided virtual method InitializeDefinition. There is on more source where properties could be read from and that is if the field is boudn to a XML-definition with the SPGENFeatureAssociationAttribute (more of that later on in this document).

The Definition property is accessed like this:
string fieldDisplayName = MyField1.Definition.DisplayName;

Most common properties

ID
This is the field ID.

InternalName
This is the internal name of the field. If the property is not specified and the field properties does not come from a XML-definition, the class name will be used when provisioning the field etc.

StaticName
Same as InternalName

DisplayName
This is the field display name. If the property is not specified and the field properties does not come from a XML-definition, the class name will be used when provisioning the field etc.

Type
This is the field type specified with the SPFieldType enumeration in the Microsoft.Sharepoint namespace.

Group
This is the field group used in web scoped fields.

Field types

Built-in types
Built-in types are fields that ships with SharePoint foundation 2010. The SPFieldType enumeration in the Microsoft.Sharepoint namespace is the source for specifying one of these field types in the Type property.

To specify a field as a Note field, use this syntax:

[SPGENField(
        ID = "{EC23CA6E-BA90-443F-9F3A-6D54889298F5}", 
        DisplayName = "My note field", 
        Type = SPFieldType.Note, 
        Group = "SPGenesis demo")]
    public class MyNoteField1 : SPGENField<MyNoteField1, SPFieldText, string>
    {
    }


Custom field types
If you want to use a custom field type, use the CustomType property:

[SPGENField(
        ID = "{EC23CA6E-BA90-443F-9F3A-6D54889298F6}", 
        DisplayName = "My custom field type", 
        CustomType = "MyCustomFieldType", 
        Group = "SPGenesis demo")]
    public class MyCustomField1 : SPGENField<MyCustomField1, SPFieldText, string>
    {
    }


Lookup fields
Lookup fields needs to have their source list specified as well ass the source field to show. To do this we use the LookupList property and the LookupField property.

The LookupList property can be specified like this:
The LookupField property accepts these values:
To specify a lookup column using a lookup list with the site relative URL Lists/MyLookupList and the Title column as the field shown for this lookup use:

[SPGENField(
        ID = "{EC23CA6E-BA90-443F-9F3A-6D54889298F7}",
        DisplayName = "My lookup field",
        Type = SPFieldType.Lookup,
        LookupList = "Lists/MyLookupList",
        LookupField = "Title",
        Group = "SPGenesis demo")]
    public class MyLookupField1 : SPGENField<MyLookupField1, SPFieldLookup, SPFieldLookupValue>
    {
    }


If the source list is managed list instance element use:
LookupList = typeof(MyListInstance)

If the source field is managed field element use:
LookupField = typeof(MyField)