Добавлена возможность получать доступ к шаблонам через встроенный ресурс
This commit is contained in:
@@ -5,6 +5,7 @@
|
|||||||
<TargetFramework>net9.0</TargetFramework>
|
<TargetFramework>net9.0</TargetFramework>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
|
<RootNamespace>BasicDemo</RootNamespace>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@@ -12,9 +13,10 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Update="exampleTemplate.cstmpl">
|
<None Remove="exampleTemplate.cstmpl" />
|
||||||
|
<EmbeddedResource Include="exampleTemplate.cstmpl">
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
</None>
|
</EmbeddedResource>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
@@ -18,6 +18,8 @@ using mROA.CodegenTools;
|
|||||||
// doc.Insert("insert", "inserted text by insert template => ");
|
// doc.Insert("insert", "inserted text by insert template => ");
|
||||||
// doc.Parts.Add(new DefineTemplateSection("post added", "post", doc));
|
// doc.Parts.Add(new DefineTemplateSection("post added", "post", doc));
|
||||||
// Console.WriteLine(doc.Compile());
|
// Console.WriteLine(doc.Compile());
|
||||||
|
var doc = TemplateReader.FromEmbeddedResource("exampleTemplate.cstmpl");
|
||||||
|
doc.Insert("ctorInserting", "test inserting");
|
||||||
|
Console.WriteLine(doc.Compile());
|
||||||
|
|
||||||
var doc = TemplateReader.Parce(File.ReadAllText("exampleTemplate.cstmpl"));
|
|
||||||
Console.WriteLine(doc.Parts.Count);
|
Console.WriteLine(doc.Parts.Count);
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
// <auto-generated/>
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Reflection;
|
||||||
|
using mROA.Abstract;
|
||||||
|
using mROA.Implementation;
|
||||||
|
using System;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
|
namespace mROA.Codegen
|
||||||
|
{
|
||||||
|
public class CoCodegenMethodRepository : IMethodRepository
|
||||||
|
{
|
||||||
|
private readonly List<IMethodInvoker> _methods = new () {
|
||||||
|
<!I invoker>
|
||||||
|
};
|
||||||
|
|
||||||
|
public IMethodInvoker GetMethod(int id)
|
||||||
|
{
|
||||||
|
if (id == -1)
|
||||||
|
return mROA.Implementation.MethodInvoker.Dispose;
|
||||||
|
|
||||||
|
if (_methods.Count <= id)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return _methods[id];
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Inject<T>(T dependency)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -34,7 +34,10 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Remove="test.tpt" />
|
<None Remove="test.tpt" />
|
||||||
<EmbeddedResource Include="test.tpt" />
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\mROA.CodegenTools\mROA.CodegenTools.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
test text
|
|
||||||
@@ -21,7 +21,7 @@ namespace mROA.CodegenTools
|
|||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return $"{nameof(_tag)}: {_tag}, {nameof(StoredText)}: {StoredText}";
|
return StoredText;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,7 +4,8 @@ namespace mROA.CodegenTools
|
|||||||
{
|
{
|
||||||
public class InnerTemplateSectionReader : LeadingTextSectionReader
|
public class InnerTemplateSectionReader : LeadingTextSectionReader
|
||||||
{
|
{
|
||||||
public InnerTemplateSectionReader() : base("<!T")
|
public InnerTemplateSectionReader()
|
||||||
|
: base("<!T")
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
namespace mROA.CodegenTools
|
namespace mROA.CodegenTools
|
||||||
{
|
{
|
||||||
@@ -66,5 +68,14 @@ namespace mROA.CodegenTools
|
|||||||
|
|
||||||
return doc;
|
return doc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static TemplateDocument FromEmbeddedResource(string resourceName)
|
||||||
|
{
|
||||||
|
var fileName = Assembly.GetCallingAssembly().GetManifestResourceNames().First(n => n.EndsWith(resourceName));
|
||||||
|
var res = Assembly.GetCallingAssembly().GetManifestResourceStream(fileName);
|
||||||
|
var reader = new StreamReader(res);
|
||||||
|
var templateText = reader.ReadToEnd();
|
||||||
|
return Parce(templateText);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -35,7 +35,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "mROA.CodegenTools", "mROA.C
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Codegen", "Codegen", "{3DB22457-E65B-426F-B3DD-08C615132B3E}"
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Codegen", "Codegen", "{3DB22457-E65B-426F-B3DD-08C615132B3E}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BasicDemo", "BasicDemo\BasicDemo.csproj", "{87396E86-D7ED-4556-AB50-F3696FEF9072}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Codegen.Basic", "Codegen.Basic\Codegen.Basic.csproj", "{87396E86-D7ED-4556-AB50-F3696FEF9072}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
|||||||
Reference in New Issue
Block a user