internal APGenSection GetSectionInstance(SectionInfo sectionInfo, bool createDefaultInstance) { object data = _elementData[sectionInfo]; APGenSection section = data as APGenSection; if (section != null || !createDefaultInstance) { return(section); } object sectionObj = sectionInfo.CreateInstance(); section = sectionObj as APGenSection; if (section == null) { APGenDefaultSection defaultSection = new APGenDefaultSection(); defaultSection.SectionHandler = sectionObj as IAPGenSectionHandler; section = defaultSection; } if (data != null) { string xml = data as string; section.RawXml = xml; using (XmlTextReader reader = new XmlTextReader(new StringReader(xml))) { section.DeserializeSection(reader); } } _elementData[sectionInfo] = section; return(section); }
public override void WriteData(APGen gen, XmlWriter writer) { string xml; APGenSection section = gen.GetSectionInstance(this, false); if (section != null) { xml = section.SerializeSection(Name); string externalDataXml = section.ExternalDataXml; string filePath = gen.FileName; if (!String.IsNullOrEmpty(filePath) && !String.IsNullOrEmpty(externalDataXml)) { using (StreamWriter sw = new StreamWriter(filePath)) { sw.Write(externalDataXml); } } } else { xml = gen.GetSectionXml(this); } if (xml != null) { writer.WriteRaw(xml); } }
public override object CreateInstance() { object obj = base.CreateInstance(); APGenSection section = obj as APGenSection; if (section != null) { section.SectionInformation.SetName(Name); } return(obj); }
internal void CreateSection(SectionGroupInfo groupInfo, string name, APGenSection section) { if (groupInfo.HasChild(name)) { throw new APGenException(APResource.GetString(APResource.APGen_SectionAlreadyExists, name)); } if (section.SectionInformation.Type == null) { section.SectionInformation.Type = GenHost.GetGenTypeName(section.GetType()); } SectionInfo sectionInfo = new SectionInfo(name, section.SectionInformation); sectionInfo.StreamName = _streamName; sectionInfo.GenHost = GenHost; groupInfo.AddChild(sectionInfo); _elementData[sectionInfo] = section; }
/// <summary> /// Get a section by name. /// </summary> /// <param name="name">The specified section name.</param> /// <returns>The section object.</returns> public APGenSection this[string name] { get { APGenSection section = BaseGet(name) as APGenSection; if (section == null) { SectionInfo sectionInfo = _group.Sections[name] as SectionInfo; if (sectionInfo == null) { return(null); } section = _gen.GetSectionInstance(sectionInfo, true); if (section == null) { return(null); } BaseSet(name, section); } return(section); } }
/// <summary> /// Adds a APGenSection object to the APGenSectionCollection. /// </summary> /// <param name="name">The name of the section to be added.</param> /// <param name="section">The section to be added.</param> public void Add(string name, APGenSection section) { _gen.CreateSection(_group, name, section); }
/// <summary> /// Copies this APGenSectionCollection object to an array. /// </summary> /// <param name="array">The array to which to copy.</param> /// <param name="index">The index location at which to begin copying.</param> public void CopyTo(APGenSection[] array, int index) { for (int n = 0; n < _group.Sections.Count; n++) array[n + index] = this[n]; }
internal void CreateSection(SectionGroupInfo groupInfo, string name, APGenSection section) { if (groupInfo.HasChild(name)) throw new APGenException(APResource.GetString(APResource.APGen_SectionAlreadyExists, name)); if (section.SectionInformation.Type == null) section.SectionInformation.Type = GenHost.GetGenTypeName(section.GetType()); SectionInfo sectionInfo = new SectionInfo(name, section.SectionInformation); sectionInfo.StreamName = _streamName; sectionInfo.GenHost = GenHost; groupInfo.AddChild(sectionInfo); _elementData[sectionInfo] = section; }