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

DomCR / ACadSharp / 12619114630

05 Jan 2025 11:27AM UTC coverage: 75.645% (+0.6%) from 75.001%
12619114630

Pull #490

github

web-flow
Merge 01b5ca4aa into 0d0db0394
Pull Request #490: Issue 474 header defaults

5217 of 7612 branches covered (68.54%)

Branch coverage included in aggregate %.

129 of 157 new or added lines in 5 files covered. (82.17%)

581 existing lines in 13 files now uncovered.

20882 of 26890 relevant lines covered (77.66%)

39172.96 hits per line

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

97.87
/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;
8
using ACadSharp.XData;
9
using System.Collections.Generic;
10

11
namespace ACadSharp
12
{
13
        /// <summary>
14
        /// Represents an element in a CadDocument
15
        /// </summary>
16
        public abstract class CadObject : IHandledCadObject
17
        {
18
                /// <summary>
19
                /// Get the object type
20
                /// </summary>
21
                public abstract ObjectType ObjectType { get; }
22

23
                /// <summary>
24
                /// The CAD class name of an object
25
                /// </summary>
UNCOV
26
                public virtual string ObjectName { get; }
×
27

28
                /// <summary>
29
                /// Object Subclass marker
30
                /// </summary>
31
                public abstract string SubclassMarker { get; }
32

33
                /// <inheritdoc/>
34
                /// <remarks>
35
                /// If the value is 0 the object is not assigned to a document or a parent
36
                /// </remarks>
37
                [DxfCodeValue(5)]
38
                public ulong Handle { get; internal set; }
1,973,661✔
39

40
                /// <summary>
41
                /// Soft-pointer ID/handle to owner object
42
                /// </summary>
43
                [DxfCodeValue(DxfReferenceType.Handle, 330)]
44
                public IHandledCadObject Owner { get; internal set; }
442,146✔
45

46
                /// <summary>
47
                /// Extended Dictionary object.
48
                /// </summary>
49
                /// <remarks>
50
                /// An extended dictionary can be created using <see cref="CreateExtendedDictionary"/>
51
                /// </remarks>
52
                public CadDictionary XDictionary
53
                {
54
                        get { return this._xdictionary; }
576,291✔
55
                        internal set
56
                        {
18,870✔
57
                                if (value == null)
18,870✔
58
                                        return;
2,794✔
59

60
                                this._xdictionary = value;
16,076✔
61
                                this._xdictionary.Owner = this;
16,076✔
62

63
                                if (this.Document != null)
16,076✔
64
                                        this.Document.RegisterCollection(this._xdictionary);
5,826✔
65
                        }
18,870✔
66
                }
67

68
                /// <summary>
69
                /// Objects that are attached to this object
70
                /// </summary>
71
                public Dictionary<ulong, CadObject> Reactors { get; } = new Dictionary<ulong, CadObject>();
736,909✔
72

73
                /// <summary>
74
                /// Extended data attached to this object
75
                /// </summary>
76
                public ExtendedDataDictionary ExtendedData { get; }
42,889✔
77

78
                /// <summary>
79
                /// Document where this element belongs
80
                /// </summary>
81
                public CadDocument Document
82
                {
83
                        get;
474,842✔
84
                        private set;
167,754✔
85
                }
86

87
                private CadDictionary _xdictionary = null;
665,620✔
88

89
                /// <summary>
90
                /// Default constructor.
91
                /// </summary>
92
                public CadObject()
665,620✔
93
                {
665,620✔
94
                        this.ExtendedData = new ExtendedDataDictionary(this);
665,620✔
95
                }
665,620✔
96

97
                /// <summary>
98
                /// Creates the extended dictionary if null.
99
                /// </summary>
100
                /// <returns>The <see cref="CadDictionary"/> attached to this <see cref="CadObject"/></returns>
101
                public CadDictionary CreateExtendedDictionary()
102
                {
2✔
103
                        if (this._xdictionary == null)
2✔
104
                        {
2✔
105
                                this.XDictionary = new CadDictionary();
2✔
106
                        }
2✔
107

108
                        return this._xdictionary;
2✔
109
                }
2✔
110

111
                /// <summary>
112
                /// Creates a new object that is a copy of the current instance.
113
                /// </summary>
114
                /// <remarks>
115
                /// The copy will be unattached from the document or any reference.
116
                /// </remarks>
117
                /// <returns>A new object that is a copy of this instance.</returns>
118
                public virtual CadObject Clone()
119
                {
7,977✔
120
                        CadObject clone = (CadObject)this.MemberwiseClone();
7,977✔
121

122
                        clone.Handle = 0;
7,977✔
123

124
                        clone.Document = null;
7,977✔
125
                        clone.Owner = null;
7,977✔
126

127
                        //Collections
128
                        clone.Reactors.Clear();
7,977✔
129
                        clone.XDictionary = new CadDictionary();
7,977✔
130
                        clone.ExtendedData.Clear();
7,977✔
131

132
                        return clone;
7,977✔
133
                }
7,977✔
134

135
                /// <inheritdoc/>
136
                public override string ToString()
137
                {
5,339✔
138
                        return $"{this.ObjectName}:{this.Handle}";
5,339✔
139
                }
5,339✔
140

141
                internal virtual void AssignDocument(CadDocument doc)
142
                {
157,869✔
143
                        this.Document = doc;
157,869✔
144

145
                        if (this.XDictionary != null)
157,869✔
146
                                doc.RegisterCollection(this.XDictionary);
849✔
147
                }
157,869✔
148

149
                internal virtual void UnassignDocument()
150
                {
1,908✔
151
                        if (this.XDictionary != null)
1,908✔
152
                                this.Document.UnregisterCollection(this.XDictionary);
134✔
153

154
                        this.Handle = 0;
1,908✔
155
                        this.Document = null;
1,908✔
156
                }
1,908✔
157

158
                protected T updateTable<T>(T entry, Table<T> table)
159
                        where T : TableEntry
160
                {
325,051✔
161
                        if (table == null)
325,051✔
162
                        {
143✔
163
                                return entry;
143✔
164
                        }
165

166
                        if (table.TryGetValue(entry.Name, out T existing))
324,908✔
167
                        {
324,601✔
168
                                return existing;
324,601✔
169
                        }
170
                        else
171
                        {
307✔
172
                                table.Add(entry);
307✔
173
                                return entry;
307✔
174
                        }
175
                }
325,051✔
176

177
                protected T updateCollection<T>(T entry, ObjectDictionaryCollection<T> collection)
178
                        where T : NonGraphicalObject
179
                {
3,147✔
180
                        if (collection == null || entry == null)
3,147!
181
                        {
1,409✔
182
                                return entry;
1,409✔
183
                        }
184

185
                        if (collection.TryGetValue(entry.Name, out T existing))
1,738✔
186
                        {
1,603✔
187
                                return existing;
1,603✔
188
                        }
189
                        else
190
                        {
135✔
191
                                collection.Add(entry);
135✔
192
                                return entry;
135✔
193
                        }
194
                }
3,147✔
195
        }
196
}
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