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

DomCR / ACadSharp / 24787695133

22 Apr 2026 03:40PM UTC coverage: 77.131% (+0.06%) from 77.076%
24787695133

Pull #1041

github

web-flow
Merge a09f177c0 into 98bd2e4f4
Pull Request #1041: issue-1035 Add progress reporting to CAD file reading process

8459 of 11919 branches covered (70.97%)

Branch coverage included in aggregate %.

332 of 385 new or added lines in 12 files covered. (86.23%)

8 existing lines in 3 files now uncovered.

30462 of 38542 relevant lines covered (79.04%)

153328.47 hits per line

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

75.0
/src/ACadSharp/IO/CadReaderFactory.cs
1
using System;
2
using System.IO;
3

4
namespace ACadSharp.IO;
5

6
/// <summary>
7
/// Provides factory methods for creating CAD file readers based on file format.
8
/// </summary>
9
/// <remarks>Use this class to obtain an appropriate ICadReader instance for supported CAD file types such as DWG
10
/// and DXF. The factory selects the correct reader implementation based on the file extension. This class does not
11
/// validate file existence or content; it only inspects the file extension.</remarks>
12
public static class CadReaderFactory
13
{
14
        /// <summary>
15
        /// Creates an <see cref="ICadReader"/> instance for the specified CAD file format.
16
        /// </summary>
17
        /// <remarks>Supported file formats include DWG and DXF. The method selects the appropriate reader based on the
18
        /// file extension.</remarks>
19
        /// <param name="filename">The path to the CAD file to read. The file extension determines the reader type. Must not be null or empty.</param>
20
        /// <param name="notification">An optional event handler for receiving notifications during the reading process. Can be null if no notifications
21
        /// are needed.</param>
22
        /// <returns>An <see cref="ICadReader"/> instance capable of reading the specified CAD file.</returns>
23
        /// <exception cref="NotSupportedException">Thrown if the file extension is not supported.</exception>
24
        public static ICadReader CreateReader(string filename, NotificationEventHandler notification = null)
25
        {
133✔
26
                switch (GetFileFormat(filename))
133!
27
                {
28
                        case CadFileFormat.DWG:
29
                                return new DwgReader(filename, notification);
49✔
30
                        case CadFileFormat.DXF:
31
                                return new DxfReader(filename, notification);
84✔
32
                        case CadFileFormat.Unknown:
33
                        default:
NEW
34
                                throw new NotSupportedException($"Extension {Path.GetExtension(filename)} is not supported.");
×
35
                }
36
        }
133✔
37

38
        /// <summary>
39
        /// Determines the CAD file format based on the file extension of the specified filename.
40
        /// </summary>
41
        /// <remarks>The method does not validate whether the file exists or whether the file content matches the
42
        /// extension. Only the file extension is considered when determining the format.</remarks>
43
        /// <param name="filename">The path or name of the file whose format is to be identified. The file extension is used to determine the format.</param>
44
        /// <returns>A value of the CadFileFormat enumeration that corresponds to the file's extension. Returns  <see cref="CadFileFormat.DWG"/> for
45
        /// ".dwg" files,  <see cref="CadFileFormat.DXF"/> for ".dxf" files, or <see cref="CadFileFormat.Unknown"/> if the extension is not recognized.</returns>
46
        public static CadFileFormat GetFileFormat(string filename)
47
        {
133✔
48
                switch (Path.GetExtension(filename))
133!
49
                {
50
                        case ".dwg":
51
                                return CadFileFormat.DWG;
49✔
52
                        case ".dxf":
53
                                return CadFileFormat.DXF;
84✔
54
                        default:
NEW
55
                                return CadFileFormat.Unknown;
×
56
                }
57
        }
133✔
58
}
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