Skip to content

Commit 70a5530

Browse files
committed
Expression bodied accessors from R# introduction.
1 parent cd113a8 commit 70a5530

21 files changed

+160
-185
lines changed

RetailCoder.VBE/UI/About/AboutControlViewModel.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,7 @@ public AboutControlViewModel(IVersionCheck version)
1616
_version = version;
1717
}
1818

19-
public string Version
20-
{
21-
get
22-
{
23-
return string.Format(RubberduckUI.Rubberduck_AboutBuild, _version.CurrentVersion);
24-
}
25-
}
19+
public string Version => string.Format(RubberduckUI.Rubberduck_AboutBuild, _version.CurrentVersion);
2620

2721
private CommandBase _uriCommand;
2822
public CommandBase UriCommand

RetailCoder.VBE/UI/CodeExplorer/CodeExplorerControl.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public CodeExplorerControl()
1515
InitializeComponent();
1616
}
1717

18-
private CodeExplorerViewModel ViewModel { get { return DataContext as CodeExplorerViewModel; } }
18+
private CodeExplorerViewModel ViewModel => DataContext as CodeExplorerViewModel;
1919

2020
private void TreeView_OnMouseDoubleClick(object sender, MouseButtonEventArgs e)
2121
{

RetailCoder.VBE/UI/CodeExplorer/Commands/AddComponentCommand.cs

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,31 @@ private Declaration GetDeclaration(CodeExplorerItemViewModel node)
5252

5353
private string GetFolder(CodeExplorerItemViewModel node)
5454
{
55-
if (node == null)
56-
{
57-
return DefaultFolder;
58-
}
55+
//if (node == null)
56+
//{
57+
// return DefaultFolder;
58+
//}
59+
60+
//if (node is ICodeExplorerDeclarationViewModel declarationNode)
61+
//{
62+
// return string.IsNullOrEmpty(declarationNode.Declaration.CustomFolder)
63+
// ? DefaultFolder
64+
// : declarationNode.Declaration.CustomFolder.Replace("\"", string.Empty);
65+
//}
5966

60-
var declarationNode = node as ICodeExplorerDeclarationViewModel;
61-
if (declarationNode != null)
67+
//return ((CodeExplorerCustomFolderViewModel)node).FullPath;
68+
69+
switch (node)
6270
{
63-
return string.IsNullOrEmpty(declarationNode.Declaration.CustomFolder)
64-
? DefaultFolder
65-
: declarationNode.Declaration.CustomFolder.Replace("\"", string.Empty);
71+
case null:
72+
return DefaultFolder;
73+
case ICodeExplorerDeclarationViewModel declarationNode:
74+
return string.IsNullOrEmpty(declarationNode.Declaration.CustomFolder)
75+
? DefaultFolder
76+
: declarationNode.Declaration.CustomFolder.Replace("\"", string.Empty);
77+
default:
78+
return ((CodeExplorerCustomFolderViewModel)node).FullPath;
6679
}
67-
68-
return ((CodeExplorerCustomFolderViewModel)node).FullPath;
6980
}
7081
}
7182
}

