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

DomCR / ACadSharp / 20690577669

04 Jan 2026 09:05AM UTC coverage: 77.04% (+0.02%) from 77.022%
20690577669

push

github

web-flow
Merge pull request #924 from DomCR/issue-923_dimstyle-override

issue 923 - dim style override

7788 of 10971 branches covered (70.99%)

Branch coverage included in aggregate %.

156 of 225 new or added lines in 10 files covered. (69.33%)

4 existing lines in 3 files now uncovered.

28530 of 36171 relevant lines covered (78.88%)

158791.55 hits per line

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

86.57
/src/ACadSharp/DxfClassMap.cs
1
using ACadSharp.Attributes;
2
using System;
3
using System.Collections.Concurrent;
4
using System.Reflection;
5

6
namespace ACadSharp
7
{
8
        /// <summary>
9
        /// Represents the mapping information for a DXF class, including metadata and property mappings used for serialization
10
        /// and deserialization of CAD objects.
11
        /// </summary>
12
        /// <remarks>Instances of this class are typically created and managed via the static Create methods, which
13
        /// provide caching to improve performance when mapping types multiple times. Use the ClearCache method to clear all
14
        /// cached mappings if the underlying type information changes or to force remapping.</remarks>
15
        public class DxfClassMap : DxfMapBase
16
        {
17
                /// <summary>
18
                /// Cache of created DXF mapped classes.
19
                /// </summary>
20
                private static readonly ConcurrentDictionary<Type, DxfClassMap> _cache = new ConcurrentDictionary<Type, DxfClassMap>();
1✔
21

22
                public DxfClassMap() : base()
28,173✔
23
                {
28,173✔
24
                }
28,173✔
25

26
                public DxfClassMap(string name) : base()
2,352✔
27
                {
2,352✔
28
                        this.Name = name;
2,352✔
29
                }
2,352✔
30

31
                public DxfClassMap(DxfClassMap map) : base()
139,568✔
32
                {
139,568✔
33
                        this.Name = map.Name;
139,568✔
34
                        foreach (var item in map.DxfProperties)
3,181,066✔
35
                        {
1,381,181✔
36
                                this.DxfProperties.Add(item.Key, item.Value);
1,381,181✔
37
                        }
1,381,181✔
38
                }
139,568✔
39

40
                /// <summary>
41
                /// Creates a DXF map of the passed type.
42
                /// </summary>
43
                /// <remarks>
44
                /// Will return a cached instance if it exists.  if not, it will be created on call.
45
                /// Use the <see cref="ClearCache"/> method to clear the cache and force a new mapping to be created.
46
                /// </remarks>
47
                /// <typeparam name="T">Type of CadObject to map.</typeparam>
48
                /// <returns>Mapped class</returns>
49
                public static DxfClassMap Create<T>()
50
                        where T : CadObject
51
                {
37,367✔
52
                        return Create(typeof(T));
37,367✔
53
                }
37,367✔
54

55
                public static DxfClassMap Create<T>(T obj)
56
                        where T : CadObject
57
                {
1✔
58
                        return Create(typeof(T), obj: obj);
1✔
59
                }
1✔
60

61
                /// <summary>
62
                /// Clears the map cache.
63
                /// </summary>
64
                public void ClearCache()
65
                {
×
66
                        _cache.Clear();
×
67
                }
×
68

69
                /// <inheritdoc/>
70
                public override string ToString()
71
                {
×
72
                        return $"DxfClassMap:{this.Name}";
×
73
                }
×
74

75
                internal static DxfClassMap Create(Type type, string name = null, CadObject obj = null)
76
                {
139,568✔
77
                        if (_cache.TryGetValue(type, out var classMap) && obj == null)
139,568✔
78
                        {
139,505✔
79
                                return new DxfClassMap(classMap);
139,505✔
80
                        }
81

82
                        classMap = new DxfClassMap();
63✔
83

84
                        if (string.IsNullOrEmpty(name))
63✔
85
                        {
55✔
86
                                var att = type.GetCustomAttribute<DxfSubClassAttribute>();
55✔
87
                                if (att == null)
55!
NEW
88
                                {
×
UNCOV
89
                                        throw new ArgumentException($"{type.FullName} is not a dxf subclass");
×
90
                                }
91

92
                                classMap.Name = att.ClassName;
55✔
93
                        }
55✔
94
                        else
95
                        {
8✔
96
                                classMap.Name = name;
8✔
97
                        }
8✔
98

99
                        addClassProperties(classMap, type, obj);
63✔
100

101
                        DxfSubClassAttribute baseAtt = type.BaseType.GetCustomAttribute<DxfSubClassAttribute>();
63✔
102
                        if (baseAtt != null && baseAtt.IsEmpty)
63✔
103
                        {
22✔
104
                                //Properties in the table seem to be embeded to the hinerit type
105
                                addClassProperties(classMap, type.BaseType, obj);
22✔
106
                        }
22✔
107

108
                        _cache.TryAdd(type, classMap);
63✔
109

110
                        return new DxfClassMap(classMap);
63✔
111
                }
139,568✔
112
        }
113
}
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