• 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/CadObject.cs
1
using ACadSharp.Attributes;
2
using ACadSharp.Extensions;
3
using ACadSharp.Objects;
4
using ACadSharp.Objects.Collections;
5
using ACadSharp.Tables;
6
using ACadSharp.Tables.Collections;
7
using ACadSharp.XData;
8
using System;
9
using System.Collections.Generic;
10
using System.Linq;
11

12
namespace ACadSharp
13
{
14
        /// <summary>
15
        /// Represents an element in a CadDocument.
16
        /// </summary>
17
        public abstract class CadObject : IHandledCadObject
18
        {
19
                /// <summary>
20
                /// Document where this element belongs.
21
                /// </summary>
UNCOV
22
                public CadDocument Document { get; private set; }
×
23

24
                /// <summary>
25
                /// Extended data attached to this object.
26
                /// </summary>
UNCOV
27
                public ExtendedDataDictionary ExtendedData { get; private set; }
×
28

29
                /// <inheritdoc/>
30
                /// <remarks>
31
                /// If the value is 0 the object is not assigned to a document or a parent.
32
                /// </remarks>
33
                [DxfCodeValue(5)]
UNCOV
34
                public ulong Handle { get; internal set; }
×
35

36
                /// <summary>
37
                /// Flag that indicates if this object has a dynamic dxf sublcass.
38
                /// </summary>
UNCOV
39
                public virtual bool HasDynamicSubclass { get { return false; } }
×
40

41
                /// <summary>
42
                /// The CAD class name of an object.
43
                /// </summary>
44
                public virtual string ObjectName { get; }
×
45

46
                /// <summary>
47
                /// Get the object type.
48
                /// </summary>
49
                public abstract ObjectType ObjectType { get; }
50

51
                /// <summary>
52
                /// Soft-pointer ID/handle to owner object.
53
                /// </summary>
54
                [DxfCodeValue(DxfReferenceType.Handle, 330)]
UNCOV
55
                public IHandledCadObject Owner { get; internal set; }
×
56

57
                /// <summary>
58
                /// Objects that are attached to this object.
59
                /// </summary>
60
                public IEnumerable<CadObject> Reactors
61
                {
62
                        get
UNCOV
63
                        {
×
UNCOV
64
                                return this._reactors;
×
UNCOV
65
                        }
×
66
                }
67

68
                /// <summary>
69
                /// Object Subclass marker.
70
                /// </summary>
71
                public abstract string SubclassMarker { get; }
72

73
                /// <summary>
74
                /// Extended Dictionary object.
75
                /// </summary>
76
                /// <remarks>
77
                /// An extended dictionary can be created using <see cref="CreateExtendedDictionary"/>.
78
                /// </remarks>
79
                public CadDictionary XDictionary
80
                {
UNCOV
81
                        get { return this._xdictionary; }
×
82
                        internal set
UNCOV
83
                        {
×
UNCOV
84
                                if (value == null)
×
UNCOV
85
                                        return;
×
86

UNCOV
87
                                this._xdictionary = value;
×
UNCOV
88
                                this._xdictionary.Owner = this;
×
89

UNCOV
90
                                if (this.Document != null)
×
UNCOV
91
                                        this.Document.RegisterCollection(this._xdictionary);
×
UNCOV
92
                        }
×
93
                }
94

UNCOV
95
                private List<CadObject> _reactors = new List<CadObject>();
×
96

UNCOV
97
                private CadDictionary _xdictionary = null;
×
98

99
                /// <summary>
100
                /// Default constructor.
101
                /// </summary>
UNCOV
102
                public CadObject()
×
UNCOV
103
                {
×
UNCOV
104
                        this.ExtendedData = new ExtendedDataDictionary(this);
×
UNCOV
105
                }
×
106

107
                /// <summary>
108
                /// Add a reactor object linked to this one.
109
                /// </summary>
110
                /// <remarks>
111
                /// The <see cref="CadObject"/> and its reactors must be in the same <see cref="CadDocument"/> to be valid.
112
                /// </remarks>
113
                /// <param name="reactor"></param>
114
                public void AddReactor(CadObject reactor)
UNCOV
115
                {
×
UNCOV
116
                        this._reactors.Add(reactor);
×
UNCOV
117
                }
×
118

119
                /// <summary>
120
                /// Removes any reactor object that doesn't belong to the same <see cref="CadDocument"/> as this <see cref="CadObject"/>.
121
                /// </summary>
122
                public void CleanReactors()
UNCOV
123
                {
×
UNCOV
124
                        var reactors = this._reactors.ToArray();
×
UNCOV
125
                        foreach (var reactor in reactors)
×
UNCOV
126
                        {
×
UNCOV
127
                                if (reactor.Document != this.Document)
×
UNCOV
128
                                {
×
UNCOV
129
                                        this._reactors.Remove(reactor);
×
UNCOV
130
                                }
×
UNCOV
131
                        }
×
UNCOV
132
                }
×
133

134
                /// <summary>
135
                /// Creates a new object that is a copy of the current instance.
136
                /// </summary>
137
                /// <remarks>
138
                /// The copy will be unattached from the document or any reference.
139
                /// </remarks>
140
                /// <returns>A new object that is a copy of this instance.</returns>
141
                public virtual CadObject Clone()
UNCOV
142
                {
×
UNCOV
143
                        CadObject clone = (CadObject)this.MemberwiseClone();
×
144

UNCOV
145
                        clone.Handle = 0;
×
146

UNCOV
147
                        clone.Document = null;
×
UNCOV
148
                        clone.Owner = null;
×
149

150
                        //Collections
UNCOV
151
                        clone._reactors = new List<CadObject>();
×
UNCOV
152
                        clone.ExtendedData = new ExtendedDataDictionary(clone);
×
UNCOV
153
                        clone.XDictionary = this._xdictionary?.CloneTyped();
×
154

UNCOV
155
                        return clone;
×
UNCOV
156
                }
×
157

158
                /// <summary>
159
                /// Creates the extended dictionary if null.
160
                /// </summary>
161
                /// <returns>The <see cref="CadDictionary"/> attached to this <see cref="CadObject"/></returns>
162
                public CadDictionary CreateExtendedDictionary()
UNCOV
163
                {
×
UNCOV
164
                        if (this._xdictionary == null)
×
UNCOV
165
                        {
×
UNCOV
166
                                this.XDictionary = new CadDictionary();
×
UNCOV
167
                        }
×
168

UNCOV
169
                        return this._xdictionary;
×
UNCOV
170
                }
×
171

172
                /// <summary>
173
                /// Remove a reactor linked to this object.
174
                /// </summary>
175
                /// <param name="reactor"></param>
176
                /// <returns></returns>
177
                public bool RemoveReactor(CadObject reactor)
UNCOV
178
                {
×
UNCOV
179
                        return this._reactors.Remove(reactor);
×
UNCOV
180
                }
×
181

182
                /// <inheritdoc/>
183
                public override string ToString()
UNCOV
184
                {
×
UNCOV
185
                        return $"{this.ObjectName}:{this.Handle}";
×
UNCOV
186
                }
×
187

188
                internal virtual void AssignDocument(CadDocument doc)
UNCOV
189
                {
×
UNCOV
190
                        this.Document = doc;
×
191

UNCOV
192
                        if (this.XDictionary != null)
×
UNCOV
193
                        {
×
UNCOV
194
                                doc.RegisterCollection(this.XDictionary);
×
UNCOV
195
                        }
×
196

UNCOV
197
                        if (this.ExtendedData.Any())
×
UNCOV
198
                        {
×
199
                                //Reset existing collection
UNCOV
200
                                var entries = this.ExtendedData.ToArray();
×
UNCOV
201
                                this.ExtendedData.Clear();
×
202

UNCOV
203
                                foreach (var item in entries)
×
UNCOV
204
                                {
×
UNCOV
205
                                        this.ExtendedData.Add(item.Key, item.Value);
×
UNCOV
206
                                }
×
UNCOV
207
                        }
×
UNCOV
208
                }
×
209

210
                internal virtual void UnassignDocument()
UNCOV
211
                {
×
UNCOV
212
                        if (this.XDictionary != null)
×
UNCOV
213
                        {
×
UNCOV
214
                                this.Document.UnregisterCollection(this.XDictionary);
×
UNCOV
215
                        }
×
216

UNCOV
217
                        this.Handle = 0;
×
UNCOV
218
                        this.Document = null;
×
219

UNCOV
220
                        if (this.ExtendedData.Any())
×
UNCOV
221
                        {
×
222
                                //Reset existing collection
UNCOV
223
                                var entries = this.ExtendedData.ToArray();
×
UNCOV
224
                                this.ExtendedData.Clear();
×
225

UNCOV
226
                                foreach (var item in entries)
×
UNCOV
227
                                {
×
UNCOV
228
                                        this.ExtendedData.Add(item.Key.Clone() as AppId, item.Value);
×
UNCOV
229
                                }
×
UNCOV
230
                        }
×
231

UNCOV
232
                        this._reactors.Clear();
×
UNCOV
233
                }
×
234

235
                protected static T updateCollection<T>(T entry, ICadCollection<T> table)
236
                        where T : CadObject, INamedCadObject
UNCOV
237
                {
×
UNCOV
238
                        if (table == null || entry == null)
×
UNCOV
239
                        {
×
UNCOV
240
                                return entry;
×
241
                        }
242

UNCOV
243
                        return table.TryAdd(entry);
×
UNCOV
244
                }
×
245
        }
246
}
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