• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

b1f6c1c4 / ProfessionalAccounting / 307

25 Sep 2023 04:48AM UTC coverage: 56.975% (-1.3%) from 58.254%
307

push

appveyor

b1f6c1c4
raw subtotal more controllable

5947 of 10438 relevant lines covered (56.97%)

125.9 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

69.57
/AccountingServer.Shell/Serializer/AlternativeSerializer.cs
1
/* Copyright (C) 2020-2023 b1f6c1c4
2
 *
3
 * This file is part of ProfessionalAccounting.
4
 *
5
 * ProfessionalAccounting is free software: you can redistribute it and/or
6
 * modify it under the terms of the GNU Affero General Public License as
7
 * published by the Free Software Foundation, version 3.
8
 *
9
 * ProfessionalAccounting is distributed in the hope that it will be useful, but
10
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License
12
 * for more details.
13
 *
14
 * You should have received a copy of the GNU Affero General Public License
15
 * along with ProfessionalAccounting.  If not, see
16
 * <https://www.gnu.org/licenses/>.
17
 */
18

19
using System;
20
using System.Linq;
21
using AccountingServer.Entities;
22

23
namespace AccountingServer.Shell.Serializer;
24

25
internal class AlternativeSerializer : IEntitySerializer
26
{
27
    /// <summary>
28
    ///     主要表示器
29
    /// </summary>
30
    private readonly IEntitySerializer m_Primary;
31

32
    /// <summary>
33
    ///     次要表示器
34
    /// </summary>
35
    private readonly IEntitySerializer m_Secondary;
36

37
    private AlternativeSerializer(IEntitySerializer primary, IEntitySerializer secondary)
20✔
38
    {
20✔
39
        m_Primary = primary;
20✔
40
        m_Secondary = secondary;
20✔
41
    }
20✔
42

43
    public string PresentVoucher(Voucher voucher) => Run(s => s.PresentVoucher(voucher));
42✔
44
    public string PresentVoucher(Voucher voucher, string inject) => Run(s => s.PresentVoucher(voucher, inject));
×
45
    public Voucher ParseVoucher(string str) => Run(s => s.ParseVoucher(str));
42✔
46
    public string PresentVoucherDetail(VoucherDetail detail) => Run(s => s.PresentVoucherDetail(detail));
×
47
    public string PresentVoucherDetail(VoucherDetailR detail) => Run(s => s.PresentVoucherDetail(detail));
6✔
48
    public VoucherDetail ParseVoucherDetail(string str) => Run(s => s.ParseVoucherDetail(str));
×
49
    public string PresentAsset(Asset asset) => Run(s => s.PresentAsset(asset));
×
50
    public Asset ParseAsset(string str) => Run(s => s.ParseAsset(str));
×
51
    public string PresentAmort(Amortization amort) => Run(s => s.PresentAmort(amort));
×
52
    public Amortization ParseAmort(string str) => Run(s => s.ParseAmort(str));
×
53

54
    public static IEntitySerializer Compose(params IEntitySerializer[] serializers)
55
        => serializers.Aggregate(static (p, s) => new AlternativeSerializer(p, s));
20✔
56

57
    private TOut Run<TOut>(Func<IEntitySerializer, TOut> func)
58
    {
60✔
59
        try
60
        {
60✔
61
            return func(m_Primary);
60✔
62
        }
63
        catch (NotImplementedException)
30✔
64
        {
30✔
65
            return func(m_Secondary);
30✔
66
        }
67
    }
60✔
68
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc