Skip to content

Commit a0d1cbf

Browse files
committed
Fix Codacy issues
1 parent a5bad5c commit a0d1cbf

6 files changed

Lines changed: 51 additions & 28 deletions

File tree

src/MahApps.Metro.Samples/MahApps.Metro.Demo/MainWindowViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ private void ToggleIconScaling(object obj)
537537

538538
public bool IsToggleSwitchVisible { get; set; }
539539

540-
public ObservableCollection<string> Animals { get; } = new ObservableCollection<string>()
540+
public ObservableCollection<string> Animals { get; } = new ObservableCollection<string>
541541
{
542542
"African elephant",
543543
"Ant",

src/MahApps.Metro.Samples/MahApps.Metro.Demo/Models/ObjectParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public object CreateObjectFromString(string input, CultureInfo culture, string s
3232
return null;
3333
}
3434

35-
MetroDialogSettings dialogSettings = new MetroDialogSettings()
35+
MetroDialogSettings dialogSettings = new MetroDialogSettings
3636
{
3737
AffirmativeButtonText = "Yes",
3838
NegativeButtonText = "No",

src/MahApps.Metro/Controls/Helper/BindingHelper.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,12 @@ public static object Eval(object source, string expression, string format)
6464
/// <returns></returns>
6565
public static object Eval(Binding binding, object source)
6666
{
67-
if (binding is null) throw new ArgumentNullException(nameof(binding));
67+
if (binding is null)
68+
{
69+
throw new ArgumentNullException(nameof(binding));
70+
}
6871

69-
Binding newBinding = new Binding()
72+
Binding newBinding = new Binding
7073
{
7174
Source = source,
7275
AsyncState = binding.AsyncState,
@@ -91,7 +94,7 @@ public static object Eval(Binding binding, object source)
9194
/// <param name="binding">The <see cref="Binding"/> to evaluate</param>
9295
/// <param name="dependencyObject">optional: The <see cref="DependencyObject"/> to evalutate</param>
9396
/// <returns>The resulting object</returns>
94-
public static object Eval(Binding binding, DependencyObject dependencyObject = null)
97+
public static object Eval(Binding binding, DependencyObject dependencyObject)
9598
{
9699
dependencyObject ??= new DependencyObject();
97100

@@ -106,5 +109,15 @@ public static object Eval(Binding binding, DependencyObject dependencyObject = n
106109
return dependencyObject.GetValue(DummyTextProperty);
107110
}
108111
}
112+
113+
/// <summary>
114+
/// Evaluates a defined <see cref="Binding"/> on the given <see cref="DependencyObject"/>
115+
/// </summary>
116+
/// <param name="binding">The <see cref="Binding"/> to evaluate</param>
117+
/// <returns>The resulting object</returns>
118+
public static object Eval(Binding binding)
119+
{
120+
return Eval(binding, null);
121+
}
109122
}
110123
}

src/MahApps.Metro/Controls/Helper/TextBoxHelper.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -954,6 +954,8 @@ public static void ButtonClicked(object sender, RoutedEventArgs e)
954954
case SelectionMode.Extended:
955955
multiSelectionComboBox.SelectedItems.Clear();
956956
break;
957+
default:
958+
throw new NotSupportedException("Unknown SelectionMode");
957959
}
958960
}
959961
}

src/MahApps.Metro/Controls/MultiSelectionComboBox/ICompareObjectToString.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public interface ICompareObjectToString
2828
[MarkupExtensionReturnType(typeof(DefaultObjectToStringComparer))]
2929
public class DefaultObjectToStringComparer : MarkupExtension, ICompareObjectToString
3030
{
31-
static DefaultObjectToStringComparer _Instance;
31+
private static DefaultObjectToStringComparer _Instance;
3232

3333
/// <inheritdoc/>
3434
public bool CheckIfStringMatchesObject(string input, object objectToCompare, StringComparison stringComparison, string stringFormat)
@@ -48,7 +48,7 @@ public bool CheckIfStringMatchesObject(string input, object objectToCompare, Str
4848
{
4949
objectText = objectToCompare.ToString();
5050
}
51-
else if (stringFormat.Contains('{') && stringFormat.Contains('{'))
51+
else if (stringFormat.Contains('{') && stringFormat.Contains('}'))
5252
{
5353
objectText = string.Format(stringFormat, objectToCompare);
5454
}

src/MahApps.Metro/Controls/MultiSelectionComboBox/MultiSelectionComboBox.cs

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,9 @@ public int SelectItemsFromTextInputDelay
519519
private void UpdateEditableText()
520520
{
521521
if (PART_EditableTextBox is null || SelectedItems is null)
522+
{
522523
return;
524+
}
523525

524526
var selectedItemsText = GetSelectedItemsText();
525527

@@ -583,14 +585,13 @@ private void UpdateHasCustomText(string selectedItemsText)
583585

584586
private void UpdateDisplaySelectedItems(OrderSelectedItemsBy orderBy)
585587
{
586-
switch (orderBy)
588+
if (orderBy == OrderSelectedItemsBy.SelectedOrder)
587589
{
588-
case OrderSelectedItemsBy.SelectedOrder:
589-
SetCurrentValue(DisplaySelectedItemsProperty, SelectedItems);
590-
break;
591-
case OrderSelectedItemsBy.ItemsSourceOrder:
592-
SetCurrentValue(DisplaySelectedItemsProperty, ((IEnumerable<object>)PART_PopupListBox.SelectedItems).OrderBy(o => Items.IndexOf(o)));
593-
break;
590+
SetCurrentValue(DisplaySelectedItemsProperty, SelectedItems);
591+
}
592+
else if (orderBy == OrderSelectedItemsBy.ItemsSourceOrder)
593+
{
594+
SetCurrentValue(DisplaySelectedItemsProperty, ((IEnumerable<object>)PART_PopupListBox.SelectedItems).OrderBy(o => Items.IndexOf(o)));
594595
}
595596
}
596597

@@ -638,7 +639,7 @@ private void UpdateSelectedItemsFromTextTimer_Tick(object sender, EventArgs e)
638639
SelectedItems.Clear();
639640
break;
640641
default:
641-
break;
642+
throw new NotSupportedException("Unknown SelectionMode");
642643
}
643644
return;
644645
}
@@ -671,7 +672,7 @@ private void UpdateSelectedItemsFromTextTimer_Tick(object sender, EventArgs e)
671672
case SelectionMode.Multiple:
672673
case SelectionMode.Extended:
673674

674-
var strings = Text.Split(new string[] { Separator }, StringSplitOptions.RemoveEmptyEntries);
675+
var strings = Text.Split(new [] { Separator }, StringSplitOptions.RemoveEmptyEntries);
675676

676677
SelectedItems.Clear();
677678

@@ -698,7 +699,7 @@ private void UpdateSelectedItemsFromTextTimer_Tick(object sender, EventArgs e)
698699
}
699700
break;
700701
default:
701-
break;
702+
throw new NotSupportedException("Unknown SelectionMode");
702703
}
703704

