Scripting Example - Humanizer¶
This example demonstrates how to set cell values using an action registered on the Filter
event. It leverages the Humanizer library included with Vinyl. In this example, the script generates a user friendly description of the file size.
Table Schema¶
Column | Data Type | Primary Key | Auto-generate | Nullable |
---|---|---|---|---|
FileId | GUID | Yes | Yes | No |
FileName | NVARCHAR(255) | No | No | No |
FileSize | INTEGER | No | No | Yes |
FileSizeDescription | NVARCHAR(50) | No | No | Yes |
Note that the FileSizeDescription
column does not need to be defined on the table: it can be defined on the business object.
Script¶
#r "Humanizer.dll"
using Humanizer.Bytes;
foreach (EventRow row in Table.Rows)
{
int fileSize = row["FileSize"].GetValueAsInteger();
var byteSize = new ByteSize(fileSize);
row["FileSizeDescription"].Value = byteSize.ToString("#.#");
}