98 lines
2.1 KiB
C#
98 lines
2.1 KiB
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
using Newtonsoft.Json;
|
|||
|
using TrainInfomationProviderService.StationInfo;
|
|||
|
using TrainInfomationProviderService.StationInfo.Entities;
|
|||
|
|
|||
|
namespace TrainInfomationProviderService.TrainInfo.Entities
|
|||
|
{
|
|||
|
public class Train : IEquatable<Train>
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// ID
|
|||
|
/// </summary>
|
|||
|
[JsonProperty("i")]
|
|||
|
public string Id { get; set; }
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 列车编号
|
|||
|
/// </summary>
|
|||
|
[JsonProperty("c")]
|
|||
|
public string Code { get; set; }
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 发站
|
|||
|
/// </summary>
|
|||
|
[JsonProperty("f")]
|
|||
|
public string From { get; set; }
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 到站
|
|||
|
/// </summary>
|
|||
|
[JsonProperty("t")]
|
|||
|
public string To { get; set; }
|
|||
|
|
|||
|
[JsonProperty("s")]
|
|||
|
public List<TrainStop> TrainStops { get; set; }
|
|||
|
|
|||
|
#region Implementation of IEquatable<Train>
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 指示当前对象是否等于同一类型的另一个对象。
|
|||
|
/// </summary>
|
|||
|
/// <returns>
|
|||
|
/// 如果当前对象等于 <paramref name="other"/> 参数,则为 true;否则为 false。
|
|||
|
/// </returns>
|
|||
|
/// <param name="other">与此对象进行比较的对象。</param>
|
|||
|
public bool Equals(Train other)
|
|||
|
{
|
|||
|
return Key == other.Key;
|
|||
|
}
|
|||
|
|
|||
|
private string _key;
|
|||
|
private string Key
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
if (string.IsNullOrEmpty(_key))
|
|||
|
{
|
|||
|
_key = Id + Code + From + To;
|
|||
|
}
|
|||
|
|
|||
|
return _key;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 用作特定类型的哈希函数。
|
|||
|
/// </summary>
|
|||
|
/// <returns>
|
|||
|
/// 当前 <see cref="T:System.Object"/> 的哈希代码。
|
|||
|
/// </returns>
|
|||
|
public override int GetHashCode()
|
|||
|
{
|
|||
|
return Key.GetHashCode();
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 确定指定的 <see cref="T:System.Object"/> 是否等于当前的 <see cref="T:System.Object"/>。
|
|||
|
/// </summary>
|
|||
|
/// <returns>
|
|||
|
/// 如果指定的对象等于当前对象,则为 true;否则为 false。
|
|||
|
/// </returns>
|
|||
|
/// <param name="obj">要与当前对象进行比较的对象。</param>
|
|||
|
public override bool Equals(object obj)
|
|||
|
{
|
|||
|
if (obj == null || !(obj is Train))
|
|||
|
return false;
|
|||
|
|
|||
|
return Key == (obj as Train).Key;
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|