54 lines
1.3 KiB
C#
54 lines
1.3 KiB
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Runtime.Serialization;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
using Newtonsoft.Json;
|
|||
|
|
|||
|
namespace TrainInfomationProviderService.StationInfo.Entities
|
|||
|
{
|
|||
|
public class StationStorage
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// 创建 <see cref="StationStorage" /> 的新实例(StationStorage)
|
|||
|
/// </summary>
|
|||
|
[JsonConstructor]
|
|||
|
protected StationStorage()
|
|||
|
{
|
|||
|
Stations = new Dictionary<string, StationDetailInfo>(StringComparer.OrdinalIgnoreCase);
|
|||
|
}
|
|||
|
|
|||
|
public StationStorage(int version, IEnumerable<StationDetailInfo> detail)
|
|||
|
{
|
|||
|
Version = version;
|
|||
|
Stations = detail.ToDictionary(s => s.Code, s => s, StringComparer.OrdinalIgnoreCase);
|
|||
|
StationNameMap = detail.ToDictionary(s => s.Name, s => s, StringComparer.OrdinalIgnoreCase);
|
|||
|
}
|
|||
|
|
|||
|
[JsonProperty("v")]
|
|||
|
public int Version { get; set; }
|
|||
|
|
|||
|
[JsonProperty("s")]
|
|||
|
public Dictionary<string, StationDetailInfo> Stations { get; set; }
|
|||
|
|
|||
|
[JsonIgnore]
|
|||
|
public Dictionary<string, StationDetailInfo> StationNameMap { get; private set; }
|
|||
|
|
|||
|
|
|||
|
[OnDeserialized]
|
|||
|
void DeserializeCallback(StreamingContext context)
|
|||
|
{
|
|||
|
Init();
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 初始化
|
|||
|
/// </summary>
|
|||
|
protected void Init()
|
|||
|
{
|
|||
|
StationNameMap = Stations.ToDictionary(s => s.Value.Name, s => s.Value, StringComparer.OrdinalIgnoreCase);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|