The requested page is not available for the requested platform. You are viewing the content for Default platform.

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.v19.1.dll

Declaration

public static string Format(
    string format,
    object obj,
    EmptyEntriesMode mode
)
Public Shared Function Format(
    format As String,
    obj As Object,
    mode As EmptyEntriesMode
) As String

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.

See Also