コード例 #1
0
        internal bool AddElement(GraphElement element)
        {
            Ensure.Argument.NotNull(element, nameof(element));

            var owner = element.Owner;

            if (owner != null)
            {
                if (owner == this)
                {
                    return(false);
                }

                throw new InvalidOperationException(
                          "Attempt to add element which belongs to another graph to current graph.");
            }

            bool added = _elements.Add(element);

            Debug.Assert(added);
            element._OnAddedToGraph(this);

            OnElementAdded(element);
            ElementAdded?.Invoke(this, element);

            return(true);
        }
コード例 #2
0
        internal bool RemoveElement(GraphElement element)
        {
            Ensure.Argument.NotNull(element, nameof(element));

            if (element.Owner != this)
            {
                return(false);
            }

            ElementRemoving?.Invoke(this, element);
            OnElementRemoving(element);

            element._OnRemovingFromGraph(this);
            bool removed = _elements.Remove(element);

            Debug.Assert(removed);

            return(true);
        }
コード例 #3
0
 /// <summary>
 ///     Event method for derived classes automatically invoked before any element is removing from current graph.
 ///     Note that the method is invoked after the public event <see cref="ElementRemoving" />.
 /// </summary>
 /// <param name="element">The element about to remove.</param>
 protected virtual void OnElementRemoving(GraphElement element)
 {
 }
コード例 #4
0
 /// <summary>
 ///     Event method for derived classes automatically invoked after any element is added to current graph. Note
 ///     that the method is invoked before the public event <see cref="ElementAdded" />.
 /// </summary>
 /// <param name="element">The newly added element.</param>
 protected virtual void OnElementAdded(GraphElement element)
 {
 }
コード例 #5
0
 /// <summary>
 ///     Get a value indicates whether the specified <see cref="GraphElement" /> is part of current graph.
 /// </summary>
 /// <param name="element">The element instance to test.</param>
 /// <returns>
 ///     <see langword="true" /> if the specified <see cref="GraphElement" /> is part of current graph; otherwise,
 ///     <see langword="false" />.
 /// </returns>
 public bool Contains(GraphElement element)
 {
     return(_elements.Contains(element));
 }