public LDLBOBase CreateItem(string[] definition, string id) { LDLTrackCircuit toPopulate = new LDLTrackCircuit(id); int nLines = definition.GetUpperBound(0); int startOfSections = 0; for (int i = 0; i < nLines; i++) { if (string.IsNullOrEmpty(toPopulate.InterlockingStr)) if (definition[i].Contains(LDLInterlocking.Identifier)) toPopulate.InterlockingStr = ParseItem(definition[i]); if (definition[i].Contains(typedefStr)) { string typeStr = ParseItem(definition[i]); if (!string.IsNullOrEmpty(typeStr)) toPopulate.TCType = (LDLTrackCircuitTypeEnum)Enum.Parse(typeof(LDLTrackCircuitTypeEnum), typeStr); startOfSections = i; break; } } toPopulate.Sections = LDLSectionList.ExtractSectionList(definition, nLines+1, startOfSections,true); return toPopulate; }
/// <summary> /// Not exactly a constructor - this extracts a section list from a part - parsed definition and returns the section list as an object /// /// </summary> /// <param name="definition">the definition of your object</param> /// <param name="nLines">The size, in lines, of the definition of the entire object, not just the section list</param> /// <param name="startIDX">how far through the definition to start looking - the last line on which you parsed something else</param> /// <returns>A LDLSectionList</returns> public static LDLSectionList ExtractSectionList(string[] definition, int nLines, int startIDX, bool isMultiPartSection = false) { List <string> sectionsDef = new List <string>(); bool addToSections = false; string startMark = isMultiPartSection ? LDLSectionList.Section : LDLSectionList.SectionList; for (int idx = startIDX; idx < nLines; idx++) { if (definition[idx].Contains(startMark)) { addToSections = true; } if (addToSections) { sectionsDef.Add(definition[idx]); } if ((addToSections) && (definition[idx].Contains(LDLSectionList.SectionListEndMark))) { addToSections = false; } } LDLSectionList sections = new LDLSectionList(sectionsDef); return(sections); }
public LDLBOBase CreateItem(string[] definition, string id) { LDLInterlocking result = new LDLInterlocking(id); int nLines = definition.GetLength(0); LDLSectionList sections = LDLSectionList.ExtractSectionList(definition, nLines, 0); result.Sections = sections; return(result); }
public LDLInterlocking(string id) : base(id) { Sections = new LDLSectionList(); }