/// <summary> /// Precompile the specified type /// </summary> /// <typeparam name="T"></typeparam> public static void Compile <T>() { if (typeof(T).IsCollectionAssignable()) { CustomBinary.GetSerializer <InternalWrapper <T> >(); return; } CustomBinary.GetSerializer <T>(); }
/// <summary> /// Deserialize stream into T type /// </summary> /// <typeparam name="T"></typeparam> /// <param name="stream"></param> /// <returns></returns> public static T Deserialize <T>(Stream stream) { if (typeof(T).IsCollectionAssignable()) { var obj = CustomBinary.GetSerializer <InternalWrapper <T> >().Deserialize(stream); return(obj.Value); } return(CustomBinary.GetSerializer <T>().Deserialize(stream)); }
/// <summary> /// Serialize value into a byte array /// </summary> /// <typeparam name="T"></typeparam> /// <param name="value"></param> /// <returns></returns> public static byte[] Serialize <T>(T value) { if (value is ICollection) { return(CustomBinary.GetSerializer <InternalWrapper <T> >().Serialize(new InternalWrapper <T> { Value = value })); } return(CustomBinary.GetSerializer <T>().Serialize(value)); }
/// <summary> /// Serialize value to specified stream /// </summary> /// <typeparam name="T"></typeparam> /// <param name="value"></param> /// <param name="stream"></param> public static void Serialize <T>(T value, Stream stream) { if (value is ICollection) { CustomBinary.GetSerializer <InternalWrapper <T> >().Serialize(new InternalWrapper <T> { Value = value }, stream); } else { CustomBinary.GetSerializer <T>().Serialize(value, stream); } }
static Type GetGenericListType(Type type, out bool useGenericArguments) { useGenericArguments = false; if (type.IsGenericType) { Type[] genericTypes = type.GetGenericArguments(); if (genericTypes != null && genericTypes.Length > 0) { useGenericArguments = true; return(genericTypes[0]); } } return(CustomBinary.FindGenericType(type)); }
/// <summary> /// Returns true if type is already register for TType /// </summary> /// <typeparam name="TType"></typeparam> /// <param name="type"></param> /// <returns></returns> public static bool IsTypeRegisterFor <TType>(Type type) { return(CustomBinary.IsTypeRegisterFor <TType>(type)); }
/// <summary> /// Set type as a subclass for TType. This would be used for registering implementation for interfaces /// and classes requires inheritant /// </summary> /// <typeparam name="TType"></typeparam> /// <param name="type"></param> /// <param name="tag"></param> public static void RegisterTypeFor <TType>(Type type, byte tag) { CustomBinary.RegisterTypeFor <TType>(type, tag); }
/// <summary> /// Register a new method that would be used to read custom type from bytes that requires /// Type information to be passed during deserialization /// </summary> /// <typeparam name="T"></typeparam> /// <param name="func"></param> public static void RegisterReader <T>(Func <byte[], Type, T> func) { CustomBinary.RegisterReader(func); }
/// <summary> /// Register a method that would be used for serializing custom types to bytes /// The method must be a public method /// </summary> /// <typeparam name="T"></typeparam> /// <param name="func"></param> public static void RegisterWriter <T>(Action <CustomBuffer, T, int, bool> func) { CustomBinary.RegisterWriter(func); }
/// <summary> /// Register any type that requires length of buffer size when serializing/deserializing /// </summary> /// <typeparam name="T"></typeparam> public static void RegisterBufferedType <T>() { CustomBinary.RegisterBufferedType <T>(); }
/// <summary> /// Generate meta data for serializing interfaces and classes using inheritant /// </summary> public static void Build() { CustomBinary.Build(); }