Пример #1
0
        public static bool WritePrimitive(IWritingCoder coder, Type type, ref object obj)
        {
            Action <IWritingCoder, object> writer;

            if (TypeWriterMap.TryGetValue(type, out writer))
            {
                writer(coder, obj);
                return(true);
            }
            else if (type.IsEnum)
            {
                coder.CodeEnum(type, ref obj);
                return(true);
            }
            else if (type.IsArray)
            {
                Array a = (Array)obj;
                coder.Code(type, ref a);
                return(true);
            }
            else if (type.IsGenericType)
            {
                Action <IWritingCoder, Type, object> genericWriter;
                if (s_genericWriterMap.TryGetValue(
                        type.GetGenericTypeDefinition(),
                        out genericWriter))
                {
                    genericWriter(coder, type, obj);
                    return(true);
                }
            }
            return(false);
        }
Пример #2
0
 /// <summary>
 /// Write an object based on the supplied type.
 /// </summary>
 public static void Write(IWritingCoder coder, Type type, ref object obj)
 {
     if (!WritePrimitive(coder, type, ref obj))
     {
         coder.Code(ref obj);
     }
 }