Example #1
0
        public static ElementLocator Parse(string str)
        {
            int ichColon = str.IndexOf(':');

            if (ichColon < 0)
            {
                string message = string.Format(Resources.ElementLocator_Parse__0__is_not_a_valid_element_locator_, str);
                throw new FormatException(message);
            }
            var            type         = str.Substring(0, ichColon);
            ElementLocator result       = null;
            var            stringReader = new StringReader(str);

            stringReader.Read(new char[ichColon + 1], 0, ichColon + 1);
            foreach (var elementLocator in ParseParts(stringReader))
            {
                result = elementLocator.ChangeParent(result);
            }
            if (result == null)
            {
                string message = string.Format(Resources.ElementLocator_Parse__0__is_not_a_valid_element_locator_, str);
                throw new FormatException(message);
            }
            result = result.ChangeType(type);
            return(result);
        }
Example #2
0
 /// <summary>
 /// Returns an ElementLocator with the new parent.
 /// The parent's Type is changed to null, since only the child ElementLocator has a type. The type of its parent
 /// can be inferred from the type of the child.
 /// </summary>
 public ElementLocator ChangeParent(ElementLocator parent)
 {
     if (ReferenceEquals(Parent, parent))
     {
         return(this);
     }
     if (parent != null && parent.Type != null)
     {
         parent = parent.ChangeType(null);
     }
     return(ChangeProp(ImClone(this), im => im.Parent = parent));
 }