From 252ed19b61b9b9c59055299d91be8b4a5d57786e Mon Sep 17 00:00:00 2001 From: walon Date: Tue, 20 Jul 2021 15:41:27 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BF=AE=E5=A4=8D=E3=80=91=E4=BF=AE?= =?UTF-8?q?=E5=A4=8Dproto=20typescript=E4=BB=A3=E7=A0=81=EF=BC=8C=E5=BD=93?= =?UTF-8?q?namespace=E4=B8=BA=E7=A9=BA=E6=97=B6=E7=94=9F=E6=88=90=E7=9A=84?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E7=BC=96=E8=AF=91=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Luban.Common/Source/Utils/TypeUtil.cs | 27 +++++++++++++++++++ .../Source/Defs/DefTypeBase.cs | 2 +- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/Luban.Common/Source/Utils/TypeUtil.cs b/src/Luban.Common/Source/Utils/TypeUtil.cs index 325f46b..6a24e7e 100644 --- a/src/Luban.Common/Source/Utils/TypeUtil.cs +++ b/src/Luban.Common/Source/Utils/TypeUtil.cs @@ -39,11 +39,19 @@ namespace Luban.Common.Utils public static string MakeCppNamespaceBegin(string module) { + if (string.IsNullOrEmpty(module)) + { + return ""; + } return string.Join("", module.Split('.').Select(n => $"namespace {n} {{")); } public static string MakeCppNamespaceEnd(string module) { + if (string.IsNullOrEmpty(module)) + { + return ""; + } return string.Join("", module.Split('.').Select(n => $"}}")); } @@ -59,9 +67,22 @@ namespace Luban.Common.Utils public static string MakeTypescriptNamespaceBegin(string module) { + if (string.IsNullOrEmpty(module)) + { + return ""; + } return string.Join("", module.Split('.').Select(n => $"export namespace {n} {{")); } + public static string MakeTypescriptNamespaceEnd(string module) + { + if (string.IsNullOrEmpty(module)) + { + return ""; + } + return MakeCppNamespaceEnd(module); + } + public static string MakeFullName(string module, string name) { if (string.IsNullOrEmpty(module)) @@ -83,6 +104,10 @@ namespace Luban.Common.Utils public static string MakeGoNamespace(string module) { + if (string.IsNullOrEmpty(module)) + { + return ""; + } return string.Join("", module.Split('.').Where(s => !string.IsNullOrWhiteSpace(s)).Select(s => UpperCaseFirstChar(s))); } @@ -146,6 +171,7 @@ namespace Luban.Common.Utils "const", "is", "as", + "of", "typeid", "typeof", "object", @@ -154,6 +180,7 @@ namespace Luban.Common.Utils "in", "os", "sb", + "if", "ele", "new", "friend", diff --git a/src/Luban.Job.Common/Source/Defs/DefTypeBase.cs b/src/Luban.Job.Common/Source/Defs/DefTypeBase.cs index a19316c..1cefe39 100644 --- a/src/Luban.Job.Common/Source/Defs/DefTypeBase.cs +++ b/src/Luban.Job.Common/Source/Defs/DefTypeBase.cs @@ -35,7 +35,7 @@ namespace Luban.Job.Common.Defs public string TypescriptNamespaceBegin => TypeUtil.MakeTypescriptNamespaceBegin(Namespace); - public string TypescriptNamespaceEnd => TypeUtil.MakeCppNamespaceEnd(Namespace); + public string TypescriptNamespaceEnd => TypeUtil.MakeTypescriptNamespaceEnd(Namespace); public string CppFullName => TypeUtil.MakeCppFullName(Namespace, Name);