-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathHoliday.cs
196 lines (169 loc) · 6.69 KB
/
Holiday.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
// Generated by https://quicktype.io
namespace QuickType
{
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Runtime.Serialization;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
public partial class Holiday
{
[JsonProperty("result")]
public HolidayResult Result { get; set; }
}
public partial class HolidayResult
{
[JsonProperty("limit")]
public long Limit { get; set; }
[JsonProperty("offset")]
public long Offset { get; set; }
[JsonProperty("count")]
public long Count { get; set; }
[JsonProperty("sort")]
public string Sort { get; set; }
[JsonProperty("results")]
public ResultElement[] Results { get; set; }
}
public partial class ResultElement
{
[JsonProperty("description")]
public string Description { get; set; }
[JsonProperty("holidayCategory")]
public HolidayCategory HolidayCategory { get; set; }
[JsonProperty("isHoliday")]
public IsHoliday IsHoliday { get; set; }
[JsonProperty("date")]
public string Date { get; set; }
[JsonProperty("_id")]
public long Id { get; set; }
[JsonProperty("name")]
public string Name { get; set; }
}
public enum HolidayCategory {
放假之紀念日及節日,
[EnumMember(Value = "星期六、星期日")]
星期六星期日,
特定節日,
補假,
補行上班日,
調整放假日
};
public enum IsHoliday { 否, 是 };
public partial class Holiday
{
public static Holiday FromJson(string json) => JsonConvert.DeserializeObject<Holiday>(json, QuickType.Converter.Settings);
}
public static class Serialize
{
public static string ToJson(this Holiday self) => JsonConvert.SerializeObject(self, QuickType.Converter.Settings);
}
internal static class Converter
{
public static readonly JsonSerializerSettings Settings = new JsonSerializerSettings
{
MetadataPropertyHandling = MetadataPropertyHandling.Ignore,
DateParseHandling = DateParseHandling.None,
Converters =
{
HolidayCategoryConverter.Singleton,
IsHolidayConverter.Singleton,
new IsoDateTimeConverter { DateTimeStyles = DateTimeStyles.AssumeUniversal }
},
};
}
internal class HolidayCategoryConverter : JsonConverter
{
public override bool CanConvert(Type t) => t == typeof(HolidayCategory) || t == typeof(HolidayCategory?);
public override object ReadJson(JsonReader reader, Type t, object existingValue, JsonSerializer serializer)
{
if (reader.TokenType == JsonToken.Null) return null;
var value = serializer.Deserialize<string>(reader);
switch (value)
{
case "放假之紀念日及節日":
return HolidayCategory.放假之紀念日及節日;
case "星期六、星期日":
return HolidayCategory.星期六星期日;
case "特定節日":
return HolidayCategory.特定節日;
case "補假":
return HolidayCategory.補假;
case "補行上班日":
return HolidayCategory.補行上班日;
case "調整放假日":
return HolidayCategory.調整放假日;
}
throw new Exception("Cannot unmarshal type HolidayCategory");
}
public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer)
{
if (untypedValue == null)
{
serializer.Serialize(writer, null);
return;
}
var value = (HolidayCategory)untypedValue;
switch (value)
{
case HolidayCategory.放假之紀念日及節日:
serializer.Serialize(writer, "放假之紀念日及節日");
return;
case HolidayCategory.星期六星期日:
serializer.Serialize(writer, "星期六、星期日");
return;
case HolidayCategory.特定節日:
serializer.Serialize(writer, "特定節日");
return;
case HolidayCategory.補假:
serializer.Serialize(writer, "補假");
return;
case HolidayCategory.補行上班日:
serializer.Serialize(writer, "補行上班日");
return;
case HolidayCategory.調整放假日:
serializer.Serialize(writer, "調整放假日");
return;
}
throw new Exception("Cannot marshal type HolidayCategory");
}
public static readonly HolidayCategoryConverter Singleton = new HolidayCategoryConverter();
}
internal class IsHolidayConverter : JsonConverter
{
public override bool CanConvert(Type t) => t == typeof(IsHoliday) || t == typeof(IsHoliday?);
public override object ReadJson(JsonReader reader, Type t, object existingValue, JsonSerializer serializer)
{
if (reader.TokenType == JsonToken.Null) return null;
var value = serializer.Deserialize<string>(reader);
switch (value)
{
case "否":
return IsHoliday.否;
case "是":
return IsHoliday.是;
}
throw new Exception("Cannot unmarshal type IsHoliday");
}
public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer)
{
if (untypedValue == null)
{
serializer.Serialize(writer, null);
return;
}
var value = (IsHoliday)untypedValue;
switch (value)
{
case IsHoliday.否:
serializer.Serialize(writer, "否");
return;
case IsHoliday.是:
serializer.Serialize(writer, "是");
return;
}
throw new Exception("Cannot marshal type IsHoliday");
}
public static readonly IsHolidayConverter Singleton = new IsHolidayConverter();
}
}