Skip to content

Commit

Permalink
Unify FormatterName
Browse files Browse the repository at this point in the history
And define FormatterNameWithoutNameSpace
  • Loading branch information
pCYSl5EDgo committed Nov 17, 2020
1 parent bc4e38f commit 7de6921
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 9 deletions.
4 changes: 3 additions & 1 deletion src/MessagePack.GeneratorCore/CodeAnalysis/Definitions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
4 changes: 1 addition & 3 deletions src/MessagePack.GeneratorCore/Generator/FormatterTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 #>
<# } #>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,9 @@ namespace ");
list.Add(new ValueTuple<MemberSerializationInfo, byte[]>(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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@ foreach (var objInfo in ObjectSerializationInfos) {
list.Add(new ValueTuple<MemberSerializationInfo, byte[]>(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 #>
<# }#>
Expand Down

0 comments on commit 7de6921

Please sign in to comment.