コード例 #1
0
        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);
            }
        }
コード例 #2
0
ファイル: MySerializer.cs プロジェクト: E1izabeth/Serializer
        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);
        }
コード例 #3
0
 public override void Write(Stream stream)
 {
     stream.WriteByte((byte)SerializeTypes.GetTypeEnum(_type));
     stream.WritePrimitiveOrStringType(_value);
 }