/// <summary>
        ///   The GetLineByTag method returns a GEDCOMRecord by its tagName property
        /// </summary>
        /// <param name = "tagName">The provided tagName</param>
        /// <returns>A GEDCOMRecord object (null if not present)</returns>
        public GEDCOMRecord GetLineByTag(GEDCOMTag tagName)
        {
            GEDCOMRecord item   = null;
            bool         bFound = TryGetRecord(tagName, out item);

            return(item);
        }
        public CorresponderRet GetCorresponder()
        {
            GKCommunicationDir     commDir      = GKCommunicationDir.cdFrom;
            GEDCOMIndividualRecord corresponder = null;

            GEDCOMTag corrTag = FindTag("FROM", 0);

            if (corrTag == null)
            {
                corrTag = FindTag("TO", 0);
            }

            if (corrTag != null)
            {
                corresponder = (Owner.XRefIndex_Find(GEDCOMUtils.CleanXRef(corrTag.StringValue)) as GEDCOMIndividualRecord);

                if (corrTag.Name == "FROM")
                {
                    commDir = GKCommunicationDir.cdFrom;
                }
                else if (corrTag.Name == "TO")
                {
                    commDir = GKCommunicationDir.cdTo;
                }
            }

            return(new CorresponderRet(commDir, corresponder));
        }
        /// <summary>
        ///   GetXRefID fetchs the XRefID for the specified Record
        /// </summary>
        /// <param name = "tagName">The tag to fetch the data for</param>
        /// <returns>A string</returns>
        public string GetXRefID(GEDCOMTag tagName)
        {
            string       xRefId = String.Empty;
            GEDCOMRecord record = GetLineByTag(tagName);

            if (record != null && record.XRefId != null)
            {
                xRefId = record.XRefId;
            }
            return(xRefId);
        }
        /// <summary>
        ///   GetRecordData fetchs the Data for the specified Record
        /// </summary>
        /// <param name = "tag">The tag to fetch the data for</param>
        /// <returns>A string</returns>
        /// <summary>
        ///   GetRecordData fetchs the Data for the specified Record
        /// </summary>
        /// <param name = "tagName">The tag to fetch the data for</param>
        /// <returns>A string</returns>
        public string GetRecordData(GEDCOMTag tagName)
        {
            string       tagData = String.Empty;
            GEDCOMRecord record  = GetLineByTag(tagName);

            if (record != null && tagData != null)
            {
                tagData = record.Data;
            }

            return(tagData);
        }
        /// <summary>
        ///   The GetXRefIDs method returns a string Collection of xREfIDs with
        ///   the tagName specified
        /// </summary>
        /// <param name = "tagName">The tag</param>
        /// <returns>A string collection (empty if not present)</returns>
        public List <string> GetXRefIDs(GEDCOMTag tagName)
        {
            List <string>    xRefIDs = null;
            GEDCOMRecordList records = GetLinesByTag(tagName);

            if (records != null)
            {
                xRefIDs = new List <string>();

                for (int i = 0; i < records.Count; i++)
                {
                    xRefIDs.Add(records[i].XRefId);
                }
            }
            return(xRefIDs);
        }
        /// <summary>
        ///   The GetLinesByTag method returns a List<TRecord> of lines with
        ///                                            the same tagName property
        /// </summary>
        /// <param name = "tagName">The provided tagName</param>
        /// <returns>A List<TRecord> (empty if not present)</returns>
        public List <TRecord> GetLinesByTag <TRecord>(GEDCOMTag tagName) where TRecord : GEDCOMRecord
        {
            List <GEDCOMRecord> tagList = null;
            List <TRecord>      records = new List <TRecord>();
            bool bFound = tagDictionary.TryGetValue(tagName, out tagList);

            if (bFound)
            {
                foreach (GEDCOMRecord record in tagList)
                {
                    records.Add(record as TRecord);
                }
            }

            return(records);
        }
        /// <summary>
        ///   The GetLinesByTag method returns a GEDCOMRecords Collection of lines with
        ///   the same tagName property
        /// </summary>
        /// <param name = "tagName">The provided tagName</param>
        /// <returns>A GEDCOMRecords collection (empty if not present)</returns>
        public GEDCOMRecordList GetLinesByTag(GEDCOMTag tagName)
        {
            List <GEDCOMRecord> tagList = null;
            GEDCOMRecordList    records = new GEDCOMRecordList();
            bool bFound = tagDictionary.TryGetValue(tagName, out tagList);

            if (bFound)
            {
                foreach (GEDCOMRecord record in tagList)
                {
                    records.Add(record);
                }
            }

            return(records);
        }
        private bool TryGetRecord(GEDCOMTag tagName, out GEDCOMRecord item)
        {
            List <GEDCOMRecord> tagList = null;

            item = null;

            bool bFound = tagDictionary.TryGetValue(tagName, out tagList);

            if (bFound)
            {
                if (tagList.Count > 0)
                {
                    item = tagList[0];
                }
                else
                {
                    bFound = false;
                }
            }

            return(bFound);
        }
 public int GetNextId(GEDCOMTag tagName)
 {
     return((maxIdDictionary.ContainsKey(tagName)) ? maxIdDictionary[tagName] + 1 : 1);
 }
 /// <summary>
 ///   The GetLineByTag method returns a GEDCOMRecord by its tagName property
 /// </summary>
 /// <param name = "tagName">The provided tagName</param>
 /// <returns>A GEDCOMRecord object (null if not present)</returns>
 public TRecord GetLineByTag <TRecord>(GEDCOMTag tagName) where TRecord : GEDCOMRecord
 {
     return(GetLineByTag(tagName) as TRecord);
 }
        public void GEDCOMReader_Read_Reads_Correct_ChildRecords(string fileName, int recordNo, int childRecordNo, GEDCOMTag tag)
        {
            GEDCOMReader     reader;
            GEDCOMRecordList records;

            using (Stream s = GetEmbeddedFileStream(fileName))
            {
                reader  = GEDCOMReader.Create(s);
                records = reader.Read();
            }
            GEDCOMRecord record = records[recordNo];

            Assert.AreEqual(tag, record.ChildRecords[childRecordNo].TagName);
        }