本文整理汇总了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;
}