/// <summary> /// Gets data from the section. /// Returns null if not found. /// </summary> /// <param name="key">The key to get data from.</param> /// <returns>The data found, or null.</returns> public FDSData GetDataLowered(string key) { key = key.ToLowerFast(); int lind = key.LastIndexOf(SectionPathSplit); if (lind < 0) { return(GetRootDataLowered(key)); } if (lind == key.Length - 1) { return(null); } FDSSection sec = GetSectionInternal(key.Substring(0, lind), true, true); if (sec == null) { return(null); } return(sec.GetRootDataLowered(key.Substring(lind + 1))); }
/// <summary> /// Gets a sub-section of this FDS section. /// </summary> /// <param name="key">The key of the section.</param> /// <param name="allowNull">Whether to allow null returns, otherwise enforce the section's existence. If true, can throw an FDSInputException!</param> /// <param name="lowered">Whether to read lowercase section names. If set, expects lowercased input key!</param> /// <returns>The subsection.</returns> private FDSSection GetSectionInternal(string key, bool allowNull, bool lowered) { if (key == null || key.Length == 0) { return(this); } string[] dat = key.SplitFast(SectionPathSplit); FDSSection current = this; for (int i = 0; i < dat.Length; i++) { FDSData fdat = lowered ? current.GetRootDataLowered(dat[i]) : current.GetRootData(dat[i]); if (fdat != null && fdat.Internal is FDSSection) { current = (FDSSection)fdat.Internal; } else { if (allowNull) { return(null); } if (fdat != null) { throw new FDSInputException("Key contains non-section contents!"); } FDSSection temp = new FDSSection(); current.SetRootData(dat[i], new FDSData() { Internal = temp, PrecedingComments = new List <string>() }); current = temp; } } return(current); }