Custom calculated properties
To make a custom calculated property, you need to inherit from the type Telerik.Sitefinity.Web.Services.Extensibility.CalculatedProperty. This is an abstract class and implements the following mandatory methods:
-
ReturnType
TheReturnTypeparameter specified the actual return type of the property. It can be a collection, an object, or a simple type.
The calculated property has a name value collection of parameters that are used to configure the property.NOTE: When specifying the return type, the type must be either registered in the Types available in the service or must be decorated with a
DataContractattribute. -
GetValues
TheGetValuesmethod requires a developer to return the values for each of the entry in theIEnumerablecollection. This collection holds all of the queried objects that will be returned to the client. You must return a dictionary with a reference to the object as key of that dictionary and a value for that object.
Sitefinity has one OOB CalculatedProperties: MediaUrlCalculatedProperty.
The MediaUrlCalculatedProperty can be configured with the following parameters – absolute and thumbnail. This specifies whether to generate an absolute URL for the property and the type of the thumbnail to return respectively.
The following example is a custom calculated property for getting the provider name of an item:
using System;
using System.Collections;
using System.Collections.Generic;
using Telerik.Sitefinity;
using Telerik.Sitefinity.Data;
using Telerik.Sitefinity.Model;
using Telerik.Sitefinity.Web.Services.Extensibility;
namespace SitefinityWebApp
{
internal class ProviderNameProperty : CalculatedProperty
{
public override Type ReturnType
{
get
{
return typeof(string);
}
}
public override IDictionary<object, object> GetValues(IEnumerable items, IManager manager)
{
var ret = new Dictionary<object, object>();
foreach (IDataItem item in items)
{
ret.Add(item, item.GetProviderName());
}
return ret;
}
}
}