Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
468 changes: 226 additions & 242 deletions 468 sandbox/Sandbox/Generated.cs

Large diffs are not rendered by default.

99 changes: 49 additions & 50 deletions 99 sandbox/TestData2/Generated.cs

Large diffs are not rendered by default.

14 changes: 10 additions & 4 deletions 14 src/MessagePack.GeneratorCore/CodeAnalysis/Definitions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public string GetSerializeMethodString()
}
else
{
return $"formatterResolver.GetFormatterWithVerify<{this.Type}>().Serialize(ref writer, value.{this.Name}, options)";
return $"global::MessagePack.FormatterResolverExtensions.GetFormatterWithVerify<{this.Type}>(formatterResolver).Serialize(ref writer, value.{this.Name}, options)";
}
}

Expand All @@ -182,12 +182,18 @@ public string GetDeserializeMethodString()
}
else if (this.primitiveTypes.Contains(this.Type))
{
string suffix = this.Type == "byte[]" ? "?.ToArray()" : string.Empty;
return $"reader.Read{this.ShortTypeName!.Replace("[]", "s")}()" + suffix;
if (this.Type == "byte[]")
{
return "global::MessagePack.Internal.CodeGenHelpers.GetArrayFromNullableSequence(reader.ReadBytes())";
}
else
{
return $"reader.Read{this.ShortTypeName!.Replace("[]", "s")}()";
}
}
else
{
return $"formatterResolver.GetFormatterWithVerify<{this.Type}>().Deserialize(ref reader, options)";
return $"global::MessagePack.FormatterResolverExtensions.GetFormatterWithVerify<{this.Type}>(formatterResolver).Deserialize(ref reader, options)";
}
}
}
Expand Down
13 changes: 6 additions & 7 deletions 13 src/MessagePack.GeneratorCore/Generator/EnumTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,27 @@ public virtual string TransformText()
#pragma warning disable 414
#pragma warning disable 168

#pragma warning disable SA1200 // Using directives should be placed correctly
#pragma warning disable SA1403 // File may only contain a single namespace
#pragma warning disable SA1649 // File name should match first type name

namespace ");
this.Write(this.ToStringHelper.ToStringWithCulture(Namespace));
this.Write("\r\n{\r\n using System;\r\n using System.Buffers;\r\n using MessagePack;\r\n");
this.Write("\r\n{\r\n");
foreach(var info in EnumSerializationInfos) {
this.Write("\r\n public sealed class ");
this.Write(this.ToStringHelper.ToStringWithCulture(info.Name));
this.Write("Formatter : global::MessagePack.Formatters.IMessagePackFormatter<");
this.Write(this.ToStringHelper.ToStringWithCulture(info.FullName));
this.Write(">\r\n {\r\n public void Serialize(ref MessagePackWriter writer, ");
this.Write(">\r\n {\r\n public void Serialize(ref global::MessagePack.MessagePackWriter" +
" writer, ");
this.Write(this.ToStringHelper.ToStringWithCulture(info.FullName));
this.Write(" value, global::MessagePack.MessagePackSerializerOptions options)\r\n {\r\n " +
" writer.Write((");
" writer.Write((global::System.");
this.Write(this.ToStringHelper.ToStringWithCulture(info.UnderlyingType));
this.Write(")value);\r\n }\r\n\r\n public ");
this.Write(this.ToStringHelper.ToStringWithCulture(info.FullName));
this.Write(" Deserialize(ref MessagePackReader reader, global::MessagePack.MessagePackSeriali" +
"zerOptions options)\r\n {\r\n return (");
this.Write(" Deserialize(ref global::MessagePack.MessagePackReader reader, global::MessagePac" +
"k.MessagePackSerializerOptions options)\r\n {\r\n return (");
this.Write(this.ToStringHelper.ToStringWithCulture(info.FullName));
this.Write(")reader.Read");
this.Write(this.ToStringHelper.ToStringWithCulture(info.UnderlyingType));
Expand All @@ -67,7 +67,6 @@ namespace ");
#pragma warning restore 618
#pragma warning restore 612

#pragma warning restore SA1200 // Using directives should be placed correctly
#pragma warning restore SA1403 // File may only contain a single namespace
#pragma warning restore SA1649 // File name should match first type name
");
Expand Down
11 changes: 3 additions & 8 deletions 11 src/MessagePack.GeneratorCore/Generator/EnumTemplate.tt
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,21 @@
#pragma warning disable 414
#pragma warning disable 168

#pragma warning disable SA1200 // Using directives should be placed correctly
#pragma warning disable SA1403 // File may only contain a single namespace
#pragma warning disable SA1649 // File name should match first type name

