< Summary

Information
Class: JeremyAnsel.Media.WavefrontObj.ObjMaterialFile
Assembly: JeremyAnsel.Media.WavefrontObj
File(s): C:\projects\jeremyansel-media-wavefrontobj\JeremyAnsel.Media.WavefrontObj\JeremyAnsel.Media.WavefrontObj\ObjMaterialFile.cs
Line coverage
100%
Covered lines: 23
Uncovered lines: 0
Coverable lines: 23
Total lines: 77
Line coverage: 100%
Branch coverage
100%
Covered branches: 6
Total branches: 6
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor()100%11100%
FromFile(...)100%11100%
FromFile(...)100%22100%
FromStream(...)100%11100%
FromStream(...)100%11100%
WriteTo(...)100%22100%
WriteTo(...)100%22100%

File(s)

C:\projects\jeremyansel-media-wavefrontobj\JeremyAnsel.Media.WavefrontObj\JeremyAnsel.Media.WavefrontObj\ObjMaterialFile.cs

#LineLine coverage
 1// <copyright file="ObjMaterialFile.cs" company="Jérémy Ansel">
 2// Copyright (c) 2017, 2019 Jérémy Ansel
 3// </copyright>
 4// <license>
 5// Licensed under the MIT license. See LICENSE.txt
 6// </license>
 7
 8using System.Text;
 9
 10namespace JeremyAnsel.Media.WavefrontObj;
 11
 12public class ObjMaterialFile
 13{
 314    public ObjMaterialFile()
 15    {
 316        Materials = new List<ObjMaterial>();
 317    }
 18
 19    public string? HeaderText { get; set; }
 20
 21    [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.RootHidden)]
 22    public List<ObjMaterial> Materials { get; private set; }
 23
 24    public static ObjMaterialFile FromFile(string? path)
 25    {
 326        return FromFile(path, ObjMaterialFileReaderSettings.Default);
 27    }
 28
 29    public static ObjMaterialFile FromFile(string? path, ObjMaterialFileReaderSettings settings)
 30    {
 331        if (path == null)
 32        {
 333            throw new ArgumentNullException(nameof(path));
 34        }
 35
 336        using (var stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
 37        {
 338            return ObjMaterialFileReader.FromStream(stream, settings);
 39        }
 340    }
 41
 42    public static ObjMaterialFile FromStream(Stream? stream)
 43    {
 344        return FromStream(stream, ObjMaterialFileReaderSettings.Default);
 45    }
 46
 47    public static ObjMaterialFile FromStream(Stream? stream, ObjMaterialFileReaderSettings settings)
 48    {
 349        return ObjMaterialFileReader.FromStream(stream, settings);
 50    }
 51
 52    public void WriteTo(string? path)
 53    {
 354        if (path == null)
 55        {
 356            throw new ArgumentNullException(nameof(path));
 57        }
 58
 359        using (var writer = new StreamWriter(path))
 60        {
 361            ObjMaterialFileWriter.Write(this, writer);
 362        }
 363    }
 64
 65    public void WriteTo(Stream? stream)
 66    {
 367        if (stream == null)
 68        {
 369            throw new ArgumentNullException(nameof(stream));
 70        }
 71
 372        using (var writer = new StreamWriter(stream, new UTF8Encoding(false, true), 1024, true))
 73        {
 374            ObjMaterialFileWriter.Write(this, writer);
 375        }
 376    }
 77}