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

DomCR / ACadSharp / 25256733691

02 May 2026 04:42PM UTC coverage: 77.076% (-0.02%) from 77.1%
25256733691

push

github

web-flow
Merge pull request #1057 from DomCR/issue/1055_dimension-override-applied-by-dxfmap-fix

issue-1055 dimension override

8459 of 11921 branches covered (70.96%)

Branch coverage included in aggregate %.

53 of 84 new or added lines in 4 files covered. (63.1%)

20 existing lines in 3 files now uncovered.

30465 of 38580 relevant lines covered (78.97%)

154302.26 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()
26,133✔
23
        {
26,133✔
24
        }
26,133✔
25

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

31
        public DxfClassMap(DxfClassMap map) : base()
132,801✔
32
        {
132,801✔
33
                this.Name = map.Name;
132,801✔
34
                foreach (var item in map.DxfProperties)
3,362,815✔
35
                {
1,482,206✔
36
                        this.DxfProperties.Add(item.Key, new DxfProperty(item.Value));
1,482,206✔
37
                }
1,482,206✔
38
        }
132,801✔
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
        {
41,097✔
52
                return Create(typeof(T));
41,097✔
53
        }
41,097✔
54

55
        /// <summary>
56
        /// Creates a new instance of the DxfClassMap for the specified CAD object type and instance.
57
        /// </summary>
58
        /// <typeparam name="T">The type of CAD object for which to create the class map. Must inherit from CadObject.</typeparam>
59
        /// <param name="obj">The CAD object instance to associate with the created class map.</param>
60
        /// <returns>A DxfClassMap instance representing the mapping for the specified CAD object type and instance.</returns>
61
        public static DxfClassMap Create<T>(T obj)
62
                where T : CadObject
63
        {
8✔
64
                return Create(typeof(T), obj: obj);
8✔
65
        }
8✔
66

67
        /// <summary>
68
        /// Clears the map cache.
69
        /// </summary>
70
        public void ClearCache()
NEW
71
        {
×
NEW
72
                _cache.Clear();
×
NEW
73
        }
×
74

75
        /// <inheritdoc/>
76
        public override string ToString()
NEW
77
        {
×
NEW
78
                return $"DxfClassMap:{this.Name}";
×
NEW
79
        }
×
80

81
        internal static DxfClassMap Create(Type type, string name = null, CadObject obj = null)
82
        {
132,801✔
83
                if (!_cache.TryGetValue(type, out var classMap) || obj != null)
132,801✔
84
                {
71✔
85
                        classMap = new DxfClassMap();
71✔
86

87
                        if (string.IsNullOrEmpty(name))
71✔
88
                        {
63✔
89
                                var att = type.GetCustomAttribute<DxfSubClassAttribute>();
63✔
90
                                if (att == null)
63!
91
                                {
×
92
                                        throw new ArgumentException($"{type.FullName} is not a dxf subclass");
×
93
                                }
94

95
                                classMap.Name = att.ClassName;
63✔
96
                        }
63✔
97
                        else
98
                        {
8✔
99
                                classMap.Name = name;
8✔
100
                        }
8✔
101

102
                        addClassProperties(classMap, type, obj);
71✔
103

104
                        DxfSubClassAttribute baseAtt = type.BaseType.GetCustomAttribute<DxfSubClassAttribute>();
71✔
105
                        if (baseAtt != null && baseAtt.IsEmpty)
71✔
106
                        {
30✔
107
                                //Properties in the table seem to be embeded to the hinerit type
108
                                addClassProperties(classMap, type.BaseType, obj);
30✔
109
                        }
30✔
110

111
                        _cache.TryAdd(type, classMap);
71✔
112
                }
71✔
113

114
                return new DxfClassMap(classMap);
132,801✔
115
        }
132,801✔
116
}
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