Disclaimer: This website requires Please enable JavaScript in your browser settings for the best experience.

HomeDev GuideAPI Reference
Dev GuideAPI ReferenceUser GuideLegal TermsGitHubNuGetDev CommunityOptimizely AcademySubmit a ticketLog In
Dev Guide

MetaField class

Represents the information that an object contains.

A MetaField object represents a meta-class field. Fields represent information that an object contains. Fields are like variables because they can be directly read or set. For example, if you have an object named Car, you can store its color in a field named Color.

📘

Note

When you create and delete meta-enums, remember that you can only modify a meta-model in Design mode. See the MetaClassManager class section.

From the MetaField object, you can get complete information about fields:

  • Name
  • meta-Type
  • Default Value
  • Formula for auto-calculated columns
  • Is Nullable
  • Is ReadOnly
  • Is Primary Key

📘

Note

Business Foundation (BF) uses a meta-field installer assigned to the meta-type to add meta-fields to meta-classes.

Get a meta-field collection

The collection of meta-fields is available from the MetaClass.Fields property and it returns a MetaFieldCollectionobject.

Example: The following example writes all fields to trace

foreach (MetaField field in mc.Fields)
      {
        System.Diagnostics.Trace.WriteLine(field.Name);
      }

Create a meta-field

Call the CreateMetaField method of the MetaClass class, passing name, friendly name, type, is nullable flag, default value and attributes to create a new meta-field. The attributes depend on the meta-type.

Example: Create a new Guid meta-field

public MetaField CreateGuid(string name, string friendlyName, bool isNullable)
    {
    if (name == null)
    throw new ArgumentNullException("name");
    if (friendlyName == null)
    throw new ArgumentNullException("friendlyName");
    AttributeCollection attr = new AttributeCollection();
    string defaultValue = isNullable ? string.Empty : "newid()";
    MetaField retVal = this.MetaClass.CreateMetaField(name, friendlyName, MetaFieldType.Guid, isNullable, defaultValue, attr);
    return retVal;
    }

Delete a meta-field

Call the DeleteMetaField method of the MetaClass class, passing the meta-field object, to delete a field from the meta-class.

Example: Find column by name and drop

// Delete field
    mc. DeleteMetaField(mc.Fields\["Book Title"]);