From 7de6921cce32cbed933d0341804ee96df5c2d15f Mon Sep 17 00:00:00 2001 From: pCYSl5EDgo Date: Tue, 17 Nov 2020 16:02:16 +0900 Subject: [PATCH] Unify FormatterName And define FormatterNameWithoutNameSpace --- src/MessagePack.GeneratorCore/CodeAnalysis/Definitions.cs | 4 +++- src/MessagePack.GeneratorCore/Generator/FormatterTemplate.cs | 4 +--- src/MessagePack.GeneratorCore/Generator/FormatterTemplate.tt | 2 +- .../Generator/StringKey/StringKeyFormatterTemplate.cs | 3 +-- .../Generator/StringKey/StringKeyFormatterTemplate.tt | 3 +-- 5 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/MessagePack.GeneratorCore/CodeAnalysis/Definitions.cs b/src/MessagePack.GeneratorCore/CodeAnalysis/Definitions.cs index ab0534429..9e3b86899 100644 --- a/src/MessagePack.GeneratorCore/CodeAnalysis/Definitions.cs +++ b/src/MessagePack.GeneratorCore/CodeAnalysis/Definitions.cs @@ -52,7 +52,9 @@ public bool IsStruct public bool NeedsCastOnAfter { get; set; } - public string FormatterName => (this.Namespace == null ? this.Name : this.Namespace + "." + this.Name) + "Formatter" + (this.IsOpenGenericType ? $"<{string.Join(",", this.GenericTypeParameters.Select(x => x.Name))}>" : string.Empty); + public string FormatterName => this.Namespace == null ? FormatterNameWithoutNameSpace : this.Namespace + "." + FormatterNameWithoutNameSpace; + + public string FormatterNameWithoutNameSpace => this.Name + "Formatter" + (this.IsOpenGenericType ? $"<{string.Join(", ", this.GenericTypeParameters.Select(x => x.Name))}>" : string.Empty); public int WriteCount { diff --git a/src/MessagePack.GeneratorCore/Generator/FormatterTemplate.cs b/src/MessagePack.GeneratorCore/Generator/FormatterTemplate.cs index b114ee1ad..e153d5eb1 100644 --- a/src/MessagePack.GeneratorCore/Generator/FormatterTemplate.cs +++ b/src/MessagePack.GeneratorCore/Generator/FormatterTemplate.cs @@ -47,9 +47,7 @@ namespace "); foreach (var objInfo in ObjectSerializationInfos) { bool isFormatterResolverNecessary = ShouldUseFormatterResolverHelper.ShouldUseFormatterResolver(objInfo.Members); this.Write("\r\n public sealed class "); - this.Write(this.ToStringHelper.ToStringWithCulture(objInfo.Name)); - this.Write("Formatter"); - this.Write(this.ToStringHelper.ToStringWithCulture((objInfo.IsOpenGenericType ? $"<{string.Join(", ", objInfo.GenericTypeParameters.Select(x => x.Name))}>" : ""))); + this.Write(this.ToStringHelper.ToStringWithCulture(objInfo.FormatterNameWithoutNameSpace)); this.Write(" : global::MessagePack.Formatters.IMessagePackFormatter<"); this.Write(this.ToStringHelper.ToStringWithCulture(objInfo.FullName)); this.Write(">\r\n"); diff --git a/src/MessagePack.GeneratorCore/Generator/FormatterTemplate.tt b/src/MessagePack.GeneratorCore/Generator/FormatterTemplate.tt index d56d1d0af..631dc9f15 100644 --- a/src/MessagePack.GeneratorCore/Generator/FormatterTemplate.tt +++ b/src/MessagePack.GeneratorCore/Generator/FormatterTemplate.tt @@ -26,7 +26,7 @@ namespace <#= Namespace #> <# foreach (var objInfo in ObjectSerializationInfos) { bool isFormatterResolverNecessary = ShouldUseFormatterResolverHelper.ShouldUseFormatterResolver(objInfo.Members);#> - public sealed class <#= objInfo.Name #>Formatter<#= (objInfo.IsOpenGenericType ? $"<{string.Join(", ", objInfo.GenericTypeParameters.Select(x => x.Name))}>" : "") #> : global::MessagePack.Formatters.IMessagePackFormatter<<#= objInfo.FullName #>> + public sealed class <#= objInfo.FormatterNameWithoutNameSpace #> : global::MessagePack.Formatters.IMessagePackFormatter<<#= objInfo.FullName #>> <# foreach (var typeArg in objInfo.GenericTypeParameters.Where(x => x.HasConstraints)) { #> where <#= typeArg.Name #> : <#= typeArg.Constraints #> <# } #> diff --git a/src/MessagePack.GeneratorCore/Generator/StringKey/StringKeyFormatterTemplate.cs b/src/MessagePack.GeneratorCore/Generator/StringKey/StringKeyFormatterTemplate.cs index 39fef24af..521df4441 100644 --- a/src/MessagePack.GeneratorCore/Generator/StringKey/StringKeyFormatterTemplate.cs +++ b/src/MessagePack.GeneratorCore/Generator/StringKey/StringKeyFormatterTemplate.cs @@ -52,10 +52,9 @@ namespace "); list.Add(new ValueTuple(member, binary)); } - string formatterName = objInfo.Name + (objInfo.IsOpenGenericType ? $"Formatter<{string.Join(", ", objInfo.GenericTypeParameters.Select(x => x.Name))}>" : "Formatter"); bool isFormatterResolverNecessary = ShouldUseFormatterResolverHelper.ShouldUseFormatterResolver(objInfo.Members); this.Write("\r\n public sealed class "); - this.Write(this.ToStringHelper.ToStringWithCulture(formatterName)); + this.Write(this.ToStringHelper.ToStringWithCulture(objInfo.FormatterNameWithoutNameSpace)); this.Write(" : global::MessagePack.Formatters.IMessagePackFormatter<"); this.Write(this.ToStringHelper.ToStringWithCulture(objInfo.FullName)); this.Write(">\r\n"); diff --git a/src/MessagePack.GeneratorCore/Generator/StringKey/StringKeyFormatterTemplate.tt b/src/MessagePack.GeneratorCore/Generator/StringKey/StringKeyFormatterTemplate.tt index a7ce779bf..251fa55c4 100644 --- a/src/MessagePack.GeneratorCore/Generator/StringKey/StringKeyFormatterTemplate.tt +++ b/src/MessagePack.GeneratorCore/Generator/StringKey/StringKeyFormatterTemplate.tt @@ -32,10 +32,9 @@ foreach (var objInfo in ObjectSerializationInfos) { list.Add(new ValueTuple(member, binary)); } - string formatterName = objInfo.Name + (objInfo.IsOpenGenericType ? $"Formatter<{string.Join(", ", objInfo.GenericTypeParameters.Select(x => x.Name))}>" : "Formatter"); bool isFormatterResolverNecessary = ShouldUseFormatterResolverHelper.ShouldUseFormatterResolver(objInfo.Members); #> - public sealed class <#= formatterName #> : global::MessagePack.Formatters.IMessagePackFormatter<<#= objInfo.FullName #>> + public sealed class <#= objInfo.FormatterNameWithoutNameSpace #> : global::MessagePack.Formatters.IMessagePackFormatter<<#= objInfo.FullName #>> <# foreach (var typeArg in objInfo.GenericTypeParameters.Where(x => x.HasConstraints)) {#> where <#= typeArg.Name #> : <#= typeArg.Constraints #> <# }#>