private object GetValue(FilterContext context, FilterOperand operand, IFilterTarget target)
{
// return the contained value for literal operands.
LiteralOperand literal = operand as LiteralOperand;
if (literal != null)
{
return literal.Value.Value;
}
// must query the filter target for simple attribute operands.
SimpleAttributeOperand simpleAttribute = operand as SimpleAttributeOperand;
if (simpleAttribute != null)
{
return target.GetAttributeValue(
context,
simpleAttribute.TypeDefinitionId,
simpleAttribute.BrowsePath,
simpleAttribute.AttributeId,
simpleAttribute.ParsedIndexRange);
}
// must query the filter target for attribute operands.
AttributeOperand attribute = operand as AttributeOperand;
if (attribute != null)
{
// AttributeOperands only supported in advanced filter targets.
IAdvancedFilterTarget advancedTarget = target as IAdvancedFilterTarget;
if (advancedTarget == null)
{
return false;
}
return advancedTarget.GetRelatedAttributeValue(
context,
attribute.NodeId,
attribute.BrowsePath,
attribute.AttributeId,
attribute.ParsedIndexRange);
}
// recursively evaluate element operands.
ElementOperand element = operand as ElementOperand;
if (element != null)
{
return Evaluate(context, target, (int)element.Index);
}
// oops - Validate() was not called.
throw new ServiceResultException(StatusCodes.BadUnexpectedError, "FilterOperand is not supported.");
}