SetFieldFlagsAttribute [Mapping]

Estrusco edited this page Apr 22, 2016 · 2 revisions
Clone this wiki locally

(from the official guide)

[namespace: Serenity.Data.Mapping] - [assembly: Serenity.Data]

public SetFieldFlagsAttribute(FieldFlags add, FieldFlags remove = FieldFlags.Internal);

This attribute can be used on fields to include or exclude a set of flags. It takes a first required parameter to include flags, and a second optional parameter to exclude flags.

To turn on TrimToEmpty flag on a field, we use it like this:

[SetFieldFlags(FieldFlags.TrimToEmpty)]
public string MyField
{
   get { return Fields.MyField[this];
   set { Fields.MyField[this] = value;
}

To turn off Trim flag:

[SetFieldFlags(FieldFlags.None, FieldFlags.TrimToEmpty)]
public string MyField
{
   get { return Fields.MyField[this];
   set { Fields.MyField[this] = value;
}

To include TrimToEmpty and Updatable but remove Insertable:

[SetFieldFlags(FieldFlags.Updatable | FieldFlags.TrimToEmpty, FieldFlags.Insertable)]
public string MyField
{
   get { return Fields.MyField[this];
   set { Fields.MyField[this] = value;
}

Insertable and Updatable attributes are subclasses of SetFieldFlags attribute.

See also: FieldFlags Enumeration