Ticket Q539396
Visible to All Users

CriteriaOperator - How to get list of parameters and their values

created 11 years ago

Hi,

I tried to get list of parameters from CriteriaOperator with their values and I couldn't do that.I read documentation and I could generate string representation of this operator but I want to get parameter <=> value pairs.Do you have some ideas?
Regards

Answers approved by DevExpress Support

created 11 years ago (modified 8 years ago)

Hi Jacek.
Please use the static CriteriaOperator.ToString(CriteriaOperator,OperandValue[]) method to accomplish this task. The criteriaParametersList output argument will return a list of all OperandValue (including OperandParameter) instances in the criterion.

UPDATED:
If your criteria doesn't use parameters, but is composed of operators that compare property values with constants, you can write a hierarchy walker or visitor. For example, to extract name-value pars from a group of binary operators, the following code can be used:

C#
static Dictionary<string, object> Extract(CriteriaOperator op) { Dictionary<string, object> dict = new Dictionary<string, object>(); GroupOperator opGroup = op as GroupOperator; if (ReferenceEquals(opGroup, null)) { ExtractOne(dict, op); } else { if (opGroup.OperatorType == GroupOperatorType.And) { foreach (var opn in opGroup.Operands) { ExtractOne(dict, opn); } } } return dict; } private static void ExtractOne(Dictionary<string, object> dict, CriteriaOperator op) { BinaryOperator opBinary = op as BinaryOperator; if (ReferenceEquals(opBinary, null)) return; OperandProperty opProperty = opBinary.LeftOperand as OperandProperty; OperandValue opValue = opBinary.RightOperand as OperandValue; if (ReferenceEquals(opProperty, null) || ReferenceEquals(opValue, null)) return; dict.Add(opProperty.PropertyName, opValue.Value); }
    Show previous comments (7)
    DevExpress Support Team 11 years ago

      It is possible to write a hierarchy walker or visitor, but only for a specific subset of criteria operators. For example:

      C#
      static Dictionary<string, object> Extract(CriteriaOperator op) { Dictionary<string, object> dict = new Dictionary<string, object>(); GroupOperator opGroup = op as GroupOperator; if (ReferenceEquals(opGroup, null)) { ExtractOne(dict, op); } else { if (opGroup.OperatorType == GroupOperatorType.And) { foreach (var opn in opGroup.Operands) { ExtractOne(dict, opn); } } } return dict; } private static void ExtractOne(Dictionary<string, object> dict, CriteriaOperator op) { BinaryOperator opBinary = op as BinaryOperator; if (ReferenceEquals(opBinary, null)) return; OperandProperty opProperty = opBinary.LeftOperand as OperandProperty; OperandValue opValue = opBinary.RightOperand as OperandValue; if (ReferenceEquals(opProperty, null) || ReferenceEquals(opValue, null)) return; dict.Add(opProperty.PropertyName, opValue.Value); }
      AS AS
      Adrian Szerlowski 2592 11 years ago

        In this way I can retrieve data from CriteriaOperator.
        Thank you for your help.

        DevExpress Support Team 11 years ago

          You are welcome.Let me know if you need any additional assistance.

          Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

          Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.