Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [Test]
- public void ParseComplecCriteriaTest() {
- object testObject = new object();
- CriteriaOperator nameCriteria = CriteriaOperator.Parse("Name = 1");
- BinaryOperator operandCriteria = new BinaryOperator("SomeReferenceProperty", testObject);
- CriteriaOperator complexCriteria = CriteriaOperator.Or(operandCriteria, nameCriteria);
- string complexCriteriaString = complexCriteria.ToString();
- bool oldSuppressExceptionsOnParse = XpoObjectInCriteriaProcessingHelper.Tweaks.SuppressExceptionsOnParse;
- XpoObjectInCriteriaProcessingHelper.Tweaks.SuppressExceptionsOnParse = true;
- CriteriaOperator.UserValueParse += CriteriaOperator_UserValueParse;
- CriteriaOperator.UserValueToString += CriteriaOperator_UserValueToString;
- CriteriaOperator parsedComplexCriteria = CriteriaOperator.Parse(complexCriteriaString);
- //Some operations on parsedComplexCriteria
- complexCriteriaString = parsedComplexCriteria.ToString();
- CriteriaOperator.UserValueParse -= CriteriaOperator_UserValueParse;
- CriteriaOperator.UserValueToString -= CriteriaOperator_UserValueToString;
- XpoObjectInCriteriaProcessingHelper.Tweaks.SuppressExceptionsOnParse = oldSuppressExceptionsOnParse;
- }
- private void CriteriaOperator_UserValueToString(object sender, UserValueProcessingEventArgs e) {
- UserCustomValue userCustomValue = e.Value as UserCustomValue;
- if(userCustomValue != null) {
- e.Tag = userCustomValue.Tag;
- e.Data = userCustomValue.Data;
- e.Handled = true;
- }
- }
- private void CriteriaOperator_UserValueParse(object sender, UserValueProcessingEventArgs e) {
- e.Handled = true;
- UserCustomValue userCustomValue = new UserCustomValue() { Tag = e.Tag, Data = e.Data };
- e.Value = userCustomValue;
- }
- class UserCustomValue {
- public string Tag { get; set; }
- public string Data { get; set; }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement