public FindParagraph ( String id, bool create ) : Paragraph | ||
id | String | The id of the paragraph to find |
create | bool | If true, creates the paragraph tree if needed |
return | Paragraph |
/// <summary> /// Looks for a specific paragraph /// </summary> /// <param name="id">The id of the paragraph to find</param> /// <param name="create">If true, creates the paragraph tree if needed</param> /// <returns></returns> public Paragraph FindParagraph(String id, bool create) { Paragraph retVal = null; if (String.Compare(getId(), id, StringComparison.Ordinal) == 0) { retVal = this; } else { if ((id.StartsWith(FullId) && id[FullId.Length] == '.') || !create) { foreach (Paragraph sub in SubParagraphs) { retVal = sub.FindParagraph(id, create); if (retVal != null) { break; } } if (retVal == null && create) { retVal = (Paragraph)acceptor.getFactory().createParagraph(); string subId = id.Substring(FullId.Length + 1); string[] items = subId.Split('.'); if (items.Length > 0) { retVal.setId(FullId + "." + items[0]); appendParagraphs(retVal); if (retVal.getId().Length < id.Length) { // ReSharper disable once ConditionIsAlwaysTrueOrFalse retVal = retVal.FindParagraph(id, create); } } } } } return(retVal); }
/// <summary> /// Looks for a specific paragraph /// </summary> /// <param name="id">The id of the paragraph to find</param> /// <param name="create">If true, creates the paragraph tree if needed</param> /// <returns></returns> public Paragraph FindParagraph(String id, bool create) { Paragraph retVal = null; if (getId().CompareTo(id) == 0) { retVal = this; } else { if ((id.StartsWith(FullId) && id[FullId.Length] == '.') || !create) { foreach (Paragraph sub in SubParagraphs) { retVal = sub.FindParagraph(id, create); if (retVal != null) { break; } } } } if (retVal == null && create) { retVal = (Paragraph)Generated.acceptor.getFactory().createParagraph(); string subId = id.Substring(FullId.Length); string[] items = subId.Split('.'); if (items.Length > 0) { retVal.setId(FullId + "." + items[0]); appendParagraphs(retVal); if (retVal.getId().Length < id.Length) { retVal = retVal.FindParagraph(id, create); } } } return(retVal); }