From 7b5dc44e1d8c9e1c16a17a1891a1230cd453adb1 Mon Sep 17 00:00:00 2001 From: xfrogcn Date: Wed, 6 Jan 2021 17:14:13 +0800 Subject: [PATCH] language switch --- README.md | 8 +- README.zh.md | 2 +- .../Metadata/Internal/ArrayTypeGetter.cs | 29 -- .../Metadata/Internal/BaseTypeGetter.cs | 35 -- .../Metadata/Internal/ClassTypeGetter.cs | 25 -- .../Metadata/Internal/DateTimeGetter.cs | 74 ---- .../Metadata/Internal/DictionaryTypeGetter.cs | 28 -- .../Metadata/Internal/ListTypeGetter.cs | 29 -- .../Metadata/Internal/NullableTypeGetter.cs | 33 -- .../Metadata/Internal/NumbericGetter.cs | 322 ------------------ .../Metadata/Internal/ObjectTypeGetter.cs | 26 -- .../Metadata/Internal/StructTypeGetter.cs | 34 -- .../Metadata/Internal/TupleGetter.cs | 65 ---- .../Metadata/Internal/ValueTupleGetter.cs | 65 ---- 14 files changed, 5 insertions(+), 770 deletions(-) delete mode 100644 src/BinaryFormatter/Metadata/Internal/ArrayTypeGetter.cs delete mode 100644 src/BinaryFormatter/Metadata/Internal/BaseTypeGetter.cs delete mode 100644 src/BinaryFormatter/Metadata/Internal/ClassTypeGetter.cs delete mode 100644 src/BinaryFormatter/Metadata/Internal/DateTimeGetter.cs delete mode 100644 src/BinaryFormatter/Metadata/Internal/DictionaryTypeGetter.cs delete mode 100644 src/BinaryFormatter/Metadata/Internal/ListTypeGetter.cs delete mode 100644 src/BinaryFormatter/Metadata/Internal/NullableTypeGetter.cs delete mode 100644 src/BinaryFormatter/Metadata/Internal/NumbericGetter.cs delete mode 100644 src/BinaryFormatter/Metadata/Internal/ObjectTypeGetter.cs delete mode 100644 src/BinaryFormatter/Metadata/Internal/StructTypeGetter.cs delete mode 100644 src/BinaryFormatter/Metadata/Internal/TupleGetter.cs delete mode 100644 src/BinaryFormatter/Metadata/Internal/ValueTupleGetter.cs diff --git a/README.md b/README.md index a0b3837..c82f8a0 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # High Performance Binary Serialization Libraries -[quick start](doc/GettingStart.Md) | [support types](doc/SupportTypes.Md) +[中文](README.zh.md) | [Quick Start](doc/GettingStart.Md) | [Support Types](doc/SupportTypes.Md) Xfrogcn BinaryFormatter is a high performance binary serialization libraries in .NET, it through the Span and Emit to achieve high performance, BinarySerializer uses an API interface that is consistent with System.Text.JSON, so easy to use. @@ -9,11 +9,11 @@ Xfrogcn BinaryFormatter is a high performance binary serialization libraries in - [x] High performance - [x] Smaller size - [x] Simple and easy to use -- [x] keep instance refer -- [x] support the type of dynamic loading assemblies +- [x] Keep instance refer +- [x] Support the type of dynamic loading assemblies - [x] Complete built-in type support - [ ] Extended attributes -- [ ] binary document model +- [ ] Binary document model ## Performance diff --git a/README.zh.md b/README.zh.md index be70e85..70ef0b8 100644 --- a/README.zh.md +++ b/README.zh.md @@ -1,6 +1,6 @@ # 高性能二进制序列化库 -[快速开始](doc/GettingStart.zh.md) | [支持的类型](doc/SupportTypes.zh.md) +[English](README.md) | [快速开始](doc/GettingStart.zh.md) | [支持的类型](doc/SupportTypes.zh.md) Xfrogcn.BinaryFormatter是一个.NET下的高性能二进制序列化库,它通过底层的Span以及Emit最大限度地提高性能,BinarySerializer整体上采用了与System.Text.Json序列化一致的编程API接口,故简单易用,无需过多的学习成本。 diff --git a/src/BinaryFormatter/Metadata/Internal/ArrayTypeGetter.cs b/src/BinaryFormatter/Metadata/Internal/ArrayTypeGetter.cs deleted file mode 100644 index e441e16..0000000 --- a/src/BinaryFormatter/Metadata/Internal/ArrayTypeGetter.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Xfrogcn.BinaryFormatter.Metadata.Internal -{ - public class ArrayTypeGetter : IMetadataGetter - { - public bool CanProcess(Type type) - { - return type.IsArray; - } - - public bool GetTypeInfo(Type type, BinaryTypeInfo typeInfo, MetadataGetterContext context) - { - var eleType = type.GetElementType(); - typeInfo.Type = TypeEnum.Array; - typeInfo.IsGeneric = true; - typeInfo.GenericArgumentCount = 1; - typeInfo.GenericArguments = new ushort[] { context.GetTypeSeq(eleType, context) }; - typeInfo.SerializeType = SerializeTypeEnum.List; - typeInfo.Members = new BinaryMemberInfo[]{ - new BinaryMemberInfo(){ IsField =false, Seq = 0, Name = nameof(Array.Length), TypeSeq = context.GetTypeSeq(typeof(long), context)} - }; - - return true; - } - } -} diff --git a/src/BinaryFormatter/Metadata/Internal/BaseTypeGetter.cs b/src/BinaryFormatter/Metadata/Internal/BaseTypeGetter.cs deleted file mode 100644 index dfa7aed..0000000 --- a/src/BinaryFormatter/Metadata/Internal/BaseTypeGetter.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Xfrogcn.BinaryFormatter.Metadata.Internal -{ - public class BaseTypeGetter : IMetadataGetter - { - static readonly Dictionary _baseTypeMap = new Dictionary() - { - { typeof(Boolean), TypeEnum.Boolean }, - { typeof(Char), TypeEnum.Char }, - { typeof(String), TypeEnum.String }, - { typeof(Uri), TypeEnum.Uri }, - { typeof(Version), TypeEnum.Version }, - { typeof(DBNull), TypeEnum.DBNull }, - }; - - public bool CanProcess(Type type) - { - return _baseTypeMap.ContainsKey(type); - } - - public bool GetTypeInfo(Type type, BinaryTypeInfo typeInfo, MetadataGetterContext context) - { - TypeEnum te = _baseTypeMap[type]; - typeInfo.Type = te; - typeInfo.IsGeneric = false; - typeInfo.GenericArgumentCount = 0; - typeInfo.SerializeType = SerializeTypeEnum.SingleValue; - typeInfo.Members = new BinaryMemberInfo[0]; - return true; - } - } -} diff --git a/src/BinaryFormatter/Metadata/Internal/ClassTypeGetter.cs b/src/BinaryFormatter/Metadata/Internal/ClassTypeGetter.cs deleted file mode 100644 index a343080..0000000 --- a/src/BinaryFormatter/Metadata/Internal/ClassTypeGetter.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Xfrogcn.BinaryFormatter.Metadata.Internal -{ - public class ClassTypeGetter : IMetadataGetter - { - public bool CanProcess(Type type) - { - return type.IsClass; - } - - public bool GetTypeInfo(Type type, BinaryTypeInfo typeInfo, MetadataGetterContext context) - { - typeInfo.IsGeneric = type.IsGenericType; - typeInfo.GenericArgumentCount = type.GetGenericArgumentCount(); - typeInfo.SerializeType = SerializeTypeEnum.KeyValuePair; - typeInfo.GenericArguments = type.GetGenericTypeSeqs(context); - typeInfo.Members = type.GetMemberInfos(context); - typeInfo.FullName = type.AssemblyQualifiedName; - return true; - } - } -} diff --git a/src/BinaryFormatter/Metadata/Internal/DateTimeGetter.cs b/src/BinaryFormatter/Metadata/Internal/DateTimeGetter.cs deleted file mode 100644 index 5062e11..0000000 --- a/src/BinaryFormatter/Metadata/Internal/DateTimeGetter.cs +++ /dev/null @@ -1,74 +0,0 @@ -using System; -using System.Collections.Generic; - -namespace Xfrogcn.BinaryFormatter.Metadata.Internal -{ - public class DateTimeGetter : IMetadataGetter - { - static readonly Dictionary _timeTypeMap = new Dictionary() - { - { typeof(DateTime), TypeEnum.DateTime }, - { typeof(DateTimeOffset), TypeEnum.DateTimeOffset }, - { typeof(TimeSpan), TypeEnum.TimeSpan }, - { typeof(TimeZoneInfo), TypeEnum.TimeZoneInfo }, - { typeof(TimeZoneInfo.AdjustmentRule), TypeEnum.AdjustmentRule }, - { typeof(TimeZoneInfo.TransitionTime), TypeEnum.TransitionTime }, - }; - - public bool CanProcess(Type type) - { - return _timeTypeMap.ContainsKey(type); - } - - public bool GetTypeInfo(Type type, BinaryTypeInfo typeInfo, MetadataGetterContext context) - { - TypeEnum te = _timeTypeMap[type]; - typeInfo.Type = te; - typeInfo.IsGeneric = false; - typeInfo.GenericArgumentCount = 0; - typeInfo.SerializeType = SerializeTypeEnum.SingleValue; - typeInfo.Members = new BinaryMemberInfo[0]; - - if (type == typeof(TimeZoneInfo)) - { - typeInfo.SerializeType = SerializeTypeEnum.KeyValuePair; - typeInfo.Members = new BinaryMemberInfo[] - { - new BinaryMemberInfo(){ Seq = 0, IsField =false, Name = nameof(TimeZoneInfo.BaseUtcOffset), TypeSeq = context.GetTypeSeq(typeof(TimeSpan), context) }, - new BinaryMemberInfo(){ Seq = 1, IsField =false, Name = nameof(TimeZoneInfo.DisplayName), TypeSeq = context.GetTypeSeq(typeof(string), context) }, - new BinaryMemberInfo(){ Seq = 2, IsField =false, Name = nameof(TimeZoneInfo.StandardName), TypeSeq = context.GetTypeSeq(typeof(string), context) }, - new BinaryMemberInfo(){ Seq = 3, IsField =false, Name = nameof(TimeZoneInfo.DaylightName), TypeSeq = context.GetTypeSeq(typeof(string), context) }, - new BinaryMemberInfo(){ Seq = 4, IsField =false, Name = "AdjustmentRules", TypeSeq = context.GetTypeSeq(typeof(TimeZoneInfo.AdjustmentRule[]), context) }, - }; - } - if(type == typeof(TimeZoneInfo.AdjustmentRule)) - { - typeInfo.SerializeType = SerializeTypeEnum.KeyValuePair; - typeInfo.Members = new BinaryMemberInfo[] - { - new BinaryMemberInfo(){ Seq = 0, IsField =false, Name = nameof(TimeZoneInfo.AdjustmentRule.DateStart), TypeSeq = context.GetTypeSeq(typeof(DateTime), context) }, - new BinaryMemberInfo(){ Seq = 1, IsField =false, Name = nameof(TimeZoneInfo.AdjustmentRule.DateEnd), TypeSeq = context.GetTypeSeq(typeof(DateTime), context) }, - new BinaryMemberInfo(){ Seq = 2, IsField =false, Name = nameof(TimeZoneInfo.AdjustmentRule.DaylightDelta), TypeSeq = context.GetTypeSeq(typeof(TimeSpan), context) }, - new BinaryMemberInfo(){ Seq = 3, IsField =false, Name = nameof(TimeZoneInfo.AdjustmentRule.DaylightTransitionStart), TypeSeq = context.GetTypeSeq(typeof(TimeZoneInfo.TransitionTime), context) }, - new BinaryMemberInfo(){ Seq = 4, IsField =false, Name = nameof(TimeZoneInfo.AdjustmentRule.DaylightTransitionEnd), TypeSeq = context.GetTypeSeq(typeof(TimeZoneInfo.TransitionTime), context) }, - }; - } - - if (type == typeof(TimeZoneInfo.TransitionTime)) - { - typeInfo.SerializeType = SerializeTypeEnum.KeyValuePair; - typeInfo.Members = new BinaryMemberInfo[] - { - new BinaryMemberInfo(){ Seq = 0, IsField =false, Name = nameof(TimeZoneInfo.TransitionTime.IsFixedDateRule), TypeSeq = context.GetTypeSeq(typeof(bool), context) }, - new BinaryMemberInfo(){ Seq = 1, IsField =false, Name = nameof(TimeZoneInfo.TransitionTime.Day), TypeSeq = context.GetTypeSeq(typeof(int), context) }, - new BinaryMemberInfo(){ Seq = 2, IsField =false, Name = nameof(TimeZoneInfo.TransitionTime.DayOfWeek), TypeSeq = context.GetTypeSeq(typeof(DayOfWeek), context) }, - new BinaryMemberInfo(){ Seq = 3, IsField =false, Name = nameof(TimeZoneInfo.TransitionTime.Month), TypeSeq = context.GetTypeSeq(typeof(int), context) }, - new BinaryMemberInfo(){ Seq = 4, IsField =false, Name = nameof(TimeZoneInfo.TransitionTime.TimeOfDay), TypeSeq = context.GetTypeSeq(typeof(DateTime), context) }, - new BinaryMemberInfo(){ Seq = 5, IsField =false, Name = nameof(TimeZoneInfo.TransitionTime.Week), TypeSeq = context.GetTypeSeq(typeof(int), context) }, - }; - } - - return true; - } - } -} diff --git a/src/BinaryFormatter/Metadata/Internal/DictionaryTypeGetter.cs b/src/BinaryFormatter/Metadata/Internal/DictionaryTypeGetter.cs deleted file mode 100644 index 0cdd0c0..0000000 --- a/src/BinaryFormatter/Metadata/Internal/DictionaryTypeGetter.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Xfrogcn.BinaryFormatter.Metadata.Internal -{ - public class DictionaryTypeGetter : IMetadataGetter - { - public bool CanProcess(Type type) - { - return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Dictionary<,>); - } - - public bool GetTypeInfo(Type type, BinaryTypeInfo typeInfo, MetadataGetterContext context) - { - typeInfo.Type = TypeEnum.Dictionary; - typeInfo.IsGeneric = true; - typeInfo.GenericArguments = type.GetGenericTypeSeqs(context); - typeInfo.GenericArgumentCount = (sbyte)typeInfo.GenericArguments.Length; - typeInfo.SerializeType = SerializeTypeEnum.KeyValuePair; - typeInfo.Members = new BinaryMemberInfo[]{ - new BinaryMemberInfo(){ IsField =false, Seq = 0, Name = nameof(Dictionary.Count), TypeSeq = context.GetTypeSeq(typeof(int), context)} - }; - - return true; - } - } -} diff --git a/src/BinaryFormatter/Metadata/Internal/ListTypeGetter.cs b/src/BinaryFormatter/Metadata/Internal/ListTypeGetter.cs deleted file mode 100644 index ad48b13..0000000 --- a/src/BinaryFormatter/Metadata/Internal/ListTypeGetter.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Xfrogcn.BinaryFormatter.Metadata.Internal -{ - public class ListTypeGetter : IMetadataGetter - { - public bool CanProcess(Type type) - { - return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(List<>); - } - - public bool GetTypeInfo(Type type, BinaryTypeInfo typeInfo, MetadataGetterContext context) - { - typeInfo.Type = TypeEnum.List; - typeInfo.IsGeneric = true; - typeInfo.GenericArguments = type.GetGenericTypeSeqs(context); - typeInfo.GenericArgumentCount = (sbyte)typeInfo.GenericArguments.Length; - typeInfo.SerializeType = SerializeTypeEnum.List; - typeInfo.Members = new BinaryMemberInfo[]{ - new BinaryMemberInfo(){ IsField =false, Seq = 0, Name = nameof(List.Count), TypeSeq = context.GetTypeSeq(typeof(int), context)} - }; - - - return true; - } - } -} diff --git a/src/BinaryFormatter/Metadata/Internal/NullableTypeGetter.cs b/src/BinaryFormatter/Metadata/Internal/NullableTypeGetter.cs deleted file mode 100644 index ad7b673..0000000 --- a/src/BinaryFormatter/Metadata/Internal/NullableTypeGetter.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Xfrogcn.BinaryFormatter.Metadata.Internal -{ - public class NullableTypeGetter : IMetadataGetter - { - public bool CanProcess(Type type) - { - if(type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>)) - { - return true; - } - return false; - } - - public bool GetTypeInfo(Type type, BinaryTypeInfo typeInfo, MetadataGetterContext context) - { - TypeEnum te = TypeEnum.Nullable; - typeInfo.Type = te; - typeInfo.IsGeneric = true; - typeInfo.SerializeType = SerializeTypeEnum.KeyValuePair; - typeInfo.GenericArguments = type.GetGenericTypeSeqs(context); - typeInfo.GenericArgumentCount = (sbyte)typeInfo.GenericArguments.Length; - typeInfo.Members = new BinaryMemberInfo[1]{ - new BinaryMemberInfo(){ IsField =false, Name = nameof(Nullable.Value), Seq = 0, TypeSeq = context.GetTypeSeq(Nullable.GetUnderlyingType(type), context) } - }; - - return true; - } - } -} diff --git a/src/BinaryFormatter/Metadata/Internal/NumbericGetter.cs b/src/BinaryFormatter/Metadata/Internal/NumbericGetter.cs deleted file mode 100644 index af76c1e..0000000 --- a/src/BinaryFormatter/Metadata/Internal/NumbericGetter.cs +++ /dev/null @@ -1,322 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Numerics; -using System.Text; - -namespace Xfrogcn.BinaryFormatter.Metadata.Internal -{ - public class NumbericGetter : IMetadataGetter - { - static readonly Dictionary _nmbericTypeMap = new Dictionary() - { - { typeof(Byte), TypeEnum.Byte }, - { typeof(Int16), TypeEnum.Int16 }, - { typeof(Int32), TypeEnum.Int32 }, - { typeof(Int64), TypeEnum.Int64 }, - { typeof(SByte), TypeEnum.SByte }, - { typeof(UInt16), TypeEnum.UInt16 }, - { typeof(UInt32), TypeEnum.UInt32 }, - { typeof(UInt64), TypeEnum.UInt64 }, - { typeof(Single), TypeEnum.Single }, - { typeof(Double), TypeEnum.Double }, - { typeof(Decimal), TypeEnum.Decimal }, - { typeof(BigInteger), TypeEnum.BigInteger }, - { typeof(Complex), TypeEnum.Complex }, - { typeof(Vector2), TypeEnum.Vector2 }, - { typeof(Vector3), TypeEnum.Vector3 }, - { typeof(Vector4), TypeEnum.Vector4 }, - { typeof(Vector<>), TypeEnum.VectorT }, - { typeof(Matrix3x2), TypeEnum.Matrix3x2 }, - { typeof(Matrix4x4), TypeEnum.Matrix4x4 }, - { typeof(Plane), TypeEnum.Plane }, - { typeof(Quaternion), TypeEnum.Quaternion }, - { typeof(IntPtr), TypeEnum.IntPtr }, - }; - - public bool CanProcess(Type type) - { - if(type == null) - { - return false; - } - Type rt = type.GetSerializeType() ; - return _nmbericTypeMap.ContainsKey(rt); - } - - - public bool GetTypeInfo(Type type, BinaryTypeInfo typeInfo, MetadataGetterContext context) - { - Type rt = type.GetSerializeType(); - TypeEnum te = _nmbericTypeMap[rt]; - typeInfo.Type = te; - typeInfo.IsGeneric = false; - typeInfo.GenericArgumentCount = 0; - typeInfo.SerializeType = SerializeTypeEnum.SingleValue; - typeInfo.Members = new BinaryMemberInfo[0]; - - if (GetComplexTypeInfo(rt, typeInfo, context) || - GetVectorTypeInfo(rt, typeInfo, context) || - GetVectorTTypeInfo(type, typeInfo, context) || - GetMatrixTypeInfo(rt, typeInfo, context) || - GetPlaneTypeInfo(rt, typeInfo, context) || - GetQuaternionTypeInfo(rt, typeInfo, context)) - { - return true; - } - - return true; - } - - protected virtual bool GetComplexTypeInfo(Type type, BinaryTypeInfo typeInfo, MetadataGetterContext context) - { - if(type == typeof(Complex)) - { - typeInfo.Members = new BinaryMemberInfo[2] - { - new BinaryMemberInfo(){ IsField = false, Name = nameof(Complex.Real), Seq = 0, TypeSeq = context.GetTypeSeq(typeof(double), context) }, - new BinaryMemberInfo(){ IsField = false, Name = nameof(Complex.Imaginary), Seq = 1, TypeSeq = context.GetTypeSeq(typeof(double), context) } - }; - typeInfo.SerializeType = SerializeTypeEnum.KeyValuePair; - return true; - } - return false; - } - - protected virtual bool GetVectorTypeInfo(Type type, BinaryTypeInfo typeInfo, MetadataGetterContext context) - { - List mlist = new List(); - if(type == typeof(Vector2) || type == typeof(Vector3) || type == typeof(Vector4)) - { - mlist.Add(new BinaryMemberInfo() - { - IsField =true, - Name = nameof(Vector2.X), - Seq = 0, - TypeSeq = context.GetTypeSeq(typeof(float), context) - }); - mlist.Add(new BinaryMemberInfo() - { - IsField = true, - Name = nameof(Vector2.Y), - Seq = 1, - TypeSeq = context.GetTypeSeq(typeof(float), context) - }); - Vector3 v2 = new Vector3(); - v2.X = 0; - v2.Y = 0; - - } - if(type == typeof(Vector3) || type == typeof(Vector4)) - { - mlist.Add(new BinaryMemberInfo() - { - IsField = true, - Name = nameof(Vector3.Z), - Seq = 2, - TypeSeq = context.GetTypeSeq(typeof(float), context) - }); - } - if (type == typeof(Vector4)) - { - mlist.Add(new BinaryMemberInfo() - { - IsField = true, - Name = nameof(Vector4.W), - Seq = 3, - TypeSeq = context.GetTypeSeq(typeof(float), context) - }); - } - - if (mlist.Count > 0) - { - typeInfo.Members = mlist.ToArray(); - typeInfo.SerializeType = SerializeTypeEnum.KeyValuePair; - return true; - } - return false; - } - - - protected virtual bool GetVectorTTypeInfo(Type type, BinaryTypeInfo typeInfo, MetadataGetterContext context) - { - if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Vector<>)) - { - typeInfo.IsGeneric = true; - typeInfo.GenericArgumentCount = type.GetGenericArgumentCount(); - typeInfo.GenericArguments = type.GetGenericArguments() - .Select(t => context.GetTypeSeq(t, context)).ToArray(); - typeInfo.SerializeType = SerializeTypeEnum.List; - return true; - } - - return false; - } - - protected virtual bool GetMatrixTypeInfo(Type type, BinaryTypeInfo typeInfo, MetadataGetterContext context) - { - List mlist = new List(); - if(type == typeof(Matrix3x2) || type == typeof(Matrix4x4)) - { - mlist.Add(new BinaryMemberInfo() - { - Seq = 0, - IsField =true, - Name = nameof(Matrix3x2.M11), - TypeSeq = context.GetTypeSeq(typeof(float), context) - }); - mlist.Add(new BinaryMemberInfo() - { - Seq = 1, - IsField = true, - Name = nameof(Matrix3x2.M12), - TypeSeq = context.GetTypeSeq(typeof(float), context) - }); - mlist.Add(new BinaryMemberInfo() - { - Seq = 2, - IsField = true, - Name = nameof(Matrix3x2.M21), - TypeSeq = context.GetTypeSeq(typeof(float), context) - }); - mlist.Add(new BinaryMemberInfo() - { - Seq = 3, - IsField = true, - Name = nameof(Matrix3x2.M22), - TypeSeq = context.GetTypeSeq(typeof(float), context) - }); - mlist.Add(new BinaryMemberInfo() - { - Seq = 4, - IsField = true, - Name = nameof(Matrix3x2.M31), - TypeSeq = context.GetTypeSeq(typeof(float), context) - }); - mlist.Add(new BinaryMemberInfo() - { - Seq = 5, - IsField = true, - Name = nameof(Matrix3x2.M32), - TypeSeq = context.GetTypeSeq(typeof(float), context) - }); - } - if(type == typeof(Matrix4x4)) - { - Matrix4x4 m = new Matrix4x4(); - m.M14 = 0; - - mlist.Add(new BinaryMemberInfo() - { - Seq = 6, - IsField = true, - Name = nameof(Matrix4x4.M13), - TypeSeq = context.GetTypeSeq(typeof(float), context) - }); - mlist.Add(new BinaryMemberInfo() - { - Seq = 7, - IsField = true, - Name = nameof(Matrix4x4.M14), - TypeSeq = context.GetTypeSeq(typeof(float), context) - }); - mlist.Add(new BinaryMemberInfo() - { - Seq = 8, - IsField = true, - Name = nameof(Matrix4x4.M23), - TypeSeq = context.GetTypeSeq(typeof(float), context) - }); - mlist.Add(new BinaryMemberInfo() - { - Seq = 9, - IsField = true, - Name = nameof(Matrix4x4.M24), - TypeSeq = context.GetTypeSeq(typeof(float), context) - }); - mlist.Add(new BinaryMemberInfo() - { - Seq = 10, - IsField = true, - Name = nameof(Matrix4x4.M33), - TypeSeq = context.GetTypeSeq(typeof(float), context) - }); - mlist.Add(new BinaryMemberInfo() - { - Seq = 11, - IsField = true, - Name = nameof(Matrix4x4.M34), - TypeSeq = context.GetTypeSeq(typeof(float), context) - }); - - mlist.Add(new BinaryMemberInfo() - { - Seq = 12, - IsField = true, - Name = nameof(Matrix4x4.M41), - TypeSeq = context.GetTypeSeq(typeof(float), context) - }); - mlist.Add(new BinaryMemberInfo() - { - Seq = 13, - IsField = true, - Name = nameof(Matrix4x4.M42), - TypeSeq = context.GetTypeSeq(typeof(float), context) - }); - mlist.Add(new BinaryMemberInfo() - { - Seq = 14, - IsField = true, - Name = nameof(Matrix4x4.M43), - TypeSeq = context.GetTypeSeq(typeof(float), context) - }); - mlist.Add(new BinaryMemberInfo() - { - Seq = 15, - IsField = true, - Name = nameof(Matrix4x4.M44), - TypeSeq = context.GetTypeSeq(typeof(float), context) - }); - } - if (mlist.Count > 0) - { - typeInfo.SerializeType = SerializeTypeEnum.KeyValuePair; - typeInfo.Members = mlist.ToArray(); - return true; - } - return false; - } - - protected virtual bool GetPlaneTypeInfo(Type type, BinaryTypeInfo typeInfo, MetadataGetterContext context) - { - if(type == typeof(Plane)) - { - typeInfo.SerializeType = SerializeTypeEnum.KeyValuePair; - typeInfo.Members = new BinaryMemberInfo[2] - { - new BinaryMemberInfo(){ IsField = true, Name = nameof(Plane.D), Seq = 0, TypeSeq = context.GetTypeSeq(typeof(float), context)}, - new BinaryMemberInfo(){ IsField = true, Name = nameof(Plane.Normal), Seq = 1, TypeSeq = context.GetTypeSeq(typeof(Vector3), context)}, - }; - return true; - } - return false; - } - - protected virtual bool GetQuaternionTypeInfo(Type type, BinaryTypeInfo typeInfo, MetadataGetterContext context) - { - if (type == typeof(Quaternion)) - { - typeInfo.SerializeType = SerializeTypeEnum.KeyValuePair; - typeInfo.Members = new BinaryMemberInfo[4] - { - new BinaryMemberInfo(){ IsField = true, Name = nameof(Quaternion.W), Seq = 0, TypeSeq = context.GetTypeSeq(typeof(float), context)}, - new BinaryMemberInfo(){ IsField = true, Name = nameof(Quaternion.X), Seq = 1, TypeSeq = context.GetTypeSeq(typeof(float), context)}, - new BinaryMemberInfo(){ IsField = true, Name = nameof(Quaternion.Y), Seq = 2, TypeSeq = context.GetTypeSeq(typeof(float), context)}, - new BinaryMemberInfo(){ IsField = true, Name = nameof(Quaternion.Z), Seq = 3, TypeSeq = context.GetTypeSeq(typeof(float), context)}, - }; - return true; - } - return false; - } - } -} diff --git a/src/BinaryFormatter/Metadata/Internal/ObjectTypeGetter.cs b/src/BinaryFormatter/Metadata/Internal/ObjectTypeGetter.cs deleted file mode 100644 index afceb6b..0000000 --- a/src/BinaryFormatter/Metadata/Internal/ObjectTypeGetter.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Xfrogcn.BinaryFormatter.Metadata.Internal -{ - public class ObjectTypeGetter : IMetadataGetter - { - public bool CanProcess(Type type) - { - return type == typeof(object); - } - - public bool GetTypeInfo(Type type, BinaryTypeInfo typeInfo, MetadataGetterContext context) - { - typeInfo.Type = TypeEnum.Object; - typeInfo.IsGeneric = false; - typeInfo.GenericArgumentCount = 0; - typeInfo.GenericArguments = new ushort[0]; - typeInfo.SerializeType = SerializeTypeEnum.KeyValuePair; - typeInfo.Members = new BinaryMemberInfo[0]; - - return true; - } - } -} diff --git a/src/BinaryFormatter/Metadata/Internal/StructTypeGetter.cs b/src/BinaryFormatter/Metadata/Internal/StructTypeGetter.cs deleted file mode 100644 index e5582f7..0000000 --- a/src/BinaryFormatter/Metadata/Internal/StructTypeGetter.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; -using System.Text; - -namespace Xfrogcn.BinaryFormatter.Metadata.Internal -{ - public class StructTypeGetter : IMetadataGetter - { - public bool CanProcess(Type type) - { - if (type.IsValueType) - { - return true; - } - return false; - } - - public bool GetTypeInfo(Type type, BinaryTypeInfo typeInfo, MetadataGetterContext context) - { - typeInfo.Type = TypeEnum.Struct; - typeInfo.IsGeneric = type.IsGenericType; - typeInfo.GenericArgumentCount = type.GetGenericArgumentCount(); - typeInfo.SerializeType = SerializeTypeEnum.KeyValuePair; - typeInfo.GenericArguments = type.GetTypeGenericArguments() - .Select(t => context.GetTypeSeq(t, context)) - .ToArray(); - typeInfo.Members = type.GetMemberInfos(context); - typeInfo.FullName = type.AssemblyQualifiedName; - return true; - } - } -} diff --git a/src/BinaryFormatter/Metadata/Internal/TupleGetter.cs b/src/BinaryFormatter/Metadata/Internal/TupleGetter.cs deleted file mode 100644 index 78723cb..0000000 --- a/src/BinaryFormatter/Metadata/Internal/TupleGetter.cs +++ /dev/null @@ -1,65 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace Xfrogcn.BinaryFormatter.Metadata.Internal -{ - public class TupleGetter : IMetadataGetter - { - static readonly Dictionary _tupleTypeMap = new Dictionary() - { - { typeof(Tuple), TypeEnum.Tuple }, - { typeof(Tuple<>), TypeEnum.TupleT }, - { typeof(Tuple<,>), TypeEnum.TupleT }, - { typeof(Tuple<,,>), TypeEnum.TupleT }, - { typeof(Tuple<,,,>), TypeEnum.TupleT }, - { typeof(Tuple<,,,,>), TypeEnum.TupleT }, - { typeof(Tuple<,,,,,>), TypeEnum.TupleT }, - { typeof(Tuple<,,,,,,>), TypeEnum.TupleT }, - { typeof(Tuple<,,,,,,,>), TypeEnum.TupleT } - }; - - public bool CanProcess(Type type) - { - Type rt = type.GetSerializeType(); - - return _tupleTypeMap.ContainsKey(rt); - } - - public bool GetTypeInfo(Type type, BinaryTypeInfo typeInfo, MetadataGetterContext context) - { - Type rt = type.GetSerializeType(); - TypeEnum te = _tupleTypeMap[rt]; - typeInfo.Type = te; - typeInfo.IsGeneric = type.IsGenericType; - typeInfo.GenericArgumentCount = type.GetGenericArgumentCount(); - typeInfo.SerializeType = SerializeTypeEnum.KeyValuePair; - typeInfo.GenericArguments = type.GetTypeGenericArguments() - .Select(t => context.GetTypeSeq(t, context)) - .ToArray(); - - typeInfo.Members = new BinaryMemberInfo[typeInfo.GenericArguments.Length]; - for(ushort i = 0; i < typeInfo.GenericArguments.Length; i++) - { - BinaryMemberInfo mi = new BinaryMemberInfo() - { - IsField = false, - Seq = i, - TypeSeq = typeInfo.GenericArguments[i] - }; - if( i == 7) - { - mi.Name = "Rest"; - } - else - { - mi.Name = $"Item{i + 1}"; - } - typeInfo.Members[i] = mi; - } - - return true; - } - } -} diff --git a/src/BinaryFormatter/Metadata/Internal/ValueTupleGetter.cs b/src/BinaryFormatter/Metadata/Internal/ValueTupleGetter.cs deleted file mode 100644 index b0451af..0000000 --- a/src/BinaryFormatter/Metadata/Internal/ValueTupleGetter.cs +++ /dev/null @@ -1,65 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace Xfrogcn.BinaryFormatter.Metadata.Internal -{ - public class ValueTupleGetter : IMetadataGetter - { - static readonly Dictionary _tupleTypeMap = new Dictionary() - { - { typeof(ValueTuple), TypeEnum.ValueTuple }, - { typeof(ValueTuple<>), TypeEnum.ValueTupleT }, - { typeof(ValueTuple<,>), TypeEnum.ValueTupleT }, - { typeof(ValueTuple<,,>), TypeEnum.ValueTupleT }, - { typeof(ValueTuple<,,,>), TypeEnum.ValueTupleT }, - { typeof(ValueTuple<,,,,>), TypeEnum.ValueTupleT }, - { typeof(ValueTuple<,,,,,>), TypeEnum.ValueTupleT }, - { typeof(ValueTuple<,,,,,,>), TypeEnum.ValueTupleT }, - { typeof(ValueTuple<,,,,,,,>), TypeEnum.ValueTupleT } - }; - - public bool CanProcess(Type type) - { - Type rt = type.GetSerializeType(); - - return _tupleTypeMap.ContainsKey(rt); - } - - public bool GetTypeInfo(Type type, BinaryTypeInfo typeInfo, MetadataGetterContext context) - { - Type rt = type.GetSerializeType(); - TypeEnum te = _tupleTypeMap[rt]; - typeInfo.Type = te; - typeInfo.IsGeneric = type.IsGenericType; - typeInfo.GenericArgumentCount = type.GetGenericArgumentCount(); - typeInfo.SerializeType = SerializeTypeEnum.KeyValuePair; - typeInfo.GenericArguments = type.GetTypeGenericArguments() - .Select(t => context.GetTypeSeq(t, context)) - .ToArray(); - - typeInfo.Members = new BinaryMemberInfo[typeInfo.GenericArguments.Length]; - for(ushort i = 0; i < typeInfo.GenericArguments.Length; i++) - { - BinaryMemberInfo mi = new BinaryMemberInfo() - { - IsField = true, - Seq = i, - TypeSeq = typeInfo.GenericArguments[i] - }; - if( i == 7) - { - mi.Name = "Rest"; - } - else - { - mi.Name = $"Item{i + 1}"; - } - typeInfo.Members[i] = mi; - } - - return true; - } - } -}