remove UniversalCodeGenerator
This commit is contained in:
Родитель
18bfa8af5f
Коммит
9e292a57a8
|
@ -15,7 +15,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docs", "docs", "{344DC89D-8
|
|||
ProjectSection(SolutionItems) = preProject
|
||||
.gitignore = .gitignore
|
||||
LICENSE = LICENSE
|
||||
make_unity_symlink.bat = make_unity_symlink.bat
|
||||
README.md = README.md
|
||||
EndProjectSection
|
||||
EndProject
|
||||
|
@ -56,8 +55,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{301F812B
|
|||
version.json = version.json
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MessagePack.UniversalCodeGenerator", "src\MessagePack.UniversalCodeGenerator\MessagePack.UniversalCodeGenerator.csproj", "{10AD85DD-929D-49B8-BD43-45242C2644B7}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MessagePack.AspNetCoreMvcFormatter.Tests", "tests\MessagePack.AspNetCoreMvcFormatter.Tests\MessagePack.AspNetCoreMvcFormatter.Tests.csproj", "{79C2B2CB-872A-4BA9-82DC-60F6DD77F940}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MessagePack.Annotations", "src\MessagePack.Annotations\MessagePack.Annotations.csproj", "{85763F30-7733-44AB-89AB-D1B64F6E0D93}"
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
copy ..\src\MessagePack.CodeGenerator\bin\Release\*.dll tools\
|
||||
copy ..\src\MessagePack.CodeGenerator\bin\Release\mpc.exe tools\mpc.exe
|
||||
copy ..\src\MessagePack.CodeGenerator\bin\Release\mpc.exe.config tools\mpc.exe.config
|
|
@ -1,70 +0,0 @@
|
|||
#pragma warning disable 618
|
||||
#pragma warning disable 612
|
||||
#pragma warning disable 414
|
||||
#pragma warning disable 168
|
||||
|
||||
namespace MessagePack.Resolvers
|
||||
{
|
||||
using System;
|
||||
using MessagePack;
|
||||
|
||||
public class GeneratedResolver : global::MessagePack.IFormatterResolver
|
||||
{
|
||||
public static readonly global::MessagePack.IFormatterResolver Instance = new GeneratedResolver();
|
||||
|
||||
GeneratedResolver()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public global::MessagePack.Formatters.IMessagePackFormatter<T> GetFormatter<T>()
|
||||
{
|
||||
return FormatterCache<T>.formatter;
|
||||
}
|
||||
|
||||
static class FormatterCache<T>
|
||||
{
|
||||
public static readonly global::MessagePack.Formatters.IMessagePackFormatter<T> formatter;
|
||||
|
||||
static FormatterCache()
|
||||
{
|
||||
var f = GeneratedResolverGetFormatterHelper.GetFormatter(typeof(T));
|
||||
if (f != null)
|
||||
{
|
||||
formatter = (global::MessagePack.Formatters.IMessagePackFormatter<T>)f;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal static class GeneratedResolverGetFormatterHelper
|
||||
{
|
||||
static readonly global::System.Collections.Generic.Dictionary<Type, int> lookup;
|
||||
|
||||
static GeneratedResolverGetFormatterHelper()
|
||||
{
|
||||
lookup = new global::System.Collections.Generic.Dictionary<Type, int>(0)
|
||||
{
|
||||
};
|
||||
}
|
||||
|
||||
internal static object GetFormatter(Type t)
|
||||
{
|
||||
int key;
|
||||
if (!lookup.TryGetValue(t, out key)) return null;
|
||||
|
||||
switch (key)
|
||||
{
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#pragma warning restore 168
|
||||
#pragma warning restore 414
|
||||
#pragma warning restore 618
|
||||
#pragma warning restore 612
|
||||
|
||||
|
||||
|
|
@ -1 +0,0 @@
|
|||
tools\mpc.exe -i ..\sandbox\SharedData\SharedData.csproj -o mpc_check.cs
|
|
@ -1,203 +0,0 @@
|
|||
// Copyright (c) All contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
#pragma warning disable SA1649 // File name should match first type name
|
||||
|
||||
namespace MessagePack.CodeGenerator
|
||||
{
|
||||
public interface IResolverRegisterInfo
|
||||
{
|
||||
string FullName { get; }
|
||||
|
||||
string FormatterName { get; }
|
||||
}
|
||||
|
||||
public class ObjectSerializationInfo : IResolverRegisterInfo
|
||||
{
|
||||
public string Name { get; set; }
|
||||
|
||||
public string FullName { get; set; }
|
||||
|
||||
public string Namespace { get; set; }
|
||||
|
||||
public bool IsIntKey { get; set; }
|
||||
|
||||
public bool IsStringKey
|
||||
{
|
||||
get { return !this.IsIntKey; }
|
||||
}
|
||||
|
||||
public bool IsClass { get; set; }
|
||||
|
||||
public bool IsStruct
|
||||
{
|
||||
get { return !this.IsClass; }
|
||||
}
|
||||
|
||||
public MemberSerializationInfo[] ConstructorParameters { get; set; }
|
||||
|
||||
public MemberSerializationInfo[] Members { get; set; }
|
||||
|
||||
public bool HasIMessagePackSerializationCallbackReceiver { get; set; }
|
||||
|
||||
public bool NeedsCastOnBefore { get; set; }
|
||||
|
||||
public bool NeedsCastOnAfter { get; set; }
|
||||
|
||||
public string FormatterName => (this.Namespace == null ? this.Name : this.Namespace + "." + this.Name) + "Formatter";
|
||||
|
||||
public int WriteCount
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.IsStringKey)
|
||||
{
|
||||
return this.Members.Count(x => x.IsReadable);
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.MaxKey;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int MaxKey
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.Members.Where(x => x.IsReadable).Select(x => x.IntKey).DefaultIfEmpty(-1).Max();
|
||||
}
|
||||
}
|
||||
|
||||
public MemberSerializationInfo GetMember(int index)
|
||||
{
|
||||
return this.Members.FirstOrDefault(x => x.IntKey == index);
|
||||
}
|
||||
|
||||
public string GetConstructorString()
|
||||
{
|
||||
var args = string.Join(", ", this.ConstructorParameters.Select(x => "__" + x.Name + "__"));
|
||||
return $"{this.FullName}({args})";
|
||||
}
|
||||
}
|
||||
|
||||
public class MemberSerializationInfo
|
||||
{
|
||||
public bool IsProperty { get; set; }
|
||||
|
||||
public bool IsField { get; set; }
|
||||
|
||||
public bool IsWritable { get; set; }
|
||||
|
||||
public bool IsReadable { get; set; }
|
||||
|
||||
public int IntKey { get; set; }
|
||||
|
||||
public string StringKey { get; set; }
|
||||
|
||||
public string Type { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
|
||||
public string ShortTypeName { get; set; }
|
||||
|
||||
private readonly HashSet<string> primitiveTypes = new HashSet<string>(new string[]
|
||||
{
|
||||
"short",
|
||||
"int",
|
||||
"long",
|
||||
"ushort",
|
||||
"uint",
|
||||
"ulong",
|
||||
"float",
|
||||
"double",
|
||||
"bool",
|
||||
"byte",
|
||||
"sbyte",
|
||||
"char",
|
||||
////"global::System.DateTime",
|
||||
////"byte[]",
|
||||
////"string",
|
||||
});
|
||||
|
||||
public string GetSerializeMethodString()
|
||||
{
|
||||
if (this.primitiveTypes.Contains(this.Type))
|
||||
{
|
||||
return $"writer.Write(value.{this.Name})";
|
||||
}
|
||||
else
|
||||
{
|
||||
return $"formatterResolver.GetFormatterWithVerify<{this.Type}>().Serialize(ref writer, value.{this.Name}, options)";
|
||||
}
|
||||
}
|
||||
|
||||
public string GetDeserializeMethodString()
|
||||
{
|
||||
if (this.primitiveTypes.Contains(this.Type))
|
||||
{
|
||||
return $"reader.Read{this.ShortTypeName.Replace("[]", "s")}()";
|
||||
}
|
||||
else
|
||||
{
|
||||
return $"formatterResolver.GetFormatterWithVerify<{this.Type}>().Deserialize(ref reader, options)";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class EnumSerializationInfo : IResolverRegisterInfo
|
||||
{
|
||||
public string Namespace { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
|
||||
public string FullName { get; set; }
|
||||
|
||||
public string UnderlyingType { get; set; }
|
||||
|
||||
public string FormatterName => (this.Namespace == null ? this.Name : this.Namespace + "." + this.Name) + "Formatter";
|
||||
}
|
||||
|
||||
public class GenericSerializationInfo : IResolverRegisterInfo, IEquatable<GenericSerializationInfo>
|
||||
{
|
||||
public string FullName { get; set; }
|
||||
|
||||
public string FormatterName { get; set; }
|
||||
|
||||
public bool Equals(GenericSerializationInfo other)
|
||||
{
|
||||
return this.FullName.Equals(other.FullName);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return this.FullName.GetHashCode();
|
||||
}
|
||||
}
|
||||
|
||||
public class UnionSerializationInfo : IResolverRegisterInfo
|
||||
{
|
||||
public string Namespace { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
|
||||
public string FullName { get; set; }
|
||||
|
||||
public string FormatterName => (this.Namespace == null ? this.Name : this.Namespace + "." + this.Name) + "Formatter";
|
||||
|
||||
public UnionSubTypeInfo[] SubTypes { get; set; }
|
||||
}
|
||||
|
||||
public class UnionSubTypeInfo
|
||||
{
|
||||
public string Type { get; set; }
|
||||
|
||||
public int Key { get; set; }
|
||||
}
|
||||
}
|
|
@ -1,981 +0,0 @@
|
|||
// Copyright (c) All contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.CodeAnalysis;
|
||||
|
||||
namespace MessagePack.CodeGenerator
|
||||
{
|
||||
internal class TypeCollector
|
||||
{
|
||||
private const string CodegeneratorOnlyPreprocessorSymbol = "INCLUDE_ONLY_CODE_GENERATION";
|
||||
|
||||
private static readonly SymbolDisplayFormat BinaryWriteFormat = new SymbolDisplayFormat(
|
||||
genericsOptions: SymbolDisplayGenericsOptions.IncludeTypeParameters,
|
||||
miscellaneousOptions: SymbolDisplayMiscellaneousOptions.ExpandNullable,
|
||||
typeQualificationStyle: SymbolDisplayTypeQualificationStyle.NameOnly);
|
||||
|
||||
private static readonly SymbolDisplayFormat ShortTypeNameFormat = new SymbolDisplayFormat(
|
||||
typeQualificationStyle: SymbolDisplayTypeQualificationStyle.NameAndContainingTypes);
|
||||
|
||||
private readonly string csProjPath;
|
||||
private readonly bool isForceUseMap;
|
||||
private readonly ReferenceSymbols typeReferences;
|
||||
private readonly INamedTypeSymbol[] targetTypes;
|
||||
private readonly HashSet<string> embeddedTypes = new HashSet<string>(new string[]
|
||||
{
|
||||
"short",
|
||||
"int",
|
||||
"long",
|
||||
"ushort",
|
||||
"uint",
|
||||
"ulong",
|
||||
"float",
|
||||
"double",
|
||||
"bool",
|
||||
"byte",
|
||||
"sbyte",
|
||||
"decimal",
|
||||
"char",
|
||||
"string",
|
||||
"object",
|
||||
"System.Guid",
|
||||
"System.TimeSpan",
|
||||
"System.DateTime",
|
||||
"System.DateTimeOffset",
|
||||
|
||||
"MessagePack.Nil",
|
||||
|
||||
// and arrays
|
||||
"short[]",
|
||||
"int[]",
|
||||
"long[]",
|
||||
"ushort[]",
|
||||
"uint[]",
|
||||
"ulong[]",
|
||||
"float[]",
|
||||
"double[]",
|
||||
"bool[]",
|
||||
"byte[]",
|
||||
"sbyte[]",
|
||||
"decimal[]",
|
||||
"char[]",
|
||||
"string[]",
|
||||
"System.DateTime[]",
|
||||
"System.ArraySegment<byte>",
|
||||
"System.ArraySegment<byte>?",
|
||||
|
||||
// extensions
|
||||
"UnityEngine.Vector2",
|
||||
"UnityEngine.Vector3",
|
||||
"UnityEngine.Vector4",
|
||||
"UnityEngine.Quaternion",
|
||||
"UnityEngine.Color",
|
||||
"UnityEngine.Bounds",
|
||||
"UnityEngine.Rect",
|
||||
"UnityEngine.AnimationCurve",
|
||||
"UnityEngine.RectOffset",
|
||||
"UnityEngine.Gradient",
|
||||
"UnityEngine.WrapMode",
|
||||
"UnityEngine.GradientMode",
|
||||
"UnityEngine.Keyframe",
|
||||
"UnityEngine.Matrix4x4",
|
||||
"UnityEngine.GradientColorKey",
|
||||
"UnityEngine.GradientAlphaKey",
|
||||
"UnityEngine.Color32",
|
||||
"UnityEngine.LayerMask",
|
||||
"UnityEngine.Vector2Int",
|
||||
"UnityEngine.Vector3Int",
|
||||
"UnityEngine.RangeInt",
|
||||
"UnityEngine.RectInt",
|
||||
"UnityEngine.BoundsInt",
|
||||
|
||||
"System.Reactive.Unit",
|
||||
});
|
||||
|
||||
#pragma warning disable SA1509 // open braces that follow blank line
|
||||
private readonly Dictionary<string, string> knownGenericTypes = new Dictionary<string, string>
|
||||
{
|
||||
{ "System.Collections.Generic.List<>", "global::MessagePack.Formatters.ListFormatter<TREPLACE>" },
|
||||
{ "System.Collections.Generic.LinkedList<>", "global::MessagePack.Formatters.LinkedListFormatter<TREPLACE>" },
|
||||
{ "System.Collections.Generic.Queue<>", "global::MessagePack.Formatters.QeueueFormatter<TREPLACE>" },
|
||||
{ "System.Collections.Generic.Stack<>", "global::MessagePack.Formatters.StackFormatter<TREPLACE>" },
|
||||
{ "System.Collections.Generic.HashSet<>", "global::MessagePack.Formatters.HashSetFormatter<TREPLACE>" },
|
||||
{ "System.Collections.ObjectModel.ReadOnlyCollection<>", "global::MessagePack.Formatters.ReadOnlyCollectionFormatter<TREPLACE>" },
|
||||
{ "System.Collections.Generic.IList<>", "global::MessagePack.Formatters.InterfaceListFormatter<TREPLACE>" },
|
||||
{ "System.Collections.Generic.ICollection<>", "global::MessagePack.Formatters.InterfaceCollectionFormatter<TREPLACE>" },
|
||||
{ "System.Collections.Generic.IEnumerable<>", "global::MessagePack.Formatters.InterfaceEnumerableFormatter<TREPLACE>" },
|
||||
{ "System.Collections.Generic.Dictionary<,>", "global::MessagePack.Formatters.DictionaryFormatter<TREPLACE>" },
|
||||
{ "System.Collections.Generic.IDictionary<,>", "global::MessagePack.Formatters.InterfaceDictionaryFormatter<TREPLACE>" },
|
||||
{ "System.Collections.Generic.SortedDictionary<,>", "global::MessagePack.Formatters.SortedDictionaryFormatter<TREPLACE>" },
|
||||
{ "System.Collections.Generic.SortedList<,>", "global::MessagePack.Formatters.SortedListFormatter<TREPLACE>" },
|
||||
{ "System.Linq.ILookup<,>", "global::MessagePack.Formatters.InterfaceLookupFormatter<TREPLACE>" },
|
||||
{ "System.Linq.IGrouping<,>", "global::MessagePack.Formatters.InterfaceGroupingFormatter<TREPLACE>" },
|
||||
{ "System.Collections.ObjectModel.ObservableCollection<>", "global::MessagePack.Formatters.ObservableCollectionFormatter<TREPLACE>" },
|
||||
{ "System.Collections.ObjectModel.ReadOnlyObservableCollection<>", "global::MessagePack.Formatters.ReadOnlyObservableCollectionFormatter<TREPLACE>" },
|
||||
{ "System.Collections.Generic.IReadOnlyList<>", "global::MessagePack.Formatters.InterfaceReadOnlyListFormatter<TREPLACE>" },
|
||||
{ "System.Collections.Generic.IReadOnlyCollection<>", "global::MessagePack.Formatters.InterfaceReadOnlyCollectionFormatter<TREPLACE>" },
|
||||
{ "System.Collections.Generic.ISet<>", "global::MessagePack.Formatters.InterfaceSetFormatter<TREPLACE>" },
|
||||
{ "System.Collections.Concurrent.ConcurrentBag<>", "global::MessagePack.Formatters.ConcurrentBagFormatter<TREPLACE>" },
|
||||
{ "System.Collections.Concurrent.ConcurrentQueue<>", "global::MessagePack.Formatters.ConcurrentQueueFormatter<TREPLACE>" },
|
||||
{ "System.Collections.Concurrent.ConcurrentStack<>", "global::MessagePack.Formatters.ConcurrentStackFormatter<TREPLACE>" },
|
||||
{ "System.Collections.ObjectModel.ReadOnlyDictionary<,>", "global::MessagePack.Formatters.ReadOnlyDictionaryFormatter<TREPLACE>" },
|
||||
{ "System.Collections.Generic.IReadOnlyDictionary<,>", "global::MessagePack.Formatters.InterfaceReadOnlyDictionaryFormatter<TREPLACE>" },
|
||||
{ "System.Collections.Concurrent.ConcurrentDictionary<,>", "global::MessagePack.Formatters.ConcurrentDictionaryFormatter<TREPLACE>" },
|
||||
{ "System.Lazy<>", "global::MessagePack.Formatters.LazyFormatter<TREPLACE>" },
|
||||
{ "System.Threading.Tasks<>", "global::MessagePack.Formatters.TaskValueFormatter<TREPLACE>" },
|
||||
|
||||
{ "System.Tuple<>", "global::MessagePack.Formatters.TupleFormatter<TREPLACE>" },
|
||||
{ "System.Tuple<,>", "global::MessagePack.Formatters.TupleFormatter<TREPLACE>" },
|
||||
{ "System.Tuple<,,>", "global::MessagePack.Formatters.TupleFormatter<TREPLACE>" },
|
||||
{ "System.Tuple<,,,>", "global::MessagePack.Formatters.TupleFormatter<TREPLACE>" },
|
||||
{ "System.Tuple<,,,,>", "global::MessagePack.Formatters.TupleFormatter<TREPLACE>" },
|
||||
{ "System.Tuple<,,,,,>", "global::MessagePack.Formatters.TupleFormatter<TREPLACE>" },
|
||||
{ "System.Tuple<,,,,,,>", "global::MessagePack.Formatters.TupleFormatter<TREPLACE>" },
|
||||
{ "System.Tuple<,,,,,,,>", "global::MessagePack.Formatters.TupleFormatter<TREPLACE>" },
|
||||
|
||||
{ "System.ValueTuple<>", "global::MessagePack.Formatters.ValueTupleFormatter<TREPLACE>" },
|
||||
{ "System.ValueTuple<,>", "global::MessagePack.Formatters.ValueTupleFormatter<TREPLACE>" },
|
||||
{ "System.ValueTuple<,,>", "global::MessagePack.Formatters.ValueTupleFormatter<TREPLACE>" },
|
||||
{ "System.ValueTuple<,,,>", "global::MessagePack.Formatters.ValueTupleFormatter<TREPLACE>" },
|
||||
{ "System.ValueTuple<,,,,>", "global::MessagePack.Formatters.ValueTupleFormatter<TREPLACE>" },
|
||||
{ "System.ValueTuple<,,,,,>", "global::MessagePack.Formatters.ValueTupleFormatter<TREPLACE>" },
|
||||
{ "System.ValueTuple<,,,,,,>", "global::MessagePack.Formatters.ValueTupleFormatter<TREPLACE>" },
|
||||
{ "System.ValueTuple<,,,,,,,>", "global::MessagePack.Formatters.ValueTupleFormatter<TREPLACE>" },
|
||||
|
||||
{ "System.Collections.Generic.KeyValuePair<,>", "global::MessagePack.Formatters.KeyValuePairFormatter<TREPLACE>" },
|
||||
{ "System.Threading.Tasks.ValueTask<>", "global::MessagePack.Formatters.KeyValuePairFormatter<TREPLACE>" },
|
||||
{ "System.ArraySegment<>", "global::MessagePack.Formatters.ArraySegmentFormatter<TREPLACE>" },
|
||||
|
||||
// extensions
|
||||
{ "System.Collections.Immutable.ImmutableArray<>", "global::MessagePack.ImmutableCollection.ImmutableArrayFormatter<TREPLACE>" },
|
||||
{ "System.Collections.Immutable.ImmutableList<>", "global::MessagePack.ImmutableCollection.ImmutableListFormatter<TREPLACE>" },
|
||||
{ "System.Collections.Immutable.ImmutableDictionary<,>", "global::MessagePack.ImmutableCollection.ImmutableDictionaryFormatter<TREPLACE>" },
|
||||
{ "System.Collections.Immutable.ImmutableHashSet<>", "global::MessagePack.ImmutableCollection.ImmutableHashSetFormatter<TREPLACE>" },
|
||||
{ "System.Collections.Immutable.ImmutableSortedDictionary<,>", "global::MessagePack.ImmutableCollection.ImmutableSortedDictionaryFormatter<TREPLACE>" },
|
||||
{ "System.Collections.Immutable.ImmutableSortedSet<>", "global::MessagePack.ImmutableCollection.ImmutableSortedSetFormatter<TREPLACE>" },
|
||||
{ "System.Collections.Immutable.ImmutableQueue<>", "global::MessagePack.ImmutableCollection.ImmutableQueueFormatter<TREPLACE>" },
|
||||
{ "System.Collections.Immutable.ImmutableStack<>", "global::MessagePack.ImmutableCollection.ImmutableStackFormatter<TREPLACE>" },
|
||||
{ "System.Collections.Immutable.IImmutableList<>", "global::MessagePack.ImmutableCollection.InterfaceImmutableListFormatter<TREPLACE>" },
|
||||
{ "System.Collections.Immutable.IImmutableDictionary<,>", "global::MessagePack.ImmutableCollection.InterfaceImmutableDictionaryFormatter<TREPLACE>" },
|
||||
{ "System.Collections.Immutable.IImmutableQueue<>", "global::MessagePack.ImmutableCollection.InterfaceImmutableQueueFormatter<TREPLACE>" },
|
||||
{ "System.Collections.Immutable.IImmutableSet<>", "global::MessagePack.ImmutableCollection.InterfaceImmutableSetFormatter<TREPLACE>" },
|
||||
{ "System.Collections.Immutable.IImmutableStack<>", "global::MessagePack.ImmutableCollection.InterfaceImmutableStackFormatter<TREPLACE>" },
|
||||
|
||||
{ "Reactive.Bindings.ReactiveProperty<>", "global::MessagePack.ReactivePropertyExtension.ReactivePropertyFormatter<TREPLACE>" },
|
||||
{ "Reactive.Bindings.IReactiveProperty<>", "global::MessagePack.ReactivePropertyExtension.InterfaceReactivePropertyFormatter<TREPLACE>" },
|
||||
{ "Reactive.Bindings.IReadOnlyReactiveProperty<>", "global::MessagePack.ReactivePropertyExtension.InterfaceReadOnlyReactivePropertyFormatter<TREPLACE>" },
|
||||
{ "Reactive.Bindings.ReactiveCollection<>", "global::MessagePack.ReactivePropertyExtension.ReactiveCollectionFormatter<TREPLACE>" },
|
||||
};
|
||||
#pragma warning restore SA1509 // open braces that follow blank line
|
||||
|
||||
private readonly bool disallowInternal;
|
||||
|
||||
// visitor workspace:
|
||||
private HashSet<ITypeSymbol> alreadyCollected;
|
||||
private List<ObjectSerializationInfo> collectedObjectInfo;
|
||||
private List<EnumSerializationInfo> collectedEnumInfo;
|
||||
private List<GenericSerializationInfo> collectedGenericInfo;
|
||||
private List<UnionSerializationInfo> collectedUnionInfo;
|
||||
|
||||
private TypeCollector(string csProjPath, Compilation compilation, IEnumerable<string> conditionalSymbols, bool disallowInternal, bool isForceUseMap)
|
||||
{
|
||||
this.csProjPath = csProjPath;
|
||||
Diagnostic[] compilationErrors = compilation.GetDiagnostics().Where(x => x.Severity == DiagnosticSeverity.Error).ToArray();
|
||||
if (compilationErrors.Length != 0)
|
||||
{
|
||||
throw new InvalidOperationException($"detect compilation error:{string.Join("\n", compilationErrors.Select(x => x.ToString()))}");
|
||||
}
|
||||
|
||||
this.typeReferences = new ReferenceSymbols(compilation);
|
||||
this.disallowInternal = disallowInternal;
|
||||
this.isForceUseMap = isForceUseMap;
|
||||
|
||||
this.targetTypes = compilation.GetNamedTypeSymbols()
|
||||
.Where(x =>
|
||||
{
|
||||
if (x.DeclaredAccessibility == Accessibility.Public)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!disallowInternal)
|
||||
{
|
||||
return x.DeclaredAccessibility == Accessibility.Friend;
|
||||
}
|
||||
|
||||
return false;
|
||||
})
|
||||
.Where(x =>
|
||||
((x.TypeKind == TypeKind.Interface) && x.GetAttributes().Any(x2 => x2.AttributeClass == this.typeReferences.UnionAttribute))
|
||||
|| (x.TypeKind == TypeKind.Class && x.IsAbstract && x.GetAttributes().Any(x2 => x2.AttributeClass == this.typeReferences.UnionAttribute))
|
||||
|| ((x.TypeKind == TypeKind.Class) && x.GetAttributes().Any(x2 => x2.AttributeClass == this.typeReferences.MessagePackObjectAttribute))
|
||||
|| ((x.TypeKind == TypeKind.Struct) && x.GetAttributes().Any(x2 => x2.AttributeClass == this.typeReferences.MessagePackObjectAttribute)))
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
public static async Task<TypeCollector> CreateAsync(string csProjPath, IEnumerable<string> conditionalSymbols, bool disallowInternal, bool isForceUseMap)
|
||||
{
|
||||
Compilation compilation = await RoslynExtensions.GetCompilationFromProjectAsync(csProjPath, conditionalSymbols.Concat(new[] { CodegeneratorOnlyPreprocessorSymbol }).ToArray());
|
||||
return new TypeCollector(csProjPath, compilation, conditionalSymbols, disallowInternal, isForceUseMap);
|
||||
}
|
||||
|
||||
private void ResetWorkspace()
|
||||
{
|
||||
this.alreadyCollected = new HashSet<ITypeSymbol>();
|
||||
this.collectedObjectInfo = new List<ObjectSerializationInfo>();
|
||||
this.collectedEnumInfo = new List<EnumSerializationInfo>();
|
||||
this.collectedGenericInfo = new List<GenericSerializationInfo>();
|
||||
this.collectedUnionInfo = new List<UnionSerializationInfo>();
|
||||
}
|
||||
|
||||
// EntryPoint
|
||||
public (ObjectSerializationInfo[] objectInfo, EnumSerializationInfo[] enumInfo, GenericSerializationInfo[] genericInfo, UnionSerializationInfo[] unionInfo) Collect()
|
||||
{
|
||||
this.ResetWorkspace();
|
||||
|
||||
foreach (INamedTypeSymbol item in this.targetTypes)
|
||||
{
|
||||
this.CollectCore(item);
|
||||
}
|
||||
|
||||
return (this.collectedObjectInfo.ToArray(), this.collectedEnumInfo.ToArray(), this.collectedGenericInfo.Distinct().ToArray(), this.collectedUnionInfo.ToArray());
|
||||
}
|
||||
|
||||
// Gate of recursive collect
|
||||
private void CollectCore(ITypeSymbol typeSymbol)
|
||||
{
|
||||
if (!this.alreadyCollected.Add(typeSymbol))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.embeddedTypes.Contains(typeSymbol.ToString()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeSymbol.TypeKind == TypeKind.Array)
|
||||
{
|
||||
this.CollectArray(typeSymbol as IArrayTypeSymbol);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.IsAllowAccessibility(typeSymbol))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var type = typeSymbol as INamedTypeSymbol;
|
||||
|
||||
if (typeSymbol.TypeKind == TypeKind.Enum)
|
||||
{
|
||||
this.CollectEnum(type);
|
||||
return;
|
||||
}
|
||||
|
||||
if (type.IsGenericType)
|
||||
{
|
||||
this.CollectGeneric(type);
|
||||
return;
|
||||
}
|
||||
|
||||
if (type.Locations[0].IsInMetadata)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (type.TypeKind == TypeKind.Interface || (type.TypeKind == TypeKind.Class && type.IsAbstract))
|
||||
{
|
||||
this.CollectUnion(type);
|
||||
return;
|
||||
}
|
||||
|
||||
this.CollectObject(type);
|
||||
return;
|
||||
}
|
||||
|
||||
private void CollectEnum(INamedTypeSymbol type)
|
||||
{
|
||||
var info = new EnumSerializationInfo
|
||||
{
|
||||
Name = type.Name,
|
||||
Namespace = type.ContainingNamespace.IsGlobalNamespace ? null : type.ContainingNamespace.ToDisplayString(),
|
||||
FullName = type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat),
|
||||
UnderlyingType = type.EnumUnderlyingType.ToDisplayString(BinaryWriteFormat),
|
||||
};
|
||||
|
||||
this.collectedEnumInfo.Add(info);
|
||||
}
|
||||
|
||||
private void CollectUnion(INamedTypeSymbol type)
|
||||
{
|
||||
System.Collections.Immutable.ImmutableArray<TypedConstant>[] unionAttrs = type.GetAttributes().Where(x => x.AttributeClass == this.typeReferences.UnionAttribute).Select(x => x.ConstructorArguments).ToArray();
|
||||
if (unionAttrs.Length == 0)
|
||||
{
|
||||
throw new MessagePackGeneratorResolveFailedException("Serialization Type must mark UnionAttribute." + " type: " + type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat));
|
||||
}
|
||||
|
||||
// 0, Int 1, SubType
|
||||
var info = new UnionSerializationInfo
|
||||
{
|
||||
Name = type.Name,
|
||||
Namespace = type.ContainingNamespace.IsGlobalNamespace ? null : type.ContainingNamespace.ToDisplayString(),
|
||||
FullName = type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat),
|
||||
SubTypes = unionAttrs.Select(x => new UnionSubTypeInfo
|
||||
{
|
||||
Key = (int)x[0].Value,
|
||||
Type = (x[1].Value as ITypeSymbol).ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat),
|
||||
}).OrderBy(x => x.Key).ToArray(),
|
||||
};
|
||||
|
||||
this.collectedUnionInfo.Add(info);
|
||||
}
|
||||
|
||||
private void CollectArray(IArrayTypeSymbol array)
|
||||
{
|
||||
ITypeSymbol elemType = array.ElementType;
|
||||
this.CollectCore(elemType);
|
||||
|
||||
var info = new GenericSerializationInfo
|
||||
{
|
||||
FullName = array.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat),
|
||||
};
|
||||
|
||||
if (array.IsSZArray)
|
||||
{
|
||||
info.FormatterName = $"global::MessagePack.Formatters.ArrayFormatter<{elemType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)}>";
|
||||
}
|
||||
else if (array.Rank == 2)
|
||||
{
|
||||
info.FormatterName = $"global::MessagePack.Formatters.TwoDimensionalArrayFormatter<{elemType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)}>";
|
||||
}
|
||||
else if (array.Rank == 3)
|
||||
{
|
||||
info.FormatterName = $"global::MessagePack.Formatters.ThreeDimensionalArrayFormatter<{elemType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)}>";
|
||||
}
|
||||
else if (array.Rank == 4)
|
||||
{
|
||||
info.FormatterName = $"global::MessagePack.Formatters.FourDimensionalArrayFormatter<{elemType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)}>";
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InvalidOperationException("does not supports array dimension, " + info.FullName);
|
||||
}
|
||||
|
||||
this.collectedGenericInfo.Add(info);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
private void CollectGeneric(INamedTypeSymbol type)
|
||||
{
|
||||
INamedTypeSymbol genericType = type.ConstructUnboundGenericType();
|
||||
var genericTypeString = genericType.ToDisplayString();
|
||||
var fullName = type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);
|
||||
|
||||
// special case
|
||||
if (fullName == "global::System.ArraySegment<byte>" || fullName == "global::System.ArraySegment<byte>?")
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// nullable
|
||||
if (genericTypeString == "T?")
|
||||
{
|
||||
this.CollectCore(type.TypeArguments[0]);
|
||||
|
||||
if (!this.embeddedTypes.Contains(type.TypeArguments[0].ToString()))
|
||||
{
|
||||
var info = new GenericSerializationInfo
|
||||
{
|
||||
FormatterName = $"global::MessagePack.Formatters.NullableFormatter<{type.TypeArguments[0].ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)}>",
|
||||
FullName = type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat),
|
||||
};
|
||||
|
||||
this.collectedGenericInfo.Add(info);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// collection
|
||||
if (this.knownGenericTypes.TryGetValue(genericTypeString, out var formatter))
|
||||
{
|
||||
foreach (ITypeSymbol item in type.TypeArguments)
|
||||
{
|
||||
this.CollectCore(item);
|
||||
}
|
||||
|
||||
var typeArgs = string.Join(", ", type.TypeArguments.Select(x => x.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)));
|
||||
var f = formatter.Replace("TREPLACE", typeArgs);
|
||||
|
||||
var info = new GenericSerializationInfo
|
||||
{
|
||||
FormatterName = f,
|
||||
FullName = type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat),
|
||||
};
|
||||
|
||||
this.collectedGenericInfo.Add(info);
|
||||
|
||||
if (genericTypeString == "System.Linq.ILookup<,>")
|
||||
{
|
||||
formatter = this.knownGenericTypes["System.Linq.IGrouping<,>"];
|
||||
f = formatter.Replace("TREPLACE", typeArgs);
|
||||
|
||||
var groupingInfo = new GenericSerializationInfo
|
||||
{
|
||||
FormatterName = f,
|
||||
FullName = $"global::System.Linq.IGrouping<{typeArgs}>",
|
||||
};
|
||||
|
||||
this.collectedGenericInfo.Add(groupingInfo);
|
||||
|
||||
formatter = this.knownGenericTypes["System.Collections.Generic.IEnumerable<>"];
|
||||
typeArgs = type.TypeArguments[1].ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);
|
||||
f = formatter.Replace("TREPLACE", typeArgs);
|
||||
|
||||
var enumerableInfo = new GenericSerializationInfo
|
||||
{
|
||||
FormatterName = f,
|
||||
FullName = $"global::System.Collections.Generic.IEnumerable<{typeArgs}>",
|
||||
};
|
||||
|
||||
this.collectedGenericInfo.Add(enumerableInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void CollectObject(INamedTypeSymbol type)
|
||||
{
|
||||
var isClass = !type.IsValueType;
|
||||
|
||||
AttributeData contractAttr = type.GetAttributes().FirstOrDefault(x => x.AttributeClass == this.typeReferences.MessagePackObjectAttribute);
|
||||
if (contractAttr == null)
|
||||
{
|
||||
throw new MessagePackGeneratorResolveFailedException("Serialization Object must mark MessagePackObjectAttribute." + " type: " + type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat));
|
||||
}
|
||||
|
||||
var isIntKey = true;
|
||||
var intMembers = new Dictionary<int, MemberSerializationInfo>();
|
||||
var stringMembers = new Dictionary<string, MemberSerializationInfo>();
|
||||
|
||||
if (this.isForceUseMap || (bool)contractAttr.ConstructorArguments[0].Value)
|
||||
{
|
||||
// All public members are serialize target except [Ignore] member.
|
||||
isIntKey = false;
|
||||
|
||||
var hiddenIntKey = 0;
|
||||
|
||||
foreach (IPropertySymbol item in type.GetAllMembers().OfType<IPropertySymbol>().Where(x => !x.IsOverride))
|
||||
{
|
||||
if (item.GetAttributes().Any(x => x.AttributeClass == this.typeReferences.IgnoreAttribute || x.AttributeClass == this.typeReferences.IgnoreDataMemberAttribute))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var member = new MemberSerializationInfo
|
||||
{
|
||||
IsReadable = (item.GetMethod != null) && item.GetMethod.DeclaredAccessibility == Accessibility.Public && !item.IsStatic,
|
||||
IsWritable = (item.SetMethod != null) && item.SetMethod.DeclaredAccessibility == Accessibility.Public && !item.IsStatic,
|
||||
StringKey = item.Name,
|
||||
IsProperty = true,
|
||||
IsField = false,
|
||||
Name = item.Name,
|
||||
Type = item.Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat),
|
||||
ShortTypeName = item.Type.ToDisplayString(BinaryWriteFormat),
|
||||
};
|
||||
if (!member.IsReadable && !member.IsWritable)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
member.IntKey = hiddenIntKey++;
|
||||
stringMembers.Add(member.StringKey, member);
|
||||
|
||||
this.CollectCore(item.Type); // recursive collect
|
||||
}
|
||||
|
||||
foreach (IFieldSymbol item in type.GetAllMembers().OfType<IFieldSymbol>())
|
||||
{
|
||||
if (item.GetAttributes().Any(x => x.AttributeClass == this.typeReferences.IgnoreAttribute || x.AttributeClass == this.typeReferences.IgnoreDataMemberAttribute))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (item.IsImplicitlyDeclared)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var member = new MemberSerializationInfo
|
||||
{
|
||||
IsReadable = item.DeclaredAccessibility == Accessibility.Public && !item.IsStatic,
|
||||
IsWritable = item.DeclaredAccessibility == Accessibility.Public && !item.IsReadOnly && !item.IsStatic,
|
||||
StringKey = item.Name,
|
||||
IsProperty = false,
|
||||
IsField = true,
|
||||
Name = item.Name,
|
||||
Type = item.Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat),
|
||||
ShortTypeName = item.Type.ToDisplayString(BinaryWriteFormat),
|
||||
};
|
||||
if (!member.IsReadable && !member.IsWritable)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (stringMembers.ContainsKey(member.StringKey))
|
||||
{
|
||||
throw new MessagePackGeneratorResolveFailedException("key is duplicated, all members key must be unique." + " type: " + type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat) + " member:" + item.Name);
|
||||
}
|
||||
|
||||
member.IntKey = hiddenIntKey++;
|
||||
stringMembers.Add(member.StringKey, member);
|
||||
this.CollectCore(item.Type); // recursive collect
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Only KeyAttribute members
|
||||
var searchFirst = true;
|
||||
var hiddenIntKey = 0;
|
||||
|
||||
foreach (IPropertySymbol item in type.GetAllMembers().OfType<IPropertySymbol>())
|
||||
{
|
||||
if (item.IsIndexer)
|
||||
{
|
||||
continue; // .tt files don't generate good code for this yet: https://github.com/neuecc/MessagePack-CSharp/issues/390
|
||||
}
|
||||
|
||||
if (item.GetAttributes().Any(x => x.AttributeClass == this.typeReferences.IgnoreAttribute || x.AttributeClass == this.typeReferences.IgnoreDataMemberAttribute))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var member = new MemberSerializationInfo
|
||||
{
|
||||
IsReadable = (item.GetMethod != null) && item.GetMethod.DeclaredAccessibility == Accessibility.Public && !item.IsStatic,
|
||||
IsWritable = (item.SetMethod != null) && item.SetMethod.DeclaredAccessibility == Accessibility.Public && !item.IsStatic,
|
||||
IsProperty = true,
|
||||
IsField = false,
|
||||
Name = item.Name,
|
||||
Type = item.Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat),
|
||||
ShortTypeName = item.Type.ToDisplayString(BinaryWriteFormat),
|
||||
};
|
||||
if (!member.IsReadable && !member.IsWritable)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
TypedConstant? key = item.GetAttributes().FirstOrDefault(x => x.AttributeClass == this.typeReferences.KeyAttribute)?.ConstructorArguments[0];
|
||||
if (key == null)
|
||||
{
|
||||
throw new MessagePackGeneratorResolveFailedException("all public members must mark KeyAttribute or IgnoreMemberAttribute." + " type: " + type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat) + " member:" + item.Name);
|
||||
}
|
||||
|
||||
var intKey = (key.Value.Value is int) ? (int)key.Value.Value : (int?)null;
|
||||
var stringKey = (key.Value.Value is string) ? (string)key.Value.Value : (string)null;
|
||||
if (intKey == null && stringKey == null)
|
||||
{
|
||||
throw new MessagePackGeneratorResolveFailedException("both IntKey and StringKey are null." + " type: " + type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat) + " member:" + item.Name);
|
||||
}
|
||||
|
||||
if (searchFirst)
|
||||
{
|
||||
searchFirst = false;
|
||||
isIntKey = intKey != null;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((isIntKey && intKey == null) || (!isIntKey && stringKey == null))
|
||||
{
|
||||
throw new MessagePackGeneratorResolveFailedException("all members key type must be same." + " type: " + type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat) + " member:" + item.Name);
|
||||
}
|
||||
}
|
||||
|
||||
if (isIntKey)
|
||||
{
|
||||
member.IntKey = (int)intKey;
|
||||
if (intMembers.ContainsKey(member.IntKey))
|
||||
{
|
||||
throw new MessagePackGeneratorResolveFailedException("key is duplicated, all members key must be unique." + " type: " + type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat) + " member:" + item.Name);
|
||||
}
|
||||
|
||||
intMembers.Add(member.IntKey, member);
|
||||
}
|
||||
else
|
||||
{
|
||||
member.StringKey = (string)stringKey;
|
||||
if (stringMembers.ContainsKey(member.StringKey))
|
||||
{
|
||||
throw new MessagePackGeneratorResolveFailedException("key is duplicated, all members key must be unique." + " type: " + type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat) + " member:" + item.Name);
|
||||
}
|
||||
|
||||
member.IntKey = hiddenIntKey++;
|
||||
stringMembers.Add(member.StringKey, member);
|
||||
}
|
||||
|
||||
this.CollectCore(item.Type); // recursive collect
|
||||
}
|
||||
|
||||
foreach (IFieldSymbol item in type.GetAllMembers().OfType<IFieldSymbol>())
|
||||
{
|
||||
if (item.IsImplicitlyDeclared)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (item.GetAttributes().Any(x => x.AttributeClass == this.typeReferences.IgnoreAttribute))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var member = new MemberSerializationInfo
|
||||
{
|
||||
IsReadable = item.DeclaredAccessibility == Accessibility.Public && !item.IsStatic,
|
||||
IsWritable = item.DeclaredAccessibility == Accessibility.Public && !item.IsReadOnly && !item.IsStatic,
|
||||
IsProperty = true,
|
||||
IsField = false,
|
||||
Name = item.Name,
|
||||
Type = item.Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat),
|
||||
ShortTypeName = item.Type.ToDisplayString(BinaryWriteFormat),
|
||||
};
|
||||
if (!member.IsReadable && !member.IsWritable)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
TypedConstant? key = item.GetAttributes().FirstOrDefault(x => x.AttributeClass == this.typeReferences.KeyAttribute)?.ConstructorArguments[0];
|
||||
if (key == null)
|
||||
{
|
||||
throw new MessagePackGeneratorResolveFailedException("all public members must mark KeyAttribute or IgnoreMemberAttribute." + " type: " + type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat) + " member:" + item.Name);
|
||||
}
|
||||
|
||||
var intKey = (key.Value.Value is int) ? (int)key.Value.Value : (int?)null;
|
||||
var stringKey = (key.Value.Value is string) ? (string)key.Value.Value : (string)null;
|
||||
if (intKey == null && stringKey == null)
|
||||
{
|
||||
throw new MessagePackGeneratorResolveFailedException("both IntKey and StringKey are null." + " type: " + type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat) + " member:" + item.Name);
|
||||
}
|
||||
|
||||
if (searchFirst)
|
||||
{
|
||||
searchFirst = false;
|
||||
isIntKey = intKey != null;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((isIntKey && intKey == null) || (!isIntKey && stringKey == null))
|
||||
{
|
||||
throw new MessagePackGeneratorResolveFailedException("all members key type must be same." + " type: " + type.Name + " member:" + item.Name);
|
||||
}
|
||||
}
|
||||
|
||||
if (isIntKey)
|
||||
{
|
||||
member.IntKey = (int)intKey;
|
||||
if (intMembers.ContainsKey(member.IntKey))
|
||||
{
|
||||
throw new MessagePackGeneratorResolveFailedException("key is duplicated, all members key must be unique." + " type: " + type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat) + " member:" + item.Name);
|
||||
}
|
||||
|
||||
intMembers.Add(member.IntKey, member);
|
||||
}
|
||||
else
|
||||
{
|
||||
member.StringKey = (string)stringKey;
|
||||
if (stringMembers.ContainsKey(member.StringKey))
|
||||
{
|
||||
throw new MessagePackGeneratorResolveFailedException("key is duplicated, all members key must be unique." + " type: " + type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat) + " member:" + item.Name);
|
||||
}
|
||||
|
||||
member.IntKey = hiddenIntKey++;
|
||||
stringMembers.Add(member.StringKey, member);
|
||||
}
|
||||
|
||||
this.CollectCore(item.Type); // recursive collect
|
||||
}
|
||||
}
|
||||
|
||||
// GetConstructor
|
||||
IEnumerator<IMethodSymbol> ctorEnumerator = null;
|
||||
IMethodSymbol ctor = type.Constructors.Where(x => x.DeclaredAccessibility == Accessibility.Public).SingleOrDefault(x => x.GetAttributes().Any(y => y.AttributeClass == this.typeReferences.SerializationConstructorAttribute));
|
||||
if (ctor == null)
|
||||
{
|
||||
ctorEnumerator =
|
||||
type.Constructors.Where(x => x.DeclaredAccessibility == Accessibility.Public && !x.IsImplicitlyDeclared).OrderBy(x => x.Parameters.Length)
|
||||
.Concat(type.Constructors.Where(x => x.DeclaredAccessibility == Accessibility.Public).OrderByDescending(x => x.Parameters.Length).Take(1))
|
||||
.GetEnumerator();
|
||||
|
||||
if (ctorEnumerator.MoveNext())
|
||||
{
|
||||
ctor = ctorEnumerator.Current;
|
||||
}
|
||||
}
|
||||
|
||||
// struct allows null ctor
|
||||
if (ctor == null && isClass)
|
||||
{
|
||||
throw new MessagePackGeneratorResolveFailedException("can't find public constructor. type:" + type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat));
|
||||
}
|
||||
|
||||
var constructorParameters = new List<MemberSerializationInfo>();
|
||||
if (ctor != null)
|
||||
{
|
||||
ILookup<string, KeyValuePair<string, MemberSerializationInfo>> constructorLookupDictionary = stringMembers.ToLookup(x => x.Key, x => x, StringComparer.OrdinalIgnoreCase);
|
||||
do
|
||||
{
|
||||
constructorParameters.Clear();
|
||||
var ctorParamIndex = 0;
|
||||
foreach (IParameterSymbol item in ctor.Parameters)
|
||||
{
|
||||
MemberSerializationInfo paramMember;
|
||||
if (isIntKey)
|
||||
{
|
||||
if (intMembers.TryGetValue(ctorParamIndex, out paramMember))
|
||||
{
|
||||
if (item.Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat) == paramMember.Type && paramMember.IsReadable)
|
||||
{
|
||||
constructorParameters.Add(paramMember);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ctorEnumerator != null)
|
||||
{
|
||||
ctor = null;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new MessagePackGeneratorResolveFailedException("can't find matched constructor parameter, parameterType mismatch. type:" + type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat) + " parameterIndex:" + ctorParamIndex + " paramterType:" + item.Type.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ctorEnumerator != null)
|
||||
{
|
||||
ctor = null;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new MessagePackGeneratorResolveFailedException("can't find matched constructor parameter, index not found. type:" + type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat) + " parameterIndex:" + ctorParamIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
IEnumerable<KeyValuePair<string, MemberSerializationInfo>> hasKey = constructorLookupDictionary[item.Name];
|
||||
var len = hasKey.Count();
|
||||
if (len != 0)
|
||||
{
|
||||
if (len != 1)
|
||||
{
|
||||
if (ctorEnumerator != null)
|
||||
{
|
||||
ctor = null;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new MessagePackGeneratorResolveFailedException("duplicate matched constructor parameter name:" + type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat) + " parameterName:" + item.Name + " paramterType:" + item.Type.Name);
|
||||
}
|
||||
}
|
||||
|
||||
paramMember = hasKey.First().Value;
|
||||
if (item.Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat) == paramMember.Type && paramMember.IsReadable)
|
||||
{
|
||||
constructorParameters.Add(paramMember);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ctorEnumerator != null)
|
||||
{
|
||||
ctor = null;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new MessagePackGeneratorResolveFailedException("can't find matched constructor parameter, parameterType mismatch. type:" + type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat) + " parameterName:" + item.Name + " paramterType:" + item.Type.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ctorEnumerator != null)
|
||||
{
|
||||
ctor = null;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new MessagePackGeneratorResolveFailedException("can't find matched constructor parameter, index not found. type:" + type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat) + " parameterName:" + item.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ctorParamIndex++;
|
||||
}
|
||||
}
|
||||
while (TryGetNextConstructor(ctorEnumerator, ref ctor));
|
||||
|
||||
if (ctor == null)
|
||||
{
|
||||
throw new MessagePackGeneratorResolveFailedException("can't find matched constructor. type:" + type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat));
|
||||
}
|
||||
}
|
||||
|
||||
var hasSerializationConstructor = type.AllInterfaces.Any(x => x == this.typeReferences.IMessagePackSerializationCallbackReceiver);
|
||||
var needsCastOnBefore = true;
|
||||
var needsCastOnAfter = true;
|
||||
if (hasSerializationConstructor)
|
||||
{
|
||||
needsCastOnBefore = !type.GetMembers("OnBeforeSerialize").Any();
|
||||
needsCastOnAfter = !type.GetMembers("OnAfterDeserialize").Any();
|
||||
}
|
||||
|
||||
var info = new ObjectSerializationInfo
|
||||
{
|
||||
IsClass = isClass,
|
||||
ConstructorParameters = constructorParameters.ToArray(),
|
||||
IsIntKey = isIntKey,
|
||||
Members = isIntKey ? intMembers.Values.ToArray() : stringMembers.Values.ToArray(),
|
||||
Name = type.ToDisplayString(ShortTypeNameFormat).Replace(".", "_"),
|
||||
FullName = type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat),
|
||||
Namespace = type.ContainingNamespace.IsGlobalNamespace ? null : type.ContainingNamespace.ToDisplayString(),
|
||||
HasIMessagePackSerializationCallbackReceiver = hasSerializationConstructor,
|
||||
NeedsCastOnAfter = needsCastOnAfter,
|
||||
NeedsCastOnBefore = needsCastOnBefore,
|
||||
};
|
||||
this.collectedObjectInfo.Add(info);
|
||||
}
|
||||
|
||||
private static bool TryGetNextConstructor(IEnumerator<IMethodSymbol> ctorEnumerator, ref IMethodSymbol ctor)
|
||||
{
|
||||
if (ctorEnumerator == null || ctor != null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ctorEnumerator.MoveNext())
|
||||
{
|
||||
ctor = ctorEnumerator.Current;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
ctor = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsAllowAccessibility(ITypeSymbol symbol)
|
||||
{
|
||||
do
|
||||
{
|
||||
if (symbol.DeclaredAccessibility != Accessibility.Public)
|
||||
{
|
||||
if (this.disallowInternal)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (symbol.DeclaredAccessibility != Accessibility.Internal)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
symbol = symbol.ContainingType;
|
||||
}
|
||||
while (symbol != null);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
internal class ReferenceSymbols
|
||||
{
|
||||
internal INamedTypeSymbol Task { get; }
|
||||
|
||||
internal INamedTypeSymbol TaskOfT { get; }
|
||||
|
||||
internal INamedTypeSymbol MessagePackObjectAttribute { get; }
|
||||
|
||||
internal INamedTypeSymbol UnionAttribute { get; }
|
||||
|
||||
internal INamedTypeSymbol SerializationConstructorAttribute { get; }
|
||||
|
||||
internal INamedTypeSymbol KeyAttribute { get; }
|
||||
|
||||
internal INamedTypeSymbol IgnoreAttribute { get; }
|
||||
|
||||
internal INamedTypeSymbol IgnoreDataMemberAttribute { get; }
|
||||
|
||||
internal INamedTypeSymbol IMessagePackSerializationCallbackReceiver { get; }
|
||||
|
||||
public ReferenceSymbols(Compilation compilation)
|
||||
{
|
||||
this.TaskOfT = compilation.GetTypeByMetadataName("System.Threading.Tasks.Task`1");
|
||||
if (this.TaskOfT == null)
|
||||
{
|
||||
throw new InvalidOperationException("failed to get metadata of System.Threading.Tasks.Task`1");
|
||||
}
|
||||
|
||||
this.Task = compilation.GetTypeByMetadataName("System.Threading.Tasks.Task");
|
||||
if (this.Task == null)
|
||||
{
|
||||
throw new InvalidOperationException("failed to get metadata of System.Threading.Tasks.Task");
|
||||
}
|
||||
|
||||
this.MessagePackObjectAttribute = compilation.GetTypeByMetadataName("MessagePack.MessagePackObjectAttribute");
|
||||
if (this.MessagePackObjectAttribute == null)
|
||||
{
|
||||
throw new InvalidOperationException("failed to get metadata of MessagePack.MessagePackObjectAttribute");
|
||||
}
|
||||
|
||||
this.UnionAttribute = compilation.GetTypeByMetadataName("MessagePack.UnionAttribute");
|
||||
if (this.UnionAttribute == null)
|
||||
{
|
||||
throw new InvalidOperationException("failed to get metadata of MessagePack.UnionAttribute");
|
||||
}
|
||||
|
||||
this.SerializationConstructorAttribute = compilation.GetTypeByMetadataName("MessagePack.SerializationConstructorAttribute");
|
||||
if (this.SerializationConstructorAttribute == null)
|
||||
{
|
||||
throw new InvalidOperationException("failed to get metadata of MessagePack.SerializationConstructorAttribute");
|
||||
}
|
||||
|
||||
this.KeyAttribute = compilation.GetTypeByMetadataName("MessagePack.KeyAttribute");
|
||||
if (this.KeyAttribute == null)
|
||||
{
|
||||
throw new InvalidOperationException("failed to get metadata of MessagePack.KeyAttribute");
|
||||
}
|
||||
|
||||
this.IgnoreAttribute = compilation.GetTypeByMetadataName("MessagePack.IgnoreMemberAttribute");
|
||||
if (this.IgnoreAttribute == null)
|
||||
{
|
||||
throw new InvalidOperationException("failed to get metadata of MessagePack.IgnoreMemberAttribute");
|
||||
}
|
||||
|
||||
this.IgnoreDataMemberAttribute = compilation.GetTypeByMetadataName("System.Runtime.Serialization.IgnoreDataMemberAttribute");
|
||||
this.IMessagePackSerializationCallbackReceiver = compilation.GetTypeByMetadataName("MessagePack.IMessagePackSerializationCallbackReceiver");
|
||||
if (this.IMessagePackSerializationCallbackReceiver == null)
|
||||
{
|
||||
throw new InvalidOperationException("failed to get metadata of MessagePack.IMessagePackSerializationCallbackReceiver");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class MessagePackGeneratorResolveFailedException : Exception
|
||||
{
|
||||
public MessagePackGeneratorResolveFailedException(string message)
|
||||
: base(message)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,404 +0,0 @@
|
|||
// ------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Runtime Version: 16.0.0.0
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
// ------------------------------------------------------------------------------
|
||||
namespace MessagePack.CodeGenerator.Generator
|
||||
{
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
|
||||
/// <summary>
|
||||
/// Class to produce the template output
|
||||
/// </summary>
|
||||
|
||||
#line 1 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\EnumTemplate.tt"
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "16.0.0.0")]
|
||||
public partial class EnumTemplate : EnumTemplateBase
|
||||
{
|
||||
#line hidden
|
||||
/// <summary>
|
||||
/// Create the template output
|
||||
/// </summary>
|
||||
public virtual string TransformText()
|
||||
{
|
||||
this.Write(@"/* THIS (.cs) FILE IS GENERATED. DO NOT CHANGE IT.
|
||||
* CHANGE THE .tt FILE INSTEAD. */
|
||||
|
||||
#pragma warning disable 618
|
||||
#pragma warning disable 612
|
||||
#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 ");
|
||||
|
||||
#line 18 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\EnumTemplate.tt"
|
||||
this.Write(this.ToStringHelper.ToStringWithCulture(Namespace));
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write("\r\n{\r\n using System;\r\n using System.Buffers;\r\n using MessagePack;\r\n");
|
||||
|
||||
#line 23 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\EnumTemplate.tt"
|
||||
foreach(var info in EnumSerializationInfos) {
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write("\r\n public sealed class ");
|
||||
|
||||
#line 25 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\EnumTemplate.tt"
|
||||
this.Write(this.ToStringHelper.ToStringWithCulture(info.Name));
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write("Formatter : global::MessagePack.Formatters.IMessagePackFormatter<");
|
||||
|
||||
#line 25 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\EnumTemplate.tt"
|
||||
this.Write(this.ToStringHelper.ToStringWithCulture(info.FullName));
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(">\r\n {\r\n public void Serialize(ref MessagePackWriter writer, ");
|
||||
|
||||
#line 27 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\EnumTemplate.tt"
|
||||
this.Write(this.ToStringHelper.ToStringWithCulture(info.FullName));
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(" value, global::MessagePack.MessagePackSerializerOptions options)\r\n {\r\n " +
|
||||
" writer.Write((");
|
||||
|
||||
#line 29 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\EnumTemplate.tt"
|
||||
this.Write(this.ToStringHelper.ToStringWithCulture(info.UnderlyingType));
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(")value);\r\n }\r\n\r\n public ");
|
||||
|
||||
#line 32 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\EnumTemplate.tt"
|
||||
this.Write(this.ToStringHelper.ToStringWithCulture(info.FullName));
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(" Deserialize(ref MessagePackReader reader, global::MessagePack.MessagePackSeriali" +
|
||||
"zerOptions options)\r\n {\r\n return (");
|
||||
|
||||
#line 34 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\EnumTemplate.tt"
|
||||
this.Write(this.ToStringHelper.ToStringWithCulture(info.FullName));
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(")reader.Read");
|
||||
|
||||
#line 34 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\EnumTemplate.tt"
|
||||
this.Write(this.ToStringHelper.ToStringWithCulture(info.UnderlyingType));
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write("();\r\n }\r\n }\r\n");
|
||||
|
||||
#line 37 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\EnumTemplate.tt"
|
||||
}
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(@"}
|
||||
|
||||
#pragma warning restore 168
|
||||
#pragma warning restore 414
|
||||
#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
|
||||
");
|
||||
return this.GenerationEnvironment.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
#region Base class
|
||||
/// <summary>
|
||||
/// Base class for this transformation
|
||||
/// </summary>
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "16.0.0.0")]
|
||||
public class EnumTemplateBase
|
||||
{
|
||||
#region Fields
|
||||
private global::System.Text.StringBuilder generationEnvironmentField;
|
||||
private global::System.CodeDom.Compiler.CompilerErrorCollection errorsField;
|
||||
private global::System.Collections.Generic.List<int> indentLengthsField;
|
||||
private string currentIndentField = "";
|
||||
private bool endsWithNewline;
|
||||
private global::System.Collections.Generic.IDictionary<string, object> sessionField;
|
||||
#endregion
|
||||
#region Properties
|
||||
/// <summary>
|
||||
/// The string builder that generation-time code is using to assemble generated output
|
||||
/// </summary>
|
||||
protected System.Text.StringBuilder GenerationEnvironment
|
||||
{
|
||||
get
|
||||
{
|
||||
if ((this.generationEnvironmentField == null))
|
||||
{
|
||||
this.generationEnvironmentField = new global::System.Text.StringBuilder();
|
||||
}
|
||||
return this.generationEnvironmentField;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.generationEnvironmentField = value;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// The error collection for the generation process
|
||||
/// </summary>
|
||||
public System.CodeDom.Compiler.CompilerErrorCollection Errors
|
||||
{
|
||||
get
|
||||
{
|
||||
if ((this.errorsField == null))
|
||||
{
|
||||
this.errorsField = new global::System.CodeDom.Compiler.CompilerErrorCollection();
|
||||
}
|
||||
return this.errorsField;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// A list of the lengths of each indent that was added with PushIndent
|
||||
/// </summary>
|
||||
private System.Collections.Generic.List<int> indentLengths
|
||||
{
|
||||
get
|
||||
{
|
||||
if ((this.indentLengthsField == null))
|
||||
{
|
||||
this.indentLengthsField = new global::System.Collections.Generic.List<int>();
|
||||
}
|
||||
return this.indentLengthsField;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets the current indent we use when adding lines to the output
|
||||
/// </summary>
|
||||
public string CurrentIndent
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.currentIndentField;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Current transformation session
|
||||
/// </summary>
|
||||
public virtual global::System.Collections.Generic.IDictionary<string, object> Session
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.sessionField;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.sessionField = value;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
#region Transform-time helpers
|
||||
/// <summary>
|
||||
/// Write text directly into the generated output
|
||||
/// </summary>
|
||||
public void Write(string textToAppend)
|
||||
{
|
||||
if (string.IsNullOrEmpty(textToAppend))
|
||||
{
|
||||
return;
|
||||
}
|
||||
// If we're starting off, or if the previous text ended with a newline,
|
||||
// we have to append the current indent first.
|
||||
if (((this.GenerationEnvironment.Length == 0)
|
||||
|| this.endsWithNewline))
|
||||
{
|
||||
this.GenerationEnvironment.Append(this.currentIndentField);
|
||||
this.endsWithNewline = false;
|
||||
}
|
||||
// Check if the current text ends with a newline
|
||||
if (textToAppend.EndsWith(global::System.Environment.NewLine, global::System.StringComparison.CurrentCulture))
|
||||
{
|
||||
this.endsWithNewline = true;
|
||||
}
|
||||
// This is an optimization. If the current indent is "", then we don't have to do any
|
||||
// of the more complex stuff further down.
|
||||
if ((this.currentIndentField.Length == 0))
|
||||
{
|
||||
this.GenerationEnvironment.Append(textToAppend);
|
||||
return;
|
||||
}
|
||||
// Everywhere there is a newline in the text, add an indent after it
|
||||
textToAppend = textToAppend.Replace(global::System.Environment.NewLine, (global::System.Environment.NewLine + this.currentIndentField));
|
||||
// If the text ends with a newline, then we should strip off the indent added at the very end
|
||||
// because the appropriate indent will be added when the next time Write() is called
|
||||
if (this.endsWithNewline)
|
||||
{
|
||||
this.GenerationEnvironment.Append(textToAppend, 0, (textToAppend.Length - this.currentIndentField.Length));
|
||||
}
|
||||
else
|
||||
{
|
||||
this.GenerationEnvironment.Append(textToAppend);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Write text directly into the generated output
|
||||
/// </summary>
|
||||
public void WriteLine(string textToAppend)
|
||||
{
|
||||
this.Write(textToAppend);
|
||||
this.GenerationEnvironment.AppendLine();
|
||||
this.endsWithNewline = true;
|
||||
}
|
||||
/// <summary>
|
||||
/// Write formatted text directly into the generated output
|
||||
/// </summary>
|
||||
public void Write(string format, params object[] args)
|
||||
{
|
||||
this.Write(string.Format(global::System.Globalization.CultureInfo.CurrentCulture, format, args));
|
||||
}
|
||||
/// <summary>
|
||||
/// Write formatted text directly into the generated output
|
||||
/// </summary>
|
||||
public void WriteLine(string format, params object[] args)
|
||||
{
|
||||
this.WriteLine(string.Format(global::System.Globalization.CultureInfo.CurrentCulture, format, args));
|
||||
}
|
||||
/// <summary>
|
||||
/// Raise an error
|
||||
/// </summary>
|
||||
public void Error(string message)
|
||||
{
|
||||
System.CodeDom.Compiler.CompilerError error = new global::System.CodeDom.Compiler.CompilerError();
|
||||
error.ErrorText = message;
|
||||
this.Errors.Add(error);
|
||||
}
|
||||
/// <summary>
|
||||
/// Raise a warning
|
||||
/// </summary>
|
||||
public void Warning(string message)
|
||||
{
|
||||
System.CodeDom.Compiler.CompilerError error = new global::System.CodeDom.Compiler.CompilerError();
|
||||
error.ErrorText = message;
|
||||
error.IsWarning = true;
|
||||
this.Errors.Add(error);
|
||||
}
|
||||
/// <summary>
|
||||
/// Increase the indent
|
||||
/// </summary>
|
||||
public void PushIndent(string indent)
|
||||
{
|
||||
if ((indent == null))
|
||||
{
|
||||
throw new global::System.ArgumentNullException("indent");
|
||||
}
|
||||
this.currentIndentField = (this.currentIndentField + indent);
|
||||
this.indentLengths.Add(indent.Length);
|
||||
}
|
||||
/// <summary>
|
||||
/// Remove the last indent that was added with PushIndent
|
||||
/// </summary>
|
||||
public string PopIndent()
|
||||
{
|
||||
string returnValue = "";
|
||||
if ((this.indentLengths.Count > 0))
|
||||
{
|
||||
int indentLength = this.indentLengths[(this.indentLengths.Count - 1)];
|
||||
this.indentLengths.RemoveAt((this.indentLengths.Count - 1));
|
||||
if ((indentLength > 0))
|
||||
{
|
||||
returnValue = this.currentIndentField.Substring((this.currentIndentField.Length - indentLength));
|
||||
this.currentIndentField = this.currentIndentField.Remove((this.currentIndentField.Length - indentLength));
|
||||
}
|
||||
}
|
||||
return returnValue;
|
||||
}
|
||||
/// <summary>
|
||||
/// Remove any indentation
|
||||
/// </summary>
|
||||
public void ClearIndent()
|
||||
{
|
||||
this.indentLengths.Clear();
|
||||
this.currentIndentField = "";
|
||||
}
|
||||
#endregion
|
||||
#region ToString Helpers
|
||||
/// <summary>
|
||||
/// Utility class to produce culture-oriented representation of an object as a string.
|
||||
/// </summary>
|
||||
public class ToStringInstanceHelper
|
||||
{
|
||||
private System.IFormatProvider formatProviderField = global::System.Globalization.CultureInfo.InvariantCulture;
|
||||
/// <summary>
|
||||
/// Gets or sets format provider to be used by ToStringWithCulture method.
|
||||
/// </summary>
|
||||
public System.IFormatProvider FormatProvider
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.formatProviderField ;
|
||||
}
|
||||
set
|
||||
{
|
||||
if ((value != null))
|
||||
{
|
||||
this.formatProviderField = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// This is called from the compile/run appdomain to convert objects within an expression block to a string
|
||||
/// </summary>
|
||||
public string ToStringWithCulture(object objectToConvert)
|
||||
{
|
||||
if ((objectToConvert == null))
|
||||
{
|
||||
throw new global::System.ArgumentNullException("objectToConvert");
|
||||
}
|
||||
System.Type t = objectToConvert.GetType();
|
||||
System.Reflection.MethodInfo method = t.GetMethod("ToString", new System.Type[] {
|
||||
typeof(System.IFormatProvider)});
|
||||
if ((method == null))
|
||||
{
|
||||
return objectToConvert.ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
return ((string)(method.Invoke(objectToConvert, new object[] {
|
||||
this.formatProviderField })));
|
||||
}
|
||||
}
|
||||
}
|
||||
private ToStringInstanceHelper toStringHelperField = new ToStringInstanceHelper();
|
||||
/// <summary>
|
||||
/// Helper to produce culture-oriented representation of an object as a string
|
||||
/// </summary>
|
||||
public ToStringInstanceHelper ToStringHelper
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.toStringHelperField;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
#endregion
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
<#@ template debug="false" hostspecific="false" language="C#" #>
|
||||
<#@ assembly name="System.Core" #>
|
||||
<#@ import namespace="System.Linq" #>
|
||||
<#@ import namespace="System.Text" #>
|
||||
<#@ import namespace="System.Collections.Generic" #>
|
||||
/* THIS (.cs) FILE IS GENERATED. DO NOT CHANGE IT.
|
||||
* CHANGE THE .tt FILE INSTEAD. */
|
||||
|
||||
#pragma warning disable 618
|
||||
#pragma warning disable 612
|
||||
#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)
|
||||
{
|
||||
writer.Write((<#= info.UnderlyingType #>)value);
|
||||
}
|
||||
|
||||
public <#= info.FullName #> Deserialize(ref MessagePackReader reader, global::MessagePack.MessagePackSerializerOptions options)
|
||||
{
|
||||
return (<#= info.FullName #>)reader.Read<#= info.UnderlyingType #>();
|
||||
}
|
||||
}
|
||||
<# } #>
|
||||
}
|
||||
|
||||
#pragma warning restore 168
|
||||
#pragma warning restore 414
|
||||
#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
|
|
@ -1,793 +0,0 @@
|
|||
// ------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Runtime Version: 16.0.0.0
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
// ------------------------------------------------------------------------------
|
||||
namespace MessagePack.CodeGenerator.Generator
|
||||
{
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
|
||||
/// <summary>
|
||||
/// Class to produce the template output
|
||||
/// </summary>
|
||||
|
||||
#line 1 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\FormatterTemplate.tt"
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "16.0.0.0")]
|
||||
public partial class FormatterTemplate : FormatterTemplateBase
|
||||
{
|
||||
#line hidden
|
||||
/// <summary>
|
||||
/// Create the template output
|
||||
/// </summary>
|
||||
public virtual string TransformText()
|
||||
{
|
||||
this.Write(@"/* THIS (.cs) FILE IS GENERATED. DO NOT CHANGE IT.
|
||||
* CHANGE THE .tt FILE INSTEAD. */
|
||||
|
||||
#pragma warning disable 618
|
||||
#pragma warning disable 612
|
||||
#pragma warning disable 414
|
||||
#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 ");
|
||||
|
||||
#line 21 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\FormatterTemplate.tt"
|
||||
this.Write(this.ToStringHelper.ToStringWithCulture(Namespace));
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write("\r\n{\r\n using System;\r\n using System.Buffers;\r\n using MessagePack;\r\n");
|
||||
|
||||
#line 26 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\FormatterTemplate.tt"
|
||||
foreach(var objInfo in ObjectSerializationInfos) {
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write("\r\n public sealed class ");
|
||||
|
||||
#line 28 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\FormatterTemplate.tt"
|
||||
this.Write(this.ToStringHelper.ToStringWithCulture(objInfo.Name));
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write("Formatter : global::MessagePack.Formatters.IMessagePackFormatter<");
|
||||
|
||||
#line 28 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\FormatterTemplate.tt"
|
||||
this.Write(this.ToStringHelper.ToStringWithCulture(objInfo.FullName));
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(">\r\n {");
|
||||
|
||||
#line 29 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\FormatterTemplate.tt"
|
||||
if( objInfo.IsStringKey) {
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write("\r\n private readonly global::MessagePack.Internal.AutomataDictionary ____ke" +
|
||||
"yMapping;\r\n private readonly byte[][] ____stringByteKeys;\r\n\r\n publ" +
|
||||
"ic ");
|
||||
|
||||
#line 34 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\FormatterTemplate.tt"
|
||||
this.Write(this.ToStringHelper.ToStringWithCulture(objInfo.Name));
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write("Formatter()\r\n {\r\n this.____keyMapping = new global::MessagePack" +
|
||||
".Internal.AutomataDictionary()\r\n {\r\n");
|
||||
|
||||
#line 38 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\FormatterTemplate.tt"
|
||||
foreach(var x in objInfo.Members) {
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(" { \"");
|
||||
|
||||
#line 39 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\FormatterTemplate.tt"
|
||||
this.Write(this.ToStringHelper.ToStringWithCulture(x.StringKey));
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write("\", ");
|
||||
|
||||
#line 39 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\FormatterTemplate.tt"
|
||||
this.Write(this.ToStringHelper.ToStringWithCulture(x.IntKey));
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(" },\r\n");
|
||||
|
||||
#line 40 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\FormatterTemplate.tt"
|
||||
}
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(" };\r\n\r\n this.____stringByteKeys = new byte[][]\r\n " +
|
||||
" {\r\n");
|
||||
|
||||
#line 45 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\FormatterTemplate.tt"
|
||||
foreach(var x in objInfo.Members.Where(x => x.IsReadable)) {
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(" global::MessagePack.Internal.CodeGenHelpers.GetEncodedStringBytes" +
|
||||
"(\"");
|
||||
|
||||
#line 46 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\FormatterTemplate.tt"
|
||||
this.Write(this.ToStringHelper.ToStringWithCulture(x.StringKey));
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write("\"),\r\n");
|
||||
|
||||
#line 47 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\FormatterTemplate.tt"
|
||||
}
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(" };\r\n }\r\n");
|
||||
|
||||
#line 50 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\FormatterTemplate.tt"
|
||||
}
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write("\r\n public void Serialize(ref MessagePackWriter writer, ");
|
||||
|
||||
#line 52 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\FormatterTemplate.tt"
|
||||
this.Write(this.ToStringHelper.ToStringWithCulture(objInfo.FullName));
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(" value, global::MessagePack.MessagePackSerializerOptions options)\r\n {\r\n");
|
||||
|
||||
#line 54 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\FormatterTemplate.tt"
|
||||
if( objInfo.IsClass) {
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(" if (value == null)\r\n {\r\n writer.WriteNil();" +
|
||||
"\r\n return;\r\n }\r\n\r\n");
|
||||
|
||||
#line 61 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\FormatterTemplate.tt"
|
||||
}
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(" IFormatterResolver formatterResolver = options.Resolver;\r\n");
|
||||
|
||||
#line 63 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\FormatterTemplate.tt"
|
||||
if(objInfo.HasIMessagePackSerializationCallbackReceiver && objInfo.NeedsCastOnBefore) {
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(" ((IMessagePackSerializationCallbackReceiver)value).OnBeforeSerialize(" +
|
||||
");\r\n");
|
||||
|
||||
#line 65 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\FormatterTemplate.tt"
|
||||
} else if(objInfo.HasIMessagePackSerializationCallbackReceiver) {
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(" value.OnBeforeSerialize();\r\n");
|
||||
|
||||
#line 67 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\FormatterTemplate.tt"
|
||||
}
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
|
||||
#line 68 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\FormatterTemplate.tt"
|
||||
if( objInfo.IsIntKey) {
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(" writer.WriteArrayHeader(");
|
||||
|
||||
#line 69 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\FormatterTemplate.tt"
|
||||
this.Write(this.ToStringHelper.ToStringWithCulture(objInfo.MaxKey + 1));
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(");\r\n");
|
||||
|
||||
#line 70 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\FormatterTemplate.tt"
|
||||
} else {
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(" writer.WriteMapHeader(");
|
||||
|
||||
#line 71 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\FormatterTemplate.tt"
|
||||
this.Write(this.ToStringHelper.ToStringWithCulture(objInfo.WriteCount));
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(");\r\n");
|
||||
|
||||
#line 72 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\FormatterTemplate.tt"
|
||||
}
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
|
||||
#line 73 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\FormatterTemplate.tt"
|
||||
if(objInfo.IsIntKey) {
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
|
||||
#line 74 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\FormatterTemplate.tt"
|
||||
for(var i =0; i<= objInfo.MaxKey; i++) { var member = objInfo.GetMember(i);
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
|
||||
#line 75 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\FormatterTemplate.tt"
|
||||
if( member == null) {
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(" writer.WriteNil();\r\n");
|
||||
|
||||
#line 77 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\FormatterTemplate.tt"
|
||||
} else {
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(" ");
|
||||
|
||||
#line 78 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\FormatterTemplate.tt"
|
||||
this.Write(this.ToStringHelper.ToStringWithCulture(member.GetSerializeMethodString()));
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(";\r\n");
|
||||
|
||||
#line 79 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\FormatterTemplate.tt"
|
||||
} } } else {
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
|
||||
#line 80 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\FormatterTemplate.tt"
|
||||
var index = 0; foreach(var x in objInfo.Members) {
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(" writer.WriteRaw(this.____stringByteKeys[");
|
||||
|
||||
#line 81 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\FormatterTemplate.tt"
|
||||
this.Write(this.ToStringHelper.ToStringWithCulture(index++));
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write("]);\r\n ");
|
||||
|
||||
#line 82 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\FormatterTemplate.tt"
|
||||
this.Write(this.ToStringHelper.ToStringWithCulture(x.GetSerializeMethodString()));
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(";\r\n");
|
||||
|
||||
#line 83 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\FormatterTemplate.tt"
|
||||
} }
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(" }\r\n\r\n public ");
|
||||
|
||||
#line 86 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\FormatterTemplate.tt"
|
||||
this.Write(this.ToStringHelper.ToStringWithCulture(objInfo.FullName));
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(" Deserialize(ref MessagePackReader reader, global::MessagePack.MessagePackSeriali" +
|
||||
"zerOptions options)\r\n {\r\n if (reader.TryReadNil())\r\n " +
|
||||
" {\r\n");
|
||||
|
||||
#line 90 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\FormatterTemplate.tt"
|
||||
if( objInfo.IsClass) {
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(" return null;\r\n");
|
||||
|
||||
#line 92 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\FormatterTemplate.tt"
|
||||
} else {
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(" throw new InvalidOperationException(\"typecode is null, struct not" +
|
||||
" supported\");\r\n");
|
||||
|
||||
#line 94 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\FormatterTemplate.tt"
|
||||
}
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(" }\r\n\r\n IFormatterResolver formatterResolver = options.Resol" +
|
||||
"ver;\r\n");
|
||||
|
||||
#line 98 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\FormatterTemplate.tt"
|
||||
if(objInfo.IsStringKey) {
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(" var length = reader.ReadMapHeader();\r\n");
|
||||
|
||||
#line 100 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\FormatterTemplate.tt"
|
||||
} else {
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(" var length = reader.ReadArrayHeader();\r\n");
|
||||
|
||||
#line 102 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\FormatterTemplate.tt"
|
||||
}
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
|
||||
#line 103 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\FormatterTemplate.tt"
|
||||
foreach(var x in objInfo.Members) {
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(" var __");
|
||||
|
||||
#line 104 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\FormatterTemplate.tt"
|
||||
this.Write(this.ToStringHelper.ToStringWithCulture(x.Name));
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write("__ = default(");
|
||||
|
||||
#line 104 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\FormatterTemplate.tt"
|
||||
this.Write(this.ToStringHelper.ToStringWithCulture(x.Type));
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(");\r\n");
|
||||
|
||||
#line 105 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\FormatterTemplate.tt"
|
||||
}
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write("\r\n for (int i = 0; i < length; i++)\r\n {\r\n");
|
||||
|
||||
#line 109 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\FormatterTemplate.tt"
|
||||
if(objInfo.IsStringKey) {
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(@" ReadOnlySpan<byte> stringKey = Internal.CodeGenHelpers.ReadStringSpan(ref reader);
|
||||
int key;
|
||||
if (!this.____keyMapping.TryGetValue(stringKey, out key))
|
||||
{
|
||||
reader.Skip();
|
||||
continue;
|
||||
}
|
||||
");
|
||||
|
||||
#line 117 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\FormatterTemplate.tt"
|
||||
} else {
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(" var key = i;\r\n");
|
||||
|
||||
#line 119 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\FormatterTemplate.tt"
|
||||
}
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write("\r\n switch (key)\r\n {\r\n");
|
||||
|
||||
#line 123 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\FormatterTemplate.tt"
|
||||
foreach(var x in objInfo.Members) {
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(" case ");
|
||||
|
||||
#line 124 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\FormatterTemplate.tt"
|
||||
this.Write(this.ToStringHelper.ToStringWithCulture(x.IntKey));
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(":\r\n __");
|
||||
|
||||
#line 125 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\FormatterTemplate.tt"
|
||||
this.Write(this.ToStringHelper.ToStringWithCulture(x.Name));
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write("__ = ");
|
||||
|
||||
#line 125 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\FormatterTemplate.tt"
|
||||
this.Write(this.ToStringHelper.ToStringWithCulture(x.GetDeserializeMethodString()));
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(";\r\n break;\r\n");
|
||||
|
||||
#line 127 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\FormatterTemplate.tt"
|
||||
}
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(" default:\r\n reader.Skip();\r\n " +
|
||||
" break;\r\n }\r\n }\r\n\r\n var ____res" +
|
||||
"ult = new ");
|
||||
|
||||
#line 134 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\FormatterTemplate.tt"
|
||||
this.Write(this.ToStringHelper.ToStringWithCulture(objInfo.GetConstructorString()));
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(";\r\n");
|
||||
|
||||
#line 135 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\FormatterTemplate.tt"
|
||||
foreach(var x in objInfo.Members.Where(x => x.IsWritable)) {
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(" ____result.");
|
||||
|
||||
#line 136 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\FormatterTemplate.tt"
|
||||
this.Write(this.ToStringHelper.ToStringWithCulture(x.Name));
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(" = __");
|
||||
|
||||
#line 136 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\FormatterTemplate.tt"
|
||||
this.Write(this.ToStringHelper.ToStringWithCulture(x.Name));
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write("__;\r\n");
|
||||
|
||||
#line 137 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\FormatterTemplate.tt"
|
||||
}
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
|
||||
#line 138 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\FormatterTemplate.tt"
|
||||
if(objInfo.HasIMessagePackSerializationCallbackReceiver && objInfo.NeedsCastOnAfter) {
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(" ((IMessagePackSerializationCallbackReceiver)____result).OnAfterDeseri" +
|
||||
"alize();\r\n");
|
||||
|
||||
#line 140 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\FormatterTemplate.tt"
|
||||
} else if(objInfo.HasIMessagePackSerializationCallbackReceiver) {
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(" ____result.OnAfterDeserialize();\r\n");
|
||||
|
||||
#line 142 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\FormatterTemplate.tt"
|
||||
}
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(" return ____result;\r\n }\r\n }\r\n");
|
||||
|
||||
#line 146 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\FormatterTemplate.tt"
|
||||
}
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
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 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
|
||||
#pragma warning restore SA1649 // File name should match first type name
|
||||
");
|
||||
return this.GenerationEnvironment.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
#region Base class
|
||||
/// <summary>
|
||||
/// Base class for this transformation
|
||||
/// </summary>
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "16.0.0.0")]
|
||||
public class FormatterTemplateBase
|
||||
{
|
||||
#region Fields
|
||||
private global::System.Text.StringBuilder generationEnvironmentField;
|
||||
private global::System.CodeDom.Compiler.CompilerErrorCollection errorsField;
|
||||
private global::System.Collections.Generic.List<int> indentLengthsField;
|
||||
private string currentIndentField = "";
|
||||
private bool endsWithNewline;
|
||||
private global::System.Collections.Generic.IDictionary<string, object> sessionField;
|
||||
#endregion
|
||||
#region Properties
|
||||
/// <summary>
|
||||
/// The string builder that generation-time code is using to assemble generated output
|
||||
/// </summary>
|
||||
protected System.Text.StringBuilder GenerationEnvironment
|
||||
{
|
||||
get
|
||||
{
|
||||
if ((this.generationEnvironmentField == null))
|
||||
{
|
||||
this.generationEnvironmentField = new global::System.Text.StringBuilder();
|
||||
}
|
||||
return this.generationEnvironmentField;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.generationEnvironmentField = value;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// The error collection for the generation process
|
||||
/// </summary>
|
||||
public System.CodeDom.Compiler.CompilerErrorCollection Errors
|
||||
{
|
||||
get
|
||||
{
|
||||
if ((this.errorsField == null))
|
||||
{
|
||||
this.errorsField = new global::System.CodeDom.Compiler.CompilerErrorCollection();
|
||||
}
|
||||
return this.errorsField;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// A list of the lengths of each indent that was added with PushIndent
|
||||
/// </summary>
|
||||
private System.Collections.Generic.List<int> indentLengths
|
||||
{
|
||||
get
|
||||
{
|
||||
if ((this.indentLengthsField == null))
|
||||
{
|
||||
this.indentLengthsField = new global::System.Collections.Generic.List<int>();
|
||||
}
|
||||
return this.indentLengthsField;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets the current indent we use when adding lines to the output
|
||||
/// </summary>
|
||||
public string CurrentIndent
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.currentIndentField;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Current transformation session
|
||||
/// </summary>
|
||||
public virtual global::System.Collections.Generic.IDictionary<string, object> Session
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.sessionField;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.sessionField = value;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
#region Transform-time helpers
|
||||
/// <summary>
|
||||
/// Write text directly into the generated output
|
||||
/// </summary>
|
||||
public void Write(string textToAppend)
|
||||
{
|
||||
if (string.IsNullOrEmpty(textToAppend))
|
||||
{
|
||||
return;
|
||||
}
|
||||
// If we're starting off, or if the previous text ended with a newline,
|
||||
// we have to append the current indent first.
|
||||
if (((this.GenerationEnvironment.Length == 0)
|
||||
|| this.endsWithNewline))
|
||||
{
|
||||
this.GenerationEnvironment.Append(this.currentIndentField);
|
||||
this.endsWithNewline = false;
|
||||
}
|
||||
// Check if the current text ends with a newline
|
||||
if (textToAppend.EndsWith(global::System.Environment.NewLine, global::System.StringComparison.CurrentCulture))
|
||||
{
|
||||
this.endsWithNewline = true;
|
||||
}
|
||||
// This is an optimization. If the current indent is "", then we don't have to do any
|
||||
// of the more complex stuff further down.
|
||||
if ((this.currentIndentField.Length == 0))
|
||||
{
|
||||
this.GenerationEnvironment.Append(textToAppend);
|
||||
return;
|
||||
}
|
||||
// Everywhere there is a newline in the text, add an indent after it
|
||||
textToAppend = textToAppend.Replace(global::System.Environment.NewLine, (global::System.Environment.NewLine + this.currentIndentField));
|
||||
// If the text ends with a newline, then we should strip off the indent added at the very end
|
||||
// because the appropriate indent will be added when the next time Write() is called
|
||||
if (this.endsWithNewline)
|
||||
{
|
||||
this.GenerationEnvironment.Append(textToAppend, 0, (textToAppend.Length - this.currentIndentField.Length));
|
||||
}
|
||||
else
|
||||
{
|
||||
this.GenerationEnvironment.Append(textToAppend);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Write text directly into the generated output
|
||||
/// </summary>
|
||||
public void WriteLine(string textToAppend)
|
||||
{
|
||||
this.Write(textToAppend);
|
||||
this.GenerationEnvironment.AppendLine();
|
||||
this.endsWithNewline = true;
|
||||
}
|
||||
/// <summary>
|
||||
/// Write formatted text directly into the generated output
|
||||
/// </summary>
|
||||
public void Write(string format, params object[] args)
|
||||
{
|
||||
this.Write(string.Format(global::System.Globalization.CultureInfo.CurrentCulture, format, args));
|
||||
}
|
||||
/// <summary>
|
||||
/// Write formatted text directly into the generated output
|
||||
/// </summary>
|
||||
public void WriteLine(string format, params object[] args)
|
||||
{
|
||||
this.WriteLine(string.Format(global::System.Globalization.CultureInfo.CurrentCulture, format, args));
|
||||
}
|
||||
/// <summary>
|
||||
/// Raise an error
|
||||
/// </summary>
|
||||
public void Error(string message)
|
||||
{
|
||||
System.CodeDom.Compiler.CompilerError error = new global::System.CodeDom.Compiler.CompilerError();
|
||||
error.ErrorText = message;
|
||||
this.Errors.Add(error);
|
||||
}
|
||||
/// <summary>
|
||||
/// Raise a warning
|
||||
/// </summary>
|
||||
public void Warning(string message)
|
||||
{
|
||||
System.CodeDom.Compiler.CompilerError error = new global::System.CodeDom.Compiler.CompilerError();
|
||||
error.ErrorText = message;
|
||||
error.IsWarning = true;
|
||||
this.Errors.Add(error);
|
||||
}
|
||||
/// <summary>
|
||||
/// Increase the indent
|
||||
/// </summary>
|
||||
public void PushIndent(string indent)
|
||||
{
|
||||
if ((indent == null))
|
||||
{
|
||||
throw new global::System.ArgumentNullException("indent");
|
||||
}
|
||||
this.currentIndentField = (this.currentIndentField + indent);
|
||||
this.indentLengths.Add(indent.Length);
|
||||
}
|
||||
/// <summary>
|
||||
/// Remove the last indent that was added with PushIndent
|
||||
/// </summary>
|
||||
public string PopIndent()
|
||||
{
|
||||
string returnValue = "";
|
||||
if ((this.indentLengths.Count > 0))
|
||||
{
|
||||
int indentLength = this.indentLengths[(this.indentLengths.Count - 1)];
|
||||
this.indentLengths.RemoveAt((this.indentLengths.Count - 1));
|
||||
if ((indentLength > 0))
|
||||
{
|
||||
returnValue = this.currentIndentField.Substring((this.currentIndentField.Length - indentLength));
|
||||
this.currentIndentField = this.currentIndentField.Remove((this.currentIndentField.Length - indentLength));
|
||||
}
|
||||
}
|
||||
return returnValue;
|
||||
}
|
||||
/// <summary>
|
||||
/// Remove any indentation
|
||||
/// </summary>
|
||||
public void ClearIndent()
|
||||
{
|
||||
this.indentLengths.Clear();
|
||||
this.currentIndentField = "";
|
||||
}
|
||||
#endregion
|
||||
#region ToString Helpers
|
||||
/// <summary>
|
||||
/// Utility class to produce culture-oriented representation of an object as a string.
|
||||
/// </summary>
|
||||
public class ToStringInstanceHelper
|
||||
{
|
||||
private System.IFormatProvider formatProviderField = global::System.Globalization.CultureInfo.InvariantCulture;
|
||||
/// <summary>
|
||||
/// Gets or sets format provider to be used by ToStringWithCulture method.
|
||||
/// </summary>
|
||||
public System.IFormatProvider FormatProvider
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.formatProviderField ;
|
||||
}
|
||||
set
|
||||
{
|
||||
if ((value != null))
|
||||
{
|
||||
this.formatProviderField = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// This is called from the compile/run appdomain to convert objects within an expression block to a string
|
||||
/// </summary>
|
||||
public string ToStringWithCulture(object objectToConvert)
|
||||
{
|
||||
if ((objectToConvert == null))
|
||||
{
|
||||
throw new global::System.ArgumentNullException("objectToConvert");
|
||||
}
|
||||
System.Type t = objectToConvert.GetType();
|
||||
System.Reflection.MethodInfo method = t.GetMethod("ToString", new System.Type[] {
|
||||
typeof(System.IFormatProvider)});
|
||||
if ((method == null))
|
||||
{
|
||||
return objectToConvert.ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
return ((string)(method.Invoke(objectToConvert, new object[] {
|
||||
this.formatProviderField })));
|
||||
}
|
||||
}
|
||||
}
|
||||
private ToStringInstanceHelper toStringHelperField = new ToStringInstanceHelper();
|
||||
/// <summary>
|
||||
/// Helper to produce culture-oriented representation of an object as a string
|
||||
/// </summary>
|
||||
public ToStringInstanceHelper ToStringHelper
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.toStringHelperField;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
#endregion
|
||||
}
|
|
@ -1,159 +0,0 @@
|
|||
<#@ template debug="false" hostspecific="false" language="C#" #>
|
||||
<#@ assembly name="System.Core" #>
|
||||
<#@ import namespace="System.Linq" #>
|
||||
<#@ import namespace="System.Text" #>
|
||||
<#@ import namespace="System.Collections.Generic" #>
|
||||
/* THIS (.cs) FILE IS GENERATED. DO NOT CHANGE IT.
|
||||
* CHANGE THE .tt FILE INSTEAD. */
|
||||
|
||||
#pragma warning disable 618
|
||||
#pragma warning disable 612
|
||||
#pragma warning disable 414
|
||||
#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 System;
|
||||
using System.Buffers;
|
||||
using MessagePack;
|
||||
<# foreach(var objInfo in ObjectSerializationInfos) { #>
|
||||
|
||||
public sealed class <#= objInfo.Name #>Formatter : global::MessagePack.Formatters.IMessagePackFormatter<<#= objInfo.FullName #>>
|
||||
{<# if( objInfo.IsStringKey) { #>
|
||||
|
||||
private readonly global::MessagePack.Internal.AutomataDictionary ____keyMapping;
|
||||
private readonly byte[][] ____stringByteKeys;
|
||||
|
||||
public <#= objInfo.Name #>Formatter()
|
||||
{
|
||||
this.____keyMapping = new global::MessagePack.Internal.AutomataDictionary()
|
||||
{
|
||||
<# foreach(var x in objInfo.Members) { #>
|
||||
{ "<#= x.StringKey #>", <#= x.IntKey #> },
|
||||
<# } #>
|
||||
};
|
||||
|
||||
this.____stringByteKeys = new byte[][]
|
||||
{
|
||||
<# foreach(var x in objInfo.Members.Where(x => x.IsReadable)) { #>
|
||||
global::MessagePack.Internal.CodeGenHelpers.GetEncodedStringBytes("<#= x.StringKey #>"),
|
||||
<# } #>
|
||||
};
|
||||
}
|
||||
<# } #>
|
||||
|
||||
public void Serialize(ref MessagePackWriter writer, <#= objInfo.FullName #> value, global::MessagePack.MessagePackSerializerOptions options)
|
||||
{
|
||||
<# if( objInfo.IsClass) { #>
|
||||
if (value == null)
|
||||
{
|
||||
writer.WriteNil();
|
||||
return;
|
||||
}
|
||||
|
||||
<# } #>
|
||||
IFormatterResolver formatterResolver = options.Resolver;
|
||||
<#if(objInfo.HasIMessagePackSerializationCallbackReceiver && objInfo.NeedsCastOnBefore) { #>
|
||||
((IMessagePackSerializationCallbackReceiver)value).OnBeforeSerialize();
|
||||
<# } else if(objInfo.HasIMessagePackSerializationCallbackReceiver) { #>
|
||||
value.OnBeforeSerialize();
|
||||
<# } #>
|
||||
<# if( objInfo.IsIntKey) { #>
|
||||
writer.WriteArrayHeader(<#= objInfo.MaxKey + 1 #>);
|
||||
<# } else { #>
|
||||
writer.WriteMapHeader(<#= objInfo.WriteCount #>);
|
||||
<# } #>
|
||||
<# if(objInfo.IsIntKey) { #>
|
||||
<# for(var i =0; i<= objInfo.MaxKey; i++) { var member = objInfo.GetMember(i); #>
|
||||
<# if( member == null) { #>
|
||||
writer.WriteNil();
|
||||
<# } else { #>
|
||||
<#= member.GetSerializeMethodString() #>;
|
||||
<# } } } else { #>
|
||||
<# var index = 0; foreach(var x in objInfo.Members) { #>
|
||||
writer.WriteRaw(this.____stringByteKeys[<#= index++ #>]);
|
||||
<#= x.GetSerializeMethodString() #>;
|
||||
<# } } #>
|
||||
}
|
||||
|
||||
public <#= objInfo.FullName #> Deserialize(ref MessagePackReader reader, global::MessagePack.MessagePackSerializerOptions options)
|
||||
{
|
||||
if (reader.TryReadNil())
|
||||
{
|
||||
<# if( objInfo.IsClass) { #>
|
||||
return null;
|
||||
<# } else { #>
|
||||
throw new InvalidOperationException("typecode is null, struct not supported");
|
||||
<# } #>
|
||||
}
|
||||
|
||||
IFormatterResolver formatterResolver = options.Resolver;
|
||||
<# if(objInfo.IsStringKey) { #>
|
||||
var length = reader.ReadMapHeader();
|
||||
<# } else { #>
|
||||
var length = reader.ReadArrayHeader();
|
||||
<# } #>
|
||||
<# foreach(var x in objInfo.Members) { #>
|
||||
var __<#= x.Name #>__ = default(<#= x.Type #>);
|
||||
<# } #>
|
||||
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
<# if(objInfo.IsStringKey) { #>
|
||||
ReadOnlySpan<byte> stringKey = Internal.CodeGenHelpers.ReadStringSpan(ref reader);
|
||||
int key;
|
||||
if (!this.____keyMapping.TryGetValue(stringKey, out key))
|
||||
{
|
||||
reader.Skip();
|
||||
continue;
|
||||
}
|
||||
<# } else { #>
|
||||
var key = i;
|
||||
<# } #>
|
||||
|
||||
switch (key)
|
||||
{
|
||||
<# foreach(var x in objInfo.Members) { #>
|
||||
case <#= x.IntKey #>:
|
||||
__<#= x.Name #>__ = <#= x.GetDeserializeMethodString() #>;
|
||||
break;
|
||||
<# } #>
|
||||
default:
|
||||
reader.Skip();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
var ____result = new <#= objInfo.GetConstructorString() #>;
|
||||
<# foreach(var x in objInfo.Members.Where(x => x.IsWritable)) { #>
|
||||
____result.<#= x.Name #> = __<#= x.Name #>__;
|
||||
<# } #>
|
||||
<#if(objInfo.HasIMessagePackSerializationCallbackReceiver && objInfo.NeedsCastOnAfter) { #>
|
||||
((IMessagePackSerializationCallbackReceiver)____result).OnAfterDeserialize();
|
||||
<# } else if(objInfo.HasIMessagePackSerializationCallbackReceiver) { #>
|
||||
____result.OnAfterDeserialize();
|
||||
<# } #>
|
||||
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 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
|
||||
#pragma warning restore SA1649 // File name should match first type name
|
|
@ -1,489 +0,0 @@
|
|||
// ------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Runtime Version: 16.0.0.0
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
// ------------------------------------------------------------------------------
|
||||
namespace MessagePack.CodeGenerator.Generator
|
||||
{
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
|
||||
/// <summary>
|
||||
/// Class to produce the template output
|
||||
/// </summary>
|
||||
|
||||
#line 1 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\ResolverTemplate.tt"
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "16.0.0.0")]
|
||||
public partial class ResolverTemplate : ResolverTemplateBase
|
||||
{
|
||||
#line hidden
|
||||
/// <summary>
|
||||
/// Create the template output
|
||||
/// </summary>
|
||||
public virtual string TransformText()
|
||||
{
|
||||
this.Write(@"/* THIS (.cs) FILE IS GENERATED. DO NOT CHANGE IT.
|
||||
* CHANGE THE .tt FILE INSTEAD. */
|
||||
|
||||
#pragma warning disable 618
|
||||
#pragma warning disable 612
|
||||
#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 ");
|
||||
|
||||
#line 18 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\ResolverTemplate.tt"
|
||||
this.Write(this.ToStringHelper.ToStringWithCulture(Namespace));
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write("\r\n{\r\n using System;\r\n using System.Buffers;\r\n using MessagePack;\r\n\r\n " +
|
||||
"public class ");
|
||||
|
||||
#line 24 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\ResolverTemplate.tt"
|
||||
this.Write(this.ToStringHelper.ToStringWithCulture(ResolverName));
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(" : global::MessagePack.IFormatterResolver\r\n {\r\n public static readonly " +
|
||||
"global::MessagePack.IFormatterResolver Instance = new ");
|
||||
|
||||
#line 26 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\ResolverTemplate.tt"
|
||||
this.Write(this.ToStringHelper.ToStringWithCulture(ResolverName));
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write("();\r\n\r\n private ");
|
||||
|
||||
#line 28 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\ResolverTemplate.tt"
|
||||
this.Write(this.ToStringHelper.ToStringWithCulture(ResolverName));
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(@"()
|
||||
{
|
||||
}
|
||||
|
||||
public global::MessagePack.Formatters.IMessagePackFormatter<T> GetFormatter<T>()
|
||||
{
|
||||
return FormatterCache<T>.Formatter;
|
||||
}
|
||||
|
||||
private static class FormatterCache<T>
|
||||
{
|
||||
internal static readonly global::MessagePack.Formatters.IMessagePackFormatter<T> Formatter;
|
||||
|
||||
static FormatterCache()
|
||||
{
|
||||
var f = ");
|
||||
|
||||
#line 43 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\ResolverTemplate.tt"
|
||||
this.Write(this.ToStringHelper.ToStringWithCulture(ResolverName));
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(@"GetFormatterHelper.GetFormatter(typeof(T));
|
||||
if (f != null)
|
||||
{
|
||||
Formatter = (global::MessagePack.Formatters.IMessagePackFormatter<T>)f;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal static class ");
|
||||
|
||||
#line 52 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\ResolverTemplate.tt"
|
||||
this.Write(this.ToStringHelper.ToStringWithCulture(ResolverName));
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write("GetFormatterHelper\r\n {\r\n private static readonly global::System.Collect" +
|
||||
"ions.Generic.Dictionary<Type, int> lookup;\r\n\r\n static ");
|
||||
|
||||
#line 56 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\ResolverTemplate.tt"
|
||||
this.Write(this.ToStringHelper.ToStringWithCulture(ResolverName));
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write("GetFormatterHelper()\r\n {\r\n lookup = new global::System.Collecti" +
|
||||
"ons.Generic.Dictionary<Type, int>(");
|
||||
|
||||
#line 58 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\ResolverTemplate.tt"
|
||||
this.Write(this.ToStringHelper.ToStringWithCulture(RegisterInfos.Length));
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(")\r\n {\r\n");
|
||||
|
||||
#line 60 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\ResolverTemplate.tt"
|
||||
for(var i = 0; i < RegisterInfos.Length; i++) { var x = RegisterInfos[i];
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(" { typeof(");
|
||||
|
||||
#line 61 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\ResolverTemplate.tt"
|
||||
this.Write(this.ToStringHelper.ToStringWithCulture(x.FullName));
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write("), ");
|
||||
|
||||
#line 61 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\ResolverTemplate.tt"
|
||||
this.Write(this.ToStringHelper.ToStringWithCulture(i));
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(" },\r\n");
|
||||
|
||||
#line 62 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\ResolverTemplate.tt"
|
||||
}
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(@" };
|
||||
}
|
||||
|
||||
internal static object GetFormatter(Type t)
|
||||
{
|
||||
int key;
|
||||
if (!lookup.TryGetValue(t, out key))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
switch (key)
|
||||
{
|
||||
");
|
||||
|
||||
#line 76 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\ResolverTemplate.tt"
|
||||
for(var i = 0; i < RegisterInfos.Length; i++) { var x = RegisterInfos[i];
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(" case ");
|
||||
|
||||
#line 77 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\ResolverTemplate.tt"
|
||||
this.Write(this.ToStringHelper.ToStringWithCulture(i));
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(": return new ");
|
||||
|
||||
#line 77 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\ResolverTemplate.tt"
|
||||
this.Write(this.ToStringHelper.ToStringWithCulture(x.FormatterName.StartsWith("global::") ? x.FormatterName: (!string.IsNullOrEmpty(FormatterNamespace) ? FormatterNamespace + "." : FormatterNamespace) + x.FormatterName));
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write("();\r\n");
|
||||
|
||||
#line 78 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\ResolverTemplate.tt"
|
||||
}
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(@" default: return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#pragma warning restore 168
|
||||
#pragma warning restore 414
|
||||
#pragma warning restore 618
|
||||
#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();
|
||||
}
|
||||
}
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
#region Base class
|
||||
/// <summary>
|
||||
/// Base class for this transformation
|
||||
/// </summary>
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "16.0.0.0")]
|
||||
public class ResolverTemplateBase
|
||||
{
|
||||
#region Fields
|
||||
private global::System.Text.StringBuilder generationEnvironmentField;
|
||||
private global::System.CodeDom.Compiler.CompilerErrorCollection errorsField;
|
||||
private global::System.Collections.Generic.List<int> indentLengthsField;
|
||||
private string currentIndentField = "";
|
||||
private bool endsWithNewline;
|
||||
private global::System.Collections.Generic.IDictionary<string, object> sessionField;
|
||||
#endregion
|
||||
#region Properties
|
||||
/// <summary>
|
||||
/// The string builder that generation-time code is using to assemble generated output
|
||||
/// </summary>
|
||||
protected System.Text.StringBuilder GenerationEnvironment
|
||||
{
|
||||
get
|
||||
{
|
||||
if ((this.generationEnvironmentField == null))
|
||||
{
|
||||
this.generationEnvironmentField = new global::System.Text.StringBuilder();
|
||||
}
|
||||
return this.generationEnvironmentField;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.generationEnvironmentField = value;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// The error collection for the generation process
|
||||
/// </summary>
|
||||
public System.CodeDom.Compiler.CompilerErrorCollection Errors
|
||||
{
|
||||
get
|
||||
{
|
||||
if ((this.errorsField == null))
|
||||
{
|
||||
this.errorsField = new global::System.CodeDom.Compiler.CompilerErrorCollection();
|
||||
}
|
||||
return this.errorsField;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// A list of the lengths of each indent that was added with PushIndent
|
||||
/// </summary>
|
||||
private System.Collections.Generic.List<int> indentLengths
|
||||
{
|
||||
get
|
||||
{
|
||||
if ((this.indentLengthsField == null))
|
||||
{
|
||||
this.indentLengthsField = new global::System.Collections.Generic.List<int>();
|
||||
}
|
||||
return this.indentLengthsField;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets the current indent we use when adding lines to the output
|
||||
/// </summary>
|
||||
public string CurrentIndent
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.currentIndentField;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Current transformation session
|
||||
/// </summary>
|
||||
public virtual global::System.Collections.Generic.IDictionary<string, object> Session
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.sessionField;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.sessionField = value;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
#region Transform-time helpers
|
||||
/// <summary>
|
||||
/// Write text directly into the generated output
|
||||
/// </summary>
|
||||
public void Write(string textToAppend)
|
||||
{
|
||||
if (string.IsNullOrEmpty(textToAppend))
|
||||
{
|
||||
return;
|
||||
}
|
||||
// If we're starting off, or if the previous text ended with a newline,
|
||||
// we have to append the current indent first.
|
||||
if (((this.GenerationEnvironment.Length == 0)
|
||||
|| this.endsWithNewline))
|
||||
{
|
||||
this.GenerationEnvironment.Append(this.currentIndentField);
|
||||
this.endsWithNewline = false;
|
||||
}
|
||||
// Check if the current text ends with a newline
|
||||
if (textToAppend.EndsWith(global::System.Environment.NewLine, global::System.StringComparison.CurrentCulture))
|
||||
{
|
||||
this.endsWithNewline = true;
|
||||
}
|
||||
// This is an optimization. If the current indent is "", then we don't have to do any
|
||||
// of the more complex stuff further down.
|
||||
if ((this.currentIndentField.Length == 0))
|
||||
{
|
||||
this.GenerationEnvironment.Append(textToAppend);
|
||||
return;
|
||||
}
|
||||
// Everywhere there is a newline in the text, add an indent after it
|
||||
textToAppend = textToAppend.Replace(global::System.Environment.NewLine, (global::System.Environment.NewLine + this.currentIndentField));
|
||||
// If the text ends with a newline, then we should strip off the indent added at the very end
|
||||
// because the appropriate indent will be added when the next time Write() is called
|
||||
if (this.endsWithNewline)
|
||||
{
|
||||
this.GenerationEnvironment.Append(textToAppend, 0, (textToAppend.Length - this.currentIndentField.Length));
|
||||
}
|
||||
else
|
||||
{
|
||||
this.GenerationEnvironment.Append(textToAppend);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Write text directly into the generated output
|
||||
/// </summary>
|
||||
public void WriteLine(string textToAppend)
|
||||
{
|
||||
this.Write(textToAppend);
|
||||
this.GenerationEnvironment.AppendLine();
|
||||
this.endsWithNewline = true;
|
||||
}
|
||||
/// <summary>
|
||||
/// Write formatted text directly into the generated output
|
||||
/// </summary>
|
||||
public void Write(string format, params object[] args)
|
||||
{
|
||||
this.Write(string.Format(global::System.Globalization.CultureInfo.CurrentCulture, format, args));
|
||||
}
|
||||
/// <summary>
|
||||
/// Write formatted text directly into the generated output
|
||||
/// </summary>
|
||||
public void WriteLine(string format, params object[] args)
|
||||
{
|
||||
this.WriteLine(string.Format(global::System.Globalization.CultureInfo.CurrentCulture, format, args));
|
||||
}
|
||||
/// <summary>
|
||||
/// Raise an error
|
||||
/// </summary>
|
||||
public void Error(string message)
|
||||
{
|
||||
System.CodeDom.Compiler.CompilerError error = new global::System.CodeDom.Compiler.CompilerError();
|
||||
error.ErrorText = message;
|
||||
this.Errors.Add(error);
|
||||
}
|
||||
/// <summary>
|
||||
/// Raise a warning
|
||||
/// </summary>
|
||||
public void Warning(string message)
|
||||
{
|
||||
System.CodeDom.Compiler.CompilerError error = new global::System.CodeDom.Compiler.CompilerError();
|
||||
error.ErrorText = message;
|
||||
error.IsWarning = true;
|
||||
this.Errors.Add(error);
|
||||
}
|
||||
/// <summary>
|
||||
/// Increase the indent
|
||||
/// </summary>
|
||||
public void PushIndent(string indent)
|
||||
{
|
||||
if ((indent == null))
|
||||
{
|
||||
throw new global::System.ArgumentNullException("indent");
|
||||
}
|
||||
this.currentIndentField = (this.currentIndentField + indent);
|
||||
this.indentLengths.Add(indent.Length);
|
||||
}
|
||||
/// <summary>
|
||||
/// Remove the last indent that was added with PushIndent
|
||||
/// </summary>
|
||||
public string PopIndent()
|
||||
{
|
||||
string returnValue = "";
|
||||
if ((this.indentLengths.Count > 0))
|
||||
{
|
||||
int indentLength = this.indentLengths[(this.indentLengths.Count - 1)];
|
||||
this.indentLengths.RemoveAt((this.indentLengths.Count - 1));
|
||||
if ((indentLength > 0))
|
||||
{
|
||||
returnValue = this.currentIndentField.Substring((this.currentIndentField.Length - indentLength));
|
||||
this.currentIndentField = this.currentIndentField.Remove((this.currentIndentField.Length - indentLength));
|
||||
}
|
||||
}
|
||||
return returnValue;
|
||||
}
|
||||
/// <summary>
|
||||
/// Remove any indentation
|
||||
/// </summary>
|
||||
public void ClearIndent()
|
||||
{
|
||||
this.indentLengths.Clear();
|
||||
this.currentIndentField = "";
|
||||
}
|
||||
#endregion
|
||||
#region ToString Helpers
|
||||
/// <summary>
|
||||
/// Utility class to produce culture-oriented representation of an object as a string.
|
||||
/// </summary>
|
||||
public class ToStringInstanceHelper
|
||||
{
|
||||
private System.IFormatProvider formatProviderField = global::System.Globalization.CultureInfo.InvariantCulture;
|
||||
/// <summary>
|
||||
/// Gets or sets format provider to be used by ToStringWithCulture method.
|
||||
/// </summary>
|
||||
public System.IFormatProvider FormatProvider
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.formatProviderField ;
|
||||
}
|
||||
set
|
||||
{
|
||||
if ((value != null))
|
||||
{
|
||||
this.formatProviderField = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// This is called from the compile/run appdomain to convert objects within an expression block to a string
|
||||
/// </summary>
|
||||
public string ToStringWithCulture(object objectToConvert)
|
||||
{
|
||||
if ((objectToConvert == null))
|
||||
{
|
||||
throw new global::System.ArgumentNullException("objectToConvert");
|
||||
}
|
||||
System.Type t = objectToConvert.GetType();
|
||||
System.Reflection.MethodInfo method = t.GetMethod("ToString", new System.Type[] {
|
||||
typeof(System.IFormatProvider)});
|
||||
if ((method == null))
|
||||
{
|
||||
return objectToConvert.ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
return ((string)(method.Invoke(objectToConvert, new object[] {
|
||||
this.formatProviderField })));
|
||||
}
|
||||
}
|
||||
}
|
||||
private ToStringInstanceHelper toStringHelperField = new ToStringInstanceHelper();
|
||||
/// <summary>
|
||||
/// Helper to produce culture-oriented representation of an object as a string
|
||||
/// </summary>
|
||||
public ToStringInstanceHelper ToStringHelper
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.toStringHelperField;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
#endregion
|
||||
}
|
|
@ -1,92 +0,0 @@
|
|||
<#@ template language="C#" #>
|
||||
<#@ assembly name="System.Core" #>
|
||||
<#@ import namespace="System.Linq" #>
|
||||
<#@ import namespace="System.Text" #>
|
||||
<#@ import namespace="System.Collections.Generic" #>
|
||||
/* THIS (.cs) FILE IS GENERATED. DO NOT CHANGE IT.
|
||||
* CHANGE THE .tt FILE INSTEAD. */
|
||||
|
||||
#pragma warning disable 618
|
||||
#pragma warning disable 612
|
||||
#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 #>();
|
||||
|
||||
private <#= ResolverName #>()
|
||||
{
|
||||
}
|
||||
|
||||
public global::MessagePack.Formatters.IMessagePackFormatter<T> GetFormatter<T>()
|
||||
{
|
||||
return FormatterCache<T>.Formatter;
|
||||
}
|
||||
|
||||
private static class FormatterCache<T>
|
||||
{
|
||||
internal static readonly global::MessagePack.Formatters.IMessagePackFormatter<T> Formatter;
|
||||
|
||||
static FormatterCache()
|
||||
{
|
||||
var f = <#= ResolverName #>GetFormatterHelper.GetFormatter(typeof(T));
|
||||
if (f != null)
|
||||
{
|
||||
Formatter = (global::MessagePack.Formatters.IMessagePackFormatter<T>)f;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal static class <#= ResolverName #>GetFormatterHelper
|
||||
{
|
||||
private static readonly global::System.Collections.Generic.Dictionary<Type, int> lookup;
|
||||
|
||||
static <#= ResolverName #>GetFormatterHelper()
|
||||
{
|
||||
lookup = new global::System.Collections.Generic.Dictionary<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)
|
||||
{
|
||||
int key;
|
||||
if (!lookup.TryGetValue(t, out key))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
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#>();
|
||||
<# } #>
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#pragma warning restore 168
|
||||
#pragma warning restore 414
|
||||
#pragma warning restore 618
|
||||
#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
|
|
@ -1,43 +0,0 @@
|
|||
// Copyright (c) All contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MessagePack.CodeGenerator.Generator
|
||||
{
|
||||
public partial class FormatterTemplate
|
||||
{
|
||||
public string Namespace { get; set; }
|
||||
|
||||
public ObjectSerializationInfo[] ObjectSerializationInfos { get; set; }
|
||||
}
|
||||
|
||||
public partial class ResolverTemplate
|
||||
{
|
||||
public string Namespace { get; set; }
|
||||
|
||||
public string FormatterNamespace { get; set; }
|
||||
|
||||
public string ResolverName { get; set; } = "GeneratedResolver";
|
||||
|
||||
public IResolverRegisterInfo[] RegisterInfos { get; set; }
|
||||
}
|
||||
|
||||
public partial class EnumTemplate
|
||||
{
|
||||
public string Namespace { get; set; }
|
||||
|
||||
public EnumSerializationInfo[] EnumSerializationInfos { get; set; }
|
||||
}
|
||||
|
||||
public partial class UnionTemplate
|
||||
{
|
||||
public string Namespace { get; set; }
|
||||
|
||||
public UnionSerializationInfo[] UnionSerializationInfos { get; set; }
|
||||
}
|
||||
}
|
|
@ -1,579 +0,0 @@
|
|||
// ------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Runtime Version: 16.0.0.0
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
// ------------------------------------------------------------------------------
|
||||
namespace MessagePack.CodeGenerator.Generator
|
||||
{
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
|
||||
/// <summary>
|
||||
/// Class to produce the template output
|
||||
/// </summary>
|
||||
|
||||
#line 1 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\UnionTemplate.tt"
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "16.0.0.0")]
|
||||
public partial class UnionTemplate : UnionTemplateBase
|
||||
{
|
||||
#line hidden
|
||||
/// <summary>
|
||||
/// Create the template output
|
||||
/// </summary>
|
||||
public virtual string TransformText()
|
||||
{
|
||||
this.Write(@"/* THIS (.cs) FILE IS GENERATED. DO NOT CHANGE IT.
|
||||
* CHANGE THE .tt FILE INSTEAD. */
|
||||
|
||||
#pragma warning disable 618
|
||||
#pragma warning disable 612
|
||||
#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 ");
|
||||
|
||||
#line 18 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\UnionTemplate.tt"
|
||||
this.Write(this.ToStringHelper.ToStringWithCulture(Namespace));
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
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");
|
||||
|
||||
#line 25 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\UnionTemplate.tt"
|
||||
foreach(var info in UnionSerializationInfos) {
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(" public sealed class ");
|
||||
|
||||
#line 26 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\UnionTemplate.tt"
|
||||
this.Write(this.ToStringHelper.ToStringWithCulture(info.Name));
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write("Formatter : global::MessagePack.Formatters.IMessagePackFormatter<");
|
||||
|
||||
#line 26 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\UnionTemplate.tt"
|
||||
this.Write(this.ToStringHelper.ToStringWithCulture(info.FullName));
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
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 ");
|
||||
|
||||
#line 31 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\UnionTemplate.tt"
|
||||
this.Write(this.ToStringHelper.ToStringWithCulture(info.Name));
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write("Formatter()\r\n {\r\n this.typeToKeyAndJumpMap = new Dictionary<Run" +
|
||||
"timeTypeHandle, KeyValuePair<int, int>>(");
|
||||
|
||||
#line 33 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\UnionTemplate.tt"
|
||||
this.Write(this.ToStringHelper.ToStringWithCulture(info.SubTypes.Length));
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(", global::MessagePack.Internal.RuntimeTypeHandleEqualityComparer.Default)\r\n " +
|
||||
" {\r\n");
|
||||
|
||||
#line 35 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\UnionTemplate.tt"
|
||||
for(var i = 0; i < info.SubTypes.Length; i++) { var item = info.SubTypes[i];
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(" { typeof(");
|
||||
|
||||
#line 36 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\UnionTemplate.tt"
|
||||
this.Write(this.ToStringHelper.ToStringWithCulture(item.Type));
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(").TypeHandle, new KeyValuePair<int, int>(");
|
||||
|
||||
#line 36 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\UnionTemplate.tt"
|
||||
this.Write(this.ToStringHelper.ToStringWithCulture(item.Key));
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(", ");
|
||||
|
||||
#line 36 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\UnionTemplate.tt"
|
||||
this.Write(this.ToStringHelper.ToStringWithCulture(i));
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(") },\r\n");
|
||||
|
||||
#line 37 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\UnionTemplate.tt"
|
||||
}
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(" };\r\n this.keyToJumpMap = new Dictionary<int, int>(");
|
||||
|
||||
#line 39 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\UnionTemplate.tt"
|
||||
this.Write(this.ToStringHelper.ToStringWithCulture(info.SubTypes.Length));
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(")\r\n {\r\n");
|
||||
|
||||
#line 41 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\UnionTemplate.tt"
|
||||
for(var i = 0; i < info.SubTypes.Length; i++) { var item = info.SubTypes[i];
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(" { ");
|
||||
|
||||
#line 42 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\UnionTemplate.tt"
|
||||
this.Write(this.ToStringHelper.ToStringWithCulture(item.Key));
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(", ");
|
||||
|
||||
#line 42 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\UnionTemplate.tt"
|
||||
this.Write(this.ToStringHelper.ToStringWithCulture(i));
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(" },\r\n");
|
||||
|
||||
#line 43 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\UnionTemplate.tt"
|
||||
}
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(" };\r\n }\r\n\r\n public void Serialize(ref MessagePackWriter " +
|
||||
"writer, ");
|
||||
|
||||
#line 47 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\UnionTemplate.tt"
|
||||
this.Write(this.ToStringHelper.ToStringWithCulture(info.FullName));
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(@" value, global::MessagePack.MessagePackSerializerOptions options)
|
||||
{
|
||||
KeyValuePair<int, int> keyValuePair;
|
||||
if (value != null && this.typeToKeyAndJumpMap.TryGetValue(value.GetType().TypeHandle, out keyValuePair))
|
||||
{
|
||||
writer.WriteArrayHeader(2);
|
||||
writer.WriteInt32(keyValuePair.Key);
|
||||
switch (keyValuePair.Value)
|
||||
{
|
||||
");
|
||||
|
||||
#line 56 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\UnionTemplate.tt"
|
||||
for(var i = 0; i < info.SubTypes.Length; i++) { var item = info.SubTypes[i];
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(" case ");
|
||||
|
||||
#line 57 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\UnionTemplate.tt"
|
||||
this.Write(this.ToStringHelper.ToStringWithCulture(i));
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(":\r\n options.Resolver.GetFormatterWithVerify<");
|
||||
|
||||
#line 58 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\UnionTemplate.tt"
|
||||
this.Write(this.ToStringHelper.ToStringWithCulture(item.Type));
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(">().Serialize(ref writer, (");
|
||||
|
||||
#line 58 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\UnionTemplate.tt"
|
||||
this.Write(this.ToStringHelper.ToStringWithCulture(item.Type));
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(")value, options);\r\n break;\r\n");
|
||||
|
||||
#line 60 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\UnionTemplate.tt"
|
||||
}
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(" default:\r\n break;\r\n }\r\n" +
|
||||
"\r\n return;\r\n }\r\n\r\n writer.WriteNil();\r\n " +
|
||||
" }\r\n\r\n public ");
|
||||
|
||||
#line 71 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\UnionTemplate.tt"
|
||||
this.Write(this.ToStringHelper.ToStringWithCulture(info.FullName));
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(@" Deserialize(ref MessagePackReader reader, global::MessagePack.MessagePackSerializerOptions options)
|
||||
{
|
||||
if (reader.TryReadNil())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (reader.ReadArrayHeader() != 2)
|
||||
{
|
||||
throw new InvalidOperationException(""Invalid Union data was detected. Type:");
|
||||
|
||||
#line 80 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\UnionTemplate.tt"
|
||||
this.Write(this.ToStringHelper.ToStringWithCulture(info.FullName));
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write("\");\r\n }\r\n\r\n var key = reader.ReadInt32();\r\n\r\n if" +
|
||||
" (!this.keyToJumpMap.TryGetValue(key, out key))\r\n {\r\n " +
|
||||
"key = -1;\r\n }\r\n\r\n ");
|
||||
|
||||
#line 90 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\UnionTemplate.tt"
|
||||
this.Write(this.ToStringHelper.ToStringWithCulture(info.FullName));
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(" result = null;\r\n switch (key)\r\n {\r\n");
|
||||
|
||||
#line 93 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\UnionTemplate.tt"
|
||||
for(var i = 0; i < info.SubTypes.Length; i++) { var item = info.SubTypes[i];
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(" case ");
|
||||
|
||||
#line 94 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\UnionTemplate.tt"
|
||||
this.Write(this.ToStringHelper.ToStringWithCulture(i));
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(":\r\n result = (");
|
||||
|
||||
#line 95 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\UnionTemplate.tt"
|
||||
this.Write(this.ToStringHelper.ToStringWithCulture(info.FullName));
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(")options.Resolver.GetFormatterWithVerify<");
|
||||
|
||||
#line 95 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\UnionTemplate.tt"
|
||||
this.Write(this.ToStringHelper.ToStringWithCulture(item.Type));
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(">().Deserialize(ref reader, options);\r\n break;\r\n");
|
||||
|
||||
#line 97 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\UnionTemplate.tt"
|
||||
}
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(" default:\r\n reader.Skip();\r\n " +
|
||||
" break;\r\n }\r\n\r\n return result;\r\n }\r\n }\r\n\r\n");
|
||||
|
||||
#line 107 "D:\git\MessagePack-CSharp\src\MessagePack.UniversalCodeGenerator\Generator\UnionTemplate.tt"
|
||||
}
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
this.Write(@"
|
||||
}
|
||||
|
||||
#pragma warning restore 168
|
||||
#pragma warning restore 414
|
||||
#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
|
||||
");
|
||||
return this.GenerationEnvironment.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
#region Base class
|
||||
/// <summary>
|
||||
/// Base class for this transformation
|
||||
/// </summary>
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "16.0.0.0")]
|
||||
public class UnionTemplateBase
|
||||
{
|
||||
#region Fields
|
||||
private global::System.Text.StringBuilder generationEnvironmentField;
|
||||
private global::System.CodeDom.Compiler.CompilerErrorCollection errorsField;
|
||||
private global::System.Collections.Generic.List<int> indentLengthsField;
|
||||
private string currentIndentField = "";
|
||||
private bool endsWithNewline;
|
||||
private global::System.Collections.Generic.IDictionary<string, object> sessionField;
|
||||
#endregion
|
||||
#region Properties
|
||||
/// <summary>
|
||||
/// The string builder that generation-time code is using to assemble generated output
|
||||
/// </summary>
|
||||
protected System.Text.StringBuilder GenerationEnvironment
|
||||
{
|
||||
get
|
||||
{
|
||||
if ((this.generationEnvironmentField == null))
|
||||
{
|
||||
this.generationEnvironmentField = new global::System.Text.StringBuilder();
|
||||
}
|
||||
return this.generationEnvironmentField;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.generationEnvironmentField = value;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// The error collection for the generation process
|
||||
/// </summary>
|
||||
public System.CodeDom.Compiler.CompilerErrorCollection Errors
|
||||
{
|
||||
get
|
||||
{
|
||||
if ((this.errorsField == null))
|
||||
{
|
||||
this.errorsField = new global::System.CodeDom.Compiler.CompilerErrorCollection();
|
||||
}
|
||||
return this.errorsField;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// A list of the lengths of each indent that was added with PushIndent
|
||||
/// </summary>
|
||||
private System.Collections.Generic.List<int> indentLengths
|
||||
{
|
||||
get
|
||||
{
|
||||
if ((this.indentLengthsField == null))
|
||||
{
|
||||
this.indentLengthsField = new global::System.Collections.Generic.List<int>();
|
||||
}
|
||||
return this.indentLengthsField;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets the current indent we use when adding lines to the output
|
||||
/// </summary>
|
||||
public string CurrentIndent
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.currentIndentField;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Current transformation session
|
||||
/// </summary>
|
||||
public virtual global::System.Collections.Generic.IDictionary<string, object> Session
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.sessionField;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.sessionField = value;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
#region Transform-time helpers
|
||||
/// <summary>
|
||||
/// Write text directly into the generated output
|
||||
/// </summary>
|
||||
public void Write(string textToAppend)
|
||||
{
|
||||
if (string.IsNullOrEmpty(textToAppend))
|
||||
{
|
||||
return;
|
||||
}
|
||||
// If we're starting off, or if the previous text ended with a newline,
|
||||
// we have to append the current indent first.
|
||||
if (((this.GenerationEnvironment.Length == 0)
|
||||
|| this.endsWithNewline))
|
||||
{
|
||||
this.GenerationEnvironment.Append(this.currentIndentField);
|
||||
this.endsWithNewline = false;
|
||||
}
|
||||
// Check if the current text ends with a newline
|
||||
if (textToAppend.EndsWith(global::System.Environment.NewLine, global::System.StringComparison.CurrentCulture))
|
||||
{
|
||||
this.endsWithNewline = true;
|
||||
}
|
||||
// This is an optimization. If the current indent is "", then we don't have to do any
|
||||
// of the more complex stuff further down.
|
||||
if ((this.currentIndentField.Length == 0))
|
||||
{
|
||||
this.GenerationEnvironment.Append(textToAppend);
|
||||
return;
|
||||
}
|
||||
// Everywhere there is a newline in the text, add an indent after it
|
||||
textToAppend = textToAppend.Replace(global::System.Environment.NewLine, (global::System.Environment.NewLine + this.currentIndentField));
|
||||
// If the text ends with a newline, then we should strip off the indent added at the very end
|
||||
// because the appropriate indent will be added when the next time Write() is called
|
||||
if (this.endsWithNewline)
|
||||
{
|
||||
this.GenerationEnvironment.Append(textToAppend, 0, (textToAppend.Length - this.currentIndentField.Length));
|
||||
}
|
||||
else
|
||||
{
|
||||
this.GenerationEnvironment.Append(textToAppend);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Write text directly into the generated output
|
||||
/// </summary>
|
||||
public void WriteLine(string textToAppend)
|
||||
{
|
||||
this.Write(textToAppend);
|
||||
this.GenerationEnvironment.AppendLine();
|
||||
this.endsWithNewline = true;
|
||||
}
|
||||
/// <summary>
|
||||
/// Write formatted text directly into the generated output
|
||||
/// </summary>
|
||||
public void Write(string format, params object[] args)
|
||||
{
|
||||
this.Write(string.Format(global::System.Globalization.CultureInfo.CurrentCulture, format, args));
|
||||
}
|
||||
/// <summary>
|
||||
/// Write formatted text directly into the generated output
|
||||
/// </summary>
|
||||
public void WriteLine(string format, params object[] args)
|
||||
{
|
||||
this.WriteLine(string.Format(global::System.Globalization.CultureInfo.CurrentCulture, format, args));
|
||||
}
|
||||
/// <summary>
|
||||
/// Raise an error
|
||||
/// </summary>
|
||||
public void Error(string message)
|
||||
{
|
||||
System.CodeDom.Compiler.CompilerError error = new global::System.CodeDom.Compiler.CompilerError();
|
||||
error.ErrorText = message;
|
||||
this.Errors.Add(error);
|
||||
}
|
||||
/// <summary>
|
||||
/// Raise a warning
|
||||
/// </summary>
|
||||
public void Warning(string message)
|
||||
{
|
||||
System.CodeDom.Compiler.CompilerError error = new global::System.CodeDom.Compiler.CompilerError();
|
||||
error.ErrorText = message;
|
||||
error.IsWarning = true;
|
||||
this.Errors.Add(error);
|
||||
}
|
||||
/// <summary>
|
||||
/// Increase the indent
|
||||
/// </summary>
|
||||
public void PushIndent(string indent)
|
||||
{
|
||||
if ((indent == null))
|
||||
{
|
||||
throw new global::System.ArgumentNullException("indent");
|
||||
}
|
||||
this.currentIndentField = (this.currentIndentField + indent);
|
||||
this.indentLengths.Add(indent.Length);
|
||||
}
|
||||
/// <summary>
|
||||
/// Remove the last indent that was added with PushIndent
|
||||
/// </summary>
|
||||
public string PopIndent()
|
||||
{
|
||||
string returnValue = "";
|
||||
if ((this.indentLengths.Count > 0))
|
||||
{
|
||||
int indentLength = this.indentLengths[(this.indentLengths.Count - 1)];
|
||||
this.indentLengths.RemoveAt((this.indentLengths.Count - 1));
|
||||
if ((indentLength > 0))
|
||||
{
|
||||
returnValue = this.currentIndentField.Substring((this.currentIndentField.Length - indentLength));
|
||||
this.currentIndentField = this.currentIndentField.Remove((this.currentIndentField.Length - indentLength));
|
||||
}
|
||||
}
|
||||
return returnValue;
|
||||
}
|
||||
/// <summary>
|
||||
/// Remove any indentation
|
||||
/// </summary>
|
||||
public void ClearIndent()
|
||||
{
|
||||
this.indentLengths.Clear();
|
||||
this.currentIndentField = "";
|
||||
}
|
||||
#endregion
|
||||
#region ToString Helpers
|
||||
/// <summary>
|
||||
/// Utility class to produce culture-oriented representation of an object as a string.
|
||||
/// </summary>
|
||||
public class ToStringInstanceHelper
|
||||
{
|
||||
private System.IFormatProvider formatProviderField = global::System.Globalization.CultureInfo.InvariantCulture;
|
||||
/// <summary>
|
||||
/// Gets or sets format provider to be used by ToStringWithCulture method.
|
||||
/// </summary>
|
||||
public System.IFormatProvider FormatProvider
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.formatProviderField ;
|
||||
}
|
||||
set
|
||||
{
|
||||
if ((value != null))
|
||||
{
|
||||
this.formatProviderField = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// This is called from the compile/run appdomain to convert objects within an expression block to a string
|
||||
/// </summary>
|
||||
public string ToStringWithCulture(object objectToConvert)
|
||||
{
|
||||
if ((objectToConvert == null))
|
||||
{
|
||||
throw new global::System.ArgumentNullException("objectToConvert");
|
||||
}
|
||||
System.Type t = objectToConvert.GetType();
|
||||
System.Reflection.MethodInfo method = t.GetMethod("ToString", new System.Type[] {
|
||||
typeof(System.IFormatProvider)});
|
||||
if ((method == null))
|
||||
{
|
||||
return objectToConvert.ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
return ((string)(method.Invoke(objectToConvert, new object[] {
|
||||
this.formatProviderField })));
|
||||
}
|
||||
}
|
||||
}
|
||||
private ToStringInstanceHelper toStringHelperField = new ToStringInstanceHelper();
|
||||
/// <summary>
|
||||
/// Helper to produce culture-oriented representation of an object as a string
|
||||
/// </summary>
|
||||
public ToStringInstanceHelper ToStringHelper
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.toStringHelperField;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
#endregion
|
||||
}
|
|
@ -1,118 +0,0 @@
|
|||
<#@ template debug="false" hostspecific="false" language="C#" #>
|
||||
<#@ assembly name="System.Core" #>
|
||||
<#@ import namespace="System.Linq" #>
|
||||
<#@ import namespace="System.Text" #>
|
||||
<#@ import namespace="System.Collections.Generic" #>
|
||||
/* THIS (.cs) FILE IS GENERATED. DO NOT CHANGE IT.
|
||||
* CHANGE THE .tt FILE INSTEAD. */
|
||||
|
||||
#pragma warning disable 618
|
||||
#pragma warning disable 612
|
||||
#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;
|
||||
|
||||
public <#= info.Name #>Formatter()
|
||||
{
|
||||
this.typeToKeyAndJumpMap = new Dictionary<RuntimeTypeHandle, 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 #>) },
|
||||
<# } #>
|
||||
};
|
||||
this.keyToJumpMap = new Dictionary<int, int>(<#= info.SubTypes.Length #>)
|
||||
{
|
||||
<# for(var i = 0; i < info.SubTypes.Length; i++) { var item = info.SubTypes[i]; #>
|
||||
{ <#= item.Key #>, <#= i #> },
|
||||
<# } #>
|
||||
};
|
||||
}
|
||||
|
||||
public void Serialize(ref MessagePackWriter writer, <#= info.FullName #> value, global::MessagePack.MessagePackSerializerOptions options)
|
||||
{
|
||||
KeyValuePair<int, int> keyValuePair;
|
||||
if (value != null && this.typeToKeyAndJumpMap.TryGetValue(value.GetType().TypeHandle, out keyValuePair))
|
||||
{
|
||||
writer.WriteArrayHeader(2);
|
||||
writer.WriteInt32(keyValuePair.Key);
|
||||
switch (keyValuePair.Value)
|
||||
{
|
||||
<# for(var i = 0; i < info.SubTypes.Length; i++) { var item = info.SubTypes[i]; #>
|
||||
case <#= i #>:
|
||||
options.Resolver.GetFormatterWithVerify<<#= item.Type #>>().Serialize(ref writer, (<#= item.Type #>)value, options);
|
||||
break;
|
||||
<# } #>
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
writer.WriteNil();
|
||||
}
|
||||
|
||||
public <#= info.FullName #> Deserialize(ref MessagePackReader reader, global::MessagePack.MessagePackSerializerOptions options)
|
||||
{
|
||||
if (reader.TryReadNil())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (reader.ReadArrayHeader() != 2)
|
||||
{
|
||||
throw new InvalidOperationException("Invalid Union data was detected. Type:<#= info.FullName #>");
|
||||
}
|
||||
|
||||
var key = reader.ReadInt32();
|
||||
|
||||
if (!this.keyToJumpMap.TryGetValue(key, out key))
|
||||
{
|
||||
key = -1;
|
||||
}
|
||||
|
||||
<#= info.FullName #> result = null;
|
||||
switch (key)
|
||||
{
|
||||
<# for(var i = 0; i < info.SubTypes.Length; i++) { var item = info.SubTypes[i]; #>
|
||||
case <#= i #>:
|
||||
result = (<#= info.FullName #>)options.Resolver.GetFormatterWithVerify<<#= item.Type #>>().Deserialize(ref reader, options);
|
||||
break;
|
||||
<# } #>
|
||||
default:
|
||||
reader.Skip();
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
<# } #>
|
||||
|
||||
}
|
||||
|
||||
#pragma warning restore 168
|
||||
#pragma warning restore 414
|
||||
#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
|
|
@ -1,77 +0,0 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp2.1</TargetFramework>
|
||||
<AssemblyName>mpc</AssemblyName>
|
||||
<RootNamespace>MessagePack.CodeGenerator</RootNamespace>
|
||||
<CodeAnalysisRuleSet>MessagePack.UniversalCodeGenerator.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="MSBuild.StructuredLogger" Version="2.0.110" />
|
||||
<PackageReference Include="Microsoft.CodeAnalysis" Version="2.10.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Update="Generator\*.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DesignTime>True</DesignTime>
|
||||
<DependentUpon>%(FileName).tt</DependentUpon>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="Generator\*.tt">
|
||||
<Generator>TextTemplatingFilePreprocessor</Generator>
|
||||
<LastGenOutput>%(FileName).cs</LastGenOutput>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Update="Generator\EnumTemplate.cs">
|
||||
<DesignTime>True</DesignTime>
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>EnumTemplate.tt</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Update="Generator\FormatterTemplate.cs">
|
||||
<DesignTime>True</DesignTime>
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>FormatterTemplate.tt</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Update="Generator\ResolverTemplate.cs">
|
||||
<DesignTime>True</DesignTime>
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>ResolverTemplate.tt</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Update="Generator\UnionTemplate.cs">
|
||||
<DesignTime>True</DesignTime>
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>UnionTemplate.tt</DependentUpon>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="Generator\EnumTemplate.tt">
|
||||
<Generator>TextTemplatingFilePreprocessor</Generator>
|
||||
<LastGenOutput>EnumTemplate.cs</LastGenOutput>
|
||||
</None>
|
||||
<None Update="Generator\FormatterTemplate.tt">
|
||||
<Generator>TextTemplatingFilePreprocessor</Generator>
|
||||
<LastGenOutput>FormatterTemplate.cs</LastGenOutput>
|
||||
</None>
|
||||
<None Update="Generator\ResolverTemplate.tt">
|
||||
<Generator>TextTemplatingFilePreprocessor</Generator>
|
||||
<LastGenOutput>ResolverTemplate.cs</LastGenOutput>
|
||||
</None>
|
||||
<None Update="Generator\UnionTemplate.tt">
|
||||
<Generator>TextTemplatingFilePreprocessor</Generator>
|
||||
<LastGenOutput>UnionTemplate.cs</LastGenOutput>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
|
@ -1,34 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RuleSet Name="Microsoft Managed Recommended Rules" Description="These rules focus on the most critical problems in your code, including potential security holes, application crashes, and other important logic and design errors. It is recommended to include this rule set in any custom rule set you create for your projects." ToolsVersion="10.0">
|
||||
<Include Path="..\..\MessagePack.ruleset" Action="Default" />
|
||||
<Rules AnalyzerId="Microsoft.CodeAnalysis.Analyzers" RuleNamespace="Microsoft.CodeAnalysis.Analyzers">
|
||||
<Rule Id="RS1001" Action="None" />
|
||||
<Rule Id="RS1004" Action="None" />
|
||||
<Rule Id="RS1007" Action="None" />
|
||||
<Rule Id="RS1009" Action="None" />
|
||||
<Rule Id="RS1010" Action="None" />
|
||||
<Rule Id="RS1011" Action="None" />
|
||||
<Rule Id="RS1015" Action="None" />
|
||||
<Rule Id="RS1016" Action="None" />
|
||||
<Rule Id="RS1017" Action="None" />
|
||||
<Rule Id="RS1018" Action="None" />
|
||||
<Rule Id="RS1019" Action="None" />
|
||||
<Rule Id="RS1020" Action="None" />
|
||||
<Rule Id="RS1021" Action="None" />
|
||||
</Rules>
|
||||
<Rules AnalyzerId="Microsoft.CodeAnalysis.CSharp.Analyzers" RuleNamespace="Microsoft.CodeAnalysis.CSharp.Analyzers">
|
||||
<Rule Id="RS1002" Action="None" />
|
||||
<Rule Id="RS1003" Action="None" />
|
||||
<Rule Id="RS1005" Action="None" />
|
||||
<Rule Id="RS1006" Action="None" />
|
||||
<Rule Id="RS1008" Action="None" />
|
||||
<Rule Id="RS1012" Action="None" />
|
||||
<Rule Id="RS1013" Action="None" />
|
||||
<Rule Id="RS1014" Action="None" />
|
||||
<Rule Id="RS1022" Action="None" />
|
||||
<Rule Id="RS1023" Action="None" />
|
||||
</Rules>
|
||||
<Rules AnalyzerId="Microsoft.VisualStudio.Threading.Analyzers" RuleNamespace="Microsoft.VisualStudio.Threading.Analyzers">
|
||||
<Rule Id="VSTHRD111" Action="None" />
|
||||
</Rules>
|
||||
</RuleSet>
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -1,196 +0,0 @@
|
|||
// Copyright (c) All contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using MessagePack.CodeGenerator.Generator;
|
||||
using Mono.Options;
|
||||
|
||||
namespace MessagePack.CodeGenerator
|
||||
{
|
||||
internal class Program
|
||||
{
|
||||
private static async Task<int> Main(string[] args)
|
||||
{
|
||||
try
|
||||
{
|
||||
var cmdArgs = new CommandlineArguments(args);
|
||||
if (!cmdArgs.IsParsed)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Generator Start...
|
||||
var sw = Stopwatch.StartNew();
|
||||
Console.WriteLine("Project Compilation Start:" + cmdArgs.InputPath);
|
||||
|
||||
var collector = await TypeCollector.CreateAsync(cmdArgs.InputPath, cmdArgs.ConditionalSymbols, true, cmdArgs.IsUseMap);
|
||||
|
||||
Console.WriteLine("Project Compilation Complete:" + sw.Elapsed.ToString());
|
||||
Console.WriteLine();
|
||||
|
||||
sw.Restart();
|
||||
Console.WriteLine("Method Collect Start");
|
||||
|
||||
(ObjectSerializationInfo[] objectInfo, EnumSerializationInfo[] enumInfo, GenericSerializationInfo[] genericInfo, UnionSerializationInfo[] unionInfo) = collector.Collect();
|
||||
|
||||
Console.WriteLine("Method Collect Complete:" + sw.Elapsed.ToString());
|
||||
|
||||
Console.WriteLine("Output Generation Start");
|
||||
sw.Restart();
|
||||
|
||||
FormatterTemplate[] objectFormatterTemplates = objectInfo
|
||||
.GroupBy(x => x.Namespace)
|
||||
.Select(x => new FormatterTemplate()
|
||||
{
|
||||
Namespace = cmdArgs.GetNamespaceDot() + "Formatters" + ((x.Key == null) ? string.Empty : "." + x.Key),
|
||||
ObjectSerializationInfos = x.ToArray(),
|
||||
})
|
||||
.ToArray();
|
||||
|
||||
EnumTemplate[] enumFormatterTemplates = enumInfo
|
||||
.GroupBy(x => x.Namespace)
|
||||
.Select(x => new EnumTemplate()
|
||||
{
|
||||
Namespace = cmdArgs.GetNamespaceDot() + "Formatters" + ((x.Key == null) ? string.Empty : "." + x.Key),
|
||||
EnumSerializationInfos = x.ToArray(),
|
||||
})
|
||||
.ToArray();
|
||||
|
||||
UnionTemplate[] unionFormatterTemplates = unionInfo
|
||||
.GroupBy(x => x.Namespace)
|
||||
.Select(x => new UnionTemplate()
|
||||
{
|
||||
Namespace = cmdArgs.GetNamespaceDot() + "Formatters" + ((x.Key == null) ? string.Empty : "." + x.Key),
|
||||
UnionSerializationInfos = x.ToArray(),
|
||||
})
|
||||
.ToArray();
|
||||
|
||||
var resolverTemplate = new ResolverTemplate()
|
||||
{
|
||||
Namespace = cmdArgs.GetNamespaceDot() + "Resolvers",
|
||||
FormatterNamespace = cmdArgs.GetNamespaceDot() + "Formatters",
|
||||
ResolverName = cmdArgs.ResolverName,
|
||||
RegisterInfos = genericInfo.Cast<IResolverRegisterInfo>().Concat(enumInfo).Concat(unionInfo).Concat(objectInfo).ToArray(),
|
||||
};
|
||||
|
||||
var sb = new StringBuilder();
|
||||
sb.AppendLine("// <auto-generated />");
|
||||
sb.AppendLine();
|
||||
sb.AppendLine(resolverTemplate.TransformText());
|
||||
|
||||
foreach (EnumTemplate item in enumFormatterTemplates)
|
||||
{
|
||||
var text = item.TransformText();
|
||||
sb.AppendLine(text);
|
||||
}
|
||||
|
||||
foreach (UnionTemplate item in unionFormatterTemplates)
|
||||
{
|
||||
var text = item.TransformText();
|
||||
sb.AppendLine(text);
|
||||
}
|
||||
|
||||
foreach (FormatterTemplate item in objectFormatterTemplates)
|
||||
{
|
||||
var text = item.TransformText();
|
||||
sb.AppendLine(text);
|
||||
}
|
||||
|
||||
Output(cmdArgs.OutputPath, sb.ToString());
|
||||
|
||||
Console.WriteLine("String Generation Complete:" + sw.Elapsed.ToString());
|
||||
return 0;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("Unhandled Error:" + ex);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
private static void Output(string path, string text)
|
||||
{
|
||||
path = path.Replace("global::", string.Empty);
|
||||
|
||||
const string prefix = "[Out]";
|
||||
Console.WriteLine(prefix + path);
|
||||
|
||||
var fi = new FileInfo(path);
|
||||
if (!fi.Directory.Exists)
|
||||
{
|
||||
fi.Directory.Create();
|
||||
}
|
||||
|
||||
System.IO.File.WriteAllText(path, text, Encoding.UTF8);
|
||||
}
|
||||
|
||||
internal class CommandlineArguments
|
||||
{
|
||||
public string InputPath { get; private set; }
|
||||
|
||||
public string OutputPath { get; private set; }
|
||||
|
||||
public List<string> ConditionalSymbols { get; private set; }
|
||||
|
||||
public string ResolverName { get; private set; }
|
||||
|
||||
public string NamespaceRoot { get; private set; }
|
||||
|
||||
public bool IsUseMap { get; private set; }
|
||||
|
||||
public bool IsParsed { get; set; }
|
||||
|
||||
public CommandlineArguments(string[] args)
|
||||
{
|
||||
this.ConditionalSymbols = new List<string>();
|
||||
this.NamespaceRoot = "MessagePack";
|
||||
this.ResolverName = "GeneratedResolver";
|
||||
this.IsUseMap = false;
|
||||
|
||||
var option = new OptionSet()
|
||||
{
|
||||
{ "i|input=", "[required]Input path of analyze csproj", x => { this.InputPath = x; } },
|
||||
{ "o|output=", "[required]Output file path", x => { this.OutputPath = x; } },
|
||||
{ "c|conditionalsymbol=", "[optional, default=empty]conditional compiler symbol", x => { this.ConditionalSymbols.AddRange(x.Split(',')); } },
|
||||
{ "r|resolvername=", "[optional, default=GeneratedResolver]Set resolver name", x => { this.ResolverName = x; } },
|
||||
{ "n|namespace=", "[optional, default=MessagePack]Set namespace root name", x => { this.NamespaceRoot = x; } },
|
||||
{ "m|usemapmode", "[optional, default=false]Force use map mode serialization", x => { this.IsUseMap = true; } },
|
||||
};
|
||||
if (args.Length == 0)
|
||||
{
|
||||
goto SHOW_HELP;
|
||||
}
|
||||
else
|
||||
{
|
||||
option.Parse(args);
|
||||
|
||||
if (this.InputPath == null || this.OutputPath == null)
|
||||
{
|
||||
Console.WriteLine("Invalid Argument:" + string.Join(" ", args));
|
||||
Console.WriteLine();
|
||||
goto SHOW_HELP;
|
||||
}
|
||||
|
||||
this.IsParsed = true;
|
||||
return;
|
||||
}
|
||||
|
||||
SHOW_HELP:
|
||||
Console.WriteLine("mpc arguments help:");
|
||||
option.WriteOptionDescriptions(Console.Out);
|
||||
this.IsParsed = false;
|
||||
}
|
||||
|
||||
public string GetNamespaceDot()
|
||||
{
|
||||
return string.IsNullOrWhiteSpace(this.NamespaceRoot) ? string.Empty : this.NamespaceRoot + ".";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,135 +0,0 @@
|
|||
// Copyright (c) All contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MessagePack.CodeGenerator
|
||||
{
|
||||
internal static class ProcessUtil
|
||||
{
|
||||
public static async Task<int> ExecuteProcessAsync(string fileName, string args, Stream stdout, Stream stderr, TextReader stdin, CancellationToken ct = default(CancellationToken))
|
||||
{
|
||||
var psi = new ProcessStartInfo(fileName, args);
|
||||
psi.UseShellExecute = false;
|
||||
psi.CreateNoWindow = true;
|
||||
psi.RedirectStandardError = stderr != null;
|
||||
psi.RedirectStandardOutput = stdout != null;
|
||||
psi.RedirectStandardInput = stdin != null;
|
||||
using (var proc = new Process())
|
||||
using (var cts = new CancellationTokenSource())
|
||||
using (var exitedct = CancellationTokenSource.CreateLinkedTokenSource(cts.Token, ct))
|
||||
{
|
||||
proc.StartInfo = psi;
|
||||
proc.EnableRaisingEvents = true;
|
||||
proc.Exited += (sender, ev) =>
|
||||
{
|
||||
cts.Cancel();
|
||||
};
|
||||
if (!proc.Start())
|
||||
{
|
||||
throw new InvalidOperationException($"failed to start process(fileName = {fileName}, args = {args})");
|
||||
}
|
||||
|
||||
int exitCode = 0;
|
||||
await Task.WhenAll(
|
||||
Task.Run(() =>
|
||||
{
|
||||
exitCode = StdinTask(proc, stdin, exitedct, cts);
|
||||
if (exitCode < 0)
|
||||
{
|
||||
proc.Dispose();
|
||||
}
|
||||
}),
|
||||
Task.Run(async () =>
|
||||
{
|
||||
if (stdout != null)
|
||||
{
|
||||
await RedirectOutputTaskAsync(proc.StandardOutput.BaseStream, stdout, exitedct.Token, "stdout");
|
||||
}
|
||||
}),
|
||||
Task.Run(async () =>
|
||||
{
|
||||
if (stderr != null)
|
||||
{
|
||||
await RedirectOutputTaskAsync(proc.StandardError.BaseStream, stderr, exitedct.Token, "stderr");
|
||||
}
|
||||
}));
|
||||
if (exitCode >= 0)
|
||||
{
|
||||
return proc.ExitCode;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static int StdinTask(Process proc, TextReader stdin, CancellationTokenSource exitedct, CancellationTokenSource cts)
|
||||
{
|
||||
if (stdin != null)
|
||||
{
|
||||
while (!exitedct.Token.IsCancellationRequested)
|
||||
{
|
||||
var l = stdin.ReadLine();
|
||||
if (l == null)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
proc.StandardInput.WriteLine(l);
|
||||
}
|
||||
|
||||
proc.StandardInput.Dispose();
|
||||
}
|
||||
|
||||
exitedct.Token.WaitHandle.WaitOne();
|
||||
if (cts.IsCancellationRequested)
|
||||
{
|
||||
proc.WaitForExit();
|
||||
var exitCode = proc.ExitCode;
|
||||
return exitCode;
|
||||
}
|
||||
else
|
||||
{
|
||||
proc.StandardOutput.Dispose();
|
||||
proc.StandardError.Dispose();
|
||||
proc.Kill();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
private static async Task RedirectOutputTaskAsync(Stream procStdout, Stream stdout, CancellationToken ct, string suffix)
|
||||
{
|
||||
if (stdout != null)
|
||||
{
|
||||
var buf = new byte[1024];
|
||||
while (!ct.IsCancellationRequested)
|
||||
{
|
||||
try
|
||||
{
|
||||
var bytesread = await procStdout.ReadAsync(buf, 0, 1024, ct).ConfigureAwait(false);
|
||||
if (bytesread <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
await stdout.WriteAsync(buf, 0, bytesread, ct);
|
||||
}
|
||||
catch (NullReferenceException)
|
||||
{
|
||||
break;
|
||||
}
|
||||
catch (ObjectDisposedException)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,429 +0,0 @@
|
|||
// Copyright (c) All contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.CSharp.Formatting;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Microsoft.CodeAnalysis.Text;
|
||||
using StLogger = Microsoft.Build.Logging.StructuredLogger;
|
||||
|
||||
namespace MessagePack.CodeGenerator
|
||||
{
|
||||
// Utility and Extension methods for Roslyn
|
||||
internal static class RoslynExtensions
|
||||
{
|
||||
private static (string fname, string args) GetBuildCommandLine(string csprojPath, string tempPath, bool useDotNet)
|
||||
{
|
||||
string fname = "dotnet";
|
||||
const string tasks = "Restore;ResolveReferences";
|
||||
|
||||
// from Buildalyzer implementation
|
||||
// https://github.com/daveaglick/Buildalyzer/blob/b42d2e3ba1b3673a8133fb41e72b507b01bce1d6/src/Buildalyzer/Environment/BuildEnvironment.cs#L86-L96
|
||||
Dictionary<string, string> properties = new Dictionary<string, string>()
|
||||
{
|
||||
{ "ProviderCommandLineArgs", "true" },
|
||||
{ "GenerateResourceMSBuildArchitecture", "CurrentArchitecture" },
|
||||
{ "DesignTimeBuild", "true" },
|
||||
{ "BuildProjectReferences", "false" },
|
||||
|
||||
// {"SkipCompilerExecution","true"},
|
||||
{ "DisableRarCache", "true" },
|
||||
{ "AutoGenerateBindingRedirects", "false" },
|
||||
{ "CopyBuildOutputToOutputDirectory", "false" },
|
||||
{ "CopyOutputSymbolsToOutputDirectory", "false" },
|
||||
{ "SkipCopyBuildProduct", "true" },
|
||||
{ "AddModules", "false" },
|
||||
{ "UseCommonOutputDirectory", "true" },
|
||||
{ "GeneratePackageOnBuild", "false" },
|
||||
{ "RunPostBuildEvent", "false" },
|
||||
{ "SolutionDir", new FileInfo(csprojPath).Directory.FullName + "/" },
|
||||
};
|
||||
var propargs = string.Join(" ", properties.Select(kv => $"/p:{kv.Key}=\"{kv.Value}\""));
|
||||
|
||||
// how to determine whether command should be executed('dotnet msbuild' or 'msbuild')?
|
||||
if (useDotNet)
|
||||
{
|
||||
fname = "dotnet";
|
||||
return (fname, $"msbuild \"{csprojPath}\" /t:{tasks} {propargs} /bl:\"{Path.Combine(tempPath, "build.binlog")}\" /v:n");
|
||||
}
|
||||
else
|
||||
{
|
||||
fname = "msbuild";
|
||||
return (fname, $"\"{csprojPath}\" /t:{tasks} {propargs} /bl:\"{Path.Combine(tempPath, "build.binlog")}\" /v:n");
|
||||
}
|
||||
}
|
||||
|
||||
private static async Task<bool> TryExecuteAsync(string csprojPath, string tempPath, bool useDotNet)
|
||||
{
|
||||
// executing build command with output binary log
|
||||
(string fname, string args) = GetBuildCommandLine(csprojPath, tempPath, useDotNet);
|
||||
try
|
||||
{
|
||||
var buildlogpath = Path.Combine(tempPath, "build.binlog");
|
||||
if (File.Exists(buildlogpath))
|
||||
{
|
||||
try
|
||||
{
|
||||
File.Delete(buildlogpath);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
using (var stdout = new MemoryStream())
|
||||
using (var stderr = new MemoryStream())
|
||||
{
|
||||
var exitCode = await ProcessUtil.ExecuteProcessAsync(fname, args, stdout, stderr, null).ConfigureAwait(false);
|
||||
if (exitCode != 0)
|
||||
{
|
||||
// write process output to stdout and stderr when error.
|
||||
using (var stdout2 = new MemoryStream(stdout.ToArray()))
|
||||
using (var stderr2 = new MemoryStream(stderr.ToArray()))
|
||||
using (Stream consoleStdout = Console.OpenStandardOutput())
|
||||
using (Stream consoleStderr = Console.OpenStandardError())
|
||||
{
|
||||
await stdout2.CopyToAsync(consoleStdout).ConfigureAwait(false);
|
||||
await stderr2.CopyToAsync(consoleStderr).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
return File.Exists(buildlogpath);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine($"exception occured(fname={fname}, args={args}):{e}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static IEnumerable<StLogger.Error> FindAllErrors(StLogger.Build build)
|
||||
{
|
||||
var lst = new List<StLogger.Error>();
|
||||
build.VisitAllChildren<StLogger.Error>(er => lst.Add(er));
|
||||
return lst;
|
||||
}
|
||||
|
||||
private static (StLogger.Build, IEnumerable<StLogger.Error>) ProcessBuildLog(string tempPath)
|
||||
{
|
||||
var reader = new StLogger.BinLogReader();
|
||||
var stlogger = new StLogger.StructuredLogger();
|
||||
|
||||
// prevent output temporary file
|
||||
StLogger.StructuredLogger.SaveLogToDisk = false;
|
||||
|
||||
// never output, but if not set, throw exception when initializing
|
||||
stlogger.Parameters = "tmp.buildlog";
|
||||
stlogger.Initialize(reader);
|
||||
reader.Replay(Path.Combine(tempPath, "build.binlog"));
|
||||
stlogger.Shutdown();
|
||||
StLogger.Build buildlog = stlogger.Construction.Build;
|
||||
if (buildlog.Succeeded)
|
||||
{
|
||||
return (buildlog, null);
|
||||
}
|
||||
else
|
||||
{
|
||||
IEnumerable<StLogger.Error> errors = FindAllErrors(buildlog);
|
||||
return (null, errors);
|
||||
}
|
||||
}
|
||||
|
||||
private static async Task<(StLogger.Build, IEnumerable<StLogger.Error>)> TryGetBuildResultAsync(string csprojPath, string tempPath, bool useDotNet, params string[] preprocessorSymbols)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!await TryExecuteAsync(csprojPath, tempPath, useDotNet).ConfigureAwait(false))
|
||||
{
|
||||
return (null, Array.Empty<StLogger.Error>());
|
||||
}
|
||||
else
|
||||
{
|
||||
return ProcessBuildLog(tempPath);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (Directory.Exists(tempPath))
|
||||
{
|
||||
Directory.Delete(tempPath, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static async Task<StLogger.Build> GetBuildResultAsync(string csprojPath, params string[] preprocessorSymbols)
|
||||
{
|
||||
var tempPath = Path.Combine(new FileInfo(csprojPath).Directory.FullName, "__buildtemp");
|
||||
try
|
||||
{
|
||||
(StLogger.Build build, IEnumerable<StLogger.Error> errors) = await TryGetBuildResultAsync(csprojPath, tempPath, true, preprocessorSymbols).ConfigureAwait(false);
|
||||
if (build == null)
|
||||
{
|
||||
Console.WriteLine("execute `dotnet msbuild` failed, retrying with `msbuild`");
|
||||
var dotnetException = new InvalidOperationException($"failed to build project with dotnet:{string.Join("\n", errors)}");
|
||||
(build, errors) = await TryGetBuildResultAsync(csprojPath, tempPath, false, preprocessorSymbols).ConfigureAwait(false);
|
||||
if (build == null)
|
||||
{
|
||||
throw new InvalidOperationException($"failed to build project: {string.Join("\n", errors)}");
|
||||
}
|
||||
}
|
||||
|
||||
return build;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (Directory.Exists(tempPath))
|
||||
{
|
||||
Directory.Delete(tempPath, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Workspace GetWorkspaceFromBuild(this StLogger.Build build, params string[] preprocessorSymbols)
|
||||
{
|
||||
StLogger.Project csproj = build.Children.OfType<StLogger.Project>().FirstOrDefault();
|
||||
if (csproj == null)
|
||||
{
|
||||
throw new InvalidOperationException("cannot find cs project build");
|
||||
}
|
||||
|
||||
StLogger.Item[] compileItems = Array.Empty<StLogger.Item>();
|
||||
var properties = new Dictionary<string, StLogger.Property>();
|
||||
foreach (StLogger.Folder folder in csproj.Children.OfType<StLogger.Folder>())
|
||||
{
|
||||
if (folder.Name == "Items")
|
||||
{
|
||||
StLogger.Folder compileFolder = folder.Children.OfType<StLogger.Folder>().FirstOrDefault(x => x.Name == "Compile");
|
||||
if (compileFolder == null)
|
||||
{
|
||||
throw new InvalidOperationException("failed to get compililation documents");
|
||||
}
|
||||
|
||||
compileItems = compileFolder.Children.OfType<StLogger.Item>().ToArray();
|
||||
}
|
||||
else if (folder.Name == "Properties")
|
||||
{
|
||||
properties = folder.Children.OfType<StLogger.Property>().ToDictionary(x => x.Name);
|
||||
}
|
||||
}
|
||||
|
||||
StLogger.Item[] assemblies = Array.Empty<StLogger.Item>();
|
||||
foreach (StLogger.Target target in csproj.Children.OfType<StLogger.Target>())
|
||||
{
|
||||
if (target.Name == "ResolveReferences")
|
||||
{
|
||||
StLogger.Folder folder = target.Children.OfType<StLogger.Folder>().Where(x => x.Name == "TargetOutputs").FirstOrDefault();
|
||||
if (folder == null)
|
||||
{
|
||||
throw new InvalidOperationException("cannot find result of resolving assembly");
|
||||
}
|
||||
|
||||
assemblies = folder.Children.OfType<StLogger.Item>().ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
var ws = new AdhocWorkspace();
|
||||
Project roslynProject = ws.AddProject(Path.GetFileNameWithoutExtension(csproj.ProjectFile), Microsoft.CodeAnalysis.LanguageNames.CSharp);
|
||||
var projectDir = properties["ProjectDir"].Value;
|
||||
Guid pguid = properties.ContainsKey("ProjectGuid") ? Guid.Parse(properties["ProjectGuid"].Value) : Guid.NewGuid();
|
||||
var projectGuid = ProjectId.CreateFromSerialized(pguid);
|
||||
foreach (StLogger.Item compile in compileItems)
|
||||
{
|
||||
var filePath = compile.Text;
|
||||
var absFilePath = Path.Combine(projectDir, filePath);
|
||||
roslynProject = roslynProject.AddDocument(filePath, File.ReadAllText(absFilePath)).Project;
|
||||
}
|
||||
|
||||
foreach (StLogger.Item asm in assemblies)
|
||||
{
|
||||
roslynProject = roslynProject.AddMetadataReference(MetadataReference.CreateFromFile(asm.Text));
|
||||
}
|
||||
|
||||
var compopt = roslynProject.CompilationOptions as CSharpCompilationOptions;
|
||||
compopt = roslynProject.CompilationOptions as CSharpCompilationOptions;
|
||||
compopt = compopt ?? new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary);
|
||||
OutputKind kind;
|
||||
switch (properties["OutputType"].Value)
|
||||
{
|
||||
case "Exe":
|
||||
kind = OutputKind.ConsoleApplication;
|
||||
break;
|
||||
case "Library":
|
||||
kind = OutputKind.DynamicallyLinkedLibrary;
|
||||
break;
|
||||
default:
|
||||
kind = OutputKind.DynamicallyLinkedLibrary;
|
||||
break;
|
||||
}
|
||||
|
||||
roslynProject = roslynProject.WithCompilationOptions(compopt.WithOutputKind(kind).WithAllowUnsafe(true));
|
||||
var parseopt = roslynProject.ParseOptions as CSharpParseOptions;
|
||||
roslynProject = roslynProject.WithParseOptions(parseopt.WithPreprocessorSymbols(preprocessorSymbols));
|
||||
if (!ws.TryApplyChanges(roslynProject.Solution))
|
||||
{
|
||||
throw new InvalidOperationException("failed to apply solution changes to workspace");
|
||||
}
|
||||
|
||||
return ws;
|
||||
}
|
||||
|
||||
public static async Task<Compilation> GetCompilationFromProjectAsync(string csprojPath, params string[] preprocessorSymbols)
|
||||
{
|
||||
StLogger.Build build = await GetBuildResultAsync(csprojPath, preprocessorSymbols).ConfigureAwait(false);
|
||||
|
||||
using (Workspace workspace = GetWorkspaceFromBuild(build, preprocessorSymbols))
|
||||
{
|
||||
workspace.WorkspaceFailed += WorkSpaceFailed;
|
||||
Project project = workspace.CurrentSolution.Projects.First();
|
||||
project = project
|
||||
.WithParseOptions((project.ParseOptions as CSharpParseOptions)
|
||||
.WithLanguageVersion(LanguageVersion.CSharp7_3) // force latest version.
|
||||
.WithPreprocessorSymbols(preprocessorSymbols))
|
||||
.WithCompilationOptions((project.CompilationOptions as CSharpCompilationOptions).WithAllowUnsafe(true));
|
||||
|
||||
Compilation compilation = await project.GetCompilationAsync().ConfigureAwait(false);
|
||||
return compilation;
|
||||
}
|
||||
}
|
||||
|
||||
private static void WorkSpaceFailed(object sender, WorkspaceDiagnosticEventArgs e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
}
|
||||
|
||||
public static IEnumerable<INamedTypeSymbol> GetNamedTypeSymbols(this Compilation compilation)
|
||||
{
|
||||
foreach (SyntaxTree syntaxTree in compilation.SyntaxTrees)
|
||||
{
|
||||
SemanticModel semModel = compilation.GetSemanticModel(syntaxTree);
|
||||
|
||||
foreach (ISymbol item in syntaxTree.GetRoot()
|
||||
.DescendantNodes()
|
||||
.Select(x => semModel.GetDeclaredSymbol(x))
|
||||
.Where(x => x != null))
|
||||
{
|
||||
var namedType = item as INamedTypeSymbol;
|
||||
if (namedType != null)
|
||||
{
|
||||
yield return namedType;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static IEnumerable<INamedTypeSymbol> EnumerateBaseType(this ITypeSymbol symbol)
|
||||
{
|
||||
INamedTypeSymbol t = symbol.BaseType;
|
||||
while (t != null)
|
||||
{
|
||||
yield return t;
|
||||
t = t.BaseType;
|
||||
}
|
||||
}
|
||||
|
||||
public static AttributeData FindAttribute(this IEnumerable<AttributeData> attributeDataList, string typeName)
|
||||
{
|
||||
return attributeDataList
|
||||
.Where(x => x.AttributeClass.ToDisplayString() == typeName)
|
||||
.FirstOrDefault();
|
||||
}
|
||||
|
||||
public static AttributeData FindAttributeShortName(
|
||||
this IEnumerable<AttributeData> attributeDataList,
|
||||
string typeName)
|
||||
{
|
||||
return attributeDataList
|
||||
.Where(x => x.AttributeClass.Name == typeName)
|
||||
.FirstOrDefault();
|
||||
}
|
||||
|
||||
public static AttributeData FindAttributeIncludeBasePropertyShortName(
|
||||
this IPropertySymbol property,
|
||||
string typeName)
|
||||
{
|
||||
do
|
||||
{
|
||||
AttributeData data = FindAttributeShortName(property.GetAttributes(), typeName);
|
||||
if (data != null)
|
||||
{
|
||||
return data;
|
||||
}
|
||||
|
||||
property = property.OverriddenProperty;
|
||||
}
|
||||
while (property != null);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static AttributeSyntax FindAttribute(this BaseTypeDeclarationSyntax typeDeclaration, SemanticModel model, string typeName)
|
||||
{
|
||||
return typeDeclaration.AttributeLists
|
||||
.SelectMany(x => x.Attributes)
|
||||
.Where(x => model.GetTypeInfo(x).Type?.ToDisplayString() == typeName)
|
||||
.FirstOrDefault();
|
||||
}
|
||||
|
||||
public static INamedTypeSymbol FindBaseTargetType(this ITypeSymbol symbol, string typeName)
|
||||
{
|
||||
return symbol.EnumerateBaseType()
|
||||
.Where(x => x.OriginalDefinition?.ToDisplayString() == typeName)
|
||||
.FirstOrDefault();
|
||||
}
|
||||
|
||||
public static object GetSingleNamedArgumentValue(this AttributeData attribute, string key)
|
||||
{
|
||||
foreach (KeyValuePair<string, TypedConstant> item in attribute.NamedArguments)
|
||||
{
|
||||
if (item.Key == key)
|
||||
{
|
||||
return item.Value.Value;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static bool IsNullable(this INamedTypeSymbol symbol)
|
||||
{
|
||||
if (symbol.IsGenericType)
|
||||
{
|
||||
if (symbol.ConstructUnboundGenericType().ToDisplayString() == "T?")
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static IEnumerable<ISymbol> GetAllMembers(this ITypeSymbol symbol)
|
||||
{
|
||||
ITypeSymbol t = symbol;
|
||||
while (t != null)
|
||||
{
|
||||
foreach (ISymbol item in t.GetMembers())
|
||||
{
|
||||
yield return item;
|
||||
}
|
||||
|
||||
t = t.BaseType;
|
||||
}
|
||||
}
|
||||
|
||||
public static IEnumerable<ISymbol> GetAllInterfaceMembers(this ITypeSymbol symbol)
|
||||
{
|
||||
return symbol.GetMembers()
|
||||
.Concat(symbol.AllInterfaces.SelectMany(x => x.GetMembers()));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,3 +0,0 @@
|
|||
dotnet publish %~dp0MessagePack.UniversalCodeGenerator.csproj -c Release --self-contained -r win-x64
|
||||
dotnet publish %~dp0MessagePack.UniversalCodeGenerator.csproj -c Release --self-contained -r linux-x64
|
||||
dotnet publish %~dp0MessagePack.UniversalCodeGenerator.csproj -c Release --self-contained -r osx-x64
|
Загрузка…
Ссылка в новой задаче