The requested page is not available for the requested platform. You are viewing the content for .NET Framework 4.5.2+ platform.

XPMemberInfo.Converter Property

Gets the value converter.

Namespace: DevExpress.Xpo.Metadata

Assembly: DevExpress.Xpo.v19.1.dll

Declaration

public ValueConverter Converter { get; }
Public ReadOnly Property Converter As ValueConverter
public ValueConverter Converter { get; }
Public ReadOnly Property Converter As ValueConverter

Property Value

Type Description
ValueConverter

A ValueConverter object which represents the value converter.

Property Value

Type Description
ValueConverter

A ValueConverter object which represents the value converter.

Remarks

There are cases when it is necessary to modify property values prior to saving them to a data store (e.g. data protection and data compression). In this case, data prior to being stored in a data store is modified according to an encryption or compression algorithm. When data is retrieved from the data store it's decrypted or decompressed to return it to its original form.

XPO provides a way to perform such conversions by applying the ValueConverterAttribute.

Examples

The following code example demonstrates how to store your boolean data in the database using the "T" string for true and "F" for false by defining a new ValueConverter descendant. You may need this converter when using an existing database in which boolean properties are stored such form.

//...       
[Size(1), ValueConverter(typeof(BooleanToStringValueConverter))]
public bool Answer {
    get { return GetPropertyValue<bool>("Answer"); }
    set { SetPropertyValue<bool>("Answer", value); }
}

//...
public class BooleanToStringValueConverter : ValueConverter {
    public override object ConvertFromStorageType(object value) {
        return Convert.ToString(value) == "T";
    }
    public override object ConvertToStorageType(object value) {
        return Convert.ToBoolean(value) ? "T" : "F";
    }
    public override System.Type StorageType {
        get { return typeof(string); }
    }
}
See Also