本文整理汇总了C#中Operator.IsEquivalent方法的典型用法代码示例。如果您正苦于以下问题:C# Operator.IsEquivalent方法的具体用法?C# Operator.IsEquivalent怎么用?C# Operator.IsEquivalent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Operator
的用法示例。
在下文中一共展示了Operator.IsEquivalent方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Intersect
/// <summary>
/// Intersects this range with the given Operator and value constant.
/// </summary>
/// <example>
/// For example, if a range is <c>'a' -> [END]</c> and the given
/// operator is '<=' and the value is 'z' the result range is 'a' -> 'z'.
/// </example>
public void Intersect(Operator op, DataObject val)
{
lock (this) {
int sz = rangeSet.Count;
List<SelectableRange> i = rangeSet.GetRange(0, sz);
if (op.IsEquivalent(Operator.NotEqual) ||
op.IsEquivalent(Operator.IsNot)) {
bool nullCheck = op.IsEquivalent(Operator.NotEqual);
int j = 0;
while (j < sz) {
SelectableRange range = i[j];
SelectableRange leftRange = IntersectRange(range, Operator.Smaller, val, nullCheck);
SelectableRange rightRange = IntersectRange(range, Operator.Greater, val, nullCheck);
i.RemoveAt(j);
if (leftRange != null) {
i.Add(leftRange);
}
if (rightRange != null) {
i.Add(rightRange);
}
j++;
}
rangeSet = new List<SelectableRange>(i);
} else {
bool nullCheck = !op.IsEquivalent(Operator.Is);
int j = 0;
while (j < sz) {
SelectableRange range = i[j];
range = IntersectRange(range, op, val, nullCheck);
if (range == null) {
i.RemoveAt(j);
} else {
i[j] = range;
}
j++;
}
rangeSet = new List<SelectableRange>(i);
}
}
}
示例2: IntersectRange
/// <summary>
/// Intersects the given SelectableRange object with the given operator and
/// value constraint.
/// </summary>
/// <remarks>
/// <b>Note</b>: This does not work with the <c><></c> operator
/// which must be handled another way.
/// </remarks>
private static SelectableRange IntersectRange(SelectableRange range, Operator op, DataObject val, bool nullCheck)
{
DataObject start = range.Start;
RangePosition startPosition = range.StartPosition;
DataObject end = range.End;
RangePosition endPosition = range.EndPosition;
bool inclusive = op.IsEquivalent(Operator.Is) ||
op.IsEquivalent(Operator.Equal) ||
op.IsEquivalent(Operator.GreaterOrEqual) ||
op.IsEquivalent(Operator.SmallerOrEqual);
if (op.IsEquivalent(Operator.Is) ||
op.IsEquivalent(Operator.Equal) ||
op.IsEquivalent(Operator.Greater) ||
op.IsEquivalent(Operator.GreaterOrEqual)) {
// With this operator, NULL values must return null.
if (nullCheck && val.IsNull) {
return null;
}
if (start == SelectableRange.FirstInSet) {
start = val;
startPosition = inclusive
? RangePosition.FirstValue
: RangePosition.AfterLastValue;
} else {
int c = val.CompareTo(start);
if ((c == 0 && startPosition == RangePosition.FirstValue) || c > 0) {
start = val;
startPosition = inclusive
? RangePosition.FirstValue
: RangePosition.AfterLastValue;
}
}
}
if (op.IsEquivalent(Operator.Is) ||
op.IsEquivalent(Operator.Equal) ||
op.IsEquivalent(Operator.Smaller) ||
op.IsEquivalent(Operator.SmallerOrEqual)) {
// With this operator, NULL values must return null.
if (nullCheck && val.IsNull) {
return null;
}
// If start is first in set, then we have to change it to after NULL
if (nullCheck && start == SelectableRange.FirstInSet) {
start = DataObject.Null;
startPosition = RangePosition.AfterLastValue;
}
if (end == SelectableRange.LastInSet) {
end = val;
endPosition = inclusive
? RangePosition.LastValue
: RangePosition.BeforeFirstValue;
} else {
int c = val.CompareTo(end);
if ((c == 0 && endPosition == RangePosition.LastValue) || c < 0) {
end = val;
endPosition = inclusive
? RangePosition.LastValue
: RangePosition.BeforeFirstValue;
}
}
}
// If start and end are not null types (if either are, then it means it
// is a placeholder value meaning start or end of set).
if (start != SelectableRange.FirstInSet &&
end != SelectableRange.LastInSet) {
// If start is higher than end, return null
int c = start.CompareTo(end);
if ((c == 0 && (startPosition == RangePosition.AfterLastValue ||
endPosition == RangePosition.BeforeFirstValue)) ||
c > 0) {
return null;
}
}
// The new intersected range
return new SelectableRange(startPosition, start, endPosition, end);
}