public IEnumerable <IPDFComponent> Instantiate(int index, IPDFComponent owner) { //Create the container TemplateInstance instance = new TemplateInstance(); //Init all the custom contents this.InitializeComponents(instance); //return wrapped in an array return(new IPDFComponent[] { instance }); }
// // IPDFTemplate Instantiate method. // public IEnumerable <IPDFComponent> Instantiate(int index, IPDFComponent owner) { if (!_initialised) { this.InitTemplate(this.XmlContent, this.NamespacePrefixMappings); } if (null == owner) { throw new ArgumentNullException("owner"); } using (System.IO.StringReader sr = new System.IO.StringReader(this._toparse)) { //Get the closest remote component IPDFRemoteComponent remote = this.GetRemoteComponent(owner); IPDFDocument doc = owner.Document; IPDFComponent comp; if (doc is IPDFTemplateParser) { comp = ((IPDFTemplateParser)doc).ParseTemplate(remote, sr); } else { throw RecordAndRaise.NullReference(Errors.ParentDocumentMustBeTemplateParser); } if (this.IsBlock) { if (!(comp is TemplateBlockInstance)) { throw RecordAndRaise.InvalidCast(Errors.CannotConvertObjectToType, comp.GetType(), typeof(TemplateBlockInstance)); } TemplateBlockInstance template = (TemplateBlockInstance)comp; if (null != this.Style && (template is IPDFStyledComponent)) { this.Style.MergeInto((template as IPDFStyledComponent).Style); } template.StyleClass = this.StyleClass; template.ElementName = this.ElementName; } else { if (!(comp is TemplateInstance)) { throw RecordAndRaise.InvalidCast(Errors.CannotConvertObjectToType, comp.GetType(), typeof(TemplateInstance)); } TemplateInstance template = (TemplateInstance)comp; if (null != this.Style && (template is IPDFStyledComponent)) { this.Style.MergeInto((template as IPDFStyledComponent).Style); } template.StyleClass = this.StyleClass; template.ElementName = this.ElementName; } if (comp is Component && owner is Component && this.UseDataStyleIdentifier) { var stem = this.DataStyleStem; if (string.IsNullOrEmpty(stem)) { stem = ((Component)owner).UniqueID; } DataStyleIdentifierVisitor visitor = new DataStyleIdentifierVisitor(stem, 1); visitor.PushToComponents(comp as Component); } List <IPDFComponent> all = new List <IPDFComponent>(1); all.Add(comp); return(all); } }
protected abstract void InitializeComponents(TemplateInstance instance);