コード例 #1
0
        /// <summary>
        /// Read a <see cref="ArrayData{TypeOfValueInArray}"/> from its value in string representation
        /// </summary>
        public static ArrayData <TypeOfValueInArray> FromString(string value, DatContainer dat, FieldType typeOfarrayInArray)
        {
            value = typeOfarrayInArray == FieldType.String || typeOfarrayInArray == FieldType.ValueString ? value : Regex.Replace(value, @"\s", "").Replace(",", ", ");
            if (dat.ReferenceDataOffsets.TryGetValue(value, out long offset) && dat.ReferenceDatas.TryGetValue(offset, out IReferenceData? rd) && rd is ArrayData <TypeOfValueInArray> a)
            {
                return(a);
            }

            var ad = new ArrayData <TypeOfValueInArray>(dat, typeOfarrayInArray);

            ad.FromString(value);
            return(ad);
        }
コード例 #2
0
        /// <summary>
        /// Read a <see cref="ArrayData{TypeOfValueInArray}"/> from a dat file
        /// </summary>
        public static ArrayData <TypeOfValueInArray> Read(BinaryReader reader, DatContainer dat, FieldType typeOfarrayInArray)
        {
            long length;
            long offset;

            if (dat.x64)
            {
                length = reader.ReadInt64();
                offset = reader.ReadInt64();
            }
            else
            {
                length = reader.ReadInt32();
                offset = reader.ReadInt32();
            }

            if (typeOfarrayInArray == FieldType.Unknown || length == 0)
            {
                return new(dat, typeOfarrayInArray) {
                           Value  = Array.Empty <TypeOfValueInArray>(),
                           Offset = offset,
                           Length = (int)length
                }
            }
            ;

            if (dat.ReferenceDatas.TryGetValue(offset, out IReferenceData? rd) && rd is ArrayData <TypeOfValueInArray> a)
            {
                return(a);
            }

            reader.BaseStream.Seek(dat.x64 ? -16 : -8, SeekOrigin.Current);
            var ad = new ArrayData <TypeOfValueInArray>(dat, typeOfarrayInArray);

            ad.Read(reader);

            return(ad);
        }