1+ using System ;
12using System . Collections . Generic ;
3+ using System . ComponentModel ;
4+ using System . Globalization ;
5+ using System . IO ;
6+ using Newtonsoft . Json ;
27
38namespace Coverlet . Core . Instrumentation
49{
5- internal class Line
10+ public class Line
611 {
712 public int Number ;
813 public string Class ;
914 public string Method ;
1015 public int Hits ;
1116 }
1217
13- internal class Branch : Line
18+ public class Branch : Line
1419 {
1520 public int Offset ;
1621 public int EndOffset ;
1722 public int Path ;
1823 public uint Ordinal ;
1924 }
2025
21- internal class Document
26+ public class BranchKeyConverter : TypeConverter
27+ {
28+ public override bool CanConvertFrom ( ITypeDescriptorContext context , Type sourceType )
29+ {
30+ return sourceType == typeof ( string ) ;
31+ }
32+
33+ public override object ConvertFrom ( ITypeDescriptorContext context , CultureInfo culture , object value )
34+ {
35+ return JsonConvert . DeserializeObject < BranchKey > ( value . ToString ( ) ) ;
36+ }
37+
38+ public override bool CanConvertTo ( ITypeDescriptorContext context , Type destinationType )
39+ {
40+ return destinationType == typeof ( BranchKey ) ;
41+ }
42+ }
43+
44+ [ TypeConverter ( typeof ( BranchKeyConverter ) ) ]
45+ public class BranchKey : IEquatable < BranchKey >
46+ {
47+ public BranchKey ( int line , int ordinal ) => ( Line , Ordinal ) = ( line , ordinal ) ;
48+
49+ public int Line { get ; set ; }
50+ public int Ordinal { get ; set ; }
51+
52+ public override bool Equals ( object obj ) => Equals ( obj ) ;
53+
54+ public bool Equals ( BranchKey other ) => other is BranchKey branchKey && branchKey . Line == this . Line && branchKey . Ordinal == this . Ordinal ;
55+
56+ public override int GetHashCode ( )
57+ {
58+ return ( this . Line , this . Ordinal ) . GetHashCode ( ) ;
59+ }
60+
61+ public override string ToString ( )
62+ {
63+ return JsonConvert . SerializeObject ( this ) ;
64+ }
65+ }
66+
67+ public class Document
2268 {
2369 public Document ( )
2470 {
2571 Lines = new Dictionary < int , Line > ( ) ;
26- Branches = new Dictionary < ( int Line , int Ordinal ) , Branch > ( ) ;
72+ Branches = new Dictionary < BranchKey , Branch > ( ) ;
2773 }
2874
2975 public string Path ;
3076 public int Index ;
3177 public Dictionary < int , Line > Lines { get ; private set ; }
32- public Dictionary < ( int Line , int Ordinal ) , Branch > Branches { get ; private set ; }
78+ public Dictionary < BranchKey , Branch > Branches { get ; private set ; }
79+ }
80+
81+ public class HitCandidate
82+ {
83+ public HitCandidate ( bool isBranch , int docIndex , int start , int end ) => ( this . isBranch , this . docIndex , this . start , this . end ) = ( isBranch , docIndex , start , end ) ;
84+
85+ public bool isBranch { get ; set ; }
86+ public int docIndex { get ; set ; }
87+ public int start { get ; set ; }
88+ public int end { get ; set ; }
3389 }
3490
35- internal class InstrumenterResult
91+ public class InstrumenterResult
3692 {
3793 public InstrumenterResult ( )
3894 {
3995 Documents = new Dictionary < string , Document > ( ) ;
40- HitCandidates = new List < ( bool isBranch , int docIndex , int start , int end ) > ( ) ;
96+ HitCandidates = new List < HitCandidate > ( ) ;
4197 }
4298
4399 public string Module ;
@@ -46,6 +102,6 @@ public InstrumenterResult()
46102 public string ModulePath ;
47103 public string SourceLink ;
48104 public Dictionary < string , Document > Documents { get ; private set ; }
49- public List < ( bool isBranch , int docIndex , int start , int end ) > HitCandidates { get ; private set ; }
105+ public List < HitCandidate > HitCandidates { get ; private set ; }
50106 }
51- }
107+ }
0 commit comments