Exemplo n.º 1
0
 /// <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>();
 }
Exemplo n.º 2
0
 /// <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));
 }
Exemplo n.º 3
0
 /// <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));
 }
Exemplo n.º 4
0
 /// <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);
     }
 }
Exemplo n.º 5
0
        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));
        }
Exemplo n.º 6
0
 /// <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));
 }
Exemplo n.º 7
0
 /// <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);
 }
Exemplo n.º 8
0
 /// <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);
 }
Exemplo n.º 9
0
 /// <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);
 }
Exemplo n.º 10
0
 /// <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>();
 }
Exemplo n.º 11
0
 /// <summary>
 /// Generate meta data for serializing interfaces and classes using inheritant
 /// </summary>
 public static void Build()
 {
     CustomBinary.Build();
 }