给出一个课程:
public class
{
public void Foo() {}
}
我可以生成TypeScript函数
foo() {
}
没有它被封闭在课堂上?
答案 0 :(得分:1)
抱歉,我的错误地读了你的问题
要拯救的代码生成器:
"scripts": {
"ng": "ng",
"start:client": "ng serve",
"build:client": "ng build",
"build:client:watch": "ng build --watch",
"build:server": "dotnet build",
"build:all": "npm run build:client && npm run build:server",
"build:client:prod": "ng build --prod --env=prod",
"build:all:prod": "npm run build:client:prod && npm run build:server",
"test:client": "ng test",
"lint:client": "ng lint",
"e2e:client": "ng e2e",
"restore": "dotnet restore",
"start:all": "ng serve --live-reload false && dotnet run",
"start:all:watch": "concurrently -k \"npm run build:client:watch\" \"dotnet watch run\"",
"saw": "npm run start:all:watch"
}
然后,流畅的配置:
public class FunClassCodeGenerator : ClassCodeGenerator
{
public override RtClass GenerateNode(Type element, RtClass result, TypeResolver resolver)
{
// obtain current namespace
var ns = this.Context.Location.CurrentNamespace;
// invoke base generation method
var r = base.GenerateNode(element, result, resolver);
foreach (var rMember in r.Members)
{
var m = rMember as RtFuncion;
if (m!=null)
{
// remove access modifier
m.AccessModifier = null;
// here you can override implementation by
// m.Body = new RtRaw("...code...");
// append function body to current namespace
ns.CompilationUnits.Add(m);
}
}
// return null instead of result to
// suppress writing AST of original class
// to resulting file
return null;
}
}
因此,对于public static void Configure(ConfigurationBuilder cb)
{
cb.ExportAsClass<SomeClass>()
.WithPublicMethods()
.WithCodeGenerator<FunClassCodeGenerator>()
.DontIncludeToNamespace();
}
声明如下:
SomeClass
这种方法会在你的TypeScript文件中产生这样的代码:
public class SomeClass
{
public void DoSomething() { }
public string GetName(int arg) { return string.Empty; }
}