Программная часть шаблона
This commit is contained in:
@@ -3,7 +3,7 @@ using System.Collections.Generic;
|
|||||||
|
|
||||||
namespace mROA.CodegenTools
|
namespace mROA.CodegenTools
|
||||||
{
|
{
|
||||||
public class InsertTemplatePart : ITemplatePart, ITagged
|
public class InsertTemplatePart : ITagged
|
||||||
{
|
{
|
||||||
private object _insertedValue;
|
private object _insertedValue;
|
||||||
private string _tag;
|
private string _tag;
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace mROA.CodegenTools
|
||||||
|
{
|
||||||
|
public class ProgrammableTextPart : ITemplatePart
|
||||||
|
{
|
||||||
|
public TemplateDocument Context { get; set; }
|
||||||
|
public int TargetLength => 0;
|
||||||
|
|
||||||
|
private Func<object, string> _bakeFunc;
|
||||||
|
|
||||||
|
public ProgrammableTextPart(Func<object, string> bakeFunc, TemplateDocument context)
|
||||||
|
{
|
||||||
|
_bakeFunc = bakeFunc;
|
||||||
|
Context = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public string Bake()
|
||||||
|
{
|
||||||
|
return _bakeFunc(Context.AdditionalContext);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,6 +7,7 @@ namespace mROA.CodegenTools
|
|||||||
public class TemplateDocument
|
public class TemplateDocument
|
||||||
{
|
{
|
||||||
public List<ITemplatePart> Parts { get; }
|
public List<ITemplatePart> Parts { get; }
|
||||||
|
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)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user