CriteriaOperator.UserValueParse Event
Occurs when restoring a serialized criteria operator that references a user object.
Namespace: DevExpress.Data.Filtering
Assembly: DevExpress.Core.v21.2.dll
NuGet Package: DevExpress.Uwp.Controls
Declaration
Event Data
The UserValueParse event's data class is DevExpress.Data.Filtering.UserValueProcessingEventArgs.
Remarks
The CriteriaOperator.UserValueParse
and CriteriaOperator.UserValueToString events provide the capability to serialize and deserialize criteria containing arbitrary user objects via the CriteriaOperator.ToString and CriteriaOperator.Parse methods.
When the ToString method is called to serialize a criteria operator referencing an object, the UserValueToString event is raised. When the resulting string representation needs to be parsed, the UserValueParse event is raised. Both the events use the same event arguments class exposing three fields. When handing the UserValueToString event, the object Value field holds the object reference to serialize. After converting the reference to a string presentation, assign it to the string Data field and specify an appropriate tag by specifying the string Tag field. The tag should be unique for each particular object kind. When handing the UserValueParse, the Data and Tag field contain previously specified values. Parse them and provide a corresponding object reference by setting the Value field. Since the event arguments class is derived from HandledEventArgs, set the Handled argument to true after handling the UserValueToString and UserValueParse events and specifying other arguments.
The eXpress Persistent Objects (XPO) utilize this functionality to serialize persistent objects to strings. When handling the UserValueParse event, XPO assigns the fully qualified type of a persistent object along with its identifier to the Data field. “XpoObject” is assigned to the Tag field. So, a sample serialized criteria containing a persistent object reference can look like this.
[Owner] = ##XpoObject#FeatureCenter.Module.PropertyEditors.CriteriaReferencedObject(54)#
To enable this functionality in your XPO application, use the Session.ParseCriteria method instead of CriteriaOperator.Parse to restore persistent objects serialized into a string. If you already have code that uses the regular CriteriaOperator.Parse method, you can wrap the method call with Session.CreateParseCriteriaSessionScope.
using(mySession.CreateParseCriteriaSessionScope()) {
//...
CriteriaOperator.Parse("...");
//...
}
In this instance, the existing CriteriaOperator.Parse method will correctly restore persistent objects in the “mySession” session.
The cross-platform data library provides similar functionality for serialization of enumeration types without handling the UserValueParse/UserValueToString events. For enumerations registered via the static EnumProcessingHelper.RegisterEnum method, corresponding criteria values will be serialized in the following way.
[EnumProperty] = ##Enum#FeatureCenter.Module.PropertyEditors.TextAndImageEnum,Normal#
To enable this functionality in your application, you can register all application enumeration types in the following way.
using DevExpress.Data.Filtering;
//...
EnumProcessingHelper.RegisterEnums(AppDomain.CurrentDomain.GetAssemblies());