RetailCoder.VBE/UI/Controls/BindableSelectedItemBehavior.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ public class BindableSelectedItemBehavior : Behavior<TreeView>
1111
{
1212
public object SelectedItem
1313
{
14-
get { return (object) GetValue(SelectedItemProperty); }
15-
set { SetValue(SelectedItemProperty, value); }
14+
get => (object) GetValue(SelectedItemProperty);
15+
set => SetValue(SelectedItemProperty, value);
1616
}
1717

1818
public static readonly DependencyProperty SelectedItemProperty =
@@ -21,8 +21,7 @@ public object SelectedItem
2121

2222
private static void OnSelectedItemChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
2323
{
24-
var item = e.NewValue as TreeViewItem;
25-
if (item != null)
24+
if (e.NewValue is TreeViewItem item)
2625
{
2726
item.SetValue(TreeViewItem.IsSelectedProperty, true);
2827
}

RetailCoder.VBE/UI/Controls/BindableTextEditor.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ public BindableTextEditor()
3131

3232
public new string Text
3333
{
34-
get { return base.Text; }
35-
set { base.Text = value; }
34+
get => base.Text;
35+
set => base.Text = value;
3636
}
3737

3838
public static readonly DependencyProperty TextProperty =
@@ -50,10 +50,7 @@ protected override void OnTextChanged(EventArgs e)
5050

5151
public void RaisePropertyChanged(string property)
5252
{
53-
if (PropertyChanged != null)
54-
{
55-
PropertyChanged(this, new PropertyChangedEventArgs(property));
56-
}
53+
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(property));
5754
}
5855

5956
public event PropertyChangedEventHandler PropertyChanged;

RetailCoder.VBE/UI/Controls/DeclarationTypeToStringConverter.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,13 @@ public class DeclarationTypeToStringConverter : IValueConverter
99
{
1010
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
1111
{
12-
if (value is DeclarationType)
12+
if (!(value is DeclarationType type))
1313
{
14-
var type = (DeclarationType)value;
15-
var text = RubberduckUI.ResourceManager.GetString("DeclarationType_" + type, CultureInfo.CurrentUICulture) ?? string.Empty;
16-
return CultureInfo.CurrentCulture.TextInfo.ToTitleCase(text);
14+
return null;
1715
}
1816

19-
return null;
17+
var text = RubberduckUI.ResourceManager.GetString("DeclarationType_" + type, CultureInfo.CurrentUICulture) ?? string.Empty;
18+
return CultureInfo.CurrentCulture.TextInfo.ToTitleCase(text);
2019
}
2120

2221
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)

RetailCoder.VBE/UI/Controls/EmptyUIRefresh.xaml.cs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
6-
using System.Windows;
7-
using System.Windows.Controls;
8-
using System.Windows.Data;
9-
using System.Windows.Documents;
10-
using System.Windows.Input;
11-
using System.Windows.Media;
12-
using System.Windows.Media.Imaging;
13-
using System.Windows.Navigation;
14-
using System.Windows.Shapes;
1+
using System.Windows.Controls;
152

163
namespace Rubberduck.UI.Controls
174
{

RetailCoder.VBE/UI/Controls/GroupingGrid.xaml.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ public partial class GroupingGrid
1010

1111
public bool ShowGroupingItemCount
1212
{
13-
get { return (bool) GetValue(ShowGroupingItemCountProperty); }
14-
set { SetValue(ShowGroupingItemCountProperty, value); }
13+
get => (bool) GetValue(ShowGroupingItemCountProperty);
14+
set => SetValue(ShowGroupingItemCountProperty, value);
1515
}
1616

1717
public GroupingGrid()
@@ -21,11 +21,11 @@ public GroupingGrid()
2121

2222
private void GroupingGridItem_MouseDoubleClick(object sender, MouseButtonEventArgs e)
2323
{
24-
var context = DataContext as INavigateSelection;
25-
if (context == null)
24+
if (!(DataContext is INavigateSelection context))
2625
{
2726
return;
2827
}
28+
2929
var selection = context.SelectedItem;
3030
if (selection != null)
3131
{

RetailCoder.VBE/UI/Controls/MenuItemGroup.cs

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,31 +30,34 @@ public static string GetGroupName(MenuItem element)
3030
private static void OnGroupNameChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
3131
{
3232
//Add an entry to the group name collection
33-
var menuItem = d as MenuItem;
3433

35-
if (menuItem != null)
34+
if (!(d is MenuItem menuItem))
3635
{
37-
var newGroupName = e.NewValue.ToString();
38-
var oldGroupName = e.OldValue.ToString();
39-
if (string.IsNullOrEmpty(newGroupName))
36+
return;
37+
}
38+
39+
var newGroupName = e.NewValue.ToString();
40+
var oldGroupName = e.OldValue.ToString();
41+
if (string.IsNullOrEmpty(newGroupName))
42+
{
43+
//Removing the toggle button from grouping
44+
RemoveCheckboxFromGrouping(menuItem);
45+
}
46+
else
47+
{
48+
//Switching to a new group
49+
if (newGroupName == oldGroupName)
4050
{
41-
//Removing the toggle button from grouping
42-
RemoveCheckboxFromGrouping(menuItem);
51+
return;
4352
}
44-
else
53+
54+
if (!string.IsNullOrEmpty(oldGroupName))
4555
{
46-
//Switching to a new group
47-
if (newGroupName != oldGroupName)
48-
{
49-
if (!string.IsNullOrEmpty(oldGroupName))
50-
{
51-
//Remove the old group mapping
52-
RemoveCheckboxFromGrouping(menuItem);
53-
}
54-
ElementToGroupNames.Add(menuItem, e.NewValue.ToString());
55-
menuItem.Checked += MenuItemChecked;
56-
}
56+
//Remove the old group mapping
57+
RemoveCheckboxFromGrouping(menuItem);
5758
}
59+
ElementToGroupNames.Add(menuItem, e.NewValue.ToString());
60+
menuItem.Checked += MenuItemChecked;
5861
}
5962
}
6063

@@ -65,7 +68,7 @@ private static void RemoveCheckboxFromGrouping(MenuItem checkBox)
6568
}
6669

6770

68-
static void MenuItemChecked(object sender, RoutedEventArgs e)
71+
private static void MenuItemChecked(object sender, RoutedEventArgs e)
6972
{
7073
var menuItem = e.OriginalSource as MenuItem;
7174
foreach (var item in ElementToGroupNames)

RetailCoder.VBE/UI/Controls/NumberPicker.xaml.cs

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,17 @@ public partial class NumberPicker : IDataErrorInfo
1414

1515
public int NumValue
1616
{
17-
get
18-
{
19-
return (int)GetValue(NumValueProperty);
20-
}
17+
get => (int)GetValue(NumValueProperty);
2118
set
2219
{
2320
SetValue(NumValueProperty, value);
2421
OnPropertyChanged(new DependencyPropertyChangedEventArgs(NumValueProperty, NumValue - 1, NumValue));
2522
}
2623
}
2724

28-
private int _minNumber = int.MinValue;
29-
public int MinNumber
30-
{
31-
get { return _minNumber; }
32-
set { _minNumber = value; }
33-
}
25+
public int MinNumber { get; set; } = int.MinValue;
3426

35-
private int _maxNumber = int.MaxValue;
36-
public int MaxNumber
37-
{
38-
get { return _maxNumber; }
39-
set { _maxNumber = value; }
40-
}
27+
public int MaxNumber { get; set; } = int.MaxValue;
4128

4229
public NumberPicker()
4330
{

0 commit comments

Comments
 (0)