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

DomCR / ACadSharp / 18679672476

21 Oct 2025 09:40AM UTC coverage: 77.906% (-0.2%) from 78.126%
18679672476

Pull #832

github

web-flow
Merge e48c45ee6 into 03242f9d6
Pull Request #832: multileader dxf

6923 of 9695 branches covered (71.41%)

Branch coverage included in aggregate %.

341 of 429 new or added lines in 16 files covered. (79.49%)

77 existing lines in 8 files now uncovered.

26671 of 33426 relevant lines covered (79.79%)

110330.18 hits per line

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

92.11
/src/ACadSharp/DxfMap.cs
1
using ACadSharp.Attributes;
2
using ACadSharp.Entities;
3
using ACadSharp.Tables;
4
using System;
5
using System.Collections.Concurrent;
6
using System.Collections.Generic;
7
using System.Linq;
8
using System.Reflection;
9

10
namespace ACadSharp
11
{
12
        public class DxfMap : DxfMapBase
13
        {
14
                /// <summary>
15
                /// Cache of created DXF mapped classes.
16
                /// </summary>
17
                private static readonly ConcurrentDictionary<Type, DxfMap> _cache = new ConcurrentDictionary<Type, DxfMap>();
1✔
18

19
                public Dictionary<string, DxfClassMap> SubClasses { get; private set; } = new Dictionary<string, DxfClassMap>();
7,517,323✔
20

21
                /// <summary>
22
                /// Creates a dxf map for an <see cref="Entity"/> or a <see cref="TableEntry"/>
23
                /// </summary>
24
                /// <remarks>
25
                /// This method does not work with the entities <see cref="AttributeEntity"/> and <see cref="AttributeDefinition"/>
26
                /// </remarks>
27
                public static DxfMap Create<T>()
28
                        where T : CadObject
29
                {
358,247✔
30
                        return DxfMap.Create(typeof(T));
358,247✔
31
                }
358,247✔
32

33
                //Useful only for none cad objects
34
                internal static DxfMap Create(Type type, string name = null)
35
                {
358,304✔
36
                        if (tryGetFromCache(type, out var map))
358,304✔
37
                        {
342,939✔
38
                                return map;
342,939✔
39
                        }
40

41
                        map = new DxfMap();
15,365✔
42
                        bool isDimensionStyle = false;
15,365✔
43

44
                        DxfNameAttribute dxf = type.GetCustomAttribute<DxfNameAttribute>();
15,365✔
45

46
                        if (string.IsNullOrEmpty(name))
15,365!
47
                        {
15,365✔
48
                                map.Name = dxf?.Name;
15,365✔
49
                        }
15,365✔
50
                        else
NEW
51
                        {
×
NEW
52
                                map.Name = name;
×
NEW
53
                        }
×
54

55
                        for (Type t = type; t != null; t = t.BaseType)
99,136✔
56
                        {
49,568✔
57
                                DxfSubClassAttribute subclass = t.GetCustomAttribute<DxfSubClassAttribute>();
49,568✔
58

59
                                if (t.Equals(typeof(DimensionStyle)))
49,568✔
60
                                {
294✔
61
                                        isDimensionStyle = true;
294✔
62
                                }
294✔
63

64
                                if (t.Equals(typeof(CadObject)))
49,568✔
65
                                {
15,365✔
66
                                        addClassProperties(map, t);
15,365✔
67
                                        break;
15,365✔
68
                                }
69
                                else if (subclass != null && subclass.IsEmpty)
34,203✔
70
                                {
7,542✔
71
                                        DxfClassMap classMap = map.SubClasses.Last().Value;
7,542✔
72

73
                                        addClassProperties(classMap, t);
7,542✔
74

75
                                        if (subclass.ClassName != null)
7,542✔
76
                                        {
2,306✔
77
                                                map.SubClasses.Add(subclass.ClassName, new DxfClassMap(subclass.ClassName));
2,306✔
78
                                        }
2,306✔
79
                                }
7,542✔
80
                                else if (t.GetCustomAttribute<DxfSubClassAttribute>() != null)
26,661✔
81
                                {
26,140✔
82
                                        DxfClassMap classMap = new DxfClassMap();
26,140✔
83
                                        classMap.Name = subclass.ClassName;
26,140✔
84

85
                                        addClassProperties(classMap, t);
26,140✔
86

87
                                        map.SubClasses.Add(classMap.Name, classMap);
26,140✔
88
                                }
26,140✔
89
                        }
34,203✔
90

91
                        if (isDimensionStyle)
15,365✔
92
                        {
294✔
93
                                //TODO: Dimensions use the 105 instead of the 5... try to find a better fix
94
                                map.DxfProperties.Add(105, map.DxfProperties[5]);
294✔
95
                                map.DxfProperties.Remove(5);
294✔
96
                        }
294✔
97

98
                        map.SubClasses =
15,365✔
99
                                new Dictionary<string, DxfClassMap>(map.SubClasses.Reverse()
15,365✔
100
                                        .ToDictionary(o => o.Key, o => o.Value));
72,257✔
101

102
                        _cache.TryAdd(type, map);
15,365✔
103

104
                        if (tryGetFromCache(type, out map))
15,365!
105
                        {
15,365✔
106
                                return map;
15,365✔
107
                        }
108

109
                        return map;
×
110
                }
358,304✔
111

112
                /// <summary>
113
                /// Clears the map cache.
114
                /// </summary>
115
                public static void ClearCache()
116
                {
350✔
117
                        _cache.Clear();
350✔
118
                }
350✔
119

120
                /// <inheritdoc/>
121
                public override string ToString()
122
                {
×
123
                        return $"DxfMap:{this.Name}";
×
124
                }
×
125

126
                private static bool tryGetFromCache(Type type, out DxfMap map)
127
                {
373,669✔
128
                        map = null;
373,669✔
129

130
                        if (_cache.TryGetValue(type, out var curr))
373,669✔
131
                        {
358,304✔
132
                                map = new DxfMap();
358,304✔
133
                                map.Name = curr.Name;
358,304✔
134

135
                                foreach (var p in curr.DxfProperties)
2,508,128✔
136
                                {
716,608✔
137
                                        map.DxfProperties.Add(p.Key, p.Value);
716,608✔
138
                                }
716,608✔
139

140
                                foreach (var sub in curr.SubClasses)
2,223,272✔
141
                                {
574,180✔
142
                                        map.SubClasses.Add(sub.Key, sub.Value);
574,180✔
143
                                }
574,180✔
144

145
                                return true;
358,304✔
146
                        }
147

148
                        return false;
15,365✔
149
                }
373,669✔
150
        }
151
}
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