PageRenderTime 19ms CodeModel.GetById 14ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/NRefactory/ICSharpCode.NRefactory.CSharp/Refactoring/TextReplaceAction.cs

http://github.com/icsharpcode/ILSpy
C# | 134 lines | 43 code | 7 blank | 84 comment | 4 complexity | acb6471cf05005f4224aff49206b6246 MD5 | raw file
  1// 
  2// TextReplaceChange.cs
  3//  
  4// Author:
  5//       Mike Kr?ger <mkrueger@novell.com>
  6// 
  7// Copyright (c) 2011 Mike Kr?ger <mkrueger@novell.com>
  8// 
  9// Permission is hereby granted, free of charge, to any person obtaining a copy
 10// of this software and associated documentation files (the "Software"), to deal
 11// in the Software without restriction, including without limitation the rights
 12// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 13// copies of the Software, and to permit persons to whom the Software is
 14// furnished to do so, subject to the following conditions:
 15// 
 16// The above copyright notice and this permission notice shall be included in
 17// all copies or substantial portions of the Software.
 18// 
 19// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 20// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 21// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 22// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 23// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 24// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 25// THE SOFTWARE.
 26
 27using System;
 28
 29namespace ICSharpCode.NRefactory.CSharp.Refactoring
 30{
 31	/// <summary>
 32	/// This is the base action for changes in a text document.
 33	/// </summary>
 34	public abstract class TextReplaceAction : Action
 35	{
 36		/// <summary>
 37		/// Gets or sets the offset.
 38		/// </summary>
 39		/// <value>
 40		/// The offset of the replace.
 41		/// </value>
 42		public int Offset {
 43			get;
 44			set;
 45		}
 46		
 47		int removedChars;
 48		/// <summary>
 49		/// Gets or sets the numer of chars to removed.
 50		/// </summary>
 51		/// <value>
 52		/// The numer of chars to remove.
 53		/// </value>
 54		/// <exception cref='ArgumentOutOfRangeException'>
 55		/// Is thrown when an argument passed to a method is invalid because it is outside the allowable range of values as
 56		/// specified by the method.
 57		/// </exception>
 58		public int RemovedChars {
 59			get { 
 60				return removedChars; 
 61			}
 62			set {
 63				if (value < 0)
 64					throw new ArgumentOutOfRangeException ("RemovedChars", "needs to be >= 0");
 65				removedChars = value; 
 66			}
 67		}
 68		
 69		/// <summary>
 70		/// Gets or sets the inserted text.
 71		/// </summary>
 72		/// <value>
 73		/// The text to insert.
 74		/// </value>
 75		public virtual string InsertedText {
 76			get;
 77			set;
 78		}
 79		
 80		/// <summary>
 81		/// Initializes a new instance of the <see cref="ICSharpCode.NRefactory.CSharp.Refactoring.TextReplaceAction"/> class.
 82		/// </summary>
 83		/// <param name='offset'>
 84		/// The offset of the replace.
 85		/// </param>
 86		/// <param name='removedChars'>
 87		/// The numer of chars to remove.
 88		/// </param>
 89		/// <exception cref='ArgumentOutOfRangeException'>
 90		/// Is thrown when an argument passed to a method is invalid because it is outside the allowable range of values as
 91		/// specified by the method.
 92		/// </exception>
 93		protected TextReplaceAction (int offset, int removedChars)
 94		{
 95			if (removedChars < 0)
 96				throw new ArgumentOutOfRangeException ("removedChars", "removedChars needs to be >= 0");
 97			if (offset < 0)
 98				throw new ArgumentOutOfRangeException ("offset", "offset needs to be >= 0");
 99			this.removedChars = removedChars;
100			this.Offset = offset;
101		}
102		
103		/// <summary>
104		/// Initializes a new instance of the <see cref="ICSharpCode.NRefactory.CSharp.Refactoring.TextReplaceAction"/> class.
105		/// </summary>
106		/// <param name='offset'>
107		/// The offset of the replace.
108		/// </param>
109		/// <param name='removedChars'>
110		/// The numer of chars to remove.
111		/// </param>
112		/// <param name='insertedText'>
113		/// The text to insert.
114		/// </param>
115		/// <exception cref='ArgumentOutOfRangeException'>
116		/// Is thrown when an argument passed to a method is invalid because it is outside the allowable range of values as
117		/// specified by the method.
118		public TextReplaceAction (int offset, int removedChars, string insertedText) : this (offset, removedChars)
119		{ 
120			this.InsertedText = insertedText;
121		}
122		
123		/// <summary>
124		/// Returns a <see cref="System.String"/> that represents the current <see cref="ICSharpCode.NRefactory.CSharp.Refactoring.TextReplaceAction"/>.
125		/// </summary>
126		/// <returns>
127		/// A <see cref="System.String"/> that represents the current <see cref="ICSharpCode.NRefactory.CSharp.Refactoring.TextReplaceAction"/>.
128		/// </returns>
129		public override string ToString ()
130		{
131			return string.Format ("[TextReplaceAction: Offset={0}, RemovedChars={1}, InsertedText={2}]", Offset, RemovedChars, InsertedText == null ? "<null>" : InsertedText.Replace ("\t", "\\t").Replace ("\n", "\\n").Replace ("\r", "\\r"));
132		}
133	}
134}