Skip to content

Commit bb7abee

Browse files
committed
Рефакторинг
1 parent 3974bb8 commit bb7abee

File tree

10 files changed

+68
-73
lines changed

10 files changed

+68
-73
lines changed

MathCore.WPF/CollectionSelector.cs

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,50 +13,33 @@ public class CollectionSelector<T>(bool SelectFirstItem = true) : ViewModel
1313
{
1414
#region Items : IEnumerable<T> - Коллекция
1515

16-
/// <summary>Коллекция</summary>
17-
private IEnumerable<T>? _Items;
18-
1916
/// <summary>Коллекция</summary>
2017
public IEnumerable<T>? Items
2118
{
22-
get => _Items;
19+
get;
2320
set
2421
{
25-
if (Set(ref _Items, value))
22+
if (Set(ref field, value))
2623
SelectedItem = value switch
2724
{
28-
T[] { Length : > 0 } array => array[0],
29-
List<T> { Count : > 0 } list => list[0],
30-
LinkedList<T> { First.Value : { } first_value } => first_value,
31-
ObservableCollection<T> { Count: > 0 } collection => collection[0],
32-
IList<T> { Count : > 0 } list => list[0],
33-
{ } items => items.FirstOrDefault(),
34-
_ => default
25+
T[] { Length: > 0 } array => array[0],
26+
List<T> { Count: > 0 } list => list[0],
27+
LinkedList<T> { First.Value: { } first_value } => first_value,
28+
ObservableCollection<T> { Count: > 0 } collection => collection[0],
29+
IList<T> { Count: > 0 } list => list[0],
30+
{ } items => items.FirstOrDefault(),
31+
_ => default
3532
};
3633
}
3734
}
3835

3936
#endregion
4037

41-
#region SelectedItem : T - Выбранный элемент
42-
4338
/// <summary>Выбранный элемент</summary>
44-
private T? _SelectedItem;
45-
46-
/// <summary>Выбранный элемент</summary>
47-
public T? SelectedItem { get => _SelectedItem; set => Set(ref _SelectedItem, value); }
48-
49-
#endregion
50-
51-
#region SelectFirstItem : bool - Выбирать первый элемент для нового значения коллекции
52-
53-
/// <summary>Выбирать первый элемент для нового значения коллекции</summary>
54-
private bool _SelectFirstItem = SelectFirstItem;
39+
public T? SelectedItem { get; set => Set(ref field, value); }
5540

5641
/// <summary>Выбирать первый элемент для нового значения коллекции</summary>
57-
public bool SelectFirstItem { get => _SelectFirstItem; set => Set(ref _SelectFirstItem, value); }
58-
59-
#endregion
42+
public bool SelectFirstItem { get; set => Set(ref field, value); } = SelectFirstItem;
6043

6144
public CollectionSelector(IEnumerable<T> Items, bool SelectFirstItem = true) : this(SelectFirstItem) => this.Items = Items;
6245

MathCore.WPF/CollectionViewShaper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace MathCore.WPF;
88

9-
/// <summary> </summary>
9+
/// <summary>Формирует fluent-api для задания представления коллекции WPF с помощью LINQ-подобного синтаксиса</summary>
1010
/// <remarks>
1111
/// <code>
1212
/// // Collection to which the view is bound
@@ -128,7 +128,7 @@ public CollectionViewShaper<T> GroupBy<TKey>(Expression<Func<T, TKey>> selector)
128128
private static string GetPropertyPath(Expression expression)
129129
{
130130
var names = new Stack<string>();
131-
var expr = expression;
131+
var expr = expression;
132132
while (expr is not null and not ParameterExpression and not ConstantExpression)
133133
{
134134
if (expr is not MemberExpression member)

MathCore.WPF/EventsTrigger.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ private class EventTriggersPool : TriggersPool;
6262

6363
private static readonly TriggersPool __Pool;
6464

65-
private static TriggersPool Pool => __Pool;
65+
//private static TriggersPool Pool => __Pool;
6666

6767
public event PropertyChangedEventHandler PropertyChanged;
6868

@@ -90,7 +90,7 @@ public bool Check(object? obj)
9090
bool current;
9191
lock (_SyncRoot)
9292
{
93-
var last = _LastState;
93+
var last = _LastState;
9494
current = _LastState = Checker(obj);
9595
Checked?.Invoke(this, EventArgs.Empty);
9696
if (current == last) return current;

MathCore.WPF/FileDialogEx.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,20 @@ static void AppendFilterText(StringBuilder str, IEnumerable<string> vvv)
5252
}
5353

5454
public bool Equals(FileFilterItem other) => Title == other.Title && Values.SequenceEqual(other.Values, StringComparer.OrdinalIgnoreCase);
55+
56+
public override bool Equals(object? obj) => obj is FileFilterItem item && Equals(item);
57+
58+
public static bool operator ==(FileFilterItem left, FileFilterItem right) => left.Equals(right);
59+
60+
public static bool operator !=(FileFilterItem left, FileFilterItem right) => !(left == right);
61+
62+
public override int GetHashCode()
63+
{
64+
var hash = new HashBuilder("FileDialog".GetHashCode()).Append("FileFileter");
65+
foreach (var item in Values)
66+
hash = hash.Append(item.GetHashCode());
67+
return hash;
68+
}
5569
}
5670

5771
public static FileDialogEx OpenFile() => new() { IsSaveFileDialog = false };
@@ -91,8 +105,8 @@ public FileDialogEx AddFilter(string Name, params string[] Ext) => Filter is { }
91105
: this with { Filter = [new(Name, Ext)] };
92106
#endif
93107

94-
public FileDialogEx AddFilterAllFiles() => Filter is null || Filter.Last().Title != "Все файлы"
95-
? AddFilter("Все файлы", "*.*")
108+
public FileDialogEx AddFilterAllFiles() => Filter is null || Filter.Last().Title != "Все файлы"
109+
? AddFilter("Все файлы", "*.*")
96110
: this;
97111

98112
public OpenFileDialog CreateOpenFileDialog()

MathCore.WPF/FileInfoCollection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
namespace MathCore.WPF;
55

66
[Serializable]
7-
public class FileInfoCollection : ObservableCollection<FileInfo>;
7+
public class FileInfoCollection : ObservableCollection<FileInfo>;

MathCore.WPF/GIF.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
using System.Windows.Media.Animation;
2-
using System.Windows.Media.Imaging;
3-
using System.Windows;
1+
using System.Windows;
42
using System.Windows.Controls;
3+
using System.Windows.Media.Animation;
4+
using System.Windows.Media.Imaging;
55

66
namespace MathCore.WPF;
77

@@ -24,7 +24,7 @@ private void Initialize()
2424
_GifDecoder = new(new Uri(GifSource), BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
2525

2626
_Animation = new(
27-
fromValue: 0,
27+
fromValue: 0,
2828
toValue: _GifDecoder.Frames.Count - 1,
2929
// ReSharper disable once PossibleLossOfFraction
3030
duration: new(new(0, 0, 0, _GifDecoder.Frames.Count / 10, (int)(1000 * (_GifDecoder.Frames.Count / 10d - _GifDecoder.Frames.Count / 10)))))
@@ -53,7 +53,7 @@ private static void VisibilityPropertyChanged(DependencyObject sender, Dependenc
5353
public static readonly DependencyProperty FrameIndexProperty =
5454
DependencyProperty.Register(
5555
nameof(FrameIndex),
56-
typeof(int),
56+
typeof(int),
5757
typeof(GIF),
5858
new UIPropertyMetadata(0, ChangingFrameIndex));
5959

@@ -76,7 +76,7 @@ public bool AutoStart
7676
DependencyProperty.Register(
7777
nameof(AutoStart),
7878
typeof(bool),
79-
typeof(GIF),
79+
typeof(GIF),
8080
new UIPropertyMetadata(false, AutoStartPropertyChanged));
8181

8282
private static void AutoStartPropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
@@ -93,9 +93,9 @@ public string GifSource
9393

9494
public static readonly DependencyProperty GifSourceProperty =
9595
DependencyProperty.Register(
96-
nameof(GifSource),
97-
typeof(string),
98-
typeof(GIF),
96+
nameof(GifSource),
97+
typeof(string),
98+
typeof(GIF),
9999
new UIPropertyMetadata(string.Empty, GifSourcePropertyChanged));
100100

101101
private static void GifSourcePropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) => (sender as GIF).Initialize();

MathCore.WPF/InputCultureManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ public class InputCultureManager
1616
public CultureInfo Culture
1717
{
1818
get => _Culture;
19-
set => InputLanguageManager.Current.CurrentInputLanguage = value;
19+
set => InputLanguageManager.Current.CurrentInputLanguage = _Culture = value;
2020
}
2121

2222
/// <summary>Событие, возникающее при изменении текущей культуры ввода.</summary>
2323
public event EventHandler? CultureChanged;
2424

2525
/// <summary>Конструктор менеджера культуры ввода.</summary>
26-
private InputCultureManager()
26+
private InputCultureManager()
2727
=> InputLanguageManager.Current.InputLanguageChanged += OnInputLanguageChanged;
2828

2929
/// <summary>Обработчик события изменения текущей культуры ввода.</summary>

MathCore.WPF/LongPress.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ private static void UnregisterHandlers(Control control)
6969
control.MouseLeftButtonDown -= OnMouseDown;
7070
control.MouseLeftButtonUp -= OnMouseUp;
7171
control.MouseLeave -= OnMouseLeave;
72-
72+
7373
// Отменяем текущую задачу если она есть
7474
if (control.GetValue(__CancellationTokenSource) is CancellationTokenSource cts)
7575
{
@@ -104,10 +104,10 @@ private static async void OnMouseDown(object sender, MouseButtonEventArgs e)
104104

105105
var down_time = DateTime.Now;
106106
control.SetValue(__LastClickTime, down_time);
107-
107+
108108
var cts = new CancellationTokenSource();
109109
control.SetValue(__CancellationTokenSource, cts);
110-
110+
111111
var timeout = Math.Max(100, GetTimeout(control));
112112

113113
try
@@ -139,11 +139,11 @@ private static async void OnMouseDown(object sender, MouseButtonEventArgs e)
139139
}
140140
}
141141

142-
private static void OnMouseUp(object sender, MouseButtonEventArgs e)
142+
private static void OnMouseUp(object sender, MouseButtonEventArgs e)
143143
{
144144
var control = (DependencyObject)sender;
145145
control.ClearValue(__LastClickTime);
146-
146+
147147
// Отменяем текущую задачу
148148
if (control.GetValue(__CancellationTokenSource) is CancellationTokenSource cts)
149149
{
@@ -156,7 +156,7 @@ private static void OnMouseLeave(object sender, MouseEventArgs e)
156156
{
157157
var control = (DependencyObject)sender;
158158
control.ClearValue(__LastClickTime);
159-
159+
160160
// Отменяем текущую задачу при уходе мыши с элемента
161161
if (control.GetValue(__CancellationTokenSource) is CancellationTokenSource cts)
162162
{
@@ -188,7 +188,6 @@ private static void OnMouseLeave(object sender, MouseEventArgs e)
188188

189189
#endregion
190190

191-
192191
#region Attached property LongPress.Timeout : int - Задержка (не меньше 100) мс
193192

194193
/// <Summary>Задержка (не меньше 100) мс</Summary>
@@ -208,7 +207,6 @@ private static void OnMouseLeave(object sender, MouseEventArgs e)
208207

209208
#endregion
210209

211-
212210
#region Attached property LongPress.AnimationTimeout : int - Шаг анимации
213211

214212
/// <Summary>Шаг анимации</Summary>

MathCore.WPF/MouseWheelGesture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ public class MouseWheelGesture : InputGesture
1212
public override bool Matches(object element, InputEventArgs e)
1313
{
1414
// Проверяем, является ли событие ввода событием колесом мыши и не равен ли delta нулю.
15-
return e is MouseWheelEventArgs wheel && wheel.Delta != 0;
15+
return e is MouseWheelEventArgs { Delta: not 0 };
1616
}
1717
}

MathCore.WPF/RadialProgressIndicator.cs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ static RadialProgressIndicator() =>
4747
/// <summary>Initializes a new instance of <see cref="RadialProgressIndicator" /></summary>
4848
public RadialProgressIndicator()
4949
{
50-
_IsListening = false;
51-
_Radius = 0;
52-
_Center = new();
53-
_RotationAngle = 0;
54-
Unloaded += OnUnloaded;
50+
_IsListening = false;
51+
_Radius = 0;
52+
_Center = new();
53+
_RotationAngle = 0;
54+
Unloaded += OnUnloaded;
5555
}
5656

5757
#endregion
@@ -191,7 +191,7 @@ private void OnRendering(object sender, EventArgs e)
191191

192192
var tick = Environment.TickCount;
193193
_TickCount = tick - _LastTick;
194-
_LastTick = tick;
194+
_LastTick = tick;
195195

196196
CreateProgressPath(_TickCount);
197197
}
@@ -205,7 +205,7 @@ private void CreateProgressPath(int variation)
205205
{
206206
var path_geometry = (PathGeometry)_CurrentGeometry.Clone();
207207
path_geometry.Transform = new RotateTransform(_RotationAngle, _Center.X, _Center.Y);
208-
_ProgressGeometry = path_geometry.GetFlattenedPathGeometry();
208+
_ProgressGeometry = path_geometry.GetFlattenedPathGeometry();
209209
}
210210

211211
if (_BorderGeometry != null)
@@ -239,7 +239,7 @@ private void StartListening()
239239
if (_IsListening)
240240
return;
241241

242-
_IsListening = true;
242+
_IsListening = true;
243243
CompositionTarget.Rendering += OnRendering;
244244
}
245245

@@ -250,7 +250,7 @@ private void StopListening()
250250
if (!_IsListening)
251251
return;
252252

253-
_IsListening = false;
253+
_IsListening = false;
254254
CompositionTarget.Rendering -= OnRendering;
255255
}
256256

@@ -277,8 +277,8 @@ private void OnIsEnabledChanged(bool OldValue, bool NewValue)
277277
{
278278
if (_IsListening)
279279
StopListening();
280-
_RotationAngle = 0;
281-
_CurrentGeometry = null;
280+
_RotationAngle = 0;
281+
_CurrentGeometry = null;
282282
_ProgressGeometry = null;
283283
}
284284

@@ -307,7 +307,7 @@ private void OnActiveForegroundChanged(Brush NewValue)
307307
#endregion Property Changes
308308
}
309309

310-
internal static class GeometryExtensions
310+
file static class GeometryExtensions
311311
{
312312
#region Static
313313

@@ -327,7 +327,7 @@ public static double EaseAngle(this double angle)
327327
var sign = Sign(angle);
328328

329329
var normalized_angle = Abs(angle).Normalize();
330-
var percentage = normalized_angle / 360;
330+
var percentage = normalized_angle / 360;
331331

332332
normalized_angle = percentage.EaseInOut(normalized_angle, 5, 2);
333333
normalized_angle = Max(normalized_angle, 1);
@@ -387,7 +387,7 @@ public static PathGeometry CreatePath(this Point location, double angle, double
387387

388388
var is_large_arc = angle > __FullCircleInDegrees / 2;
389389

390-
var arc_point = ConvertRadianToCartesian(angle, radius);
390+
var arc_point = ConvertRadianToCartesian(angle, radius);
391391
var inner_arc_point = ConvertRadianToCartesian(angle, InnerRadius);
392392

393393
var segments = new PathSegmentCollection
@@ -469,8 +469,8 @@ public static Point ConvertRadianToCartesian(this double angle, double radius)
469469
throw new ArgumentOutOfRangeException($"{nameof(radius)} '{radius}' must be greater than zero.");
470470

471471
var angle_radius = PI / (__FullCircleInDegrees / 2) * (angle - __FullCircleInDegrees / 4);
472-
var x = radius * Cos(angle_radius);
473-
var y = radius * Sin(angle_radius);
472+
var x = radius * Cos(angle_radius);
473+
var y = radius * Sin(angle_radius);
474474
return new(x, y);
475475
}
476476

@@ -551,7 +551,7 @@ public static double EaseInOut(this double TimeFraction, double start, double de
551551
#endregion
552552
}
553553

554-
internal static class DoubleUtil
554+
file static class DoubleUtil
555555
{
556556
#region Types
557557

@@ -597,7 +597,7 @@ public static bool AreClose(double value1, double value2)
597597
// ReSharper restore CompareOfFloatsByEqualityOperator
598598

599599
// This computes (|value1-value2| / (|value1| + |value2| + 10.0)) < DoubleEpsilon
600-
var eps = (Abs(value1) + Abs(value2) + 10.0) * __DoubleEpsilon;
600+
var eps = (Abs(value1) + Abs(value2) + 10.0) * __DoubleEpsilon;
601601
var delta = value1 - value2;
602602
return (-eps < delta) && (eps > delta);
603603
}

0 commit comments

Comments
 (0)