Show / Hide Table of Contents

Class CKRange

Represents a simple wrapper for the Word.Range object. Provides caching of text and boundary values for robust equality and hash code calculations, even if the underlying COM object becomes orphaned.

Inheritance
object
CKRange
CKParagraph
CKSection
CKCell
CKTable
Implements
IDOMObject
IDisposable
Inherited Members
object.ToString()
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetType()
object.MemberwiseClone()
Namespace: CoverageKiller2.DOM
Assembly: CoverageKiller2.dll
Syntax
public class CKRange : IDOMObject, IDisposable

Constructors

CKRange(IDOMObject, bool, string)

Declaration
public CKRange(IDOMObject parent, bool deferCom = true, string caller = "")
Parameters
Type Name Description
IDOMObject parent
bool deferCom
string caller

CKRange(Range, IDOMObject, bool, string)

Initializes a new instance of the CKRange class.

Declaration
public CKRange(Range range, IDOMObject parent, bool deferCom = false, string caller = "")
Parameters
Type Name Description
Range range

The Word.Range object to wrap.

IDOMObject parent

Parent DOM object; if not provided, will be looked up via CKDocuments.

bool deferCom
string caller
Exceptions
Type Condition
ArgumentNullException

Thrown when the range parameter is null.

Fields

_isRefreshing

Declaration
public bool _isRefreshing
Field Value
Type Description
bool

Properties

Application

Gets the Word application managing the document.

Declaration
public CKApplication Application { get; }
Property Value
Type Description
CKApplication

COMRange

Gets the underlying Word.Range COM object.

Declaration
[Obsolete("Planned for privatization")]
public Range COMRange { get; protected set; }
Property Value
Type Description
Range

Cells

1 based list.

Declaration
public CKCells Cells { get; }
Property Value
Type Description
CKCells

Document

Gets the document associated with this CKRange.

Declaration
public CKDocument Document { get; }
Property Value
Type Description
CKDocument

End

Gets the ending position of the range.

Declaration
public int End { get; }
Property Value
Type Description
int

Font

unsage.

Declaration
public Font Font { get; set; }
Property Value
Type Description
Font

FormattedText

Gets or sets the formatted text for this range. Setting this value replaces the contents and formatting of the range.

Declaration
public CKRange FormattedText { get; set; }
Property Value
Type Description
CKRange

IsCOMDeferred

Declaration
public bool IsCOMDeferred { get; }
Property Value
Type Description
bool

IsDirty

Indicates whether this DOM object has unsaved changes.

Declaration
public virtual bool IsDirty { get; set; }
Property Value
Type Description
bool

IsOrphan

Gets a value indicating whether this CKRange is orphaned, i.e. its underlying COMRange is no longer valid.

Declaration
public bool IsOrphan { get; }
Property Value
Type Description
bool

Paragraphs

Gets the paragraphs contained in the range.

Declaration
public CKParagraphs Paragraphs { get; }
Property Value
Type Description
CKParagraphs

Parent

Gets the parent DOM object.

Declaration
public IDOMObject Parent { get; protected set; }
Property Value
Type Description
IDOMObject

PrettyText

Gets a "pretty" version of the range's text. This version replaces cell markers with tabs, preserves Windows-style newlines, and removes extraneous control characters.

Declaration
public string PrettyText { get; }
Property Value
Type Description
string

ScrunchedText

Gets the scrunched version of the range's text, i.e. all whitespace removed, for reliable comparisons.

Declaration
public string ScrunchedText { get; }
Property Value
Type Description
string

Sections

Gets the sections contained in the range.

Declaration
public CKSections Sections { get; }
Property Value
Type Description
CKSections

Snapshot

Declaration
public RangeSnapshot Snapshot { get; }
Property Value
Type Description
RangeSnapshot

Start

Gets the starting position of the range.

Declaration
public int Start { get; }
Property Value
Type Description
int

Tables

Gets the tables contained in the range.

Declaration
public CKTables Tables { get; }
Property Value
Type Description
CKTables
Remarks

Parent of a Tables collection is ALWAYS the document.

Text

Gets the raw text of the range as returned by Word without caching.

Declaration
public string Text { get; set; }
Property Value
Type Description
string

Methods

Cache<T>(ref T)

Declaration
protected T Cache<T>(ref T cachedField)
Parameters
Type Name Description
T cachedField
Returns
Type Description
T
Type Parameters
Name Description
T

Cache<T>(ref T, Func<T>)

