StockSharp

Форк
0
178 строк · 4.4 Кб
1
#region S# License
2
/******************************************************************************************
3
NOTICE!!!  This program and source code is owned and licensed by
4
StockSharp, LLC, www.stocksharp.com
5
Viewing or use of this code requires your acceptance of the license
6
agreement found at https://github.com/StockSharp/StockSharp/blob/master/LICENSE
7
Removal of this comment is a violation of the license agreement.
8

9
Project: StockSharp.BusinessEntities.BusinessEntities
10
File: Exchange.cs
11
Created: 2015, 11, 11, 2:32 PM
12

13
Copyright 2010 by StockSharp, LLC
14
*******************************************************************************************/
15
#endregion S# License
16
namespace StockSharp.BusinessEntities
17
{
18
	using System;
19
	using System.ComponentModel;
20
	using System.Runtime.CompilerServices;
21
	using System.Runtime.Serialization;
22

23
	using Ecng.Common;
24
	using Ecng.Serialization;
25

26
	using 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))]
38
	public partial class Exchange : Equatable<Exchange>, IPersistable, INotifyPropertyChanged
39
	{
40
		/// <summary>
41
		/// Initializes a new instance of the <see cref="Exchange"/>.
42
		/// </summary>
43
		public Exchange()
44
		{
45
		}
46

47
		private string _name;
48

49
		/// <summary>
50
		/// Exchange code name.
51
		/// </summary>
52
		[DataMember]
53
		public string Name
54
		{
55
			get => _name;
56
			set
57
			{
58
				if (Name == value)
59
					return;
60

61
				_name = value;
62
				Notify();
63
			}
64
		}
65

66
		private string GetLocName(string language) => FullNameLoc.IsEmpty() ? null : LocalizedStrings.GetString(FullNameLoc, language);
67

68
		/// <summary>
69
		/// Full name.
70
		/// </summary>
71
		public string FullName => GetLocName(null);
72

73
		private string _fullNameLoc;
74

75
		/// <summary>
76
		/// Full name (localization key).
77
		/// </summary>
78
		[DataMember]
79
		public string FullNameLoc
80
		{
81
			get => _fullNameLoc;
82
			set
83
			{
84
				if (FullNameLoc == value)
85
					return;
86

87
				_fullNameLoc = value;
88
				Notify();
89
			}
90
		}
91

92
		private CountryCodes? _countryCode;
93

94
		/// <summary>
95
		/// ISO country code.
96
		/// </summary>
97
		[DataMember]
98
		public CountryCodes? CountryCode
99
		{
100
			get => _countryCode;
101
			set
102
			{
103
				if (CountryCode == value)
104
					return;
105

106
				_countryCode = value;
107
				Notify();
108
			}
109
		}
110

111
		[field: NonSerialized]
112
		private PropertyChangedEventHandler _propertyChanged;
113

114
		event PropertyChangedEventHandler INotifyPropertyChanged.PropertyChanged
115
		{
116
			add => _propertyChanged += value;
117
			remove => _propertyChanged -= value;
118
		}
119

120
		private void Notify([CallerMemberName]string propertyName = null)
121
		{
122
			_propertyChanged?.Invoke(this, propertyName);
123
		}
124

125
		/// <inheritdoc />
126
		public 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>
133
		protected override bool OnEquals(Exchange other)
134
		{
135
			return 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>
140
		public override int GetHashCode() => Name?.GetHashCode() ?? 0;
141

142
		/// <summary>
143
		/// Create a copy of <see cref="Exchange"/>.
144
		/// </summary>
145
		/// <returns>Copy.</returns>
146
		public override Exchange Clone()
147
		{
148
			return new Exchange
149
			{
150
				Name = Name,
151
				FullNameLoc = FullNameLoc,
152
				CountryCode = CountryCode,
153
			};
154
		}
155

156
		/// <summary>
157
		/// Load settings.
158
		/// </summary>
159
		/// <param name="storage">Settings storage.</param>
160
		public void Load(SettingsStorage storage)
161
		{
162
			Name = storage.GetValue<string>(nameof(Name));
163
			FullNameLoc = storage.GetValue<string>(nameof(FullNameLoc));
164
			CountryCode = storage.GetValue<CountryCodes?>(nameof(CountryCode));
165
		}
166

167
		/// <summary>
168
		/// Save settings.
169
		/// </summary>
170
		/// <param name="storage">Settings storage.</param>
171
		public void Save(SettingsStorage storage)
172
		{
173
			storage.SetValue(nameof(Name), Name);
174
			storage.SetValue(nameof(FullNameLoc), FullNameLoc);
175
			storage.SetValue(nameof(CountryCode), CountryCode.To<string>());
176
		}
177
	}
178
}

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.