ValueConverter.ConvertFromStorageType(Object) Method
When overridden in a derived class, converts the value which is stored in a data store to the persistent property’s value.
Namespace: DevExpress.Xpo.Metadata
Assembly: DevExpress.Xpo.v24.1.dll
NuGet Packages: DevExpress.Win.PivotGrid, DevExpress.Win.TreeMap, DevExpress.Xpo
NuGet Package: DevExpress.Xpo
Declaration
Parameters
Name | Type | Description |
---|---|---|
value | Object | An object which represents the value to convert. |
Returns
Type | Description |
---|---|
Object | An object which represents the converted value. |
Example
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>(nameof(Answer)); }
set { SetPropertyValue<bool>(nameof(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); }
}
}