Esempio n. 1
0
            private static void Check_DR(DeserializeData Data)
            {
                var Type   = typeof(t);
                var DR_Pos = Data.From;
                var SR_Pos = BitConverter.ToInt64(Data.Data, Data.From);

                Data.From += 8;
                if (DR_Pos != SR_Pos ||
                    SR_Pos < 0)
                {
                    throw new Exception($"Position Isn't Valid. SR:{SR_Pos} , DR:{DR_Pos}");
                }
                var TypeName = Serializere.Read(Data);
                var SR_Type  = TypeName.GetTypeByName();

                if (SR_Type != Type)
                {
                    throw new Exception($"Type isn't match\nSR: {SR_Type.MidName()}\nDR: {Type.MidName()}");
                }
            }
Esempio n. 2
0
            public override void Make()
            {
                var Type = typeof(t);

                var IsSerializable = Type.GetInterfaces().Where(
                    (c) =>
                {
                    if (c.IsGenericType)
                    {
                        if (c.GetGenericTypeDefinition() == ISerializableType)
                        {
                            return(true);
                        }
                    }
                    return(false);
                }).FirstOrDefault();

                if (IsSerializable != null)
                {
                    InsertSerializer(() =>
                    {
                        var sr = MakeSerializer_Serializable();
                        return(sr.Serializer, sr.Deserializer);
                    });
                }
                else if (Type == typeof(Delegate))
                {
                    InsertSerializer(
                        (Data, obj) =>
                    {
                        var DType      = obj.GetType();
                        var Serializer = GetSerialize(DType);
                        Serializere.VisitedInfoSerialize <object>(Data, DType, () => (Serializer.NameAsByte, null));
                        Serializer.Serializer(Data, obj);
                    },
                        (Data) =>
                    {
                        var Info = Serializere.VisitedInfoDeserialize(Data, () => Serializere.Read(Data));

                        return(GetSerialize(Info).Deserializer(Data));
                    });
                }
                else if (Type.GetInterfaces().Where((c) => c == typeof(Collection.Array.Base.IArray)).FirstOrDefault() != null)
                {
                    InsertSerializer(() =>
                    {
                        var sr = MakeSerializer_Monsajem_Array();
                        return(sr.Serializer, sr.Deserializer);
                    });
                }
                else if (Type.IsInterface)
                {
                    InsertSerializer(() =>
                    {
                        var Sr = SerializeInfo <object> .GetSerialize();
                        return(Sr.Serializer, Sr.Deserializer);
                    });
                }
                else if (Type.IsArray)
                {
                    var size = SerializeInfo.GetSerialize(Type.GetElementType()).ConstantSize;
                    if (size != -1)
                    {
                        InsertSerializer(() =>
                        {
                            var sr = MakeSerializer_Array_Struct(size);
                            return(sr.Serializer, sr.Deserializer);
                        });
                    }
                    else
                    {
                        InsertSerializer(() =>
                        {
                            var sr = MakeSerializer_Array_Class();
                            return(sr.Serializer, sr.Deserializer);
                        });
                    }
                }
                else if (Type == typeof(System.Array))
                {
                    InsertSerializer(() =>
                    {
                        var Sr = SerializeInfo <object> .GetSerialize();
                        return(Sr.Serializer, Sr.Deserializer);
                    });
                }
                else if (Type == typeof(System.Array))
                {
                    InsertSerializer(() =>
                    {
                        var sr = MakeSerializer_Array_Class();
                        return((Data, obj) =>
                        {
                            var ar = (System.Array)obj;
                        }, (Data) =>
                        {
                            return null;
                        }
                               );
                    });
                }
                else if (Type.BaseType == typeof(MulticastDelegate))
                {
                    InsertSerializer(() =>
                    {
                        var sr = MakeSerializer_Delegate();
                        return(sr.Serializer, sr.Deserializer);
                    });
                }
                else if (Nullable.GetUnderlyingType(Type) != null)
                {
                    InsertSerializer(() =>
                    {
                        var sr = MakeSerializer_Nullable();
                        return(sr.Serializer, sr.Deserializer);
                    });
                }
                else if (Type.IsValueType)
                {
                    if (ConstantSize == -1)
                    {
                        InsertSerializer(() =>
                        {
                            var sr = MakeSerializer_ValueType();
                            return(sr.Serializer, sr.Deserializer);
                        });
                    }
                    else
                    {
                        InsertSerializer(() => (Default_Serializer, Default_Deserializer));
                    }
                }
                else
                {
                    InsertSerializer(() =>
                    {
                        var sr = MakeSerializer_Else();
                        return(sr.Serializer, sr.Deserializer);
                    });
                }
            }