Добавление клонирования шаблонов
This commit is contained in:
@@ -23,5 +23,10 @@ namespace mROA.CodegenTools
|
|||||||
{
|
{
|
||||||
return StoredText;
|
return StoredText;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public object Clone()
|
||||||
|
{
|
||||||
|
return new DefineTemplateSection(StoredText, _tag, Context);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
namespace mROA.CodegenTools
|
namespace mROA.CodegenTools
|
||||||
{
|
{
|
||||||
public interface ITemplateSection
|
public interface ITemplateSection : ICloneable
|
||||||
{
|
{
|
||||||
TemplateDocument Context { get; set; }
|
TemplateDocument Context { get; set; }
|
||||||
int TargetLength { get; }
|
int TargetLength { get; }
|
||||||
|
|||||||
@@ -16,5 +16,10 @@ namespace mROA.CodegenTools
|
|||||||
Context = context;
|
Context = context;
|
||||||
InnerTemplate = innerTemplate;
|
InnerTemplate = innerTemplate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public object Clone()
|
||||||
|
{
|
||||||
|
return new InnerTemplateSection(_tag, InnerTemplate, Context);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -65,5 +65,10 @@ namespace mROA.CodegenTools
|
|||||||
return ((ITemplateSection)_insertedValue).ToString();
|
return ((ITemplateSection)_insertedValue).ToString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public object Clone()
|
||||||
|
{
|
||||||
|
return new InsertTemplatePart(_tag, Context, Parameters.ToArray());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -34,5 +34,10 @@ namespace mROA.CodegenTools
|
|||||||
{
|
{
|
||||||
return $"{nameof(LinkedTag)}: {_linkedTag}";
|
return $"{nameof(LinkedTag)}: {_linkedTag}";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public object Clone()
|
||||||
|
{
|
||||||
|
return new LinkTemplateSection(_linkedTag, Context);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -22,5 +22,10 @@ namespace mROA.CodegenTools
|
|||||||
{
|
{
|
||||||
return _internalText;
|
return _internalText;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public object Clone()
|
||||||
|
{
|
||||||
|
return new LiteralTemplateSection(_internalText, Context);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -20,5 +20,10 @@ namespace mROA.CodegenTools
|
|||||||
{
|
{
|
||||||
return _bakeFunc(Context.AdditionalContext);
|
return _bakeFunc(Context.AdditionalContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public object Clone()
|
||||||
|
{
|
||||||
|
return new ProgrammableTextSection(_bakeFunc, Context);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,14 +1,16 @@
|
|||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace mROA.CodegenTools
|
namespace mROA.CodegenTools
|
||||||
{
|
{
|
||||||
public class TemplateDocument
|
public class TemplateDocument : ICloneable
|
||||||
{
|
{
|
||||||
public List<ITemplateSection> Parts { get; set; } = new List<ITemplateSection>();
|
public List<ITemplateSection> Parts { get; set; } = new List<ITemplateSection>();
|
||||||
public object AdditionalContext { get; set; }
|
public object AdditionalContext { get; set; }
|
||||||
public ITagged this[string tag] => Parts.OfType<ITagged>().FirstOrDefault(i => i.Tag == tag);
|
public ITagged this[string tag] => Parts.OfType<ITagged>().FirstOrDefault(i => i.Tag == tag);
|
||||||
|
|
||||||
public void Insert(string tag, object value)
|
public void Insert(string tag, object value)
|
||||||
{
|
{
|
||||||
var selectedPart = this[tag];
|
var selectedPart = this[tag];
|
||||||
@@ -31,5 +33,20 @@ namespace mROA.CodegenTools
|
|||||||
|
|
||||||
return stringBuilder.ToString();
|
return stringBuilder.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public object Clone()
|
||||||
|
{
|
||||||
|
var cloneDoc = new TemplateDocument();
|
||||||
|
cloneDoc.AdditionalContext = AdditionalContext is ICloneable c ? c.Clone() : AdditionalContext;
|
||||||
|
|
||||||
|
cloneDoc.Parts = Parts.Select(i =>
|
||||||
|
{
|
||||||
|
var clone = i.Clone() as ITemplateSection;
|
||||||
|
clone.Context = cloneDoc;
|
||||||
|
return clone;
|
||||||
|
}).ToList();
|
||||||
|
|
||||||
|
return cloneDoc;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user