704705

@@ -771,6 +772,8 @@ private void ExecutedClearContentCommand(object sender, ExecutedRoutedEventArgs
771772
case SelectionMode.Extended:
772773
multiSelectionCombo.SelectedItems.Clear();
773774
break;
775+
default:
776+
throw new NotSupportedException("Unknown SelectionMode");
774777
}
775778
}
776779
}
@@ -889,7 +892,10 @@ protected override void OnItemsChanged(NotifyCollectionChangedEventArgs e)
889892
}
890893

891894
// If we have the ItemsSource set, we need to exit here.
892-
if (ReadLocalValue(ItemsSourceProperty) != DependencyProperty.UnsetValue) return;
895+
if (ReadLocalValue(ItemsSourceProperty) != DependencyProperty.UnsetValue)
896+
{
897+
return;
898+
}
893899

894900
switch (e.Action)
895901
{
@@ -908,11 +914,7 @@ protected override void OnItemsChanged(NotifyCollectionChangedEventArgs e)
908914
break;
909915

910916
case NotifyCollectionChangedAction.Replace:
911-
// TODO Add Handler
912-
break;
913917
case NotifyCollectionChangedAction.Move:
914-
// TODO Add Handler
915-
break;
916918
case NotifyCollectionChangedAction.Reset:
917919
PART_PopupListBox.Items.Clear();
918920
foreach (var item in Items)
@@ -921,7 +923,7 @@ protected override void OnItemsChanged(NotifyCollectionChangedEventArgs e)
921923
}
922924
break;
923925
default:
924-
break;
926+
throw new NotSupportedException("Unsupported NotifyCollectionChangedAction");
925927
}
926928
}
927929

@@ -951,10 +953,16 @@ protected override void OnDropDownOpened(EventArgs e)
951953

952954
PART_PopupListBox.Focus();
953955

954-
if (PART_PopupListBox.Items.Count == 0) return;
956+
if (PART_PopupListBox.Items.Count == 0)
957+
{
958+
return;
959+
}
955960

956961
var index = PART_PopupListBox.SelectedIndex;
957-
if (index < 0) index = 0;
962+
if (index < 0)
963+
{
964+
index = 0;
965+
}
958966

959967
Action action = () =>
960968
{
@@ -1078,15 +1086,15 @@ private void PART_SelectedItemsPresenter_SelectionChanged(object sender, Selecti
10781086
PART_SelectedItemsPresenter.SelectedItem = null;
10791087
}
10801088

1081-
private static void UpdateText(DependencyObject d, DependencyPropertyChangedEventArgs e)
1089+
private static void UpdateText(DependencyObject d, DependencyPropertyChangedEventArgs _)
10821090
{
10831091
if (d is MultiSelectionComboBox multiSelectionComboBox)
10841092
{
10851093
multiSelectionComboBox.UpdateEditableText();
10861094
}
10871095
}
10881096

1089-
private static void OnTextChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
1097+
private static void OnTextChanged(DependencyObject d, DependencyPropertyChangedEventArgs _)
10901098
{
10911099
if (d is MultiSelectionComboBox multiSelectionComboBox)
10921100
{
@@ -1101,7 +1109,7 @@ private static void OnTextChanged(DependencyObject d, DependencyPropertyChangedE
11011109
}
11021110
}
11031111

1104-
private static void OnOrderSelectedItemsByChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
1112+
private static void OnOrderSelectedItemsByChanged(DependencyObject d, DependencyPropertyChangedEventArgs _)
11051113
{
11061114
if (d is MultiSelectionComboBox multiSelectionComboBox && !multiSelectionComboBox.HasCustomText)
11071115
{

0 commit comments

Comments
 (0)