public override void Read(Stream stream) { _elementType = (SerializeTypeEnum)stream.ReadByte(); var elementType = SerializeTypes.GetType(_elementType); _rank = stream.ReadInt32(); _dimensions = new int[_rank]; for (int i = 0; i < _rank; i++) { _dimensions[i] = stream.ReadInt32(); } int currDim = 0; int count = 1; var ind = new int[_rank]; for (int i = 0; i < _rank; i++) { count *= _dimensions[i]; } _values = new object[count]; for (int i = 0; i < count; i++) { ind = MySerializer.GetNewArrayIndexes(_rank, _dimensions, ind, ref currDim); _values[i] = stream.ReadPrimitiveOrStringType(elementType); } }
internal ArrayOfPrimitivesInfo(Array obj, ISerializationContext ctx) : base(obj, ctx) { _elementType = SerializeTypes.GetTypeEnum(obj.GetType().GetElementType()); _rank = obj.Rank; _dimensions = new int[_rank]; for (int i = 0; i < _rank; i++) { _dimensions[i] = obj.GetLength(i); } int[] ind = new int[_rank]; int currDim = 0; int count = 1; for (int i = 0; i < _rank; i++) { count *= _dimensions[i]; } this._values = new object[count]; for (int i = 0; i < count; i++) { ind = MySerializer.GetNewArrayIndexes(_rank, _dimensions, ind, ref currDim); _values[i] = obj.GetValue(ind); } }
public override object Get(List <ISerializeInstanceInfo> instanceInfos) { var arr = Array.CreateInstance(SerializeTypes.GetType(_elementType), _dimensions); this.Instance = arr; int count = 1; var ind = new int[_rank]; for (int i = 0; i < _rank; i++) { count *= _dimensions[i]; } int currDim = 0; for (int i = 0; i < count; i++) { ind = MySerializer.GetNewArrayIndexes(_rank, _dimensions, ind, ref currDim); arr.SetValue(_values[i], ind); } return(arr); }
private SerializeInstanceInfo GetInstanceInfo(object obj) { if (obj is null) { return(null); } var t = obj.GetType(); SerializeInstanceInfo info; if (t.IsPrimitive || t == typeof(string)) { info = new PrimitiveTypeInfo(obj, this); } else if (t.IsEnum) { info = new EnumInfo(obj); } else if (t.IsArray) { var arr = obj as Array; if (SerializeTypes.GetTypeEnum(t.GetElementType()) != SerializeTypeEnum.Custom) { info = new ArrayOfPrimitivesInfo(arr, this); } else { info = new ArrayOfByRefInfo(arr, this); } } else { info = new CustomInfo(obj, this); } // _serializedInstances.Add(info); return(info); }
public override void Write(Stream stream) { stream.WriteByte((byte)SerializeTypes.GetTypeEnum(_type)); stream.WritePrimitiveOrStringType(_value); }
internal PrimitiveTypeInfo(SerializeTypeEnum type, ISerializationContext ctx) : base(ctx) { _type = SerializeTypes.GetType(type); }