Declaration
protected T Cache<T>(ref T cachedField, Func<T> refreshFunc)
Parameters
Type Name Description
T cachedField
Func<T> refreshFunc
Returns
Type Description
T
Type Parameters
Name Description
T

CheckDirtyFor()

Declaration
protected virtual bool CheckDirtyFor()
Returns
Type Description
bool

CollapseToEnd()

Returns a new CKRange collapsed to the end of this range.

Declaration
public CKRange CollapseToEnd()
Returns
Type Description
CKRange

A new CKRange positioned at the end of this range.

Remarks

Version: CK2.00.01.0015

CollapseToStart()

Returns a new CKRange collapsed to the start of this range.

Declaration
public CKRange CollapseToStart()
Returns
Type Description
CKRange

A new CKRange positioned at the start of this range.

Remarks

Version: CK2.00.01.0016

Contains(CKRange)

Determines whether this range fully contains the specified range.

Declaration
public bool Contains(CKRange other)
Parameters
Type Name Description
CKRange other

The range to check for containment.

Returns
Type Description
bool

True if the other range is entirely within this range; otherwise, false.

Remarks

Version: CK2.00.01.0002

Delete(CKTables)

Deletes all tables in the specified CKTables collection that fall within this range.

Declaration
public void Delete(CKTables tables)
Parameters
Type Name Description
CKTables tables

The collection of tables to consider for deletion.

Remarks

Version: CK2.00.01.0001

Exceptions
Type Condition
ArgumentNullException

Thrown if tables is null.

Dispose(bool)

Declaration
protected virtual void Dispose(bool disposing)
Parameters
Type Name Description
bool disposing

DoRefreshThings()

Declaration
protected virtual void DoRefreshThings()

Equals(CKRange)

Declaration
public bool Equals(CKRange other)
Parameters
Type Name Description
CKRange other
Returns
Type Description
bool

Equals(object)

Declaration
public override bool Equals(object obj)
Parameters
Type Name Description
object obj
Returns
Type Description
bool
Overrides
object.Equals(object)

GetHashCode()

Declaration
public override int GetHashCode()
Returns
Type Description
int
Overrides
object.GetHashCode()

SetBackgroundColor(WdColor)

Sets the background color for all cells in this range if present, or for the range itself if no cells exist.

Declaration
public void SetBackgroundColor(WdColor color)
Parameters
Type Name Description
WdColor color

The Word color to apply.

Remarks

Version: CK2.00.01.0003

SetCache<T>(ref T, T, Action<T>)

Sets a cached field value, updates the underlying COM object, and marks the object dirty to force revalidation of related caches.

Declaration
protected void SetCache<T>(ref T cachedField, T value, Action<T> comSetter)
Parameters
Type Name Description
T cachedField

Reference to the cached field to update.

T value

The new value to set.

Action<T> comSetter

An action that sets the underlying COM object. Must not be null.

Type Parameters
Name Description
T

The type of the cached field.

TryFindNext(string, bool, bool, bool)

Attempts to find the next occurrence of the specified text using Word's Find functionality.

Declaration
public CKRange TryFindNext(string text, bool matchWildcards = false, bool matchCase = false, bool matchWholeWord = false)
Parameters
Type Name Description
string text

The text to search for.

bool matchWildcards

Whether to enable wildcard matching.

bool matchCase

Whether to perform a case-sensitive search.

bool matchWholeWord

Whether to match the whole word only.

Returns
Type Description
CKRange

A new CKRange containing the match if found; otherwise, null.

Remarks

Version: CK2.00.01.0034

Operators

operator ==(CKRange, CKRange)

Declaration
public static bool operator ==(CKRange left, CKRange right)
Parameters
Type Name Description
CKRange left
CKRange right
Returns
Type Description
bool

operator !=(CKRange, CKRange)

Declaration
public static bool operator !=(CKRange left, CKRange right)
Parameters
Type Name Description
CKRange left
CKRange right
Returns
Type Description
bool

Implements

IDOMObject
IDisposable

Extension Methods

PingService.PingPong<T>(T, string)
PingService.PingPong<T>(T, string, string)
PingService.PingPong<T, TResult>(T, Func<TResult>, string, string)
PingService.Ping<T>(T, string)
PingService.Ping<T>(T, string, string)
PingService.Ping<T>(T, Type[], string)
PingService.Pong<T>(T, string)
PingService.Pong<T>(T, string, string)
PingService.Pong<T>(T, Type, string)
PingService.Pong<T>(T, Type[], string)
PingService.Pong<T, TResult>(T, Func<TResult>, string, string)
In this article
Back to top Generated by DocFX