public override Amortization Deserialize(IBsonReader bsonReader)
        {
            string read = null;

            bsonReader.ReadStartDocument();

            var amort = new Amortization
            {
                ID        = bsonReader.ReadGuid("_id", ref read),
                User      = bsonReader.ReadString("user", ref read),
                Name      = bsonReader.ReadString("name", ref read),
                Value     = bsonReader.ReadDouble("value", ref read),
                Date      = bsonReader.ReadDateTime("date", ref read),
                TotalDays = bsonReader.ReadInt32("tday", ref read),
            };

            amort.Interval = bsonReader.ReadString("interval", ref read) switch
            {
                "d" => AmortizeInterval.EveryDay,
                "w" => AmortizeInterval.SameDayOfWeek,
                "W" => AmortizeInterval.LastDayOfWeek,
                "m" => AmortizeInterval.SameDayOfMonth,
                "M" => AmortizeInterval.LastDayOfMonth,
                "y" => AmortizeInterval.SameDayOfYear,
                "Y" => AmortizeInterval.LastDayOfYear,
                _ => amort.Interval,
            };

            amort.Template = bsonReader.ReadDocument("template", ref read, VoucherSerializer.Deserialize);
            amort.Schedule = bsonReader.ReadArray("schedule", ref read, ItemSerializer.Deserialize);
            amort.Remark   = bsonReader.ReadString("remark", ref read);
            bsonReader.ReadEndDocument();
            return(amort);
        }
示例#2
0
    public override Balance Deserialize(IBsonReader bsonReader)
    {
        string read = null;

        bsonReader.ReadStartDocument();
        var balance =
            bsonReader
            .ReadDocument(
                "_id",
                ref read,
                bR =>
        {
            // ReSharper disable AccessToModifiedClosure
            bR.ReadStartDocument();
            var bal =
                new Balance
            {
                Date     = bR.ReadDateTime("date", ref read),
                User     = bR.ReadString("user", ref read),
                Currency = bR.ReadString("currency", ref read),
                Title    = bR.ReadInt32("title", ref read),
                SubTitle = bR.ReadInt32("subtitle", ref read),
                Content  = bR.ReadString("content", ref read),
                Remark   = bR.ReadString("remark", ref read),
            };
            bR.ReadEndDocument();
            return(bal);
            // ReSharper restore AccessToModifiedClosure
        });

        balance.Fund = bsonReader.ReadDouble("total", ref read) ?? bsonReader.ReadInt32("count", ref read) !.Value;
        bsonReader.ReadEndDocument();

        return(balance);
    }
        public override Amortization Deserialize(IBsonReader bsonReader)
        {
            string read = null;

            bsonReader.ReadStartDocument();

            var amort = new Amortization
            {
                ID        = bsonReader.ReadGuid("_id", ref read),
                User      = bsonReader.ReadString("user", ref read),
                Name      = bsonReader.ReadString("name", ref read),
                Value     = bsonReader.ReadDouble("value", ref read),
                Date      = bsonReader.ReadDateTime("date", ref read),
                TotalDays = bsonReader.ReadInt32("tday", ref read)
            };

            switch (bsonReader.ReadString("interval", ref read))
            {
            case "d":
                amort.Interval = AmortizeInterval.EveryDay;
                break;

            case "w":
                amort.Interval = AmortizeInterval.SameDayOfWeek;
                break;

            case "W":
                amort.Interval = AmortizeInterval.LastDayOfWeek;
                break;

            case "m":
                amort.Interval = AmortizeInterval.SameDayOfMonth;
                break;

            case "M":
                amort.Interval = AmortizeInterval.LastDayOfMonth;
                break;

            case "y":
                amort.Interval = AmortizeInterval.SameDayOfYear;
                break;

            case "Y":
                amort.Interval = AmortizeInterval.LastDayOfYear;
                break;
            }

            amort.Template = bsonReader.ReadDocument("template", ref read, VoucherSerializer.Deserialize);
            amort.Schedule = bsonReader.ReadArray("schedule", ref read, ItemSerializer.Deserialize);
            amort.Remark   = bsonReader.ReadString("remark", ref read);
            bsonReader.ReadEndDocument();
            return(amort);
        }
    public override ExchangeRecord Deserialize(IBsonReader bsonReader)
    {
        string read = null;

        bsonReader.ReadStartDocument();
        var record = bsonReader.ReadDocument("_id", ref read, br =>
        {
            // ReSharper disable AccessToModifiedClosure
            br.ReadStartDocument();
            var rec = new ExchangeRecord
            {
                Time = br.ReadDateTime("date", ref read) !.Value,
                From = br.ReadString("from", ref read),
                To   = br.ReadString("to", ref read),
            };
            br.ReadEndDocument();
            return(rec);
            // ReSharper restore AccessToModifiedClosure
        });
        public override ExchangeRecord Deserialize(IBsonReader bsonReader)
        {
            string read = null;

            bsonReader.ReadStartDocument();
            var record = bsonReader.ReadDocument("_id", ref read, br =>
            {
                br.ReadStartDocument();
                var rec = new ExchangeRecord
                {
                    Date = br.ReadDateTime("date", ref read).Value,
                    From = br.ReadString("from", ref read),
                    To   = br.ReadString("to", ref read),
                };
                br.ReadEndDocument();
                return(rec);
            });

            record.Value = bsonReader.ReadDouble("value", ref read).Value;
            bsonReader.ReadEndDocument();
            return(record);
        }