Ejemplo n.º 1
0
        /// <summary>
        /// Tries to mark an object. Returns false if the object is already in the cycle detector,
        /// ie, it has already been encountered (which implies that it's part of a cycle).
        /// </summary>
        public bool TryMark(object obj)
        {
            if (obj == null)
            {
                return(true);
            }
            if (obj.GetType().IsPrimitive)
            {
                return(true);
            }
            if (obj.GetType().IsValueType)
            {
                return(true);
            }

            if (_objects.IsEmpty)
            {
                _objects = fiOption.Just(Factory.GetInstance());
            }

            if (IsCycle(obj))
            {
                return(false);
            }

            _objects.Value.Add(obj);
            return(true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Decrease the recursion / nesting depth.
        /// </summary>
        public void Exit()
        {
            if (_depth == 0)
            {
                throw new InvalidOperationException("Mismatched Enter/Exit");
            }

            --_depth;
            if (_depth == 0 && _objects.HasValue)
            {
                Factory.ReuseInstance(_objects.Value);
                _objects = fiOption <HashSet <object> > .Empty;
            }
        }
Ejemplo n.º 3
0
 public fiCycleDetector(params fiCycleDetector[] parents)
 {
     _parents = parents;
     _objects = fiOption <HashSet <object> > .Empty;
 }