@@ -25,11 +25,11 @@ public static MathListIndex InsertAndAdvance(this MathList self, MathListIndex i
2525 throw new IndexOutOfRangeException ( $ "Index { index . AtomIndex } is out of bounds for list of size { self . Atoms . Count } ") ;
2626 switch ( index . SubIndexInfo ) {
2727 case null :
28- return self . InsertAtAtomIndexAndAdvance ( index . AtomIndex , atom , index , null ) ;
28+ return self . InsertAtAtomIndexAndAdvance ( index . AtomIndex , atom , index , advanceType ) ;
2929 case ( MathListSubIndexType . BetweenBaseAndScripts , _ ) :
3030 var currentAtom = self . Atoms [ index . AtomIndex ] ;
3131 if ( currentAtom . Subscript . IsEmpty ( ) && currentAtom . Superscript . IsEmpty ( ) )
32- throw new SubIndexTypeMismatchException ( index ) ;
32+ throw new SubIndexTypeMismatchException ( nameof ( MathListSubIndexType . BetweenBaseAndScripts ) , index . AtomIndex ) ;
3333 if ( atom . Subscript . IsNonEmpty ( ) || atom . Superscript . IsNonEmpty ( ) )
3434 throw new ArgumentException ( "Cannot fuse with an atom that already has a subscript or a superscript" ) ;
3535 atom . Subscript . Append ( currentAtom . Subscript ) ;
@@ -42,30 +42,30 @@ public static MathListIndex InsertAndAdvance(this MathList self, MathListIndex i
4242 return self . InsertAtAtomIndexAndAdvance ( atomIndex + 1 , atom , index , advanceType ) ;
4343 case ( MathListSubIndexType . Degree , var subIndex )
4444 when self . Atoms [ index . AtomIndex ] is Atoms . Radical radical ? true
45- : throw new SubIndexTypeMismatchException ( typeof ( Atoms . Radical ) , index ) :
46- return radical . Degree . InsertAndAdvance ( subIndex , atom , advanceType ) . WrapInIndex ( index . AtomIndex , MathListSubIndexType . Degree ) ;
45+ : throw new SubIndexTypeMismatchException ( nameof ( Atoms . Radical ) , index . AtomIndex ) :
46+ return radical . Degree . InsertAndAdvance ( subIndex , atom , advanceType ) . Wrap ( index . AtomIndex , MathListSubIndexType . Degree ) ;
4747 case ( MathListSubIndexType . Radicand , var subIndex )
4848 when self . Atoms [ index . AtomIndex ] is Atoms . Radical radical ? true
49- : throw new SubIndexTypeMismatchException ( typeof ( Atoms . Radical ) , index ) :
50- return radical . Degree . InsertAndAdvance ( subIndex , atom , advanceType ) . WrapInIndex ( index . AtomIndex , MathListSubIndexType . Radicand ) ;
49+ : throw new SubIndexTypeMismatchException ( nameof ( Atoms . Radical ) , index . AtomIndex ) :
50+ return radical . Radicand . InsertAndAdvance ( subIndex , atom , advanceType ) . Wrap ( index . AtomIndex , MathListSubIndexType . Radicand ) ;
5151 case ( MathListSubIndexType . Numerator , var subIndex )
5252 when self . Atoms [ index . AtomIndex ] is Atoms . Fraction frac ? true
53- : throw new SubIndexTypeMismatchException ( typeof ( Atoms . Fraction ) , index ) :
54- return frac . Numerator . InsertAndAdvance ( subIndex , atom , advanceType ) . WrapInIndex ( index . AtomIndex , MathListSubIndexType . Numerator ) ;
53+ : throw new SubIndexTypeMismatchException ( nameof ( Atoms . Fraction ) , index . AtomIndex ) :
54+ return frac . Numerator . InsertAndAdvance ( subIndex , atom , advanceType ) . Wrap ( index . AtomIndex , MathListSubIndexType . Numerator ) ;
5555 case ( MathListSubIndexType . Denominator , var subIndex )
5656 when self . Atoms [ index . AtomIndex ] is Atoms . Fraction frac ? true
57- : throw new SubIndexTypeMismatchException ( typeof ( Atoms . Fraction ) , index ) :
58- return frac . Denominator . InsertAndAdvance ( subIndex , atom , advanceType ) . WrapInIndex ( index . AtomIndex , MathListSubIndexType . Denominator ) ;
57+ : throw new SubIndexTypeMismatchException ( nameof ( Atoms . Fraction ) , index . AtomIndex ) :
58+ return frac . Denominator . InsertAndAdvance ( subIndex , atom , advanceType ) . Wrap ( index . AtomIndex , MathListSubIndexType . Denominator ) ;
5959 case ( MathListSubIndexType . Subscript , var subIndex ) :
60- return self . Atoms [ index . AtomIndex ] . Subscript . InsertAndAdvance ( subIndex , atom , advanceType ) . WrapInIndex ( index . AtomIndex , MathListSubIndexType . Subscript ) ;
60+ return self . Atoms [ index . AtomIndex ] . Subscript . InsertAndAdvance ( subIndex , atom , advanceType ) . Wrap ( index . AtomIndex , MathListSubIndexType . Subscript ) ;
6161 case ( MathListSubIndexType . Superscript , var subIndex ) :
62- return self . Atoms [ index . AtomIndex ] . Superscript . InsertAndAdvance ( subIndex , atom , advanceType ) . WrapInIndex ( index . AtomIndex , MathListSubIndexType . Superscript ) ;
62+ return self . Atoms [ index . AtomIndex ] . Superscript . InsertAndAdvance ( subIndex , atom , advanceType ) . Wrap ( index . AtomIndex , MathListSubIndexType . Superscript ) ;
6363 case ( MathListSubIndexType . Inner , var subIndex )
6464 when self . Atoms [ index . AtomIndex ] is Atoms . Inner inner ? true
65- : throw new SubIndexTypeMismatchException ( typeof ( Atoms . Fraction ) , index ) :
66- return inner . InnerList . InsertAndAdvance ( subIndex , atom , advanceType ) . WrapInIndex ( index . AtomIndex , MathListSubIndexType . Inner ) ;
67- default :
68- throw new SubIndexTypeMismatchException ( index ) ;
65+ : throw new SubIndexTypeMismatchException ( nameof ( Atoms . Inner ) , index . AtomIndex ) :
66+ return inner . InnerList . InsertAndAdvance ( subIndex , atom , advanceType ) . Wrap ( index . AtomIndex , MathListSubIndexType . Inner ) ;
67+ case ( var type , _ ) :
68+ throw new ArgumentOutOfRangeException ( nameof ( index ) , type , "Index type out of valid range." ) ;
6969 }
7070 }
7171 /// <summary>Removes the atom at <paramref name="index"/>, placing a new placeholder if all atoms removed, and returns a new <see cref="MathListIndex"/> with <paramref name="index"/> advanced to the next position indicated by <paramref name="advanceType"/>.</summary>
@@ -79,7 +79,7 @@ public static MathListIndex RemoveAt(this MathList self, MathListIndex index) {
7979 case ( MathListSubIndexType . BetweenBaseAndScripts , _ ) :
8080 var currentAtom = self . Atoms [ index . AtomIndex ] ;
8181 if ( currentAtom . Subscript . IsEmpty ( ) && currentAtom . Superscript . IsEmpty ( ) )
82- throw new SubIndexTypeMismatchException ( index ) ;
82+ throw new SubIndexTypeMismatchException ( nameof ( MathListSubIndexType . BetweenBaseAndScripts ) , index . AtomIndex ) ;
8383 var downIndex = index . LevelDown ( ) ?? throw new InvalidCodePathException ( "downIndex is null" ) ;
8484 if ( index . AtomIndex > 0 &&
8585 self . Atoms [ index . AtomIndex - 1 ] is MathAtom previous &&
@@ -112,43 +112,43 @@ public static MathListIndex RemoveAt(this MathList self, MathListIndex index) {
112112 return index . Previous ?? throw new InvalidCodePathException ( "Cannot go back after insertion?" ) ;
113113 case ( MathListSubIndexType . Degree , var subIndex )
114114 when self . Atoms [ index . AtomIndex ] is Atoms . Radical radical ? true
115- : throw new SubIndexTypeMismatchException ( typeof ( Atoms . Radical ) , index ) :
116- index = radical . Degree . RemoveAt ( subIndex ) . WrapInIndex ( index . AtomIndex , MathListSubIndexType . Degree ) ;
115+ : throw new SubIndexTypeMismatchException ( nameof ( Atoms . Radical ) , index . AtomIndex ) :
116+ index = radical . Degree . RemoveAt ( subIndex ) . Wrap ( index . AtomIndex , MathListSubIndexType . Degree ) ;
117117 break ;
118118 case ( MathListSubIndexType . Radicand , var subIndex )
119119 when self . Atoms [ index . AtomIndex ] is Atoms . Radical radical ? true
120- : throw new SubIndexTypeMismatchException ( typeof ( Atoms . Radical ) , index ) :
121- index = radical . Radicand . RemoveAt ( subIndex ) . WrapInIndex ( index . AtomIndex , MathListSubIndexType . Radicand ) ;
120+ : throw new SubIndexTypeMismatchException ( nameof ( Atoms . Radical ) , index . AtomIndex ) :
121+ index = radical . Radicand . RemoveAt ( subIndex ) . Wrap ( index . AtomIndex , MathListSubIndexType . Radicand ) ;
122122 break ;
123123 case ( MathListSubIndexType . Numerator , var subIndex )
124124 when self . Atoms [ index . AtomIndex ] is Atoms . Fraction frac ? true
125- : throw new SubIndexTypeMismatchException ( typeof ( Atoms . Fraction ) , index ) :
126- index = frac . Numerator . RemoveAt ( subIndex ) . WrapInIndex ( index . AtomIndex , MathListSubIndexType . Numerator ) ;
125+ : throw new SubIndexTypeMismatchException ( nameof ( Atoms . Fraction ) , index . AtomIndex ) :
126+ index = frac . Numerator . RemoveAt ( subIndex ) . Wrap ( index . AtomIndex , MathListSubIndexType . Numerator ) ;
127127 break ;
128128 case ( MathListSubIndexType . Denominator , var subIndex )
129129 when self . Atoms [ index . AtomIndex ] is Atoms . Fraction frac ? true
130- : throw new SubIndexTypeMismatchException ( typeof ( Atoms . Fraction ) , index ) :
131- index = frac . Denominator . RemoveAt ( subIndex ) . WrapInIndex ( index . AtomIndex , MathListSubIndexType . Denominator ) ;
130+ : throw new SubIndexTypeMismatchException ( nameof ( Atoms . Fraction ) , index . AtomIndex ) :
131+ index = frac . Denominator . RemoveAt ( subIndex ) . Wrap ( index . AtomIndex , MathListSubIndexType . Denominator ) ;
132132 break ;
133133 case ( MathListSubIndexType . Subscript , var subIndex ) :
134134 var current = self . Atoms [ index . AtomIndex ] ;
135135 if ( current . Subscript . IsEmpty ( ) )
136- throw new SubIndexTypeMismatchException ( index ) ;
137- index = current . Subscript . RemoveAt ( subIndex ) . WrapInIndex ( index . AtomIndex , MathListSubIndexType . Subscript ) ;
136+ throw new SubIndexTypeMismatchException ( nameof ( MathListSubIndexType . Subscript ) , index . AtomIndex ) ;
137+ index = current . Subscript . RemoveAt ( subIndex ) . Wrap ( index . AtomIndex , MathListSubIndexType . Subscript ) ;
138138 break ;
139139 case ( MathListSubIndexType . Superscript , var subIndex ) :
140140 current = self . Atoms [ index . AtomIndex ] ;
141141 if ( current . Superscript . IsEmpty ( ) )
142- throw new SubIndexTypeMismatchException ( index ) ;
143- index = current . Superscript . RemoveAt ( subIndex ) . WrapInIndex ( index . AtomIndex , MathListSubIndexType . Superscript ) ;
142+ throw new SubIndexTypeMismatchException ( nameof ( MathListSubIndexType . Superscript ) , index . AtomIndex ) ;
143+ index = current . Superscript . RemoveAt ( subIndex ) . Wrap ( index . AtomIndex , MathListSubIndexType . Superscript ) ;
144144 break ;
145145 case ( MathListSubIndexType . Inner , var subIndex )
146146 when self . Atoms [ index . AtomIndex ] is Atoms . Inner inner ? true
147- : throw new SubIndexTypeMismatchException ( typeof ( Atoms . Inner ) , index ) :
148- index = inner . InnerList . RemoveAt ( subIndex ) . WrapInIndex ( index . AtomIndex , MathListSubIndexType . Inner ) ;
147+ : throw new SubIndexTypeMismatchException ( nameof ( Atoms . Inner ) , index . AtomIndex ) :
148+ index = inner . InnerList . RemoveAt ( subIndex ) . Wrap ( index . AtomIndex , MathListSubIndexType . Inner ) ;
149149 break ;
150- default :
151- throw new SubIndexTypeMismatchException ( index ) ;
150+ case ( var type , _ ) :
151+ throw new ArgumentOutOfRangeException ( nameof ( index ) , type , "Index type out of valid range." ) ;
152152 }
153153 if ( index . Previous is null && index . SubIndexInfo is { } )
154154 // We have deleted to the beginning of the line and it is not the outermost line
@@ -168,37 +168,37 @@ public static void RemoveAtoms(this MathList self, MathListRange? nullableRange)
168168 throw new NotSupportedException ( "Nuclear fission is not supported" ) ;
169169 case ( MathListSubIndexType . Degree , _ )
170170 when self . Atoms [ start . AtomIndex ] is Atoms . Radical radical ? true
171- : throw new SubIndexTypeMismatchException ( typeof ( Atoms . Radical ) , start ) :
171+ : throw new SubIndexTypeMismatchException ( nameof ( Atoms . Radical ) , start . AtomIndex ) :
172172 radical . Degree . RemoveAtoms ( range . SubIndexRange ) ;
173173 break ;
174174 case ( MathListSubIndexType . Radicand , _ )
175175 when self . Atoms [ start . AtomIndex ] is Atoms . Radical radical ? true
176- : throw new SubIndexTypeMismatchException ( typeof ( Atoms . Radical ) , start ) :
176+ : throw new SubIndexTypeMismatchException ( nameof ( Atoms . Radical ) , start . AtomIndex ) :
177177 radical . Radicand . RemoveAtoms ( range . SubIndexRange ) ;
178178 break ;
179179 case ( MathListSubIndexType . Numerator , _ )
180180 when self . Atoms [ start . AtomIndex ] is Atoms . Fraction frac ? true
181- : throw new SubIndexTypeMismatchException ( typeof ( Atoms . Fraction ) , start ) :
181+ : throw new SubIndexTypeMismatchException ( nameof ( Atoms . Fraction ) , start . AtomIndex ) :
182182 frac . Numerator . RemoveAtoms ( range . SubIndexRange ) ;
183183 break ;
184- case ( MathListSubIndexType . Radicand , _ )
184+ case ( MathListSubIndexType . Denominator , _ )
185185 when self . Atoms [ start . AtomIndex ] is Atoms . Fraction frac ? true
186- : throw new SubIndexTypeMismatchException ( typeof ( Atoms . Fraction ) , start ) :
186+ : throw new SubIndexTypeMismatchException ( nameof ( Atoms . Fraction ) , start . AtomIndex ) :
187187 frac . Denominator . RemoveAtoms ( range . SubIndexRange ) ;
188188 break ;
189189 case ( MathListSubIndexType . Subscript , _ ) :
190190 var current = self . Atoms [ start . AtomIndex ] ;
191- if ( current . Subscript . IsEmpty ( ) ) throw new SubIndexTypeMismatchException ( start ) ;
191+ if ( current . Subscript . IsEmpty ( ) ) throw new SubIndexTypeMismatchException ( nameof ( MathListSubIndexType . Subscript ) , start . AtomIndex ) ;
192192 current . Subscript . RemoveAtoms ( range . SubIndexRange ) ;
193193 break ;
194194 case ( MathListSubIndexType . Superscript , _ ) :
195195 current = self . Atoms [ start . AtomIndex ] ;
196- if ( current . Superscript . IsEmpty ( ) ) throw new SubIndexTypeMismatchException ( start ) ;
196+ if ( current . Superscript . IsEmpty ( ) ) throw new SubIndexTypeMismatchException ( nameof ( MathListSubIndexType . Superscript ) , start . AtomIndex ) ;
197197 current . Superscript . RemoveAtoms ( range . SubIndexRange ) ;
198198 break ;
199199 case ( MathListSubIndexType . Inner , _ )
200200 when self . Atoms [ start . AtomIndex ] is Atoms . Inner inner ? true
201- : throw new SubIndexTypeMismatchException ( typeof ( Atoms . Fraction ) , start ) :
201+ : throw new SubIndexTypeMismatchException ( nameof ( Atoms . Inner ) , start . AtomIndex ) :
202202 inner . InnerList . RemoveAtoms ( range . SubIndexRange ) ;
203203 break ;
204204 }
@@ -217,7 +217,7 @@ when self.Atoms[start.AtomIndex] is Atoms.Inner inner ? true
217217 ( MathListSubIndexType . Numerator , var subIndex ) => atom is Atoms . Fraction frac ? frac . Numerator . AtomAt ( subIndex ) : null ,
218218 ( MathListSubIndexType . Denominator , var subIndex ) => atom is Atoms . Fraction frac ? frac . Denominator . AtomAt ( subIndex ) : null ,
219219 ( MathListSubIndexType . Inner , var subIndex ) => atom is Atoms . Inner inner ? inner . InnerList . AtomAt ( subIndex ) : null ,
220- _ => throw new SubIndexTypeMismatchException ( index ) ,
220+ ( var type , _ ) => throw new ArgumentOutOfRangeException ( nameof ( index ) , type , "Index type out of valid range." ) ,
221221 } ;
222222 }
223223 }
0 commit comments