Beispiel #1
0
 static void WriteGeneric <TKey, TValue>(IBinarySerializerForHandle serializer, BinaryWriter writer, Dictionary <TKey, TValue> obj)
 {
     writer.Write(obj.Count);
     foreach (var item in obj)
     {
         serializer.InternalWrite(writer, item.Key, typeof(TKey));
         serializer.InternalWrite(writer, item.Value, typeof(TValue));
     }
 }
Beispiel #2
0
 static void WriteGeneric <T>(IBinarySerializerForHandle serializer, BinaryWriter writer, List <T> obj)
 {
     writer.Write(obj.Count);
     for (int i = 0; i < obj.Count; ++i)
     {
         serializer.InternalWrite(writer, obj[i], typeof(T));
     }
 }
Beispiel #3
0
        public override void Write(IBinarySerializerForHandle serializer, BinaryWriter writer, object obj)
        {
            var fields = serializer.GetClassFieldInfos(obj.GetType());

            foreach (var field in fields)
            {
                var val = field.GetValue(obj);
                serializer.InternalWrite(writer, val, field.FieldType);
            }
        }
        public override void Write(IBinarySerializerForHandle serializer, BinaryWriter writer, object obj)
        {
            Array arr          = (Array)obj;
            var   type         = obj.GetType();
            var   element_type = type.GetElementType();
            int   rank         = type.GetArrayRank();

            int[] lengths     = new int[rank];
            int[] lowerBounds = new int[rank];
            int[] uperBounds  = new int[rank];
            int[] idxs        = new int[rank];// for read will use
            bool  is_empty    = false;

            for (int i = 0; i < rank; ++i)
            {
                lengths[i] = arr.GetLength(i);
                writer.Write(lengths[i]);
                lowerBounds[i] = arr.GetLowerBound(i);
                writer.Write(lowerBounds[i]);
                uperBounds[i] = arr.GetUpperBound(i);
                idxs[i]       = lowerBounds[i];
                is_empty      = is_empty || (lengths[i] == 0);
            }
            if (is_empty)
            {
                return; // why c# allow `new int[0,0]`
            }

            for (; ;)
            {
                var val = arr.GetValue(idxs);
                serializer.InternalWrite(writer, val, element_type);
                // next
                int dim = rank - 1;
                for (; dim >= 0; --dim)
                {
                    if (idxs[dim] < uperBounds[dim])
                    {
                        break;
                    }
                }
                if (dim == -1)
                {
                    break;           // loop end
                }
                idxs[dim]++;
                for (dim++; dim < rank; ++dim)
                {
                    idxs[dim] = lowerBounds[dim];
                }
            }
        }
Beispiel #5
0
 public override void Write(IBinarySerializerForHandle serializer, BinaryWriter writer, object obj)
 {
     serializer.InternalWrite(writer, obj, Enum.GetUnderlyingType(obj.GetType()));
 }