namespace <#= Namespace #>
{
using System;
using System.Buffers;
using MessagePack;
<# foreach(var info in EnumSerializationInfos) { #>

public sealed class <#= info.Name #>Formatter : global::MessagePack.Formatters.IMessagePackFormatter<<#= info.FullName #>>
{
public void Serialize(ref MessagePackWriter writer, <#= info.FullName #> value, global::MessagePack.MessagePackSerializerOptions options)
public void Serialize(ref global::MessagePack.MessagePackWriter writer, <#= info.FullName #> value, global::MessagePack.MessagePackSerializerOptions options)
{
writer.Write((<#= info.UnderlyingType #>)value);
writer.Write((global::System.<#= info.UnderlyingType #>)value);
}

public <#= info.FullName #> Deserialize(ref MessagePackReader reader, global::MessagePack.MessagePackSerializerOptions options)
public <#= info.FullName #> Deserialize(ref global::MessagePack.MessagePackReader reader, global::MessagePack.MessagePackSerializerOptions options)
{
return (<#= info.FullName #>)reader.Read<#= info.UnderlyingType #>();
}
Expand All @@ -43,6 +39,5 @@ namespace <#= Namespace #>
#pragma warning restore 618
#pragma warning restore 612

#pragma warning restore SA1200 // Using directives should be placed correctly
#pragma warning restore SA1403 // File may only contain a single namespace
#pragma warning restore SA1649 // File name should match first type name
8 changes: 3 additions & 5 deletions 8 src/MessagePack.GeneratorCore/Generator/FormatterTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,17 @@ public virtual string TransformText()
#pragma warning disable 168

#pragma warning disable SA1129 // Do not use default value type constructor
#pragma warning disable SA1200 // Using directives should be placed correctly
#pragma warning disable SA1309 // Field names should not begin with underscore
#pragma warning disable SA1312 // Variable names should begin with lower-case letter
#pragma warning disable SA1403 // File may only contain a single namespace
#pragma warning disable SA1649 // File name should match first type name

namespace ");
this.Write(this.ToStringHelper.ToStringWithCulture(Namespace));
this.Write("\r\n{\r\n using global::System.Buffers;\r\n using global::MessagePack;\r\n");
this.Write("\r\n{\r\n");
foreach (var objInfo in ObjectSerializationInfos) {
bool isFormatterResolverNecessary = ShouldUseFormatterResolverHelper.ShouldUseFormatterResolver(objInfo.Members);
this.Write("\r\n public sealed class ");
this.Write(" public sealed class ");
this.Write(this.ToStringHelper.ToStringWithCulture(objInfo.FormatterNameWithoutNameSpace));
this.Write(" : global::MessagePack.Formatters.IMessagePackFormatter<");
this.Write(this.ToStringHelper.ToStringWithCulture(objInfo.FullName));
Expand Down Expand Up @@ -205,7 +204,7 @@ namespace ");
}
this.Write(" reader.Depth--;\r\n return ____result;\r\n");
}
this.Write(" }\r\n }\r\n");
this.Write(" }\r\n }\r\n\r\n");
}
this.Write(@"}

Expand All @@ -215,7 +214,6 @@ namespace ");
#pragma warning restore 612

#pragma warning restore SA1129 // Do not use default value type constructor
#pragma warning restore SA1200 // Using directives should be placed correctly
#pragma warning restore SA1309 // Field names should not begin with underscore
#pragma warning restore SA1312 // Variable names should begin with lower-case letter
#pragma warning restore SA1403 // File may only contain a single namespace
Expand Down
9 changes: 2 additions & 7 deletions 9 src/MessagePack.GeneratorCore/Generator/FormatterTemplate.tt
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,15 @@
#pragma warning disable 168

#pragma warning disable SA1129 // Do not use default value type constructor
#pragma warning disable SA1200 // Using directives should be placed correctly
#pragma warning disable SA1309 // Field names should not begin with underscore
#pragma warning disable SA1312 // Variable names should begin with lower-case letter
#pragma warning disable SA1403 // File may only contain a single namespace
#pragma warning disable SA1649 // File name should match first type name

namespace <#= Namespace #>
{
using global::System.Buffers;
using global::MessagePack;
<# foreach (var objInfo in ObjectSerializationInfos) {
bool isFormatterResolverNecessary = ShouldUseFormatterResolverHelper.ShouldUseFormatterResolver(objInfo.Members);#>

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 Expand Up @@ -155,16 +151,15 @@ namespace <#= Namespace #>
<# } #>
}
}
<# } #>
}

<# } #>}

#pragma warning restore 168
#pragma warning restore 414
#pragma warning restore 618
#pragma warning restore 612

#pragma warning restore SA1129 // Do not use default value type constructor
#pragma warning restore SA1200 // Using directives should be placed correctly
#pragma warning restore SA1309 // Field names should not begin with underscore
#pragma warning restore SA1312 // Variable names should begin with lower-case letter
#pragma warning restore SA1403 // File may only contain a single namespace
Expand Down
10 changes: 4 additions & 6 deletions 10 src/MessagePack.GeneratorCore/Generator/ResolverTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,12 @@ public virtual string TransformText()
#pragma warning disable 414
#pragma warning disable 168

#pragma warning disable SA1200 // Using directives should be placed correctly
#pragma warning disable SA1312 // Variable names should begin with lower-case letter
#pragma warning disable SA1649 // File name should match first type name

namespace ");
this.Write(this.ToStringHelper.ToStringWithCulture(Namespace));
this.Write("\r\n{\r\n using System;\r\n\r\n public class ");
this.Write("\r\n{\r\n public class ");
this.Write(this.ToStringHelper.ToStringWithCulture(ResolverName));
this.Write(" : global::MessagePack.IFormatterResolver\r\n {\r\n public static readonly " +
"global::MessagePack.IFormatterResolver Instance = new ");
Expand Down Expand Up @@ -76,10 +75,10 @@ static FormatterCache()
internal static class ");
this.Write(this.ToStringHelper.ToStringWithCulture(ResolverName));
this.Write("GetFormatterHelper\r\n {\r\n private static readonly global::System.Collect" +
"ions.Generic.Dictionary<Type, int> lookup;\r\n\r\n static ");
"ions.Generic.Dictionary<global::System.Type, int> lookup;\r\n\r\n static ");
this.Write(this.ToStringHelper.ToStringWithCulture(ResolverName));
this.Write("GetFormatterHelper()\r\n {\r\n lookup = new global::System.Collecti" +
"ons.Generic.Dictionary<Type, int>(");
"ons.Generic.Dictionary<global::System.Type, int>(");
this.Write(this.ToStringHelper.ToStringWithCulture(RegisterInfos.Length));
this.Write(")\r\n {\r\n");
for(var i = 0; i < RegisterInfos.Length; i++) { var x = RegisterInfos[i];
Expand All @@ -92,7 +91,7 @@ internal static class ");
this.Write(@" };
}

internal static object GetFormatter(Type t)
internal static object GetFormatter(global::System.Type t)
{
int key;
if (!lookup.TryGetValue(t, out key))
Expand Down Expand Up @@ -122,7 +121,6 @@ internal static object GetFormatter(Type t)
#pragma warning restore 612

#pragma warning restore SA1312 // Variable names should begin with lower-case letter
#pragma warning restore SA1200 // Using directives should be placed correctly
#pragma warning restore SA1649 // File name should match first type name
");
return this.GenerationEnvironment.ToString();
Expand Down
14 changes: 4 additions & 10 deletions 14 src/MessagePack.GeneratorCore/Generator/ResolverTemplate.tt
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,11 @@
#pragma warning disable 414
#pragma warning disable 168

#pragma warning disable SA1200 // Using directives should be placed correctly
#pragma warning disable SA1312 // Variable names should begin with lower-case letter
#pragma warning disable SA1649 // File name should match first type name

namespace <#= Namespace #>
{
using System;
using System.Buffers;
using MessagePack;

public class <#= ResolverName #> : global::MessagePack.IFormatterResolver
{
public static readonly global::MessagePack.IFormatterResolver Instance = new <#= ResolverName #>();
Expand Down Expand Up @@ -52,19 +47,19 @@ namespace <#= Namespace #>

internal static class <#= ResolverName #>GetFormatterHelper
{
private static readonly global::System.Collections.Generic.Dictionary<Type, int> lookup;
private static readonly global::System.Collections.Generic.Dictionary<global::System.Type, int> lookup;

static <#= ResolverName #>GetFormatterHelper()
{
lookup = new global::System.Collections.Generic.Dictionary<Type, int>(<#= RegisterInfos.Length #>)
lookup = new global::System.Collections.Generic.Dictionary<global::System.Type, int>(<#= RegisterInfos.Length #>)
{
<# for(var i = 0; i < RegisterInfos.Length; i++) { var x = RegisterInfos[i]; #>
{ typeof(<#= x.FullName #>), <#= i #> },
<# } #>
};
}

internal static object GetFormatter(Type t)
internal static object GetFormatter(global::System.Type t)
{
int key;
if (!lookup.TryGetValue(t, out key))
Expand All @@ -75,7 +70,7 @@ namespace <#= Namespace #>
switch (key)
{
<# for(var i = 0; i < RegisterInfos.Length; i++) { var x = RegisterInfos[i]; #>
case <#= i #>: return new <#= x.FormatterName.StartsWith("global::") ? x.FormatterName: (!string.IsNullOrEmpty(FormatterNamespace) ? FormatterNamespace + "." : FormatterNamespace) + x.FormatterName#>();
case <#= i #>: return new <#= x.FormatterName.StartsWith("global::") ? x.FormatterName: (!string.IsNullOrEmpty(FormatterNamespace) ? FormatterNamespace + "." : FormatterNamespace) + x.FormatterName #>();
<# } #>
default: return null;
}
Expand All @@ -89,5 +84,4 @@ namespace <#= Namespace #>
#pragma warning restore 612

#pragma warning restore SA1312 // Variable names should begin with lower-case letter
#pragma warning restore SA1200 // Using directives should be placed correctly
#pragma warning restore SA1649 // File name should match first type name
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,14 @@ public virtual string TransformText()
#pragma warning disable 168

#pragma warning disable SA1129 // Do not use default value type constructor
#pragma warning disable SA1200 // Using directives should be placed correctly
#pragma warning disable SA1309 // Field names should not begin with underscore
#pragma warning disable SA1312 // Variable names should begin with lower-case letter
#pragma warning disable SA1403 // File may only contain a single namespace
#pragma warning disable SA1649 // File name should match first type name

namespace ");
this.Write(this.ToStringHelper.ToStringWithCulture(Namespace));
this.Write("\r\n{\r\n using global::System.Buffers;\r\n using global::MessagePack;\r\n");
this.Write("\r\n{\r\n");
var list = new List<ValueTuple<MemberSerializationInfo, byte[]>>();
foreach (var objInfo in ObjectSerializationInfos) {
list.Clear();
Expand All @@ -53,7 +52,7 @@ namespace ");
}

bool isFormatterResolverNecessary = ShouldUseFormatterResolverHelper.ShouldUseFormatterResolver(objInfo.Members);
this.Write("\r\n public sealed class ");
this.Write(" public sealed class ");
this.Write(this.ToStringHelper.ToStringWithCulture(objInfo.FormatterNameWithoutNameSpace));
this.Write(" : global::MessagePack.Formatters.IMessagePackFormatter<");
this.Write(this.ToStringHelper.ToStringWithCulture(objInfo.FullName));
Expand Down Expand Up @@ -191,9 +190,21 @@ namespace ");
if (objInfo.Members.Length != 0) {
this.Write(" reader.Depth--;\r\n");
}
this.Write(" return ____result;\r\n }\r\n }\r\n");
this.Write(" return ____result;\r\n }\r\n }\r\n\r\n");
}
this.Write("}\r\n");
this.Write(@"}

#pragma warning restore 168
#pragma warning restore 414
#pragma warning restore 618
#pragma warning restore 612

#pragma warning restore SA1129 // Do not use default value type constructor
#pragma warning restore SA1309 // Field names should not begin with underscore
#pragma warning restore SA1312 // Variable names should begin with lower-case letter
#pragma warning restore SA1403 // File may only contain a single namespace
#pragma warning restore SA1649 // File name should match first type name
");
return this.GenerationEnvironment.ToString();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,13 @@
#pragma warning disable 168

#pragma warning disable SA1129 // Do not use default value type constructor
#pragma warning disable SA1200 // Using directives should be placed correctly
#pragma warning disable SA1309 // Field names should not begin with underscore
#pragma warning disable SA1312 // Variable names should begin with lower-case letter
#pragma warning disable SA1403 // File may only contain a single namespace
#pragma warning disable SA1649 // File name should match first type name

namespace <#= Namespace #>
{
using global::System.Buffers;
using global::MessagePack;
<# var list = new List<ValueTuple<MemberSerializationInfo, byte[]>>();
foreach (var objInfo in ObjectSerializationInfos) {
list.Clear();
Expand All @@ -33,7 +30,6 @@ foreach (var objInfo in ObjectSerializationInfos) {
}

bool isFormatterResolverNecessary = ShouldUseFormatterResolverHelper.ShouldUseFormatterResolver(objInfo.Members); #>

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 Expand Up @@ -147,5 +143,16 @@ foreach (var objInfo in ObjectSerializationInfos) {
return ____result;
}
}
<# } #>
}

<# } #>}

#pragma warning restore 168
#pragma warning restore 414
#pragma warning restore 618
#pragma warning restore 612

#pragma warning restore SA1129 // Do not use default value type constructor
#pragma warning restore SA1309 // Field names should not begin with underscore
#pragma warning restore SA1312 // Variable names should begin with lower-case letter
#pragma warning restore SA1403 // File may only contain a single namespace
#pragma warning restore SA1649 // File name should match first type name
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.