• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

DomCR / ACadSharp / 17737836230

15 Sep 2025 03:12PM UTC coverage: 2.092% (-76.2%) from 78.245%
17737836230

push

github

web-flow
Merge pull request #790 from DomCR/addflag-refactor

addflag refactor

141 of 9225 branches covered (1.53%)

Branch coverage included in aggregate %.

0 of 93 new or added lines in 10 files covered. (0.0%)

24910 existing lines in 372 files now uncovered.

724 of 32119 relevant lines covered (2.25%)

5.76 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/ACadSharp/CadObjectCollection.cs
1
using CSUtilities.Extensions;
2
using System;
3
using System.Collections;
4
using System.Collections.Generic;
5
using System.Linq;
6

7
namespace ACadSharp
8
{
9
        /// <summary>
10
        /// Collection formed by <see cref="CadObject"/> managed by an owner.
11
        /// </summary>
12
        /// <typeparam name="T"></typeparam>
13
        public class CadObjectCollection<T> : IObservableCadCollection<T>
14
                where T : CadObject
15
        {
16
                /// <inheritdoc/>
17
                public event EventHandler<CollectionChangedEventArgs> OnAdd;
18

19
                /// <inheritdoc/>
20
                public event EventHandler<CollectionChangedEventArgs> OnRemove;
21

22
                /// <summary>
23
                /// Owner of the collection.
24
                /// </summary>
UNCOV
25
                public CadObject Owner { get; }
×
26

27
                /// <summary>
28
                /// Gets the number of elements that are contained in the collection.
29
                /// </summary>
UNCOV
30
                public int Count { get { return this._entries.Count; } }
×
31

32
                public T this[int index]
33
                {
34
                        get
UNCOV
35
                        {
×
UNCOV
36
                                return this._entries.ElementAtOrDefault(index);
×
UNCOV
37
                        }
×
38
                }
39

UNCOV
40
                protected readonly HashSet<T> _entries = new HashSet<T>();
×
41

42
                /// <summary>
43
                /// Default constructor for a <see cref="CadObjectCollection{T}"/> with it's owner assigned.
44
                /// </summary>
45
                /// <param name="owner">Owner of the collection.</param>
UNCOV
46
                public CadObjectCollection(CadObject owner)
×
UNCOV
47
                {
×
UNCOV
48
                        this.Owner = owner;
×
UNCOV
49
                }
×
50

51
                /// <summary>
52
                /// Add a <see cref="CadObject"/> to the collection, this method triggers <see cref="OnAdd"/>.
53
                /// </summary>
54
                /// <param name="item"></param>
55
                /// <exception cref="ArgumentException"></exception>
56
                /// <exception cref="ArgumentNullException"></exception>
57
                public virtual void Add(T item)
UNCOV
58
                {
×
UNCOV
59
                        if (item is null) throw new ArgumentNullException(nameof(item));
×
60

UNCOV
61
                        if (item.Owner != null)
×
UNCOV
62
                                throw new ArgumentException($"Item {item.GetType().FullName} already has an owner", nameof(item));
×
63

UNCOV
64
                        if (this._entries.Contains(item))
×
65
                                throw new ArgumentException($"Item {item.GetType().FullName} is already in the collection", nameof(item));
×
66

UNCOV
67
                        this._entries.Add(item);
×
UNCOV
68
                        item.Owner = this.Owner;
×
69

UNCOV
70
                        OnAdd?.Invoke(this, new CollectionChangedEventArgs(item));
×
UNCOV
71
                }
×
72

73
                /// <summary>
74
                /// Add multiple <see cref="CadObject"/> to the collection, this method triggers <see cref="OnAdd"/>.
75
                /// </summary>
76
                /// <param name="items"></param>
77
                public void AddRange(IEnumerable<T> items)
UNCOV
78
                {
×
UNCOV
79
                        foreach (var item in items)
×
UNCOV
80
                        {
×
UNCOV
81
                                this.Add(item);
×
UNCOV
82
                        }
×
UNCOV
83
                }
×
84

85
                /// <summary>
86
                /// Removes all elements from the Collection.
87
                /// </summary>
88
                public void Clear()
UNCOV
89
                {
×
UNCOV
90
                        Queue<T> q = new(this._entries.ToList());
×
UNCOV
91
                        while (q.TryDequeue(out T entry))
×
UNCOV
92
                        {
×
UNCOV
93
                                this.Remove(entry);
×
UNCOV
94
                        }
×
UNCOV
95
                }
×
96

97
                /// <summary>
98
                /// Removes a <see cref="CadObject"/> from the collection, this method triggers <see cref="OnRemove"/>.
99
                /// </summary>
100
                /// <param name="item"></param>
101
                /// <returns>The removed <see cref="CadObject"/></returns>
102
                public virtual T Remove(T item)
UNCOV
103
                {
×
UNCOV
104
                        if (!this._entries.Remove(item))
×
105
                                return null;
×
106

UNCOV
107
                        item.Owner = null;
×
108

UNCOV
109
                        OnRemove?.Invoke(this, new CollectionChangedEventArgs(item));
×
110

UNCOV
111
                        return item;
×
UNCOV
112
                }
×
113

114
                /// <inheritdoc/>
115
                public IEnumerator<T> GetEnumerator()
UNCOV
116
                {
×
UNCOV
117
                        return this._entries.GetEnumerator();
×
UNCOV
118
                }
×
119

120
                /// <inheritdoc/>
121
                IEnumerator IEnumerable.GetEnumerator()
UNCOV
122
                {
×
UNCOV
123
                        return this._entries.GetEnumerator();
×
UNCOV
124
                }
×
125
        }
126
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc