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


C# Operator.IsEquivalent方法代码示例

本文整理汇总了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' -&gt; [END]</c> and the given 
        /// operator is '&lt;=' and the value is 'z' the result range is 'a' -&gt; '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);
                }
            }
        }
开发者ID:kaktusan,项目名称:plsqlparser,代码行数:50,代码来源:SelectableRangeSet.cs

示例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>&lt;&gt;</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);
        }
开发者ID:kaktusan,项目名称:plsqlparser,代码行数:91,代码来源:SelectableRangeSet.cs


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