StockSharp
178 строк · 4.4 Кб
1#region S# License
2/******************************************************************************************
3NOTICE!!! This program and source code is owned and licensed by
4StockSharp, LLC, www.stocksharp.com
5Viewing or use of this code requires your acceptance of the license
6agreement found at https://github.com/StockSharp/StockSharp/blob/master/LICENSE
7Removal of this comment is a violation of the license agreement.
8
9Project: StockSharp.BusinessEntities.BusinessEntities
10File: Exchange.cs
11Created: 2015, 11, 11, 2:32 PM
12
13Copyright 2010 by StockSharp, LLC
14*******************************************************************************************/
15#endregion S# License
16namespace StockSharp.BusinessEntities
17{
18using System;
19using System.ComponentModel;
20using System.Runtime.CompilerServices;
21using System.Runtime.Serialization;
22
23using Ecng.Common;
24using Ecng.Serialization;
25
26using StockSharp.Localization;
27
28/// <summary>
29/// Exchange info.
30/// </summary>
31[Serializable]
32[DataContract]
33[KnownType(typeof(TimeZoneInfo))]
34[KnownType(typeof(TimeZoneInfo.AdjustmentRule))]
35[KnownType(typeof(TimeZoneInfo.AdjustmentRule[]))]
36[KnownType(typeof(TimeZoneInfo.TransitionTime))]
37[KnownType(typeof(DayOfWeek))]
38public partial class Exchange : Equatable<Exchange>, IPersistable, INotifyPropertyChanged
39{
40/// <summary>
41/// Initializes a new instance of the <see cref="Exchange"/>.
42/// </summary>
43public Exchange()
44{
45}
46
47private string _name;
48
49/// <summary>
50/// Exchange code name.
51/// </summary>
52[DataMember]
53public string Name
54{
55get => _name;
56set
57{
58if (Name == value)
59return;
60
61_name = value;
62Notify();
63}
64}
65
66private string GetLocName(string language) => FullNameLoc.IsEmpty() ? null : LocalizedStrings.GetString(FullNameLoc, language);
67
68/// <summary>
69/// Full name.
70/// </summary>
71public string FullName => GetLocName(null);
72
73private string _fullNameLoc;
74
75/// <summary>
76/// Full name (localization key).
77/// </summary>
78[DataMember]
79public string FullNameLoc
80{
81get => _fullNameLoc;
82set
83{
84if (FullNameLoc == value)
85return;
86
87_fullNameLoc = value;
88Notify();
89}
90}
91
92private CountryCodes? _countryCode;
93
94/// <summary>
95/// ISO country code.
96/// </summary>
97[DataMember]
98public CountryCodes? CountryCode
99{
100get => _countryCode;
101set
102{
103if (CountryCode == value)
104return;
105
106_countryCode = value;
107Notify();
108}
109}
110
111[field: NonSerialized]
112private PropertyChangedEventHandler _propertyChanged;
113
114event PropertyChangedEventHandler INotifyPropertyChanged.PropertyChanged
115{
116add => _propertyChanged += value;
117remove => _propertyChanged -= value;
118}
119
120private void Notify([CallerMemberName]string propertyName = null)
121{
122_propertyChanged?.Invoke(this, propertyName);
123}
124
125/// <inheritdoc />
126public override string ToString() => Name;
127
128/// <summary>
129/// Compare <see cref="Exchange"/> on the equivalence.
130/// </summary>
131/// <param name="other">Another value with which to compare.</param>
132/// <returns><see langword="true" />, if the specified object is equal to the current object, otherwise, <see langword="false" />.</returns>
133protected override bool OnEquals(Exchange other)
134{
135return Name == other.Name;
136}
137
138/// <summary>Serves as a hash function for a particular type. </summary>
139/// <returns>A hash code for the current <see cref="T:System.Object" />.</returns>
140public override int GetHashCode() => Name?.GetHashCode() ?? 0;
141
142/// <summary>
143/// Create a copy of <see cref="Exchange"/>.
144/// </summary>
145/// <returns>Copy.</returns>
146public override Exchange Clone()
147{
148return new Exchange
149{
150Name = Name,
151FullNameLoc = FullNameLoc,
152CountryCode = CountryCode,
153};
154}
155
156/// <summary>
157/// Load settings.
158/// </summary>
159/// <param name="storage">Settings storage.</param>
160public void Load(SettingsStorage storage)
161{
162Name = storage.GetValue<string>(nameof(Name));
163FullNameLoc = storage.GetValue<string>(nameof(FullNameLoc));
164CountryCode = storage.GetValue<CountryCodes?>(nameof(CountryCode));
165}
166
167/// <summary>
168/// Save settings.
169/// </summary>
170/// <param name="storage">Settings storage.</param>
171public void Save(SettingsStorage storage)
172{
173storage.SetValue(nameof(Name), Name);
174storage.SetValue(nameof(FullNameLoc), FullNameLoc);
175storage.SetValue(nameof(CountryCode), CountryCode.To<string>());
176}
177}
178}