internal Hyperlink(FieldStart fieldStart)
{
if (fieldStart == null)
throw new ArgumentNullException("fieldStart");
if (!fieldStart.FieldType.Equals(FieldType.FieldHyperlink))
throw new ArgumentException("Field start type must be FieldHyperlink.");
this.mFieldStart = fieldStart;
// Find the field separator node.
this.mFieldSeparator = FindNextSibling(this.mFieldStart, NodeType.FieldSeparator);
if (this.mFieldSeparator == null)
throw new InvalidOperationException("Cannot find field separator.");
// Find the field end node. Normally field end will always be found, but in the example document
// there happens to be a paragraph break included in the hyperlink and this puts the field end
// in the next paragraph. It will be much more complicated to handle fields which span several
// paragraphs correctly, but in this case allowing field end to be null is enough for our purposes.
this.mFieldEnd = FindNextSibling(this.mFieldSeparator, NodeType.FieldEnd);
// Field code looks something like [ HYPERLINK "http:\\www.myurl.com" ], but it can consist of several runs.
string fieldCode = GetTextSameParent(this.mFieldStart.NextSibling, this.mFieldSeparator);
Match match = gRegex.Match(fieldCode.Trim());
this.mIsLocal = (match.Groups[1].Length > 0); //The link is local if \l is present in the field code.
this.mTarget = match.Groups[2].Value;
}