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

DomCR / ACadSharp / 13518047723

25 Feb 2025 09:35AM UTC coverage: 76.06% (-0.05%) from 76.11%
13518047723

Pull #571

github

web-flow
Merge 8447451e1 into 932a17cd5
Pull Request #571: Issue 570 implement minsert

5457 of 7879 branches covered (69.26%)

Branch coverage included in aggregate %.

64 of 65 new or added lines in 5 files covered. (98.46%)

15 existing lines in 3 files now uncovered.

21535 of 27609 relevant lines covered (78.0%)

75868.06 hits per line

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

98.36
/src/ACadSharp/CadObject.cs
1
using ACadSharp.Attributes;
2
using ACadSharp.Objects;
3
using ACadSharp.Objects.Collections;
4
using ACadSharp.Tables;
5
using ACadSharp.Tables.Collections;
6
using ACadSharp.XData;
7
using System.Collections.Generic;
8
using System.Linq;
9

10
namespace ACadSharp
11
{
12
        /// <summary>
13
        /// Represents an element in a CadDocument
14
        /// </summary>
15
        public abstract class CadObject : IHandledCadObject
16
        {
17
                /// <summary>
18
                /// Document where this element belongs.
19
                /// </summary>
20
                public CadDocument Document { get; private set; }
1,104,476✔
21

22
                /// <summary>
23
                /// Extended data attached to this object.
24
                /// </summary>
25
                public ExtendedDataDictionary ExtendedData { get; }
350,348✔
26

27
                /// <inheritdoc/>
28
                /// <remarks>
29
                /// If the value is 0 the object is not assigned to a document or a parent
30
                /// </remarks>
31
                [DxfCodeValue(5)]
32
                public ulong Handle { get; internal set; }
3,899,056✔
33

34
                /// <summary>
35
                /// Flag that indicates if this object has a dynamic dxf sublcass.
36
                /// </summary>
37
                public virtual bool HasDynamicSubclass { get { return false; } }
156✔
38

39
                /// <summary>
40
                /// The CAD class name of an object
41
                /// </summary>
NEW
42
                public virtual string ObjectName { get; }
×
43

44
                /// <summary>
45
                /// Get the object type
46
                /// </summary>
47
                public abstract ObjectType ObjectType { get; }
48

49
                /// <summary>
50
                /// Soft-pointer ID/handle to owner object
51
                /// </summary>
52
                [DxfCodeValue(DxfReferenceType.Handle, 330)]
53
                public IHandledCadObject Owner { get; internal set; }
754,796✔
54

55
                /// <summary>
56
                /// Objects that are attached to this object.
57
                /// </summary>
58
                /// <remarks>
59
                /// This collection is not managed by ACadSharp, any changes may cause a corruption in the file.
60
                /// </remarks>
61
                public Dictionary<ulong, CadObject> Reactors { get; } = new Dictionary<ulong, CadObject>();
1,565,623✔
62

63
                /// <summary>
64
                /// Object Subclass marker
65
                /// </summary>
66
                public abstract string SubclassMarker { get; }
67

68
                /// <summary>
69
                /// Extended Dictionary object.
70
                /// </summary>
71
                /// <remarks>
72
                /// An extended dictionary can be created using <see cref="CreateExtendedDictionary"/>
73
                /// </remarks>
74
                public CadDictionary XDictionary
75
                {
76
                        get { return this._xdictionary; }
881,259✔
77
                        internal set
78
                        {
32,311✔
79
                                if (value == null)
32,311✔
80
                                        return;
4,522✔
81

82
                                this._xdictionary = value;
27,789✔
83
                                this._xdictionary.Owner = this;
27,789✔
84

85
                                if (this.Document != null)
27,789✔
86
                                        this.Document.RegisterCollection(this._xdictionary);
11,601✔
87
                        }
32,311✔
88
                }
89

90
                private CadDictionary _xdictionary = null;
1,448,722✔
91

92
                /// <summary>
93
                /// Default constructor.
94
                /// </summary>
95
                public CadObject()
1,448,722✔
96
                {
1,448,722✔
97
                        this.ExtendedData = new ExtendedDataDictionary(this);
1,448,722✔
98
                }
1,448,722✔
99

100
                /// <summary>
101
                /// Creates a new object that is a copy of the current instance.
102
                /// </summary>
103
                /// <remarks>
104
                /// The copy will be unattached from the document or any reference.
105
                /// </remarks>
106
                /// <returns>A new object that is a copy of this instance.</returns>
107
                public virtual CadObject Clone()
108
                {
12,967✔
109
                        CadObject clone = (CadObject)this.MemberwiseClone();
12,967✔
110

111
                        clone.Handle = 0;
12,967✔
112

113
                        clone.Document = null;
12,967✔
114
                        clone.Owner = null;
12,967✔
115

116
                        //Collections
117
                        clone.Reactors.Clear();
12,967✔
118
                        clone.XDictionary = new CadDictionary();
12,967✔
119
                        clone.ExtendedData.Clear();
12,967✔
120

121
                        return clone;
12,967✔
122
                }
12,967✔
123

124
                /// <summary>
125
                /// Creates the extended dictionary if null.
126
                /// </summary>
127
                /// <returns>The <see cref="CadDictionary"/> attached to this <see cref="CadObject"/></returns>
128
                public CadDictionary CreateExtendedDictionary()
129
                {
2✔
130
                        if (this._xdictionary == null)
2✔
131
                        {
2✔
132
                                this.XDictionary = new CadDictionary();
2✔
133
                        }
2✔
134

135
                        return this._xdictionary;
2✔
136
                }
2✔
137

138
                /// <inheritdoc/>
139
                public override string ToString()
140
                {
6,230✔
141
                        return $"{this.ObjectName}:{this.Handle}";
6,230✔
142
                }
6,230✔
143

144
                internal virtual void AssignDocument(CadDocument doc)
145
                {
247,011✔
146
                        this.Document = doc;
247,011✔
147

148
                        if (this.XDictionary != null)
247,011✔
149
                        {
1,765✔
150
                                doc.RegisterCollection(this.XDictionary);
1,765✔
151
                        }
1,765✔
152

153
                        if (this.ExtendedData.Any())
247,011✔
154
                        {
650✔
155
                                //Reset existing collection
156
                                var entries = this.ExtendedData.ToArray();
650✔
157
                                this.ExtendedData.Clear();
650✔
158

159
                                foreach (var item in entries)
3,782✔
160
                                {
916✔
161
                                        this.ExtendedData.Add(item.Key, item.Value);
916✔
162
                                }
916✔
163
                        }
650✔
164
                }
247,011✔
165

166
                internal virtual void UnassignDocument()
167
                {
3,013✔
168
                        if (this.XDictionary != null)
3,013✔
169
                                this.Document.UnregisterCollection(this.XDictionary);
214✔
170

171
                        this.Handle = 0;
3,013✔
172
                        this.Document = null;
3,013✔
173

174
                        if (this.ExtendedData.Any())
3,013✔
175
                        {
649✔
176
                                //Reset existing collection
177
                                var entries = this.ExtendedData.ToArray();
649✔
178
                                this.ExtendedData.Clear();
649✔
179

180
                                foreach (var item in entries)
3,777✔
181
                                {
915✔
182
                                        this.ExtendedData.Add(item.Key.Clone() as AppId, item.Value);
915✔
183
                                }
915✔
184
                        }
649✔
185
                }
3,013✔
186

187
                protected T updateCollection<T>(T entry, ObjectDictionaryCollection<T> collection)
188
                        where T : NonGraphicalObject
189
                {
5,205✔
190
                        if (collection == null || entry == null)
5,205!
191
                        {
2,233✔
192
                                return entry;
2,233✔
193
                        }
194

195
                        if (collection.TryGetValue(entry.Name, out T existing))
2,972✔
196
                        {
2,765✔
197
                                return existing;
2,765✔
198
                        }
199
                        else
200
                        {
207✔
201
                                collection.Add(entry);
207✔
202
                                return entry;
207✔
203
                        }
204
                }
5,205✔
205

206
                protected T updateTable<T>(T entry, Table<T> table)
207
                                        where T : TableEntry
208
                {
484,237✔
209
                        if (table == null)
484,237✔
210
                        {
157✔
211
                                return entry;
157✔
212
                        }
213

214
                        if (table.TryGetValue(entry.Name, out T existing))
484,080✔
215
                        {
483,711✔
216
                                return existing;
483,711✔
217
                        }
218
                        else
219
                        {
369✔
220
                                table.Add(entry);
369✔
221
                                return entry;
369✔
222
                        }
223
                }
484,237✔
224
        }
225
}
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

© 2026 Coveralls, Inc