22
33namespace Microsoft . Windows . PowerShell . ScriptAnalyzer
44{
5+ // TODO instead of deriving from Range, make Range a member type.
56 /// <summary>
67 /// Class to provide information about an edit
78 /// </summary>
8- public class TextEdit
9+ public class TextEdit : Range
910 {
1011 /// <summary>
1112 /// 1-based line number on which the text, which needs to be replaced, starts.
1213 /// </summary>
13- public int StartLineNumber { get ; }
14+ public int StartLineNumber { get { return this . Start . Line ; } }
1415
1516 /// <summary>
1617 /// 1-based offset on start line at which the text, which needs to be replaced, starts.
1718 /// This includes the first character of the text.
1819 /// </summary>
19- public int StartColumnNumber { get ; }
20+ public int StartColumnNumber { get { return this . Start . Column ; } }
2021
2122 /// <summary>
2223 /// 1-based line number on which the text, which needs to be replace, ends.
2324 /// </summary>
24- public int EndLineNumber { get ; }
25+ public int EndLineNumber { get { return this . End . Line ; } }
2526
2627 /// <summary>
2728 /// 1-based offset on end line at which the text, which needs to be replaced, ends.
2829 /// This offset value is 1 more than the offset of the last character of the text.
2930 /// </summary>
30- public int EndColumnNumber { get ; }
31+ public int EndColumnNumber { get { return this . End . Column ; } }
3132
3233 /// <summary>
3334 /// The text that will replace the text bounded by the Line/Column number properties.
@@ -48,47 +49,12 @@ public TextEdit(
4849 int endLineNumber ,
4950 int endColumnNumber ,
5051 string newText )
52+ : base ( startLineNumber , startColumnNumber , endLineNumber , endColumnNumber )
5153 {
52- StartLineNumber = startLineNumber ;
53- StartColumnNumber = startColumnNumber ;
54- EndLineNumber = endLineNumber ;
55- EndColumnNumber = endColumnNumber ;
5654 Text = newText ;
57- ThrowIfInvalidArguments ( ) ;
5855 }
5956
60- private void ThrowIfInvalidArguments ( )
61- {
62- ThrowIfNull < string > ( Text , "text" ) ;
6357
64- // TODO Localize
65- ThrowIfDecreasing (
66- StartLineNumber ,
67- EndLineNumber ,
68- "start line number cannot be less than end line number" ) ;
69- if ( StartLineNumber == EndLineNumber )
70- {
71- ThrowIfDecreasing (
72- StartColumnNumber ,
73- EndColumnNumber ,
74- "start column number cannot be less than end column number for a one line extent" ) ;
75- }
76- }
7758
78- private void ThrowIfDecreasing ( int start , int end , string message )
79- {
80- if ( start > end )
81- {
82- throw new ArgumentException ( message ) ;
83- }
84- }
85-
86- private void ThrowIfNull < T > ( T arg , string argName )
87- {
88- if ( arg == null )
89- {
90- throw new ArgumentNullException ( argName ) ;
91- }
92- }
9359 }
9460}
0 commit comments