コード例 #1
0
        public static void Serialize(object obj, DataStream ds, bool swaped)
        {
            Type type = obj.GetType();

            // Seriaize(DataStream ds);
            if (obj is ISerializableType)
            {
                bool saveSwap = ds.IsSwaped;
                ds.IsSwaped = swaped;

                ((ISerializableType)obj).Serialize(ds);

                ds.IsSwaped = saveSwap;
            }
            // Arrays. Записывает в указанные переменные длины массивов
            foreach (FieldInfo field in type.GetFields())
            {
                object[] attributes = field.GetCustomAttributes(typeof(ARRAY), false);
                foreach (object attribute in attributes)
                {
                    ARRAY array = attribute as ARRAY;
                    array.SetLength(obj, type, field);
                }
            }
            // Fields
            foreach (FieldInfo field in type.GetFields())
            {
                WriteField(type, field, obj, ds, swaped);
            }
        }