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

DomCR / ACadSharp / 17737836230

15 Sep 2025 03:12PM UTC coverage: 2.092% (-76.2%) from 78.245%
17737836230

push

github

web-flow
Merge pull request #790 from DomCR/addflag-refactor

addflag refactor

141 of 9225 branches covered (1.53%)

Branch coverage included in aggregate %.

0 of 93 new or added lines in 10 files covered. (0.0%)

24910 existing lines in 372 files now uncovered.

724 of 32119 relevant lines covered (2.25%)

5.76 hits per line

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

0.0
/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>
UNCOV
17
                private static readonly ConcurrentDictionary<Type, DxfMap> _cache = new ConcurrentDictionary<Type, DxfMap>();
×
18

UNCOV
19
                public Dictionary<string, DxfClassMap> SubClasses { get; private set; } = new Dictionary<string, DxfClassMap>();
×
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
UNCOV
29
                {
×
UNCOV
30
                        return DxfMap.Create(typeof(T));
×
UNCOV
31
                }
×
32

33
                //TODO: change to public? Using the type parameter does not constraing the use of the method
34
                internal static DxfMap Create(Type type)
UNCOV
35
                {
×
UNCOV
36
                        if (tryGetFromCache(type, out var map))
×
UNCOV
37
                        {
×
UNCOV
38
                                return map;
×
39
                        }
40

UNCOV
41
                        map = new DxfMap();
×
UNCOV
42
                        bool isDimensionStyle = false;
×
43

UNCOV
44
                        DxfNameAttribute dxf = type.GetCustomAttribute<DxfNameAttribute>();
×
45

UNCOV
46
                        map.Name = dxf?.Name;
×
47

UNCOV
48
                        for (Type t = type; t != null; t = t.BaseType)
×
UNCOV
49
                        {
×
UNCOV
50
                                DxfSubClassAttribute subclass = t.GetCustomAttribute<DxfSubClassAttribute>();
×
51

UNCOV
52
                                if (t.Equals(typeof(DimensionStyle)))
×
UNCOV
53
                                {
×
UNCOV
54
                                        isDimensionStyle = true;
×
UNCOV
55
                                }
×
56

UNCOV
57
                                if (t.Equals(typeof(CadObject)))
×
UNCOV
58
                                {
×
UNCOV
59
                                        addClassProperties(map, t);
×
UNCOV
60
                                        break;
×
61
                                }
UNCOV
62
                                else if (subclass != null && subclass.IsEmpty)
×
UNCOV
63
                                {
×
UNCOV
64
                                        DxfClassMap classMap = map.SubClasses.Last().Value;
×
65

UNCOV
66
                                        addClassProperties(classMap, t);
×
67

UNCOV
68
                                        if (subclass.ClassName != null)
×
UNCOV
69
                                        {
×
UNCOV
70
                                                map.SubClasses.Add(subclass.ClassName, new DxfClassMap(subclass.ClassName));
×
UNCOV
71
                                        }
×
UNCOV
72
                                }
×
UNCOV
73
                                else if (t.GetCustomAttribute<DxfSubClassAttribute>() != null)
×
UNCOV
74
                                {
×
UNCOV
75
                                        DxfClassMap classMap = new DxfClassMap();
×
UNCOV
76
                                        classMap.Name = subclass.ClassName;
×
77

UNCOV
78
                                        addClassProperties(classMap, t);
×
79

UNCOV
80
                                        map.SubClasses.Add(classMap.Name, classMap);
×
UNCOV
81
                                }
×
UNCOV
82
                        }
×
83

UNCOV
84
                        if (isDimensionStyle)
×
UNCOV
85
                        {
×
86
                                //TODO: Dimensions use the 105 instead of the 5... try to find a better fix
UNCOV
87
                                map.DxfProperties.Add(105, map.DxfProperties[5]);
×
UNCOV
88
                                map.DxfProperties.Remove(5);
×
UNCOV
89
                        }
×
90

UNCOV
91
                        map.SubClasses =
×
UNCOV
92
                                new Dictionary<string, DxfClassMap>(map.SubClasses.Reverse()
×
UNCOV
93
                                        .ToDictionary(o => o.Key, o => o.Value));
×
94

UNCOV
95
                        _cache.TryAdd(type, map);
×
96

UNCOV
97
                        if (tryGetFromCache(type, out map))
×
UNCOV
98
                        {
×
UNCOV
99
                                return map;
×
100
                        }
101

102
                        return map;
×
UNCOV
103
                }
×
104

105
                /// <summary>
106
                /// Clears the map cache.
107
                /// </summary>
108
                public static void ClearCache()
UNCOV
109
                {
×
UNCOV
110
                        _cache.Clear();
×
UNCOV
111
                }
×
112

113
                /// <inheritdoc/>
114
                public override string ToString()
115
                {
×
116
                        return $"DxfMap:{this.Name}";
×
117
                }
×
118

119
                private static bool tryGetFromCache(Type type, out DxfMap map)
UNCOV
120
                {
×
UNCOV
121
                        map = null;
×
122

UNCOV
123
                        if (_cache.TryGetValue(type, out var curr))
×
UNCOV
124
                        {
×
UNCOV
125
                                map = new DxfMap();
×
UNCOV
126
                                map.Name = curr.Name;
×
127

UNCOV
128
                                foreach (var p in curr.DxfProperties)
×
UNCOV
129
                                {
×
UNCOV
130
                                        map.DxfProperties.Add(p.Key, p.Value);
×
UNCOV
131
                                }
×
132

UNCOV
133
                                foreach (var sub in curr.SubClasses)
×
UNCOV
134
                                {
×
UNCOV
135
                                        map.SubClasses.Add(sub.Key, sub.Value);
×
UNCOV
136
                                }
×
137

UNCOV
138
                                return true;
×
139
                        }
140

UNCOV
141
                        return false;
×
UNCOV
142
                }
×
143
        }
144
}
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