Beispiel #1
0
        public bool Setup(Serialize.ReadCallback <T> fn, string[] titles, string[] lines, int lineBeg, bool hasDefault)
        {
            if (lineBeg < 1)
            {
                return(false);   // first line must be titles
            }
            if (lines.Length <= lineBeg)
            {
                return(false);   // error parameter
            }
            _idxMap = new IndexMap();
            if (!_idxMap.Setup(titles, lines[0]))
            {
                return(false);
            }

            _parser     = new Parser(_idxMap);
            _hasDefault = hasDefault;
            _index      = lineBeg;
            _lines      = lines;
            _fn         = fn;

            if (_hasDefault)
            {
                if (!Load(out _default))
                {
                    return(false);
                }
            }

            return(true);
        }
Beispiel #2
0
        public bool Setup(Serialize.ReadCallback <T> fn, byte[] data)
        {
            var stream = new MemoryStream(data);
            var reader = new BinaryReader(stream);

            _fn     = fn;
            _code   = reader.ReadInt32();
            _count  = reader.ReadInt32();
            _reader = new Serialize.BinaryReader(reader);
            return(true);
        }
Beispiel #3
0
        public bool LoadText(Info info, Serialize.ReadCallback <T> fn, string file, int startLine, bool hasDefault = true)
        {
            var lines = System.IO.File.ReadAllLines(file);

            if (lines == null || lines.Length == 0)
            {
                return(false);
            }

            return(LoadText(info, fn, lines, startLine, hasDefault));
        }
Beispiel #4
0
        public bool LoadBinary(Serialize.ReadCallback <T> fn, string file, int hashCode = 0)
        {
            var bytes = System.IO.File.ReadAllBytes(file);

            if (bytes == null || bytes.Length == 0)
            {
                return(false);
            }

            return(LoadBinary(fn, bytes));
        }
Beispiel #5
0
        public bool LoadBinary(Serialize.ReadCallback <T> fn, byte[] data, int hashCode = 0)
        {
            var loader = new BinaryLoader <T>();

            if (!loader.Setup(fn, data))
            {
                return(false);
            }

            if (hashCode != 0 && loader.Code != hashCode)
            {
                return(false);
            }

            return(Load(loader));
        }
Beispiel #6
0
        public bool LoadText(Info info, Serialize.ReadCallback <T> fn, string[] lines, int startLine, bool hasDefault = true)
        {
            if (info == null)
            {
                return(false);
            }

            var loader = new TextLoader <T>();

            if (!loader.Setup(fn, info.Titles, lines, startLine, hasDefault))
            {
                return(false);
            }

            return(Load(loader));
        }