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

DomCR / ACadSharp / 19747691062

27 Nov 2025 08:58PM UTC coverage: 77.833% (-0.2%) from 78.079%
19747691062

Pull #898

github

web-flow
Merge 7246c0e16 into b4f4477ec
Pull Request #898: DimensionStyle Overrides

7643 of 10693 branches covered (71.48%)

Branch coverage included in aggregate %.

481 of 674 new or added lines in 7 files covered. (71.36%)

54 existing lines in 7 files now uncovered.

28210 of 35371 relevant lines covered (79.75%)

134840.38 hits per line

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

89.29
/src/ACadSharp/XData/ExtendedDataDictionary.cs
1
using ACadSharp.Tables;
2
using System;
3
using System.Collections;
4
using System.Collections.Generic;
5
using System.Linq;
6

7
namespace ACadSharp.XData
8
{
9
        /// <summary>
10
        /// Dictionary containing all the extended data for a giving <see cref="CadObject"/>, 
11
        /// each entry is identified with an <see cref="AppId"/> key that identifies the application that
12
        /// has added the collection of Extended Data (XData) into the object.
13
        /// </summary>
14
        public class ExtendedDataDictionary : IEnumerable<KeyValuePair<AppId, ExtendedData>>
15
        {
16
                /// <summary>
17
                /// Owner of the Extended Data dictionary.
18
                /// </summary>
19
                public CadObject Owner { get; }
6,307✔
20

21
                private Dictionary<AppId, ExtendedData> _data = new Dictionary<AppId, ExtendedData>();
4,141,473✔
22

23
                /// <summary>
24
                /// Default constructor.
25
                /// </summary>
26
                /// <param name="owner"></param>
27
                public ExtendedDataDictionary(CadObject owner)
4,141,473✔
28
                {
4,141,473✔
29
                        this.Owner = owner;
4,141,473✔
30
                }
4,141,473✔
31

32
                /// <summary>
33
                /// Add an empty entry of ExtendedData for a given <see cref="AppId"/>.
34
                /// </summary>
35
                /// <param name="app"></param>
36
                public void Add(AppId app)
37
                {
×
38
                        this.Add(app, new ExtendedData());
×
39
                }
×
40

41
                /// <summary>
42
                /// Add ExtendedData for a specific <see cref="AppId"/> to the Dictionary.
43
                /// </summary>
44
                /// <param name="app"></param>
45
                /// <param name="extendedData"></param>
46
                public void Add(AppId app, ExtendedData extendedData)
47
                {
3,799✔
48
                        if (this.Owner.Document != null)
3,799✔
49
                        {
1,974✔
50
                                if (this.Owner.Document.AppIds.TryGetValue(app.Name, out AppId existing))
1,974✔
51
                                {
1,440✔
52
                                        this._data.Add(existing, extendedData);
1,440✔
53
                                }
1,440✔
54
                                else
55
                                {
534✔
56
                                        this.Owner.Document.AppIds.Add(app);
534✔
57
                                        this._data.Add(app, extendedData);
534✔
58
                                }
534✔
59
                        }
1,974✔
60
                        else
61
                        {
1,825✔
62
                                this._data.Add(app, extendedData);
1,825✔
63
                        }
1,825✔
64
                }
3,799✔
65

66
                /// <summary>
67
                /// Add ExtendedData for a specific <see cref="AppId"/> to the Dictionary.
68
                /// </summary>
69
                /// <param name="app">The AppId object.</param>
70
                /// <param name="records">The ExtendedData records.</param>
71
                public void Add(AppId app, IEnumerable<ExtendedDataRecord> records)
72
                {
66,539✔
73
                        this._data.Add(app, new ExtendedData(records));
66,539✔
74
                }
66,539✔
75

76
                /// <summary>
77
                /// Get the different extended data by it's name.
78
                /// </summary>
79
                /// <returns></returns>
80
                public IDictionary<string, ExtendedData> GetExtendedDataByName()
81
                {
277✔
82
                        return this._data.ToDictionary(x => x.Key.Name, x => x.Value, StringComparer.OrdinalIgnoreCase);
831✔
83
                }
277✔
84

85
                /// <summary>
86
                /// Get the Extended data for a given <see cref="AppId"/> name.
87
                /// </summary>
88
                /// <param name="name"></param>
89
                /// <returns></returns>
90
                public ExtendedData Get(string name)
91
                {
4✔
92
                        return this.GetExtendedDataByName()[name];
4✔
93
                }
4✔
94

95
                /// <summary>
96
                /// Get ExtendedData for a specific <see cref="AppId"/> from the Dictionary.
97
                /// </summary>
98
                /// <param name="app">The AppId object.</param>
99
                public ExtendedData Get(AppId app)
100
                {
39✔
101
                        return this._data[app];
39✔
102
                }
39✔
103

104
                /// <summary>
105
                /// Try to get ExtendedData for a specific <see cref="AppId"/> from the Dictionary.
106
                /// </summary>
107
                /// <param name="app">The AppId object.</param>
108
                /// <param name="value">ExtendedData object.</param>
109
                public bool TryGet(AppId app, out ExtendedData value)
110
                {
5,083✔
111
                        // First, try direct reference equality on AppId keys
112
                        if (this._data.TryGetValue(app, out value))
5,083!
NEW
113
                        {
×
NEW
114
                                return true;
×
115
                        }
116

117
                        // Fallback by AppId name to handle scenarios where the stored key is the
118
                        // document's AppId instance but the caller provides another AppId instance
119
                        // with the same name (e.g., AppId.Default vs document AppId entry).
120
                        if (app != null)
5,083✔
121
                        {
5,083✔
122
                                foreach (var kvp in this._data)
16,856✔
123
                                {
1,531✔
124
                                        if (string.Equals(kvp.Key.Name, app.Name, StringComparison.OrdinalIgnoreCase))
1,531✔
125
                                        {
1,455✔
126
                                                value = kvp.Value;
1,455✔
127
                                                return true;
1,455✔
128
                                        }
129
                                }
76✔
130
                        }
3,628✔
131

132
                        value = null;
3,628✔
133
                        return false;
3,628✔
134
                }
5,083✔
135

136
                /// <summary>
137
                /// Try to get ExtendedData for a specific <see cref="AppId"/> name from the Dictionary.
138
                /// </summary>
139
                /// <param name="name">The AppId name.</param>
140
                /// <param name="value">ExtendedData object.</param>
141
                /// <returns>true, if found.</returns>
142
                public bool TryGet(string name, out ExtendedData value)
143
                {
273✔
144
                        return this.GetExtendedDataByName().TryGetValue(name, out value);
273✔
145
                }
273✔
146

147
                /// <summary>
148
                /// Check whether a given AppId is in the Dictionary.
149
                /// </summary>
150
                /// <param name="app">The AppId object.</param>
151
                public bool ContainsKey(AppId app)
152
                {
×
153
                        return this._data.ContainsKey(app);
×
154
                }
×
155

156
                /// <summary>
157
                /// Check whether a given AppId is in the Dictionary.
158
                /// </summary>
159
                /// <param name="name">The AppId name.</param>
160
                public bool ContainsKeyName(string name)
161
                {
1✔
162
                        return this._data.Keys.Select(k => k.Name).Contains(name);
2✔
163
                }
1✔
164

165
                /// <summary>
166
                /// Clear all Dictionary entries.
167
                /// </summary>
168
                public void Clear()
169
                {
2,613✔
170
                        this._data.Clear();
2,613✔
171
                }
2,613✔
172

173
                /// <inheritdoc/>
174
                public IEnumerator<KeyValuePair<AppId, ExtendedData>> GetEnumerator()
175
                {
1,139,364✔
176
                        return this._data.GetEnumerator();
1,139,364✔
177
                }
1,139,364✔
178

179
                /// <inheritdoc/>
180
                IEnumerator IEnumerable.GetEnumerator()
181
                {
2✔
182
                        return this._data.GetEnumerator();
2✔
183
                }
2✔
184
        }
185
}
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