.NET Framework 4.5.2+
.NET Framework 4.5.2+
.NET Standard 2.0+
.NET Core 3.0+

ObjectFormatter.Format(String, Object, EmptyEntriesMode) Method

Replaces format items in the specified string with the values of the specified object’s properties. Allows you to specify the EmptyEntriesMode mode of processing the passed string.

Namespace: DevExpress.Persistent.Base

Assembly: DevExpress.ExpressApp.v21.1.dll


public static string Format(
    string format,
    object obj,
    EmptyEntriesMode mode


Name Type Description
format String

A string that contains zero or more format items.

obj Object

An object whose property values are used in the formatting of the passed string.

mode EmptyEntriesMode

An EmptyEntriesMode enumeration value that specifies the mode of processing the passed string.


Type Description

A string in which the format items have been replaced by the string representations of the specified object’s property values.


The Format method treats all the format items in the passed string as the property names of the passed object. It replaces all the format items in the passed string with the corresponding property values of the passed object.

This method can be used to create calculated properties in persistent classes. The following code snippet illustrates how to define the non-persistent read-only FullName property. This property’s value is calculated from the FirstName and LastName properties using the Format method.

using DevExpress.Xpo;
using DevExpress.Persistent.Base;
using DevExpress.Persistent.BaseImpl;


public class Contact : BaseObject {
    public Contact(Session session) : base(session) { }

    public string FirstName {
        get { return GetPropertyValue<string>(nameof(FirstName)); }
        set { SetPropertyValue<string>(nameof(FirstName), value); }

    public string LastName {
        get { return GetPropertyValue<string>(nameof(LastName)); }
        set { SetPropertyValue<string>(nameof(LastName), value); }

    public string FullName {
        get {
            return ObjectFormatter.Format(
                "{LastName}, {FirstName}", this,
                EmptyEntriesMode.RemoveDelimiterWhenEntryIsEmpty );

The following image illustrates a Detail View for the implemented Contact class.


If custom processing of the strings passed to the Format method is required, handle the ObjectFormatter.CustomFormatObject event.

See Also