< Summary

Information
Class: DirectSight.Parser.Analysis.CodeElement
Assembly DirectSight
File(s): /home/runner/work/DirectSight/DirectSight/DirectSight/Parser/Analysis/CodeElement.cs
Line coverage
82%
Covered lines: 37
Uncovered lines: 8
Coverable lines: 45
Total lines: 148
Line coverage: 82.2%
Branch coverage
62%
Covered branches: 10
Total branches: 16
Branch coverage: 62.5%
Method coverage

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor(...)100%11100%
.ctor(...)66.66%66100%
ApplyMaximumCoverageQuota(...)75%4475%
ToString()100%110%
Equals(...)50%6675%
GetHashCode()100%11100%

File(s)

/home/runner/work/DirectSight/DirectSight/DirectSight/Parser/Analysis/CodeElement.cs

#LineLine coverage
 1using System;
 2
 3namespace DirectSight.Parser.Analysis;
 4
 5/// <summary>
 6/// Represents an element (e.g. a method or property) in a code file.
 7/// </summary>
 8public class CodeElement
 9{
 10    /// <summary>
 11    /// Initializes a new instance of the <see cref="CodeElement" /> class.
 12    /// </summary>
 13    /// <param name="name">The name.</param>
 14    /// <param name="type">The <see cref="Analysis.CodeElementType"/>.</param>
 15    /// <param name="firstLine">The number of the first line.</param>
 16    /// <param name="lastLine">The number of the last line.</param>
 17    /// <param name="coverageQuota">The coverage quota.</param>
 18    internal CodeElement(string name, CodeElementType type, int firstLine, int lastLine, decimal? coverageQuota)
 319        : this(name, name, type, firstLine, lastLine, coverageQuota)
 320    {
 321    }
 22
 23    /// <summary>
 24    /// Initializes a new instance of the <see cref="CodeElement" /> class.
 25    /// </summary>
 26    /// <param name="fullName">The full name.</param>
 27    /// <param name="name">The name.</param>
 28    /// <param name="type">The <see cref="Analysis.CodeElementType"/>.</param>
 29    /// <param name="firstLine">The number of the first line.</param>
 30    /// <param name="lastLine">The number of the last line.</param>
 31    /// <param name="coverageQuota">The coverage quota.</param>
 442632    internal CodeElement(string fullName, string name, CodeElementType type, int firstLine, int lastLine, decimal? cover
 442633    {
 442634        this.FullName = fullName ?? throw new ArgumentNullException(nameof(name));
 442635        this.Name = name ?? throw new ArgumentNullException(nameof(name));
 442636        this.CodeElementType = type;
 442637        this.FirstLine = firstLine;
 442638        this.LastLine = lastLine;
 442639        if (coverageQuota.HasValue)
 442440        {
 442441            this.CoverageQuota = Math.Min(100, Math.Max(0, coverageQuota.Value));
 442442        }
 442643    }
 44
 45    /// <summary>
 46    /// Gets the full name.
 47    /// </summary>
 48    /// <value>
 49    /// The full name.
 50    /// </value>
 771751    public string FullName { get; }
 52
 53    /// <summary>
 54    /// Gets the name.
 55    /// </summary>
 56    /// <value>
 57    /// The name.
 58    /// </value>
 11159    public string Name { get; }
 60
 61    /// <summary>
 62    /// Gets the <see cref="Analysis.CodeElementType"/>.
 63    /// </summary>
 64    /// <value>
 65    /// The <see cref="Analysis.CodeElementType"/>.
 66    /// </value>
 11067    public CodeElementType CodeElementType { get; }
 68
 69    /// <summary>
 70    /// Gets the number of the first line.
 71    /// </summary>
 72    /// <value>
 73    /// The number of the first line.
 74    /// </value>
 1101475    public int FirstLine { get; }
 76
 77    /// <summary>
 78    /// Gets the number of the last line.
 79    /// </summary>
 80    /// <value>
 81    /// The number of the last line.
 82    /// </value>
 208783    public int LastLine { get; }
 84
 85    /// <summary>
 86    /// Gets the coverage quota of the code element.
 87    /// </summary>
 88    /// <value>The coverage quota.</value>
 925889    public decimal? CoverageQuota { get; private set; }
 90
 91    /// <summary>
 92    /// Applies the given coverage quota if greater than existing quota.
 93    /// </summary>
 94    /// <param name="quota">The quota.</param>
 95    public void ApplyMaximumCoverageQuota(decimal? quota)
 109796    {
 109797        if (quota.HasValue)
 109798        {
 109799            if (this.CoverageQuota.HasValue)
 1097100            {
 1097101                this.CoverageQuota = Math.Max(quota.Value, this.CoverageQuota.Value);
 1097102            }
 103            else
 0104            {
 0105                this.CoverageQuota = quota;
 0106            }
 1097107        }
 1097108    }
 109
 110    /// <summary>
 111    /// Returns a <see cref="string" /> that represents this instance.
 112    /// </summary>
 113    /// <returns>
 114    /// A <see cref="string" /> that represents this instance.
 115    /// </returns>
 116    public override string ToString()
 0117    {
 0118        return this.Name;
 0119    }
 120
 121    /// <summary>
 122    /// Determines whether the specified <see cref="object"/> is equal to this instance.
 123    /// </summary>
 124    /// <param name="obj">The <see cref="object"/> to compare with this instance.</param>
 125    /// <returns>
 126    ///   <c>true</c> if the specified <see cref="object"/> is equal to this instance; otherwise, <c>false</c>.
 127    /// </returns>
 128    public override bool Equals(object obj)
 1097129    {
 1097130        if (obj == null || !obj.GetType().Equals(typeof(CodeElement)))
 0131        {
 0132            return false;
 133        }
 134        else
 1097135        {
 1097136            var codeElement = (CodeElement)obj;
 1097137            return this.FullName.Equals(codeElement.FullName) && this.FirstLine == codeElement.FirstLine;
 138        }
 1097139    }
 140
 141    /// <summary>
 142    /// Returns a hash code for this instance.
 143    /// </summary>
 144    /// <returns>
 145    /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
 146    /// </returns>
 5523147    public override int GetHashCode() => this.FullName.GetHashCode() + this.FirstLine.GetHashCode();
 148}