Script Generation

Serenity generates client-side artifacts — dynamic scripts, TypeScript typings, and interfaces — from your server-side types. This is driven by a set of attributes you place on rows, forms, columns, and other classes, combined with the type source that discovers them.

This topic covers the attributes that cause scripts and typings to be generated. For how types are discovered in the first place, see Initialization and Startup (the ITypeSource section).

Dynamic Script Attributes

These attributes mark a type so that a dynamic script is generated and registered with the dynamic script manager. They are discovered through the type source and registered automatically by AddDynamicScripts().

[ColumnsScript]

ColumnsScriptAttribute marks a class as a columns script — an array of PropertyItem objects describing the grid columns. It's accessed from the client with Serenity.getColumns("Key").

[ColumnsScript]
public class OrderColumns
{
    [Width(150)]
    public string CustomerID { get; set; }
    // ...
}
  • Without a key, the key is the full name of the type.
  • LocalTextPrefix overrides the automatically calculated local text prefix.

[FormScript]

FormScriptAttribute marks a class as a form script — an array of PropertyItem objects describing the form fields. It's accessed from the client with Serenity.getForm("Key").

[FormScript]
public class OrderForm
{
    [TextAreaEditor(Rows = 3)]
    public string Description { get; set; }
    // ...
}
  • Without a key, the key is the full name of the type.
  • LocalTextPrefix overrides the automatically calculated local text prefix.

[LookupScript]

LookupScriptAttribute marks a row or a custom lookup class as having a lookup script, accessible from the client via getLookup("Key").

[LookupScript]
public sealed class CustomerRow : Row<CustomerRow.RowFields>, IIdRow, INameRow
{
    // ...
}
  • Without a key, the key is auto-determined from the module and type name (e.g. Northwind.Customer).
  • When placed on a row, only the ID and name fields are transferred to the client by default for security/performance; add [LookupInclude] to properties you need on the client.

See Lookups for details.

[DataScript]

DataScriptAttribute marks a type as a remote data script, accessible from the client with Serenity.getRemoteData("Key").

[DataScript("MyData", Permission = "?")]
public class MyDataScript : DataScript<MyData>
{
    // ...
}

Options include Permission ("?" for logged-in users, "*" for everyone), CacheDuration (seconds), and CacheGroupKey.

[DynamicScript]

DynamicScriptAttribute is the abstract base for dynamic script attributes. It provides the Key, CacheDuration, and CacheGroupKey members that the concrete attributes above build on.

Code Generation Attributes

These attributes control what the code generator (sergen / Serenity.Pro.Coder) produces.

[GenerateInterface]

GenerateInterfaceAttribute marks a class so that its accompanying interface is generated by the InterfaceSourceGenerator. This is used in StartSharp to generate handler interfaces (e.g. ILanguageSaveHandler) from handler classes. See Generating Handler Interfaces.

[GenerateInterface]
public class LanguageSaveHandler(IRequestContext context)
    : SaveRequestHandler<MyRow>(context)
{
}
  • RequireFeatures — features added to the generated interface via [RequiresFeature].

[GenerateFields]

GenerateFieldsAttribute marks a row class so that its fields are generated by the RowFieldsGenerator. This lets you write a row with partial properties and have the RowFields class generated for you.

[NonInterfaceMember]

NonInterfaceMemberAttribute excludes a property or method from the automatically generated interface when using [GenerateInterface].

[GenerateInterface]
public class MyHandler : ...
{
    [NonInterfaceMember]
    public void HelperMethod() { }
}

Other Extensibility Attributes

[NestedPermissionKeys]

NestedPermissionKeysAttribute marks a static class that contains permission keys (with optional nested classes). The permission keys are registered and listed by the permission key lister. See Authorization.

[NestedPermissionKeys]
public static class PermissionKeys
{
    public const string Security = "Administration:Security";
}

[NestedLocalTexts]

NestedLocalTextsAttribute marks a static class containing LocalText fields, which are registered as local texts. See Localization.

[EnumKey]

EnumKeyAttribute overrides the prefix used to generate local text keys for an enum. See Localization.

[JsonLocalTextAssets]

JsonLocalTextAssetsAttribute is an assembly-level attribute that registers a folder of JSON local text files packed as static web assets for the assembly.

[assembly: JsonLocalTextAssets("texts")]

[DefaultSectionKey]

DefaultSectionKeyAttribute declares the default configuration section key for an options class. For example, LocalTextPackages uses it to map to the LocalTextPackages section of appsettings.json.

LocalTextPackages

LocalTextPackages is the options class (backed by the LocalTextPackages section of appsettings.json) that controls which local text packages are generated and their include patterns.

See Also