当前位置: 首页>>代码示例>>C#>>正文


C# Condition.GetXPath方法代码示例

本文整理汇总了C#中System.Condition.GetXPath方法的典型用法代码示例。如果您正苦于以下问题:C# Condition.GetXPath方法的具体用法?C# Condition.GetXPath怎么用?C# Condition.GetXPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Condition的用法示例。


在下文中一共展示了Condition.GetXPath方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: EvaluateCondition

        /// <summary>
        /// Evaluates a single SIF_Condition against an object and returns whether it matches or not
        /// </summary>
        /// <param name="cond"></param>
        /// <param name="context"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        /// <exception cref="OpenADK.Library.AdkSchemaException">If the condition contains references to invalid elements</exception>
        private bool EvaluateCondition(SifXPathContext context,
                                        Condition cond,
                                        CultureInfo culture)
        {
            // TODO: Add support for comparison using the SIF Data Types
            Element def = context.GetElementOrAttribute(cond.GetXPath());
            String conditionValue = cond.Value;

            String elementValue = null;
            if (def != null)
            {
                SifSimpleType value = def.SifValue;
                if (value != null)
                {
                    // Format the value to string, based on the query version
                    elementValue = value.ToString(EffectiveVersion);
                }
                else
                {
                    // TODO: Not sure if this would ever return a value if the above does not
                    elementValue = def.TextValue;
                }
            }

            if (elementValue == null || conditionValue == null)
            {
                // Don't use standard comparision because it will fail. If
                // one or the other value is null, it cannot be compared, except for
                // if the operator is EQ or NOT
                bool bothAreNull = (elementValue == null && conditionValue == null);
                switch (cond.Operators)
                {
                    case ComparisonOperators.EQ:
                    case ComparisonOperators.GE:
                    case ComparisonOperators.LE:
                        return bothAreNull;
                    case ComparisonOperators.NE:
                        return !bothAreNull;
                    default:
                        // For any other operator, the results are indeterminate with
                        // null values. Return false in this case.
                        return false;
                }
            }

            int compareLevel = String.Compare(elementValue, conditionValue, false, culture);

            switch (cond.Operators)
            {
                case ComparisonOperators.EQ:
                    return compareLevel == 0;
                case ComparisonOperators.NE:
                    return compareLevel != 0;
                case ComparisonOperators.GT:
                    return compareLevel > 0;
                case ComparisonOperators.LT:
                    return compareLevel < 0;
                case ComparisonOperators.GE:
                    return compareLevel >= 0;
                case ComparisonOperators.LE:
                    return compareLevel <= 0;
            }
            return false;
        }
开发者ID:rafidzal,项目名称:OpenADK-csharp,代码行数:72,代码来源:Query.cs


注:本文中的System.Condition.GetXPath方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。