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

DomCR / ACadSharp / 12905761471

22 Jan 2025 10:03AM UTC coverage: 2.0% (-74.0%) from 75.963%
12905761471

push

github

DomCR
version 1.0.6

104 of 7676 branches covered (1.35%)

Branch coverage included in aggregate %.

590 of 27024 relevant lines covered (2.18%)

5.13 hits per line

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

0.0
/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; }
×
20

21
                private Dictionary<AppId, ExtendedData> _data = new Dictionary<AppId, ExtendedData>();
×
22

23
                /// <summary>
24
                /// Default constructor.
25
                /// </summary>
26
                /// <param name="owner"></param>
27
                public ExtendedDataDictionary(CadObject owner)
×
28
                {
×
29
                        this.Owner = owner;
×
30
                }
×
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
                {
×
48
                        if (this.Owner.Document != null)
×
49
                        {
×
50
                                if (this.Owner.Document.AppIds.TryGetValue(app.Name, out AppId existing))
×
51
                                {
×
52
                                        this._data.Add(existing, extendedData);
×
53
                                }
×
54
                                else
55
                                {
×
56
                                        this.Owner.Document.AppIds.Add(app);
×
57
                                        this._data.Add(app, extendedData);
×
58
                                }
×
59
                        }
×
60
                        else
61
                        {
×
62
                                this._data.Add(app, extendedData);
×
63
                        }
×
64
                }
×
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
                {
×
73
                        this._data.Add(app, new ExtendedData(records));
×
74
                }
×
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
                {
×
82
                        return this._data.ToDictionary(x => x.Key.Name, x => x.Value);
×
83
                }
×
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
                {
×
92
                        return this.GetExtendedDataByName()[name];
×
93
                }
×
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
                {
×
101
                        return this._data[app];
×
102
                }
×
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
                {
×
111
                        return this._data.TryGetValue(app, out value);
×
112
                }
×
113

114
                /// <summary>
115
                /// Try to get ExtendedData for a specific <see cref="AppId"/> name from the Dictionary.
116
                /// </summary>
117
                /// <param name="name">The AppId name.</param>
118
                /// <param name="value">ExtendedData object.</param>
119
                /// <returns>true, if found.</returns>
120
                public bool TryGet(string name, out ExtendedData value)
121
                {
×
122
                        AppId app = this._data.Keys.FirstOrDefault(k => k.Name == name);
×
123
                        if (app == null)
×
124
                        {
×
125
                                value = null;
×
126
                                return false;
×
127
                        }
128

129
                        value = this._data[app];
×
130
                        return true;
×
131
                }
×
132

133
                /// <summary>
134
                /// Check whether a given AppId is in the Dictionary.
135
                /// </summary>
136
                /// <param name="app">The AppId object.</param>
137
                public bool ContainsKey(AppId app)
138
                {
×
139
                        return this._data.ContainsKey(app);
×
140
                }
×
141

142
                /// <summary>
143
                /// Check whether a given AppId is in the Dictionary.
144
                /// </summary>
145
                /// <param name="name">The AppId name.</param>
146
                public bool ContainsKeyName(string name)
147
                {
×
148
                        return this._data.Keys.Select(k => k.Name).Contains(name);
×
149
                }
×
150

151
                /// <summary>
152
                /// Clear all Dictionary entries.
153
                /// </summary>
154
                public void Clear()
155
                {
×
156
                        this._data.Clear();
×
157
                }
×
158

159
                /// <inheritdoc/>
160
                public IEnumerator<KeyValuePair<AppId, ExtendedData>> GetEnumerator()
161
                {
×
162
                        return this._data.GetEnumerator();
×
163
                }
×
164

165
                /// <inheritdoc/>
166
                IEnumerator IEnumerable.GetEnumerator()
167
                {
×
168
                        return this._data.GetEnumerator();
×
169
                }
×
170
        }
171
}
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