예제 #1
0
            MakeSerializer_Delegate()
            {
                var Type = typeof(t);
                Action <SerializeData, object> Serializer = (Data, obj) =>
                {
                    var MD        = (MulticastDelegate)obj;
                    var Delegates = MD.GetInvocationList();
                    Data.Data.Write(BitConverter.GetBytes(Delegates.Length), 0, 4);
                    for (int i = 0; i < Delegates.Length; i++)
                    {
                        LoadedFunc LoadedFunc;
                        var        Delegate       = Delegates[i];
                        var        DelegateMethod = Delegate.Method;
                        Data.TrustToMethod?.Invoke(DelegateMethod);
                        LoadedFunc = Serializere.VisitedInfoSerialize(Data, DelegateMethod,
                                                                      () =>
                        {
                            var Key = new LoadedFunc(DelegateMethod);
                            if (Serializere.LoadedFuncs_Ser.TryGetValue(Key, out LoadedFunc) == false)
                            {
                                var TargetType = DelegateMethod.DeclaringType;

                                LoadedFunc            = Key;
                                LoadedFunc.NameAsByte =
                                    Serializere.Write(
                                        DelegateMethod.Name,
                                        DelegateMethod.ReflectedType.MidName());
                                LoadedFunc.SerializerTarget = GetSerialize(TargetType);
                                Serializere.LoadedFuncs_Ser.Add(LoadedFunc);
                            }
                            return(LoadedFunc.NameAsByte, LoadedFunc);
                        });
예제 #2
0
파일: Make.cs 프로젝트: gitter-badger/Incs
            ArrayMakeSerializer_Object(Type Type)
            {
                var Setter          = DynamicAssembly.TypeController.SetArray(Type);
                var Getter          = DynamicAssembly.TypeController.GetArray(Type);
                var ElementType     = Type.GetElementType();
                var ItemsSerializer = GetSerialize(Type.GetElementType());

                Action <SerializeData, (System.Array ar, int[] Ends)> Serializer = (Data, obj) =>
                {
                    var ar       = obj.ar;
                    var Ends     = obj.Ends;
                    var Rank     = Ends.Length;
                    var Currents = new int[Rank];
                    while (Currents[Currents.Length - 1] < Ends[Ends.Length - 1])
                    {
                        for (Currents[0] = 0; Currents[0] < Ends[0]; Currents[0]++)
                        {
                            Serializere.VisitedSerialize(Data, Getter(ar, Currents), ItemsSerializer);
                        }
                        for (int i = 1; i < Rank; i++)
                        {
                            if (Currents[i] < Ends[i])
                            {
                                Currents[i]++;
                                Currents[i - 1] = 0;
                            }
                        }
                    }
                };
                Action <DeserializeData, (System.Array ar, int[] Ends)> Deserializer = (Data, obj) =>
                {
                    var ar       = obj.ar;
                    var Ends     = obj.Ends;
                    var Rank     = Ends.Length;
                    var Currents = new int[Rank];

                    while (Currents[Currents.Length - 1] < Ends[Ends.Length - 1])
                    {
                        for (Currents[0] = 0; Currents[0] < Ends[0]; Currents[0]++)
                        {
                            var StandAloneCurrent = new int[Rank];
                            for (int i = 0; i < Rank; i++)
                            {
                                StandAloneCurrent[i] = Currents[i];
                            }
                            Serializere.VisitedDeserialize(Data, (c) => Setter(ar, c, StandAloneCurrent), ItemsSerializer);
                        }
                        for (int i = 1; i < Rank; i++)
                        {
                            if (Currents[i] < Ends[i])
                            {
                                Currents[i]++;
                                Currents[i - 1] = 0;
                            }
                        }
                    }
                };

                return(Serializer, Deserializer);
            }
예제 #3
0
파일: Debug.cs 프로젝트: monsajem/Incs
            private static void Check_SR(SerializeData Data)
            {
                var Type = typeof(t);

                Data.Data.Write(BitConverter.GetBytes(Data.Data.Length), 0, 8);
                var TypeBytes = Serializere.Write(Type.MidName());

                Data.Data.Write(TypeBytes, 0, TypeBytes.Length);
            }
예제 #4
0
            public override void ArraySerializer(SerializeData Data, Array ar)
            {
                var T_Ar = System.Runtime.CompilerServices.Unsafe.As <Array, t[]>(ref ar);
                var S_Ar = System.Runtime.InteropServices.MemoryMarshal.CreateSpan(ref T_Ar[0], ar.Length);

                for (int i = 0; i < S_Ar.Length; i++)
                {
                    Serializere.VisitedSerialize(Data, S_Ar[i], this);
                }
            }
예제 #5
0
            public override void ArrayDeserializer(DeserializeData Data, Array ar)
            {
                var T_Ar = System.Runtime.CompilerServices.Unsafe.As <Array, t[]>(ref ar);
                var S_Ar = System.Runtime.InteropServices.MemoryMarshal.CreateSpan(ref T_Ar[0], ar.Length);

                for (int i = 0; i < S_Ar.Length; i++)
                {
                    var StandAlonePos = i;
                    Serializere.VisitedDeserialize(Data, (c) => T_Ar[StandAlonePos] = (t)c, this);
                }
            }
예제 #6
0
파일: Debug.cs 프로젝트: monsajem/Incs
            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()}");
                }
            }
예제 #7
0
            MakeSerializer_Serializable()
            {
                var Type          = typeof(t);
                var InterfaceType = Type.GetInterfaces().
                                    Where((c) => c.IsGenericType).
                                    Where((c) => c.GetGenericTypeDefinition() == ISerializableType).
                                    FirstOrDefault();

                var InnerType       = InterfaceType.GenericTypeArguments[0];
                var innerSerializer = GetSerialize(InnerType);
                var Getter          = InterfaceType.GetMethod("GetData");
                var Setter          = InterfaceType.GetMethod("SetData");
                Action <SerializeData, object> Serializer = (Data, obj) =>
                {
                    if (obj == null)
                    {
                        Data.Data.WriteByte(0);
                        return;
                    }

                    Data.Data.WriteByte(1);
                    Serializere.VisitedSerialize(Data, Getter.Invoke(obj, null), innerSerializer);
                };

                Func <DeserializeData, object> Deserializer = (Data) =>
                {
                    var ThisFrom = Data.From;
                    if (Data.Data[Data.From] == 0)
                    {
                        Data.From += 1;
                        return(null);
                    }
                    Data.From += 1;

                    object Result = GetUninitializedObject(Type);
                    Serializere.VisitedDeserialize(Data, (c) => Setter.Invoke(Result, new object[] { c }), innerSerializer);
                    return(Result);
                };

                return(Serializer, Deserializer);
            }
예제 #8
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);
                    });
                }
            }