-
Notifications
You must be signed in to change notification settings - Fork 10
/
AbbrSerializer.cs
87 lines (74 loc) · 2.5 KB
/
AbbrSerializer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/* Copyright (C) 2020-2024 b1f6c1c4
*
* This file is part of ProfessionalAccounting.
*
* ProfessionalAccounting is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, version 3.
*
* ProfessionalAccounting is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
* for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with ProfessionalAccounting. If not, see
* <https://www.gnu.org/licenses/>.
*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Xml.Serialization;
using AccountingServer.BLL;
using AccountingServer.Entities.Util;
using AccountingServer.Shell.Util;
using static AccountingServer.BLL.Parsing.Facade;
namespace AccountingServer.Shell.Serializer;
public class AbbrSerializer : ExprSerializer
{
static AbbrSerializer()
=> Cfg.RegisterType<Abbreviations>("Abbr");
protected override bool AlternativeTitle(ref string expr, ICollection<string> lst, ref ITitle title) =>
GetAlternativeTitle(ref expr, lst, ref title);
public static bool GetAlternativeTitle(ref string expr, ICollection<string> lst, ref ITitle title)
{
Abbreviation d = null;
if (
Parsing.Token(
ref expr,
false,
t => (d = Cfg.Get<Abbreviations>().Abbrs.FirstOrDefault(a => a.Abbr == t)) != null) == null)
return false;
title = d;
if (!d.Editable)
lst.Add(d.Content);
if (d.Remark != null)
lst.Add(d.Remark);
return true;
}
}
[Serializable]
[XmlRoot("Abbrs")]
public class Abbreviations
{
[XmlElement("Abbr")] public List<Abbreviation> Abbrs;
}
[Serializable]
[SuppressMessage("ReSharper", "UnusedAutoPropertyAccessor.Global")]
public class Abbreviation : ITitle
{
[XmlAttribute("string")]
public string Abbr { get; set; }
[XmlAttribute("edit")]
[DefaultValue(false)]
public bool Editable { get; set; }
[DefaultValue(null)]
public string Content { get; set; }
[DefaultValue(null)]
public string Remark { get; set; }
public int? Title { get; set; }
[DefaultValue(null)]
public int? SubTitle { get; set; }
}