From d9013167b8e4a19cd124d00ed0cbefa9b0ecc931 Mon Sep 17 00:00:00 2001 From: Carson Lin <396098651@qq.com> Date: Sat, 10 Sep 2022 11:10:23 +0800 Subject: [PATCH] =?UTF-8?q?feat=20:=20=E6=94=AF=E6=8C=81=E6=97=A0=E5=91=BD?= =?UTF-8?q?=E5=90=8D=E7=A9=BA=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Source/Utils/TTypeTemplateExtends.cs | 22 +++++++++++++++++++ src/Luban.Server/Templates/common/cs/enum.tpl | 7 +++--- .../Templates/config/cs_bin/bean.tpl | 8 +++---- .../Templates/config/cs_bin/table.tpl | 6 ++--- .../Templates/config/cs_bin/tables.tpl | 7 +++--- .../config/cs_unity_editor_json/bean.tpl | 5 +++-- .../config/cs_unity_editor_json/enum.tpl | 7 +++--- 7 files changed, 41 insertions(+), 21 deletions(-) diff --git a/src/Luban.Job.Cfg/Source/Utils/TTypeTemplateExtends.cs b/src/Luban.Job.Cfg/Source/Utils/TTypeTemplateExtends.cs index 5eec48d..062b6d7 100644 --- a/src/Luban.Job.Cfg/Source/Utils/TTypeTemplateExtends.cs +++ b/src/Luban.Job.Cfg/Source/Utils/TTypeTemplateExtends.cs @@ -312,5 +312,27 @@ namespace Luban.Job.Cfg.Utils { return type.Apply(CsEditorInitValueVisitor.Ins); } + public static string CsStartNameSpaceGrace(string np) + { + if (string.IsNullOrEmpty(np)) + { + return string.Empty; + } + else + { + return $"namespace {np}\r\n{{"; + } + } + public static string CsEndNameSpaceGrace(string np) + { + if (string.IsNullOrEmpty(np)) + { + return string.Empty; + } + else + { + return "}"; + } + } } } diff --git a/src/Luban.Server/Templates/common/cs/enum.tpl b/src/Luban.Server/Templates/common/cs/enum.tpl index b928dab..e9ee3be 100644 --- a/src/Luban.Server/Templates/common/cs/enum.tpl +++ b/src/Luban.Server/Templates/common/cs/enum.tpl @@ -5,8 +5,8 @@ items = x.items ~}} -namespace {{namespace_with_top_module}} -{ + +{{cs_start_name_space_grace x.namespace_with_top_module}} {{~if comment != '' ~}} /// /// {{comment | html.escape}} @@ -26,4 +26,5 @@ namespace {{namespace_with_top_module}} {{item.name}} = {{item.value}}, {{~end~}} } -} + +{{cs_end_name_space_grace x.namespace_with_top_module}} diff --git a/src/Luban.Server/Templates/config/cs_bin/bean.tpl b/src/Luban.Server/Templates/config/cs_bin/bean.tpl index f095ba1..5a84a64 100644 --- a/src/Luban.Server/Templates/config/cs_bin/bean.tpl +++ b/src/Luban.Server/Templates/config/cs_bin/bean.tpl @@ -7,10 +7,8 @@ using System.Collections.Generic; hierarchy_export_fields = x.hierarchy_export_fields }} - -namespace {{x.namespace_with_top_module}} -{ - +{{cs_start_name_space_grace x.namespace_with_top_module}} +//ÃüÃû¿Õ¼ä{{x.namespace_with_top_module}} {{~if x.comment != '' ~}} /// /// {{x.escape_comment}} @@ -115,4 +113,4 @@ public {{x.cs_class_modifier}} partial class {{name}} : {{if parent_def_type}} { partial void PostResolve(); } -} +{{cs_end_name_space_grace x.namespace_with_top_module}} \ No newline at end of file diff --git a/src/Luban.Server/Templates/config/cs_bin/table.tpl b/src/Luban.Server/Templates/config/cs_bin/table.tpl index 1216e19..516c176 100644 --- a/src/Luban.Server/Templates/config/cs_bin/table.tpl +++ b/src/Luban.Server/Templates/config/cs_bin/table.tpl @@ -1,8 +1,8 @@ using Bright.Serialization; using System.Collections.Generic; -namespace {{x.namespace_with_top_module}} -{ + +{{cs_start_name_space_grace x.namespace_with_top_module}} {{ name = x.name key_type = x.key_ttype @@ -170,4 +170,4 @@ public partial class {{name}} partial void PostResolve(); } -} \ No newline at end of file +{{cs_end_name_space_grace x.namespace_with_top_module}} \ No newline at end of file diff --git a/src/Luban.Server/Templates/config/cs_bin/tables.tpl b/src/Luban.Server/Templates/config/cs_bin/tables.tpl index b97692e..2f5516d 100644 --- a/src/Luban.Server/Templates/config/cs_bin/tables.tpl +++ b/src/Luban.Server/Templates/config/cs_bin/tables.tpl @@ -6,9 +6,8 @@ using Bright.Serialization; tables = x.tables }} -namespace {{namespace}} -{ - + +{{cs_start_name_space_grace x.namespace_with_top_module}} public partial class {{name}} { {{~for table in tables ~}} @@ -46,4 +45,4 @@ public partial class {{name}} partial void PostResolve(); } -} \ No newline at end of file +{{cs_end_name_space_grace x.namespace_with_top_module}} \ No newline at end of file diff --git a/src/Luban.Server/Templates/config/cs_unity_editor_json/bean.tpl b/src/Luban.Server/Templates/config/cs_unity_editor_json/bean.tpl index 8b543a5..9a4a92a 100644 --- a/src/Luban.Server/Templates/config/cs_unity_editor_json/bean.tpl +++ b/src/Luban.Server/Templates/config/cs_unity_editor_json/bean.tpl @@ -10,8 +10,7 @@ using SimpleJSON; fields = x.fields }} -namespace {{x.namespace_with_editor_top_module}} -{ +{{cs_start_name_space_grace x.namespace_with_editor_top_module}} {{~if x.comment != '' ~}} /// @@ -108,3 +107,5 @@ public {{x.cs_class_modifier}} partial class {{name}} : {{if parent_def_type}} { {{~end~}} } } + +{{cs_end_name_space_grace x.namespace_with_editor_top_module}} \ No newline at end of file diff --git a/src/Luban.Server/Templates/config/cs_unity_editor_json/enum.tpl b/src/Luban.Server/Templates/config/cs_unity_editor_json/enum.tpl index 8d4a8ed..d2da366 100644 --- a/src/Luban.Server/Templates/config/cs_unity_editor_json/enum.tpl +++ b/src/Luban.Server/Templates/config/cs_unity_editor_json/enum.tpl @@ -5,9 +5,7 @@ itemType = 'Bright.Config.EditorEnumItemInfo' ~}} -namespace {{x.namespace_with_editor_top_module}} -{ - +{{cs_start_name_space_grace x.namespace_with_editor_top_module}} {{~if comment != '' ~}} /// /// {{comment | html.escape}} @@ -58,4 +56,5 @@ namespace {{x.namespace_with_editor_top_module}} return __items.Find(c => c.Value == value); } } -} + +{{cs_end_name_space_grace x.namespace_with_editor_top_module}}