Including tools into codegen
This commit is contained in:
@@ -13,4 +13,8 @@
|
|||||||
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="mROA.Codegen" Version="2.0.4" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using mROA.Abstract;
|
||||||
using mROA.Implementation;
|
using mROA.Implementation;
|
||||||
using mROA.Implementation.Attributes;
|
using mROA.Implementation.Attributes;
|
||||||
|
|
||||||
@@ -15,4 +16,35 @@ namespace Example.Shared
|
|||||||
|
|
||||||
Task AsyncTest(CancellationToken token = default);
|
Task AsyncTest(CancellationToken token = default);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
partial class LoadTestRemoteEndpoint2
|
||||||
|
: RemoteObjectBase, ILoadTest
|
||||||
|
{
|
||||||
|
public LoadTestRemoteEndpoint2(int id, IRepresentationModule representationModule, IEndPointContext context)
|
||||||
|
: base(id, representationModule, context)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public void A(){
|
||||||
|
CallAsync(0).Wait();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async System.Threading.Tasks.Task AsyncTest(System.Threading.CancellationToken token){
|
||||||
|
await CallAsync(1, cancellationToken : token);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void C(){
|
||||||
|
CallAsync(2).Wait();
|
||||||
|
}
|
||||||
|
|
||||||
|
public System.Int32 Last(System.Int32 next){
|
||||||
|
return GetResultAsync<System.Int32>(3, new System.Object[] { next }).GetAwaiter().GetResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
public System.Int32 Next(System.Int32 last){
|
||||||
|
return GetResultAsync<System.Int32>(4, new System.Object[] { last }).GetAwaiter().GetResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
namespace mROA.Codegen.Tools
|
|
||||||
{
|
|
||||||
public class DefineTemplateSection : ITagged
|
|
||||||
{
|
|
||||||
public DefineTemplateSection(string storedText, string tag, TemplateDocument context)
|
|
||||||
{
|
|
||||||
StoredText = storedText;
|
|
||||||
Tag = tag;
|
|
||||||
Context = context;
|
|
||||||
}
|
|
||||||
|
|
||||||
public string StoredText { get; }
|
|
||||||
public TemplateDocument Context { get; set; }
|
|
||||||
|
|
||||||
public string Tag { get; }
|
|
||||||
|
|
||||||
public int TargetLength => StoredText.Length;
|
|
||||||
|
|
||||||
public object Clone()
|
|
||||||
{
|
|
||||||
return new DefineTemplateSection(StoredText, Tag, Context);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public override string ToString()
|
|
||||||
{
|
|
||||||
return StoredText;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
using System;
|
|
||||||
|
|
||||||
namespace mROA.Codegen.Tools
|
|
||||||
{
|
|
||||||
public interface ITemplateSection : ICloneable
|
|
||||||
{
|
|
||||||
TemplateDocument Context { get; set; }
|
|
||||||
int TargetLength { get; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface IBaking
|
|
||||||
{
|
|
||||||
string Bake();
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface ITagged : ITemplateSection
|
|
||||||
{
|
|
||||||
string Tag { get; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
namespace mROA.Codegen.Tools
|
|
||||||
{
|
|
||||||
public class InnerTemplateSection : ITemplateSection, ITagged
|
|
||||||
{
|
|
||||||
public InnerTemplateSection(string tag, TemplateDocument innerTemplate, TemplateDocument context)
|
|
||||||
{
|
|
||||||
Tag = tag;
|
|
||||||
Context = context;
|
|
||||||
InnerTemplate = innerTemplate;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TemplateDocument InnerTemplate { get; }
|
|
||||||
|
|
||||||
public string Tag { get; }
|
|
||||||
|
|
||||||
public TemplateDocument Context { get; set; }
|
|
||||||
public int TargetLength => 0;
|
|
||||||
|
|
||||||
public object Clone()
|
|
||||||
{
|
|
||||||
return new InnerTemplateSection(Tag, InnerTemplate, Context);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,86 +0,0 @@
|
|||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
|
|
||||||
namespace mROA.Codegen.Tools
|
|
||||||
{
|
|
||||||
public class InsertTemplateSection : ITagged, IBaking
|
|
||||||
{
|
|
||||||
public readonly List<string> Parameters;
|
|
||||||
private object _insertedValue;
|
|
||||||
|
|
||||||
public InsertTemplateSection(string tag, TemplateDocument context, params string[] parameters)
|
|
||||||
{
|
|
||||||
Tag = tag;
|
|
||||||
Parameters = parameters.ToList();
|
|
||||||
Context = context;
|
|
||||||
}
|
|
||||||
|
|
||||||
public string Bake()
|
|
||||||
{
|
|
||||||
switch (_insertedValue)
|
|
||||||
{
|
|
||||||
case null:
|
|
||||||
return string.Empty;
|
|
||||||
case string s:
|
|
||||||
return s;
|
|
||||||
default:
|
|
||||||
return ((ITemplateSection)_insertedValue).ToString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public string Tag { get; private set; }
|
|
||||||
|
|
||||||
public TemplateDocument Context { get; set; }
|
|
||||||
|
|
||||||
|
|
||||||
public int TargetLength => 0;
|
|
||||||
|
|
||||||
public object Clone()
|
|
||||||
{
|
|
||||||
return new InsertTemplateSection(Tag, Context, Parameters.ToArray());
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool IsInserted(object value)
|
|
||||||
{
|
|
||||||
if (Parameters.IndexOf("r") == -1) return false;
|
|
||||||
|
|
||||||
ProduceInserted(value);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ProduceInserted(object value)
|
|
||||||
{
|
|
||||||
var currentIndex = Context.Parts.IndexOf(this);
|
|
||||||
var clone = (InsertTemplateSection)MemberwiseClone();
|
|
||||||
clone.Tag += "+";
|
|
||||||
|
|
||||||
clone._insertedValue = value;
|
|
||||||
|
|
||||||
Context.Parts.Insert(currentIndex, clone);
|
|
||||||
|
|
||||||
InsertSeparator(currentIndex + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void InsertSeparator(int currentIndex)
|
|
||||||
{
|
|
||||||
var sepIndex = Parameters.IndexOf("sep");
|
|
||||||
if (sepIndex == -1)
|
|
||||||
return;
|
|
||||||
|
|
||||||
Context.Parts.Insert(currentIndex,
|
|
||||||
new LiteralTemplateSection(Context[Parameters[sepIndex + 1]].ToString(), Context));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void Setup(object value)
|
|
||||||
{
|
|
||||||
if (!(value is string) && !(value is ITemplateSection))
|
|
||||||
return;
|
|
||||||
if (IsInserted(value))
|
|
||||||
return;
|
|
||||||
|
|
||||||
_insertedValue = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
namespace mROA.Codegen.Tools
|
|
||||||
{
|
|
||||||
public class LinkTemplateSection : ITemplateSection, IBaking
|
|
||||||
{
|
|
||||||
public LinkTemplateSection(string linkedTag, TemplateDocument context)
|
|
||||||
{
|
|
||||||
LinkedTag = linkedTag;
|
|
||||||
Context = context;
|
|
||||||
}
|
|
||||||
|
|
||||||
public string LinkedTag { get; }
|
|
||||||
|
|
||||||
public string Bake()
|
|
||||||
{
|
|
||||||
return Context[LinkedTag]?.ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public TemplateDocument Context { get; set; }
|
|
||||||
|
|
||||||
public int TargetLength
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
var attached = Context[LinkedTag];
|
|
||||||
return attached?.TargetLength ?? 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public object Clone()
|
|
||||||
{
|
|
||||||
return new LinkTemplateSection(LinkedTag, Context);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override string ToString()
|
|
||||||
{
|
|
||||||
return $"{nameof(LinkedTag)}: {LinkedTag}";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
namespace mROA.Codegen.Tools
|
|
||||||
{
|
|
||||||
public class LiteralTemplateSection : ITemplateSection, IBaking
|
|
||||||
{
|
|
||||||
private readonly string _internalText;
|
|
||||||
|
|
||||||
public LiteralTemplateSection(string internalText, TemplateDocument context)
|
|
||||||
{
|
|
||||||
_internalText = internalText;
|
|
||||||
Context = context;
|
|
||||||
}
|
|
||||||
|
|
||||||
public string Bake()
|
|
||||||
{
|
|
||||||
return ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public TemplateDocument Context { get; set; }
|
|
||||||
public int TargetLength => _internalText.Length;
|
|
||||||
|
|
||||||
public object Clone()
|
|
||||||
{
|
|
||||||
return new LiteralTemplateSection(_internalText, Context);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override string ToString()
|
|
||||||
{
|
|
||||||
return _internalText;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
using System;
|
|
||||||
|
|
||||||
namespace mROA.Codegen.Tools
|
|
||||||
{
|
|
||||||
public class ProgrammableTextSection : ITemplateSection, IBaking
|
|
||||||
{
|
|
||||||
private readonly Func<object, string> _bakeFunc;
|
|
||||||
|
|
||||||
public ProgrammableTextSection(Func<object, string> bakeFunc, TemplateDocument context)
|
|
||||||
{
|
|
||||||
_bakeFunc = bakeFunc;
|
|
||||||
Context = context;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public string Bake()
|
|
||||||
{
|
|
||||||
return _bakeFunc(Context.AdditionalContext);
|
|
||||||
}
|
|
||||||
|
|
||||||
public TemplateDocument Context { get; set; }
|
|
||||||
public int TargetLength => 0;
|
|
||||||
|
|
||||||
public object Clone()
|
|
||||||
{
|
|
||||||
return new ProgrammableTextSection(_bakeFunc, Context);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
using System;
|
|
||||||
|
|
||||||
namespace mROA.Codegen.Tools.Reading
|
|
||||||
{
|
|
||||||
public class DefineSectionReader : LeadingTextSectionReader
|
|
||||||
{
|
|
||||||
public DefineSectionReader() : base("<!D")
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public override ITemplateSection ExtractSection(ref int index, TemplateDocument document)
|
|
||||||
{
|
|
||||||
var tagEnd = TemplateText.IndexOf(">", index, StringComparison.Ordinal);
|
|
||||||
var sectionName = GetTagValue(index, tagEnd);
|
|
||||||
tagEnd += 1;
|
|
||||||
var endIndex = TemplateText.IndexOf("<!D>", tagEnd, StringComparison.Ordinal);
|
|
||||||
var storedText = TemplateText.Substring(tagEnd, endIndex - tagEnd);
|
|
||||||
index = endIndex + 4;
|
|
||||||
PassCaretToCloseSymbol();
|
|
||||||
PassCaretToCloseSymbol();
|
|
||||||
return new DefineTemplateSection(storedText, sectionName, document);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
namespace mROA.Codegen.Tools.Reading
|
|
||||||
{
|
|
||||||
public interface ISectionReader
|
|
||||||
{
|
|
||||||
string TemplateText { get; set; }
|
|
||||||
int GetNextSectionIndex(int currentIndex);
|
|
||||||
ITemplateSection ExtractSection(ref int index, TemplateDocument document);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
using System;
|
|
||||||
|
|
||||||
namespace mROA.Codegen.Tools.Reading
|
|
||||||
{
|
|
||||||
public class InnerTemplateSectionReader : LeadingTextSectionReader
|
|
||||||
{
|
|
||||||
public InnerTemplateSectionReader()
|
|
||||||
: base("<!T")
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public override ITemplateSection ExtractSection(ref int index, TemplateDocument document)
|
|
||||||
{
|
|
||||||
var end = FindEnd(index + 4);
|
|
||||||
var from = index;
|
|
||||||
index = PassCaretToCloseSymbol();
|
|
||||||
var to = index - 1;
|
|
||||||
|
|
||||||
var tagName = GetTagValue(from, to);
|
|
||||||
|
|
||||||
var innerDocText = TemplateText.Substring(index, end - index);
|
|
||||||
var innerDoc = TemplateReader.Parse(innerDocText);
|
|
||||||
_currentCaretPosition = end + 4;
|
|
||||||
index = _currentCaretPosition;
|
|
||||||
return new InnerTemplateSection(tagName, innerDoc, document);
|
|
||||||
}
|
|
||||||
|
|
||||||
private int FindEnd(int start)
|
|
||||||
{
|
|
||||||
var endSymbol = TemplateText.IndexOf("<!T>", start, StringComparison.Ordinal);
|
|
||||||
var innerStartSymbol = TemplateText.IndexOf("<!T ", start, StringComparison.Ordinal);
|
|
||||||
if (endSymbol < innerStartSymbol || innerStartSymbol == -1)
|
|
||||||
return endSymbol;
|
|
||||||
|
|
||||||
return FindEnd(endSymbol + 4);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
using System.Linq;
|
|
||||||
|
|
||||||
namespace mROA.Codegen.Tools.Reading
|
|
||||||
{
|
|
||||||
public class InsertSectionReader : LeadingTextSectionReader
|
|
||||||
{
|
|
||||||
public InsertSectionReader() : base("<!I")
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public override ITemplateSection ExtractSection(ref int index, TemplateDocument document)
|
|
||||||
{
|
|
||||||
var from = index;
|
|
||||||
index = PassCaretToCloseSymbol();
|
|
||||||
var to = index - 1;
|
|
||||||
|
|
||||||
var tagText = GetTagValue(from, to);
|
|
||||||
var parts = tagText.Split(' ');
|
|
||||||
|
|
||||||
return new InsertTemplateSection(parts[0], document, parts.Skip(1).ToArray());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
using System;
|
|
||||||
|
|
||||||
namespace mROA.Codegen.Tools.Reading
|
|
||||||
{
|
|
||||||
public abstract class LeadingTextSectionReader : ISectionReader
|
|
||||||
{
|
|
||||||
private readonly string _tagLeading;
|
|
||||||
protected int _currentCaretPosition;
|
|
||||||
|
|
||||||
protected LeadingTextSectionReader(string tagLeading)
|
|
||||||
{
|
|
||||||
_tagLeading = tagLeading + " ";
|
|
||||||
}
|
|
||||||
|
|
||||||
public string TemplateText { get; set; }
|
|
||||||
|
|
||||||
public int GetNextSectionIndex(int currentIndex)
|
|
||||||
{
|
|
||||||
_currentCaretPosition = Math.Max(currentIndex, _currentCaretPosition);
|
|
||||||
var index = TemplateText.IndexOf(_tagLeading, _currentCaretPosition, StringComparison.Ordinal);
|
|
||||||
_currentCaretPosition = index;
|
|
||||||
return index;
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract ITemplateSection ExtractSection(ref int index, TemplateDocument document);
|
|
||||||
|
|
||||||
protected int PassCaretToCloseSymbol()
|
|
||||||
{
|
|
||||||
_currentCaretPosition = TemplateText.IndexOf(">", _currentCaretPosition, StringComparison.Ordinal) + 1;
|
|
||||||
return _currentCaretPosition;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected string GetTagValue(int from, int to)
|
|
||||||
{
|
|
||||||
var realStart = from + 4;
|
|
||||||
var span = TemplateText.AsSpan();
|
|
||||||
var slice = span.Slice(realStart, to - realStart);
|
|
||||||
return new string(slice.ToArray());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
namespace mROA.Codegen.Tools.Reading
|
|
||||||
{
|
|
||||||
public class LinkSectionReader : LeadingTextSectionReader
|
|
||||||
{
|
|
||||||
public LinkSectionReader() : base("<!L")
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public override ITemplateSection ExtractSection(ref int index, TemplateDocument document)
|
|
||||||
{
|
|
||||||
var from = index;
|
|
||||||
index = PassCaretToCloseSymbol();
|
|
||||||
var to = index - 1;
|
|
||||||
|
|
||||||
var tagText = GetTagValue(from, to);
|
|
||||||
return new LinkTemplateSection(tagText, document);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,82 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Reflection;
|
|
||||||
|
|
||||||
namespace mROA.Codegen.Tools.Reading
|
|
||||||
{
|
|
||||||
public static class TemplateReader
|
|
||||||
{
|
|
||||||
private static readonly List<Type> ReaderTypes = new()
|
|
||||||
{
|
|
||||||
typeof(DefineSectionReader),
|
|
||||||
typeof(InsertSectionReader),
|
|
||||||
typeof(LinkSectionReader),
|
|
||||||
typeof(InnerTemplateSectionReader)
|
|
||||||
};
|
|
||||||
|
|
||||||
public static TemplateDocument Parse(string templateText)
|
|
||||||
{
|
|
||||||
var currentIndex = 0;
|
|
||||||
var activeReaders = new List<ISectionReader>();
|
|
||||||
|
|
||||||
foreach (var readerType in ReaderTypes)
|
|
||||||
{
|
|
||||||
var reader = Activator.CreateInstance(readerType) as ISectionReader;
|
|
||||||
reader.TemplateText = templateText;
|
|
||||||
activeReaders.Add(reader);
|
|
||||||
}
|
|
||||||
|
|
||||||
var doc = new TemplateDocument();
|
|
||||||
|
|
||||||
while (currentIndex < templateText.Length)
|
|
||||||
{
|
|
||||||
List<(ISectionReader reader, int index)> indices = activeReaders
|
|
||||||
.Select(i => ((ISectionReader Readers, int index))(i, i.GetNextSectionIndex(currentIndex)))
|
|
||||||
.Where(i => i.index > -1).ToList();
|
|
||||||
var minIndex = templateText.Length;
|
|
||||||
ISectionReader minReader = null;
|
|
||||||
if (indices.Count != 0)
|
|
||||||
{
|
|
||||||
minIndex = indices.Min(i => i.index);
|
|
||||||
minReader = indices.FirstOrDefault(i => i.index == minIndex).reader;
|
|
||||||
|
|
||||||
if (indices.Count != activeReaders.Count) activeReaders = indices.Select(i => i.reader).ToList();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (currentIndex != minIndex)
|
|
||||||
{
|
|
||||||
var literalText = templateText.Substring(currentIndex, minIndex - currentIndex);
|
|
||||||
var literal =
|
|
||||||
new LiteralTemplateSection(literalText, doc);
|
|
||||||
doc.Parts.Add(literal);
|
|
||||||
currentIndex = minIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (indices.Count != 0)
|
|
||||||
{
|
|
||||||
var section = minReader.ExtractSection(ref currentIndex, doc);
|
|
||||||
doc.Parts.Add(section);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return doc;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static TemplateDocument FromEmbeddedResource(string resourceName)
|
|
||||||
{
|
|
||||||
return FromEmbeddedResource(resourceName, Assembly.GetCallingAssembly());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static TemplateDocument FromEmbeddedResource(string resourceName, Assembly assembly)
|
|
||||||
{
|
|
||||||
var fileName = assembly.GetManifestResourceNames().First(n => n.EndsWith(resourceName));
|
|
||||||
var res = assembly.GetManifestResourceStream(fileName);
|
|
||||||
var reader = new StreamReader(res);
|
|
||||||
var templateText = reader.ReadToEnd();
|
|
||||||
return Parse(templateText);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,61 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace mROA.Codegen.Tools
|
|
||||||
{
|
|
||||||
public class TemplateDocument : ICloneable
|
|
||||||
{
|
|
||||||
public List<ITemplateSection> Parts { get; set; } = new();
|
|
||||||
public object AdditionalContext { get; set; }
|
|
||||||
public ITagged? this[string tag] => Parts.OfType<ITagged>().FirstOrDefault(i => i.Tag == tag);
|
|
||||||
|
|
||||||
public object Clone()
|
|
||||||
{
|
|
||||||
var cloneDoc = new TemplateDocument
|
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Insert(string tag, object value)
|
|
||||||
{
|
|
||||||
var selectedPart = this[tag];
|
|
||||||
if (selectedPart is InsertTemplateSection itp) itp.Setup(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public string Compile()
|
|
||||||
{
|
|
||||||
var approximatelyLength = Parts.Sum(i => i.TargetLength);
|
|
||||||
var stringBuilder = new StringBuilder(approximatelyLength);
|
|
||||||
|
|
||||||
foreach (var part in Parts.OfType<IBaking>())
|
|
||||||
{
|
|
||||||
var baked = part.Bake();
|
|
||||||
stringBuilder.Append(baked);
|
|
||||||
}
|
|
||||||
|
|
||||||
return stringBuilder.ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void AddDefine(string tag, string text)
|
|
||||||
{
|
|
||||||
Parts.Add(new DefineTemplateSection(text, tag, this));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void AddDefine(string tag, object value)
|
|
||||||
{
|
|
||||||
AddDefine(tag, value.ToString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -17,7 +17,7 @@
|
|||||||
<RepositoryUrl>https://github.com/YaslePoy/mROA</RepositoryUrl>
|
<RepositoryUrl>https://github.com/YaslePoy/mROA</RepositoryUrl>
|
||||||
<RepositoryType>git</RepositoryType>
|
<RepositoryType>git</RepositoryType>
|
||||||
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
|
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
|
||||||
<Version>2.0.3</Version>
|
<Version>2.0.4</Version>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@@ -26,6 +26,7 @@
|
|||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.3.0" />
|
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.3.0" />
|
||||||
|
<PackageReference Include="mROA.CodegenTools" Version="1.0.0" GeneratePathProperty="true" PrivateAssets="all"/>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@@ -41,5 +42,15 @@
|
|||||||
<EmbeddedResource Include="MethodRepo.cstmpl" />
|
<EmbeddedResource Include="MethodRepo.cstmpl" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<GetTargetPathDependsOn>$(GetTargetPathDependsOn);GetDependencyTargetPaths</GetTargetPathDependsOn>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<Target Name="GetDependencyTargetPaths">
|
||||||
|
<ItemGroup>
|
||||||
|
<TargetPathWithTargetPlatformMoniker Include="$(PKGmROA_CodegenTools)\lib\netstandard2.0\mROA.CodegenTools.dll" IncludeRuntimeDependency="false" />
|
||||||
|
</ItemGroup>
|
||||||
|
</Target>
|
||||||
|
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ using System.Text;
|
|||||||
using Microsoft.CodeAnalysis;
|
using Microsoft.CodeAnalysis;
|
||||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||||
using Microsoft.CodeAnalysis.Text;
|
using Microsoft.CodeAnalysis.Text;
|
||||||
using mROA.Codegen.Tools;
|
using mROA.CodegenTools;
|
||||||
using mROA.Codegen.Tools.Reading;
|
using mROA.CodegenTools.Reading;
|
||||||
|
|
||||||
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable.
|
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable.
|
||||||
|
|
||||||
@@ -40,16 +40,25 @@ namespace mROA.Codegen
|
|||||||
|
|
||||||
public void Initialize(GeneratorInitializationContext context)
|
public void Initialize(GeneratorInitializationContext context)
|
||||||
{
|
{
|
||||||
_methodRepoTemplate = TemplateReader.FromEmbeddedResource("MethodRepo.cstmpl");
|
try
|
||||||
_methodInvokerOriginal =
|
{
|
||||||
((InnerTemplateSection)_methodRepoTemplate["syncInvoker"]!).InnerTemplate;
|
|
||||||
_classTemplateOriginal = TemplateReader.FromEmbeddedResource("RemoteEndpoint.cstmpl");
|
_methodRepoTemplate = TemplateReader.FromEmbeddedResource("MethodRepo.cstmpl");
|
||||||
_binderTemplate = TemplateReader.FromEmbeddedResource("RemoteTypeBinder.cstmpl");
|
_methodInvokerOriginal =
|
||||||
_interfaceTemplateOriginal = TemplateReader.FromEmbeddedResource("PartialInterface.cstmpl");
|
((InnerTemplateSection)_methodRepoTemplate["syncInvoker"]!).InnerTemplate;
|
||||||
|
_classTemplateOriginal = TemplateReader.FromEmbeddedResource("RemoteEndpoint.cstmpl");
|
||||||
|
_binderTemplate = TemplateReader.FromEmbeddedResource("RemoteTypeBinder.cstmpl");
|
||||||
|
_interfaceTemplateOriginal = TemplateReader.FromEmbeddedResource("PartialInterface.cstmpl");
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Console.WriteLine(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Execute(GeneratorExecutionContext context)
|
public void Execute(GeneratorExecutionContext context)
|
||||||
{
|
{
|
||||||
|
// return;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var trees = context.Compilation.SyntaxTrees;
|
var trees = context.Compilation.SyntaxTrees;
|
||||||
|
|||||||
@@ -33,9 +33,8 @@ namespace mROA.CodegenTools.Reading
|
|||||||
protected string GetTagValue(int from, int to)
|
protected string GetTagValue(int from, int to)
|
||||||
{
|
{
|
||||||
var realStart = from + 4;
|
var realStart = from + 4;
|
||||||
var span = TemplateText.AsSpan();
|
var span = TemplateText.Substring(realStart, to - realStart);
|
||||||
var slice = span.Slice(realStart, to - realStart);
|
return span;
|
||||||
return new string(slice.ToArray());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,14 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>netstandard2.1</TargetFramework>
|
<TargetFramework>netstandard2.0</TargetFramework>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<LangVersion>9</LangVersion>
|
<LangVersion>9</LangVersion>
|
||||||
|
<RootNamespace>mROA.CodegenTools</RootNamespace>
|
||||||
|
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||||
|
<Title>mROA.CodegenTools</Title>
|
||||||
|
<Description>Tools for codegen</Description>
|
||||||
|
<Copyright>MIT</Copyright>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -55,8 +55,11 @@ namespace mROA.Implementation
|
|||||||
var representationModule =
|
var representationModule =
|
||||||
_representationProducer.Produce(context.OwnerId);
|
_representationProducer.Produce(context.OwnerId);
|
||||||
|
|
||||||
_producedRemoteEndpoints.Add((Activator.CreateInstance(RemoteTypes[type], -1,
|
var instance = Activator.CreateInstance(RemoteTypes[type], -1, representationModule, context);
|
||||||
representationModule, context) as RemoteObjectBase)!);
|
|
||||||
|
var remoteObjectBase = (RemoteObjectBase)instance;
|
||||||
|
|
||||||
|
_producedRemoteEndpoints.Add(remoteObjectBase);
|
||||||
|
|
||||||
return _producedRemoteEndpoints.Last();
|
return _producedRemoteEndpoints.Last();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user