Advertisement
Guest User

Untitled

a guest
Jan 18th, 2018
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.12 KB | None | 0 0
  1.     [Test]
  2.         public void ParseComplecCriteriaTest() {
  3.             object testObject = new object();
  4.             CriteriaOperator nameCriteria = CriteriaOperator.Parse("Name = 1");
  5.             BinaryOperator operandCriteria = new BinaryOperator("SomeReferenceProperty", testObject);
  6.  
  7.             CriteriaOperator complexCriteria = CriteriaOperator.Or(operandCriteria, nameCriteria);
  8.  
  9.             string complexCriteriaString = complexCriteria.ToString();
  10.  
  11.             bool oldSuppressExceptionsOnParse = XpoObjectInCriteriaProcessingHelper.Tweaks.SuppressExceptionsOnParse;
  12.             XpoObjectInCriteriaProcessingHelper.Tweaks.SuppressExceptionsOnParse = true;
  13.             CriteriaOperator.UserValueParse += CriteriaOperator_UserValueParse;
  14.             CriteriaOperator.UserValueToString += CriteriaOperator_UserValueToString;
  15.             CriteriaOperator parsedComplexCriteria = CriteriaOperator.Parse(complexCriteriaString);
  16.             //Some operations on parsedComplexCriteria
  17.             complexCriteriaString = parsedComplexCriteria.ToString();
  18.             CriteriaOperator.UserValueParse -= CriteriaOperator_UserValueParse;
  19.             CriteriaOperator.UserValueToString -= CriteriaOperator_UserValueToString;
  20.             XpoObjectInCriteriaProcessingHelper.Tweaks.SuppressExceptionsOnParse = oldSuppressExceptionsOnParse;
  21.  
  22.         }
  23.  
  24.         private void CriteriaOperator_UserValueToString(object sender, UserValueProcessingEventArgs e) {
  25.             UserCustomValue userCustomValue = e.Value as UserCustomValue;
  26.             if(userCustomValue != null) {
  27.                 e.Tag = userCustomValue.Tag;
  28.                 e.Data = userCustomValue.Data;
  29.                 e.Handled = true;
  30.             }
  31.         }
  32.  
  33.         private void CriteriaOperator_UserValueParse(object sender, UserValueProcessingEventArgs e) {
  34.             e.Handled = true;
  35.             UserCustomValue userCustomValue = new UserCustomValue() { Tag = e.Tag, Data = e.Data };
  36.             e.Value = userCustomValue;
  37.         }
  38.         class UserCustomValue {
  39.             public string Tag { get; set; }
  40.             public string Data { get; set; }
  41.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement