Microsoft.Cci.SourceLocation.CopyTo C# (CSharp) Method

CopyTo() public method

Copies the specified number of characters to the destination character array, starting at the specified offset from the start if the source location. Returns the number of characters actually copied. This number will be greater than zero as long as position is less than this.Length. The number will be precisely the number asked for unless there are not enough characters left in the document.
public CopyTo ( int offset, char destination, int destinationOffset, int length ) : int
offset int The starting index to copy from. Must be greater than zero and less than this.Length.
destination char The destination array. Must have at least destinationOffset+length elements.
destinationOffset int The starting index where the characters must be copied to in the destination array.
length int The maximum number of characters to copy. Cannot be more than this.Length-position.
return int
    public virtual int CopyTo(int offset, char[] destination, int destinationOffset, int length)
      //^^ requires 0 <= offset;
      //^^ requires 0 <= destinationOffset;
      //^^ requires 0 <= length;
      //^^ requires 0 <= offset+length;
      //^^ requires 0 <= destinationOffset+length;
      //^^ requires destinationOffset+length <= destination.Length;
      //^^ ensures 0 <= result && result <= length && offset+result <= this.Length;
      //^^ ensures result < length ==> offset+result == this.Length;
    {
      if (offset + length > this.Length) length = this.Length - offset;
      ISourceDocument sourceDocument = this.SourceDocument;
      //^ assume 0 <= length; //follows from the preconditions
      int position = this.startIndex + offset;
      //^ assume position <= sourceDocument.Length; //follows from invariant 
      int result = sourceDocument.CopyTo(position, destination, destinationOffset, length);
      //^ assert 0 <= result;
      //^ assume offset+length <= this.Length; //follows from the precondition
      //^ assert result <= length;
      //^ assert offset+result <= this.Length;
      //^ assume false; //unsatisfied postcondition: ensures 0 <= result && result <= length && offset+result <= this.Length;
      return result;
    }