Skip to main content
A newer version of this page is available. .

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.v18.2.dll

Declaration

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

Parameters

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.

Returns

Type Description
String

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

Remarks

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;

//...

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

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

    public string LastName {
        get { return GetPropertyValue<string>("LastName"); }
        set { SetPropertyValue<string>("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.

ObjectFormatter

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

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the Format(String, Object, EmptyEntriesMode) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also