Avoid C#10 global using name collisions (#1368)
This commit is contained in:
Родитель
b30874c1e4
Коммит
54b155f6e5
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -7,14 +7,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 MessagePack.Resolvers
|
||||
{
|
||||
using System;
|
||||
|
||||
public class GeneratedResolver : global::MessagePack.IFormatterResolver
|
||||
{
|
||||
public static readonly global::MessagePack.IFormatterResolver Instance = new GeneratedResolver();
|
||||
|
@ -45,11 +42,11 @@ namespace MessagePack.Resolvers
|
|||
|
||||
internal static class GeneratedResolverGetFormatterHelper
|
||||
{
|
||||
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 GeneratedResolverGetFormatterHelper()
|
||||
{
|
||||
lookup = new global::System.Collections.Generic.Dictionary<Type, int>(14)
|
||||
lookup = new global::System.Collections.Generic.Dictionary<global::System.Type, int>(14)
|
||||
{
|
||||
{ typeof(global::System.Collections.Generic.List<global::TestData2.A>), 0 },
|
||||
{ typeof(global::System.Collections.Generic.List<global::TestData2.B>), 1 },
|
||||
|
@ -68,7 +65,7 @@ namespace MessagePack.Resolvers
|
|||
};
|
||||
}
|
||||
|
||||
internal static object GetFormatter(Type t)
|
||||
internal static object GetFormatter(global::System.Type t)
|
||||
{
|
||||
int key;
|
||||
if (!lookup.TryGetValue(t, out key))
|
||||
|
@ -104,7 +101,6 @@ namespace MessagePack.Resolvers
|
|||
#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
|
||||
|
||||
|
||||
|
@ -117,24 +113,20 @@ namespace MessagePack.Resolvers
|
|||
#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 MessagePack.Formatters.TestData2
|
||||
{
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using MessagePack;
|
||||
|
||||
public sealed class Nest1_IdFormatter : global::MessagePack.Formatters.IMessagePackFormatter<global::TestData2.Nest1.Id>
|
||||
{
|
||||
public void Serialize(ref MessagePackWriter writer, global::TestData2.Nest1.Id value, global::MessagePack.MessagePackSerializerOptions options)
|
||||
public void Serialize(ref global::MessagePack.MessagePackWriter writer, global::TestData2.Nest1.Id value, global::MessagePack.MessagePackSerializerOptions options)
|
||||
{
|
||||
writer.Write((Int32)value);
|
||||
writer.Write((global::System.Int32)value);
|
||||
}
|
||||
|
||||
public global::TestData2.Nest1.Id Deserialize(ref MessagePackReader reader, global::MessagePack.MessagePackSerializerOptions options)
|
||||
public global::TestData2.Nest1.Id Deserialize(ref global::MessagePack.MessagePackReader reader, global::MessagePack.MessagePackSerializerOptions options)
|
||||
{
|
||||
return (global::TestData2.Nest1.Id)reader.ReadInt32();
|
||||
}
|
||||
|
@ -142,12 +134,12 @@ namespace MessagePack.Formatters.TestData2
|
|||
|
||||
public sealed class Nest2_IdFormatter : global::MessagePack.Formatters.IMessagePackFormatter<global::TestData2.Nest2.Id>
|
||||
{
|
||||
public void Serialize(ref MessagePackWriter writer, global::TestData2.Nest2.Id value, global::MessagePack.MessagePackSerializerOptions options)
|
||||
public void Serialize(ref global::MessagePack.MessagePackWriter writer, global::TestData2.Nest2.Id value, global::MessagePack.MessagePackSerializerOptions options)
|
||||
{
|
||||
writer.Write((Int32)value);
|
||||
writer.Write((global::System.Int32)value);
|
||||
}
|
||||
|
||||
public global::TestData2.Nest2.Id Deserialize(ref MessagePackReader reader, global::MessagePack.MessagePackSerializerOptions options)
|
||||
public global::TestData2.Nest2.Id Deserialize(ref global::MessagePack.MessagePackReader reader, global::MessagePack.MessagePackSerializerOptions options)
|
||||
{
|
||||
return (global::TestData2.Nest2.Id)reader.ReadInt32();
|
||||
}
|
||||
|
@ -159,7 +151,6 @@ namespace MessagePack.Formatters.TestData2
|
|||
#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
|
||||
|
||||
|
@ -175,7 +166,6 @@ namespace MessagePack.Formatters.TestData2
|
|||
#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
|
||||
|
@ -183,9 +173,6 @@ namespace MessagePack.Formatters.TestData2
|
|||
|
||||
namespace MessagePack.Formatters.TestData2
|
||||
{
|
||||
using global::System.Buffers;
|
||||
using global::MessagePack;
|
||||
|
||||
public sealed class AFormatter : global::MessagePack.Formatters.IMessagePackFormatter<global::TestData2.A>
|
||||
{
|
||||
// a
|
||||
|
@ -208,9 +195,9 @@ namespace MessagePack.Formatters.TestData2
|
|||
writer.WriteRaw(GetSpan_a());
|
||||
writer.Write(value.a);
|
||||
writer.WriteRaw(GetSpan_bs());
|
||||
formatterResolver.GetFormatterWithVerify<global::System.Collections.Generic.List<global::TestData2.B>>().Serialize(ref writer, value.bs, options);
|
||||
global::MessagePack.FormatterResolverExtensions.GetFormatterWithVerify<global::System.Collections.Generic.List<global::TestData2.B>>(formatterResolver).Serialize(ref writer, value.bs, options);
|
||||
writer.WriteRaw(GetSpan_c());
|
||||
formatterResolver.GetFormatterWithVerify<global::TestData2.C>().Serialize(ref writer, value.c, options);
|
||||
global::MessagePack.FormatterResolverExtensions.GetFormatterWithVerify<global::TestData2.C>(formatterResolver).Serialize(ref writer, value.c, options);
|
||||
}
|
||||
|
||||
public global::TestData2.A Deserialize(ref global::MessagePack.MessagePackReader reader, global::MessagePack.MessagePackSerializerOptions options)
|
||||
|
@ -242,13 +229,13 @@ namespace MessagePack.Formatters.TestData2
|
|||
____result.a = reader.ReadInt32();
|
||||
continue;
|
||||
case 99UL:
|
||||
____result.c = formatterResolver.GetFormatterWithVerify<global::TestData2.C>().Deserialize(ref reader, options);
|
||||
____result.c = global::MessagePack.FormatterResolverExtensions.GetFormatterWithVerify<global::TestData2.C>(formatterResolver).Deserialize(ref reader, options);
|
||||
continue;
|
||||
}
|
||||
case 2:
|
||||
if (global::MessagePack.Internal.AutomataKeyGen.GetKey(ref stringKey) != 29538UL) { goto FAIL; }
|
||||
|
||||
____result.bs = formatterResolver.GetFormatterWithVerify<global::System.Collections.Generic.List<global::TestData2.B>>().Deserialize(ref reader, options);
|
||||
____result.bs = global::MessagePack.FormatterResolverExtensions.GetFormatterWithVerify<global::System.Collections.Generic.List<global::TestData2.B>>(formatterResolver).Deserialize(ref reader, options);
|
||||
continue;
|
||||
|
||||
}
|
||||
|
@ -279,9 +266,9 @@ namespace MessagePack.Formatters.TestData2
|
|||
var formatterResolver = options.Resolver;
|
||||
writer.WriteMapHeader(3);
|
||||
writer.WriteRaw(GetSpan_ass());
|
||||
formatterResolver.GetFormatterWithVerify<global::System.Collections.Generic.List<global::TestData2.A>>().Serialize(ref writer, value.ass, options);
|
||||
global::MessagePack.FormatterResolverExtensions.GetFormatterWithVerify<global::System.Collections.Generic.List<global::TestData2.A>>(formatterResolver).Serialize(ref writer, value.ass, options);
|
||||
writer.WriteRaw(GetSpan_c());
|
||||
formatterResolver.GetFormatterWithVerify<global::TestData2.C>().Serialize(ref writer, value.c, options);
|
||||
global::MessagePack.FormatterResolverExtensions.GetFormatterWithVerify<global::TestData2.C>(formatterResolver).Serialize(ref writer, value.c, options);
|
||||
writer.WriteRaw(GetSpan_a());
|
||||
writer.Write(value.a);
|
||||
}
|
||||
|
@ -310,14 +297,14 @@ namespace MessagePack.Formatters.TestData2
|
|||
case 3:
|
||||
if (global::MessagePack.Internal.AutomataKeyGen.GetKey(ref stringKey) != 7566177UL) { goto FAIL; }
|
||||
|
||||
____result.ass = formatterResolver.GetFormatterWithVerify<global::System.Collections.Generic.List<global::TestData2.A>>().Deserialize(ref reader, options);
|
||||
____result.ass = global::MessagePack.FormatterResolverExtensions.GetFormatterWithVerify<global::System.Collections.Generic.List<global::TestData2.A>>(formatterResolver).Deserialize(ref reader, options);
|
||||
continue;
|
||||
case 1:
|
||||
switch (global::MessagePack.Internal.AutomataKeyGen.GetKey(ref stringKey))
|
||||
{
|
||||
default: goto FAIL;
|
||||
case 99UL:
|
||||
____result.c = formatterResolver.GetFormatterWithVerify<global::TestData2.C>().Deserialize(ref reader, options);
|
||||
____result.c = global::MessagePack.FormatterResolverExtensions.GetFormatterWithVerify<global::TestData2.C>(formatterResolver).Deserialize(ref reader, options);
|
||||
continue;
|
||||
case 97UL:
|
||||
____result.a = reader.ReadInt32();
|
||||
|
@ -350,7 +337,7 @@ namespace MessagePack.Formatters.TestData2
|
|||
var formatterResolver = options.Resolver;
|
||||
writer.WriteMapHeader(2);
|
||||
writer.WriteRaw(GetSpan_b());
|
||||
formatterResolver.GetFormatterWithVerify<global::TestData2.B>().Serialize(ref writer, value.b, options);
|
||||
global::MessagePack.FormatterResolverExtensions.GetFormatterWithVerify<global::TestData2.B>(formatterResolver).Serialize(ref writer, value.b, options);
|
||||
writer.WriteRaw(GetSpan_a());
|
||||
writer.Write(value.a);
|
||||
}
|
||||
|
@ -381,7 +368,7 @@ namespace MessagePack.Formatters.TestData2
|
|||
{
|
||||
default: goto FAIL;
|
||||
case 98UL:
|
||||
____result.b = formatterResolver.GetFormatterWithVerify<global::TestData2.B>().Deserialize(ref reader, options);
|
||||
____result.b = global::MessagePack.FormatterResolverExtensions.GetFormatterWithVerify<global::TestData2.B>(formatterResolver).Deserialize(ref reader, options);
|
||||
continue;
|
||||
case 97UL:
|
||||
____result.a = reader.ReadInt32();
|
||||
|
@ -414,9 +401,9 @@ namespace MessagePack.Formatters.TestData2
|
|||
var formatterResolver = options.Resolver;
|
||||
writer.WriteMapHeader(2);
|
||||
writer.WriteRaw(GetSpan_EnumId());
|
||||
formatterResolver.GetFormatterWithVerify<global::TestData2.Nest1.Id>().Serialize(ref writer, value.EnumId, options);
|
||||
global::MessagePack.FormatterResolverExtensions.GetFormatterWithVerify<global::TestData2.Nest1.Id>(formatterResolver).Serialize(ref writer, value.EnumId, options);
|
||||
writer.WriteRaw(GetSpan_ClassId());
|
||||
formatterResolver.GetFormatterWithVerify<global::TestData2.Nest1.IdType>().Serialize(ref writer, value.ClassId, options);
|
||||
global::MessagePack.FormatterResolverExtensions.GetFormatterWithVerify<global::TestData2.Nest1.IdType>(formatterResolver).Serialize(ref writer, value.ClassId, options);
|
||||
}
|
||||
|
||||
public global::TestData2.Nest1 Deserialize(ref global::MessagePack.MessagePackReader reader, global::MessagePack.MessagePackSerializerOptions options)
|
||||
|
@ -443,12 +430,12 @@ namespace MessagePack.Formatters.TestData2
|
|||
case 6:
|
||||
if (global::MessagePack.Internal.AutomataKeyGen.GetKey(ref stringKey) != 110266531802693UL) { goto FAIL; }
|
||||
|
||||
____result.EnumId = formatterResolver.GetFormatterWithVerify<global::TestData2.Nest1.Id>().Deserialize(ref reader, options);
|
||||
____result.EnumId = global::MessagePack.FormatterResolverExtensions.GetFormatterWithVerify<global::TestData2.Nest1.Id>(formatterResolver).Deserialize(ref reader, options);
|
||||
continue;
|
||||
case 7:
|
||||
if (global::MessagePack.Internal.AutomataKeyGen.GetKey(ref stringKey) != 28228257876896835UL) { goto FAIL; }
|
||||
|
||||
____result.ClassId = formatterResolver.GetFormatterWithVerify<global::TestData2.Nest1.IdType>().Deserialize(ref reader, options);
|
||||
____result.ClassId = global::MessagePack.FormatterResolverExtensions.GetFormatterWithVerify<global::TestData2.Nest1.IdType>(formatterResolver).Deserialize(ref reader, options);
|
||||
continue;
|
||||
|
||||
}
|
||||
|
@ -503,9 +490,9 @@ namespace MessagePack.Formatters.TestData2
|
|||
var formatterResolver = options.Resolver;
|
||||
writer.WriteMapHeader(2);
|
||||
writer.WriteRaw(GetSpan_EnumId());
|
||||
formatterResolver.GetFormatterWithVerify<global::TestData2.Nest2.Id>().Serialize(ref writer, value.EnumId, options);
|
||||
global::MessagePack.FormatterResolverExtensions.GetFormatterWithVerify<global::TestData2.Nest2.Id>(formatterResolver).Serialize(ref writer, value.EnumId, options);
|
||||
writer.WriteRaw(GetSpan_ClassId());
|
||||
formatterResolver.GetFormatterWithVerify<global::TestData2.Nest2.IdType>().Serialize(ref writer, value.ClassId, options);
|
||||
global::MessagePack.FormatterResolverExtensions.GetFormatterWithVerify<global::TestData2.Nest2.IdType>(formatterResolver).Serialize(ref writer, value.ClassId, options);
|
||||
}
|
||||
|
||||
public global::TestData2.Nest2 Deserialize(ref global::MessagePack.MessagePackReader reader, global::MessagePack.MessagePackSerializerOptions options)
|
||||
|
@ -532,12 +519,12 @@ namespace MessagePack.Formatters.TestData2
|
|||
case 6:
|
||||
if (global::MessagePack.Internal.AutomataKeyGen.GetKey(ref stringKey) != 110266531802693UL) { goto FAIL; }
|
||||
|
||||
____result.EnumId = formatterResolver.GetFormatterWithVerify<global::TestData2.Nest2.Id>().Deserialize(ref reader, options);
|
||||
____result.EnumId = global::MessagePack.FormatterResolverExtensions.GetFormatterWithVerify<global::TestData2.Nest2.Id>(formatterResolver).Deserialize(ref reader, options);
|
||||
continue;
|
||||
case 7:
|
||||
if (global::MessagePack.Internal.AutomataKeyGen.GetKey(ref stringKey) != 28228257876896835UL) { goto FAIL; }
|
||||
|
||||
____result.ClassId = formatterResolver.GetFormatterWithVerify<global::TestData2.Nest2.IdType>().Deserialize(ref reader, options);
|
||||
____result.ClassId = global::MessagePack.FormatterResolverExtensions.GetFormatterWithVerify<global::TestData2.Nest2.IdType>(formatterResolver).Deserialize(ref reader, options);
|
||||
continue;
|
||||
|
||||
}
|
||||
|
@ -592,9 +579,9 @@ namespace MessagePack.Formatters.TestData2
|
|||
var formatterResolver = options.Resolver;
|
||||
writer.WriteMapHeader(2);
|
||||
writer.WriteRaw(GetSpan_MyProperty1());
|
||||
formatterResolver.GetFormatterWithVerify<string>().Serialize(ref writer, value.MyProperty1, options);
|
||||
global::MessagePack.FormatterResolverExtensions.GetFormatterWithVerify<string>(formatterResolver).Serialize(ref writer, value.MyProperty1, options);
|
||||
writer.WriteRaw(GetSpan_MyProperty2());
|
||||
formatterResolver.GetFormatterWithVerify<string>().Serialize(ref writer, value.MyProperty2, options);
|
||||
global::MessagePack.FormatterResolverExtensions.GetFormatterWithVerify<string>(formatterResolver).Serialize(ref writer, value.MyProperty2, options);
|
||||
}
|
||||
|
||||
public global::TestData2.PropNameCheck1 Deserialize(ref global::MessagePack.MessagePackReader reader, global::MessagePack.MessagePackSerializerOptions options)
|
||||
|
@ -627,10 +614,10 @@ namespace MessagePack.Formatters.TestData2
|
|||
{
|
||||
default: goto FAIL;
|
||||
case 3242356UL:
|
||||
____result.MyProperty1 = formatterResolver.GetFormatterWithVerify<string>().Deserialize(ref reader, options);
|
||||
____result.MyProperty1 = global::MessagePack.FormatterResolverExtensions.GetFormatterWithVerify<string>(formatterResolver).Deserialize(ref reader, options);
|
||||
continue;
|
||||
case 3307892UL:
|
||||
____result.MyProperty2 = formatterResolver.GetFormatterWithVerify<string>().Deserialize(ref reader, options);
|
||||
____result.MyProperty2 = global::MessagePack.FormatterResolverExtensions.GetFormatterWithVerify<string>(formatterResolver).Deserialize(ref reader, options);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -662,9 +649,9 @@ namespace MessagePack.Formatters.TestData2
|
|||
var formatterResolver = options.Resolver;
|
||||
writer.WriteMapHeader(2);
|
||||
writer.WriteRaw(GetSpan_MyProperty1());
|
||||
formatterResolver.GetFormatterWithVerify<string>().Serialize(ref writer, value.MyProperty1, options);
|
||||
global::MessagePack.FormatterResolverExtensions.GetFormatterWithVerify<string>(formatterResolver).Serialize(ref writer, value.MyProperty1, options);
|
||||
writer.WriteRaw(GetSpan_MyProperty2());
|
||||
formatterResolver.GetFormatterWithVerify<string>().Serialize(ref writer, value.MyProperty2, options);
|
||||
global::MessagePack.FormatterResolverExtensions.GetFormatterWithVerify<string>(formatterResolver).Serialize(ref writer, value.MyProperty2, options);
|
||||
}
|
||||
|
||||
public global::TestData2.PropNameCheck2 Deserialize(ref global::MessagePack.MessagePackReader reader, global::MessagePack.MessagePackSerializerOptions options)
|
||||
|
@ -697,10 +684,10 @@ namespace MessagePack.Formatters.TestData2
|
|||
{
|
||||
default: goto FAIL;
|
||||
case 3242356UL:
|
||||
____result.MyProperty1 = formatterResolver.GetFormatterWithVerify<string>().Deserialize(ref reader, options);
|
||||
____result.MyProperty1 = global::MessagePack.FormatterResolverExtensions.GetFormatterWithVerify<string>(formatterResolver).Deserialize(ref reader, options);
|
||||
continue;
|
||||
case 3307892UL:
|
||||
____result.MyProperty2 = formatterResolver.GetFormatterWithVerify<string>().Deserialize(ref reader, options);
|
||||
____result.MyProperty2 = global::MessagePack.FormatterResolverExtensions.GetFormatterWithVerify<string>(formatterResolver).Deserialize(ref reader, options);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -730,7 +717,7 @@ namespace MessagePack.Formatters.TestData2
|
|||
var formatterResolver = options.Resolver;
|
||||
writer.WriteMapHeader(1);
|
||||
writer.WriteRaw(GetSpan_SomeProperty());
|
||||
formatterResolver.GetFormatterWithVerify<string>().Serialize(ref writer, value.SomeProperty, options);
|
||||
global::MessagePack.FormatterResolverExtensions.GetFormatterWithVerify<string>(formatterResolver).Serialize(ref writer, value.SomeProperty, options);
|
||||
}
|
||||
|
||||
public global::TestData2.Record Deserialize(ref global::MessagePack.MessagePackReader reader, global::MessagePack.MessagePackSerializerOptions options)
|
||||
|
@ -757,7 +744,7 @@ namespace MessagePack.Formatters.TestData2
|
|||
case 12:
|
||||
if (!global::System.MemoryExtensions.SequenceEqual(stringKey, GetSpan_SomeProperty().Slice(1))) { goto FAIL; }
|
||||
|
||||
__SomeProperty__ = formatterResolver.GetFormatterWithVerify<string>().Deserialize(ref reader, options);
|
||||
__SomeProperty__ = global::MessagePack.FormatterResolverExtensions.GetFormatterWithVerify<string>(formatterResolver).Deserialize(ref reader, options);
|
||||
continue;
|
||||
|
||||
}
|
||||
|
@ -768,5 +755,17 @@ namespace MessagePack.Formatters.TestData2
|
|||
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
|
||||
|
||||
|
|
|
@ -170,7 +170,7 @@ namespace MessagePackCompiler.CodeAnalysis
|
|||
}
|
||||
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)";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -182,12 +182,18 @@ namespace MessagePackCompiler.CodeAnalysis
|
|||
}
|
||||
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)";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,27 +34,27 @@ namespace MessagePackCompiler.Generator
|
|||
#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));
|
||||
|
@ -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
|
||||
");
|
||||
|
|
|
@ -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 #>();
|
||||
}
|
||||
|
@ -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
|
||||
|
|
|
@ -35,7 +35,6 @@ namespace MessagePackCompiler.Generator
|
|||
#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
|
||||
|
@ -43,10 +42,10 @@ namespace MessagePackCompiler.Generator
|
|||
|
||||
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));
|
||||
|
@ -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(@"}
|
||||
|
||||
|
@ -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
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
#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
|
||||
|
@ -21,11 +20,8 @@
|
|||
|
||||
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 #>
|
||||
|
@ -155,8 +151,8 @@ namespace <#= Namespace #>
|
|||
<# } #>
|
||||
}
|
||||
}
|
||||
<# } #>
|
||||
}
|
||||
|
||||
<# } #>}
|
||||
|
||||
#pragma warning restore 168
|
||||
#pragma warning restore 414
|
||||
|
@ -164,7 +160,6 @@ namespace <#= 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
|
||||
|
|
|
@ -34,13 +34,12 @@ namespace MessagePackCompiler.Generator
|
|||
#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 ");
|
||||
|
@ -76,10 +75,10 @@ namespace ");
|
|||
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];
|
||||
|
@ -92,7 +91,7 @@ namespace ");
|
|||
this.Write(@" };
|
||||
}
|
||||
|
||||
internal static object GetFormatter(Type t)
|
||||
internal static object GetFormatter(global::System.Type t)
|
||||
{
|
||||
int key;
|
||||
if (!lookup.TryGetValue(t, out key))
|
||||
|
@ -122,7 +121,6 @@ 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
|
||||
");
|
||||
return this.GenerationEnvironment.ToString();
|
||||
|
|
|
@ -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 #>();
|
||||
|
@ -52,11 +47,11 @@ 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 #> },
|
||||
|
@ -64,7 +59,7 @@ namespace <#= Namespace #>
|
|||
};
|
||||
}
|
||||
|
||||
internal static object GetFormatter(Type t)
|
||||
internal static object GetFormatter(global::System.Type t)
|
||||
{
|
||||
int key;
|
||||
if (!lookup.TryGetValue(t, out key))
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
|
|
@ -35,7 +35,6 @@ namespace MessagePackCompiler.Generator
|
|||
#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
|
||||
|
@ -43,7 +42,7 @@ namespace MessagePackCompiler.Generator
|
|||
|
||||
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();
|
||||
|
@ -53,7 +52,7 @@ 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));
|
||||
|
@ -191,9 +190,21 @@ foreach (var objInfo in ObjectSerializationInfos) {
|
|||
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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
#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
|
||||
|
@ -22,8 +21,6 @@
|
|||
|
||||
namespace <#= Namespace #>
|
||||
{
|
||||
using global::System.Buffers;
|
||||
using global::MessagePack;
|
||||
<# var list = new List<ValueTuple<MemberSerializationInfo, byte[]>>();
|
||||
foreach (var objInfo in ObjectSerializationInfos) {
|
||||
list.Clear();
|
||||
|
@ -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 #>
|
||||
|
@ -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
|
||||
|
|
|
@ -34,38 +34,41 @@ namespace MessagePackCompiler.Generator
|
|||
#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 System.Collections.G" +
|
||||
"eneric;\r\n using MessagePack;\r\n\r\n");
|
||||
this.Write("\r\n{\r\n");
|
||||
foreach(var info in UnionSerializationInfos) {
|
||||
this.Write(" 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 private readonly Dictionary<RuntimeTypeHandle, KeyValuePair<int" +
|
||||
", int>> typeToKeyAndJumpMap;\r\n private readonly Dictionary<int, int> keyT" +
|
||||
"oJumpMap;\r\n\r\n public ");
|
||||
this.Write(@">
|
||||
{
|
||||
private readonly global::System.Collections.Generic.Dictionary<global::System.RuntimeTypeHandle, global::System.Collections.Generic.KeyValuePair<int, int>> typeToKeyAndJumpMap;
|
||||
private readonly global::System.Collections.Generic.Dictionary<int, int> keyToJumpMap;
|
||||
|
||||
public ");
|
||||
this.Write(this.ToStringHelper.ToStringWithCulture(info.Name));
|
||||
this.Write("Formatter()\r\n {\r\n this.typeToKeyAndJumpMap = new Dictionary<Run" +
|
||||
"timeTypeHandle, KeyValuePair<int, int>>(");
|
||||
this.Write("Formatter()\r\n {\r\n this.typeToKeyAndJumpMap = new global::System" +
|
||||
".Collections.Generic.Dictionary<global::System.RuntimeTypeHandle, global::System" +
|
||||
".Collections.Generic.KeyValuePair<int, int>>(");
|
||||
this.Write(this.ToStringHelper.ToStringWithCulture(info.SubTypes.Length));
|
||||
this.Write(", global::MessagePack.Internal.RuntimeTypeHandleEqualityComparer.Default)\r\n " +
|
||||
" {\r\n");
|
||||
for(var i = 0; i < info.SubTypes.Length; i++) { var item = info.SubTypes[i];
|
||||
this.Write(" { typeof(");
|
||||
this.Write(this.ToStringHelper.ToStringWithCulture(item.Type));
|
||||
this.Write(").TypeHandle, new KeyValuePair<int, int>(");
|
||||
this.Write(").TypeHandle, new global::System.Collections.Generic.KeyValuePair<int, int>(");
|
||||
this.Write(this.ToStringHelper.ToStringWithCulture(item.Key));
|
||||
this.Write(", ");
|
||||
this.Write(this.ToStringHelper.ToStringWithCulture(i));
|
||||
this.Write(") },\r\n");
|
||||
}
|
||||
this.Write(" };\r\n this.keyToJumpMap = new Dictionary<int, int>(");
|
||||
this.Write(" };\r\n this.keyToJumpMap = new global::System.Collections.Ge" +
|
||||
"neric.Dictionary<int, int>(");
|
||||
this.Write(this.ToStringHelper.ToStringWithCulture(info.SubTypes.Length));
|
||||
this.Write(")\r\n {\r\n");
|
||||
for(var i = 0; i < info.SubTypes.Length; i++) { var item = info.SubTypes[i];
|
||||
|
@ -75,12 +78,12 @@ namespace ");
|
|||
this.Write(this.ToStringHelper.ToStringWithCulture(i));
|
||||
this.Write(" },\r\n");
|
||||
}
|
||||
this.Write(" };\r\n }\r\n\r\n public void Serialize(ref MessagePackWriter " +
|
||||
"writer, ");
|
||||
this.Write(" };\r\n }\r\n\r\n public void Serialize(ref global::MessagePac" +
|
||||
"k.MessagePackWriter writer, ");
|
||||
this.Write(this.ToStringHelper.ToStringWithCulture(info.FullName));
|
||||
this.Write(@" value, global::MessagePack.MessagePackSerializerOptions options)
|
||||
{
|
||||
KeyValuePair<int, int> keyValuePair;
|
||||
global::System.Collections.Generic.KeyValuePair<int, int> keyValuePair;
|
||||
if (value != null && this.typeToKeyAndJumpMap.TryGetValue(value.GetType().TypeHandle, out keyValuePair))
|
||||
{
|
||||
writer.WriteArrayHeader(2);
|
||||
|
@ -101,7 +104,7 @@ namespace ");
|
|||
"\r\n return;\r\n }\r\n\r\n writer.WriteNil();\r\n " +
|
||||
" }\r\n\r\n public ");
|
||||
this.Write(this.ToStringHelper.ToStringWithCulture(info.FullName));
|
||||
this.Write(@" Deserialize(ref MessagePackReader reader, global::MessagePack.MessagePackSerializerOptions options)
|
||||
this.Write(@" Deserialize(ref global::MessagePack.MessagePackReader reader, global::MessagePack.MessagePackSerializerOptions options)
|
||||
{
|
||||
if (reader.TryReadNil())
|
||||
{
|
||||
|
@ -110,7 +113,7 @@ namespace ");
|
|||
|
||||
if (reader.ReadArrayHeader() != 2)
|
||||
{
|
||||
throw new InvalidOperationException(""Invalid Union data was detected. Type:");
|
||||
throw new global::System.InvalidOperationException(""Invalid Union data was detected. Type:");
|
||||
this.Write(this.ToStringHelper.ToStringWithCulture(info.FullName));
|
||||
this.Write("\");\r\n }\r\n\r\n options.Security.DepthStep(ref reader);\r\n " +
|
||||
" var key = reader.ReadInt32();\r\n\r\n if (!this.keyToJumpMap.TryGet" +
|
||||
|
@ -139,7 +142,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
|
||||
");
|
||||
|
|
|
@ -12,32 +12,26 @@
|
|||
#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 System.Collections.Generic;
|
||||
using MessagePack;
|
||||
|
||||
<# foreach(var info in UnionSerializationInfos) { #>
|
||||
public sealed class <#= info.Name #>Formatter : global::MessagePack.Formatters.IMessagePackFormatter<<#= info.FullName #>>
|
||||
{
|
||||
private readonly Dictionary<RuntimeTypeHandle, KeyValuePair<int, int>> typeToKeyAndJumpMap;
|
||||
private readonly Dictionary<int, int> keyToJumpMap;
|
||||
private readonly global::System.Collections.Generic.Dictionary<global::System.RuntimeTypeHandle, global::System.Collections.Generic.KeyValuePair<int, int>> typeToKeyAndJumpMap;
|
||||
private readonly global::System.Collections.Generic.Dictionary<int, int> keyToJumpMap;
|
||||
|
||||
public <#= info.Name #>Formatter()
|
||||
{
|
||||
this.typeToKeyAndJumpMap = new Dictionary<RuntimeTypeHandle, KeyValuePair<int, int>>(<#= info.SubTypes.Length #>, global::MessagePack.Internal.RuntimeTypeHandleEqualityComparer.Default)
|
||||
this.typeToKeyAndJumpMap = new global::System.Collections.Generic.Dictionary<global::System.RuntimeTypeHandle, global::System.Collections.Generic.KeyValuePair<int, int>>(<#= info.SubTypes.Length #>, global::MessagePack.Internal.RuntimeTypeHandleEqualityComparer.Default)
|
||||
{
|
||||
<# for(var i = 0; i < info.SubTypes.Length; i++) { var item = info.SubTypes[i]; #>
|
||||
{ typeof(<#= item.Type #>).TypeHandle, new KeyValuePair<int, int>(<#= item.Key #>, <#= i #>) },
|
||||
{ typeof(<#= item.Type #>).TypeHandle, new global::System.Collections.Generic.KeyValuePair<int, int>(<#= item.Key #>, <#= i #>) },
|
||||
<# } #>
|
||||
};
|
||||
this.keyToJumpMap = new Dictionary<int, int>(<#= info.SubTypes.Length #>)
|
||||
this.keyToJumpMap = new global::System.Collections.Generic.Dictionary<int, int>(<#= info.SubTypes.Length #>)
|
||||
{
|
||||
<# for(var i = 0; i < info.SubTypes.Length; i++) { var item = info.SubTypes[i]; #>
|
||||
{ <#= item.Key #>, <#= i #> },
|
||||
|
@ -45,9 +39,9 @@ namespace <#= Namespace #>
|
|||
};
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
KeyValuePair<int, int> keyValuePair;
|
||||
global::System.Collections.Generic.KeyValuePair<int, int> keyValuePair;
|
||||
if (value != null && this.typeToKeyAndJumpMap.TryGetValue(value.GetType().TypeHandle, out keyValuePair))
|
||||
{
|
||||
writer.WriteArrayHeader(2);
|
||||
|
@ -69,7 +63,7 @@ namespace <#= Namespace #>
|
|||
writer.WriteNil();
|
||||
}
|
||||
|
||||
public <#= info.FullName #> Deserialize(ref MessagePackReader reader, global::MessagePack.MessagePackSerializerOptions options)
|
||||
public <#= info.FullName #> Deserialize(ref global::MessagePack.MessagePackReader reader, global::MessagePack.MessagePackSerializerOptions options)
|
||||
{
|
||||
if (reader.TryReadNil())
|
||||
{
|
||||
|
@ -78,7 +72,7 @@ namespace <#= Namespace #>
|
|||
|
||||
if (reader.ReadArrayHeader() != 2)
|
||||
{
|
||||
throw new InvalidOperationException("Invalid Union data was detected. Type:<#= info.FullName #>");
|
||||
throw new global::System.InvalidOperationException("Invalid Union data was detected. Type:<#= info.FullName #>");
|
||||
}
|
||||
|
||||
options.Security.DepthStep(ref reader);
|
||||
|
@ -116,6 +110,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
|
||||
|
|
Загрузка…
Ссылка в новой задаче