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

DomCR / ACadSharp / 12905761471

22 Jan 2025 10:03AM UTC coverage: 2.0% (-74.0%) from 75.963%
12905761471

push

github

DomCR
version 1.0.6

104 of 7676 branches covered (1.35%)

Branch coverage included in aggregate %.

590 of 27024 relevant lines covered (2.18%)

5.13 hits per line

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

0.0
/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
        public class DxfClassMap : DxfMapBase
9
        {
10
                /// <summary>
11
                /// Cache of created DXF mapped classes.
12
                /// </summary>
13
                private static readonly ConcurrentDictionary<Type, DxfClassMap> _cache = new ConcurrentDictionary<Type, DxfClassMap>();
×
14

15
                public DxfClassMap() : base() { }
×
16

17
                public DxfClassMap(string name) : base()
×
18
                {
×
19
                        this.Name = name;
×
20
                }
×
21

22
                /// <summary>
23
                /// Creates a DXF map of the passed type.
24
                /// </summary>
25
                /// <remarks>
26
                ///   Will return a cached instance if it exists.  if not, it will be created on call.
27
                /// Use the <see cref="ClearCache"/> method to clear the cache and force a new mapping to be created.
28
                /// </remarks>
29
                /// <typeparam name="T">Type of CadObject to map.</typeparam>
30
                /// <returns>Mapped class</returns>
31
                public static DxfClassMap Create<T>()
32
                        where T : CadObject
33
                {
×
34
                        Type type = typeof(T);
×
35

36
                        if (_cache.TryGetValue(type, out var classMap))
×
37
                        {
×
38
                                return classMap;
×
39
                        }
40

41
                        classMap = new DxfClassMap();
×
42

43
                        var att = type.GetCustomAttribute<DxfSubClassAttribute>();
×
44
                        if (att == null)
×
45
                                throw new ArgumentException($"{type.FullName} is not a dxf subclass");
×
46

47
                        classMap.Name = type.GetCustomAttribute<DxfSubClassAttribute>().ClassName;
×
48

49
                        addClassProperties(classMap, type);
×
50

51
                        DxfSubClassAttribute baseAtt = type.BaseType.GetCustomAttribute<DxfSubClassAttribute>();
×
52
                        if (baseAtt != null && baseAtt.IsEmpty)
×
53
                        {
×
54
                                //Properties in the table seem to be embeded to the hinerit type
55
                                addClassProperties(classMap, type.BaseType);
×
56
                        }
×
57

58
                        _cache.TryAdd(type, classMap);
×
59

60
                        return classMap;
×
61
                }
×
62

63

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

72
                public override string ToString()
73
                {
×
74
                        return $"DxfClassMap:{this.Name}";
×
75
                }
×
76
        }
77
}
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