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

DomCR / ACadSharp / 18679832337

21 Oct 2025 09:46AM UTC coverage: 77.883% (-0.2%) from 78.126%
18679832337

push

github

web-flow
Merge pull request #832 from DomCR/multileader-dxf

multileader dxf

6920 of 9695 branches covered (71.38%)

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.

26664 of 33426 relevant lines covered (79.77%)

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,317✔
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,940✔
38
                                return map;
342,940✔
39
                        }
40

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

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

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

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

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

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

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

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

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

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

91
                        if (isDimensionStyle)
15,364✔
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,364✔
99
                                new Dictionary<string, DxfClassMap>(map.SubClasses.Reverse()
15,364✔
100
                                        .ToDictionary(o => o.Key, o => o.Value));
72,252✔
101

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

104
                        if (tryGetFromCache(type, out map))
15,364!
105
                        {
15,364✔
106
                                return map;
15,364✔
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,668✔
128
                        map = null;
373,668✔
129

130
                        if (_cache.TryGetValue(type, out var curr))
373,668✔
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,364✔
149
                }
373,668✔
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