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

b1f6c1c4 / ProfessionalAccounting / 327

28 Apr 2025 05:37PM UTC coverage: 51.346% (-3.0%) from 54.325%
327

push

appveyor

b1f6c1c4
ci buildx

6620 of 12893 relevant lines covered (51.35%)

126.37 hits per line

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

68.0
/AccountingServer.Shell/Serializer/SerializerFactory.cs
1
using System;
2
using AccountingServer.BLL;
3

4
namespace AccountingServer.Shell.Serializer;
5

6
internal class SerializerFactory
7
{
8
    private readonly Client m_Client;
9
    private readonly Identity m_Identity;
10

11
    public SerializerFactory(Client client, Identity id)
10✔
12
    {
10✔
13
        m_Client = client;
10✔
14
        m_Identity = id;
10✔
15
    }
10✔
16

17
    /// <summary>
18
    ///     从表示器代号寻找表示器
19
    /// </summary>
20
    /// <param name="spec">表示器代号</param>
21
    /// <returns>表示器</returns>
22
    public IEntitiesSerializer GetSerializer(string spec = null)
23
    {
10✔
24
        if (string.IsNullOrWhiteSpace(spec))
10✔
25
            return new TrivialEntitiesSerializer(
10✔
26
                AlternativeSerializer.Compose(
27
                    Create<DiscountSerializer>(),
28
                    Create<AbbrSerializer>(),
29
                    Create<CSharpSerializer>()));
30

31
        return spec.Initial() switch
×
32
            {
33
                "abbr" => new TrivialEntitiesSerializer(Create<AbbrSerializer>()),
×
34
                "csharp" => new TrivialEntitiesSerializer(Create<CSharpSerializer>()),
×
35
                "discount" => new TrivialEntitiesSerializer(Create<DiscountSerializer>()),
×
36
                "expr" => new TrivialEntitiesSerializer(Create<ExprSerializer>()),
×
37
                "json" => new JsonSerializer(),
×
38
                "csv" => new CsvSerializer(spec.Rest()),
×
39
                _ => throw new ArgumentException("表示器未知", nameof(spec)),
×
40
            };
41
    }
10✔
42

43
    private T Create<T>() where T : IEntitySerializer, new()
44
    {
30✔
45
        var serializer = new T();
30✔
46
        // ReSharper disable once SuspiciousTypeConversion.Global
47
        if (serializer is IClientDependable cd)
30✔
48
            cd.Client = m_Client;
20✔
49
        // ReSharper disable once SuspiciousTypeConversion.Global
50
        if (serializer is IIdentityDependable id)
30✔
51
            id.Identity = m_Identity;
10✔
52
        return serializer;
30✔
53
    }
30✔
54
}
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