Example #1
0
 /// <summary>
 /// Read an object based on the supplied type.
 /// </summary>
 public static void Read(IReadingCoder coder, Type type, ref object obj)
 {
     if (!ReadPrimitive(coder, type, ref obj))
     {
         coder.Code(ref obj);
     }
 }
Example #2
0
        /// <summary>
        /// Read an object based on the supplied type.
        /// </summary>
        public static bool ReadPrimitive(IReadingCoder coder, Type type, ref object obj)
        {
            Func <IReadingCoder, object> reader;

            if (TypeReaderMap.TryGetValue(type, out reader))
            {
                obj = reader(coder);
                return(true);
            }
            else if (type.IsEnum)
            {
                coder.CodeEnum(type, ref obj);
                return(true);
            }
            else if (type.IsArray)
            {
                Array a = null;
                coder.Code(type, ref a);
                obj = a;
                return(true);
            }
            else if (type.IsGenericType)
            {
                Func <IReadingCoder, Type, object> genericReader;
                Type genericType = type.GetGenericTypeDefinition();
                if (s_genericReaderMap.TryGetValue(genericType, out genericReader))
                {
                    obj = genericReader(coder, type);
                    return(true);
                }
            }
            return(false);
        }