Skip to content

Commit 59c52f8

Browse files
committed
C#7 out parameters, String Interpolation, If bracketing {}
1 parent c765112 commit 59c52f8

File tree

12 files changed

+119
-49
lines changed

12 files changed

+119
-49
lines changed

Rubberduck.VBEEditor/SafeComWrappers/Office.Core/CommandBarButton.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public event EventHandler<CommandBarButtonClickEventArgs> Click
3636
((Microsoft.Office.Core.CommandBarButton)Target).Click += Target_Click;
3737
}
3838
_clickHandler += value;
39-
System.Diagnostics.Debug.WriteLine("Added handler for: {0} '{1}' (tag: {2}, hashcode:{3})", Parent.Name, Target.Caption, Tag, Target.GetHashCode());
39+
System.Diagnostics.Debug.WriteLine($"Added handler for: {Parent.Name} '{Target.Caption}' (tag: {Tag}, hashcode:{Target.GetHashCode()})");
4040
}
4141
remove
4242
{
@@ -52,7 +52,7 @@ public event EventHandler<CommandBarButtonClickEventArgs> Click
5252
{
5353
// he's gone, dave.
5454
}
55-
System.Diagnostics.Debug.WriteLine("Removed handler for: {0} '{1}' (tag: {2}, hashcode:{3})", Parent.GetType().Name, Target.Caption, Tag, Target.GetHashCode());
55+
System.Diagnostics.Debug.WriteLine($"Removed handler for: {Parent.GetType().Name} '{Target.Caption}' (tag: {Tag}, hashcode:{Target.GetHashCode()})");
5656
}
5757
}
5858

@@ -67,7 +67,7 @@ private void Target_Click(Microsoft.Office.Core.CommandBarButton ctrl, ref bool
6767
System.Diagnostics.Debug.Assert(handler.GetInvocationList().Length == 1, "Multicast delegate is registered more than once.");
6868

6969
//note: event is fired for every parent the command exists under. not sure why.
70-
System.Diagnostics.Debug.WriteLine("Executing handler for: {0} '{1}' (tag: {2}, hashcode:{3})", Parent.GetType().Name, Target.Caption, Tag, Target.GetHashCode());
70+
System.Diagnostics.Debug.WriteLine($"Executing handler for: {Parent.GetType().Name} '{Target.Caption}' (tag: {Tag}, hashcode:{Target.GetHashCode()})";
7171

7272
var button = new CommandBarButton(ctrl);
7373
var args = new CommandBarButtonClickEventArgs(button);

Rubberduck.VBEEditor/SafeComWrappers/VB6/CodeModule.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,7 @@ private void StripLineNumbers(string[] lines)
117117
for (var line = 0; line < lines.Length; line++)
118118
{
119119
var code = lines[line];
120-
int? lineNumber;
121-
if (!continuing && HasNumberedLine(code, out lineNumber))
120+
if (!continuing && HasNumberedLine(code, out int? lineNumber))
122121
{
123122
var lineNumberLength = lineNumber.ToString().Length;
124123
if (lines[line].Length > lineNumberLength)
@@ -141,9 +140,8 @@ private bool HasNumberedLine(string codeLine, out int? lineNumber)
141140
return false;
142141
}
143142

144-
int line;
145143
var firstToken = codeLine.TrimStart().Split(' ')[0];
146-
if (int.TryParse(firstToken, out line))
144+
if (int.TryParse(firstToken, out int line))
147145
{
148146
lineNumber = line;
149147
return true;
@@ -218,14 +216,12 @@ public int GetProcCountLines(string procName, ProcKind procKind)
218216

219217
public string GetProcOfLine(int line)
220218
{
221-
vbext_ProcKind procKind;
222-
return Target.get_ProcOfLine(line, out procKind);
219+
return Target.get_ProcOfLine(line, out vbext_ProcKind procKind);
223220
}
224221

225222
public ProcKind GetProcKindOfLine(int line)
226223
{
227-
vbext_ProcKind procKind;
228-
Target.get_ProcOfLine(line, out procKind);
224+
Target.get_ProcOfLine(line, out vbext_ProcKind procKind);
229225
return (ProcKind)procKind;
230226
}
231227

Rubberduck.VBEEditor/SafeComWrappers/VB6/CodePane.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,7 @@ public CodePaneView CodePaneView
5050

5151
private Selection GetSelection()
5252
{
53-
int startLine;
54-
int startColumn;
55-
int endLine;
56-
int endColumn;
57-
Target.GetSelection(out startLine, out startColumn, out endLine, out endColumn);
53+
Target.GetSelection(out int startLine, out int startColumn, out int endLine, out int endColumn);
5854

5955
if (endLine > startLine && endColumn == 1)
6056
{

Rubberduck.VBEEditor/SafeComWrappers/VB6/Reference.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public int Minor
3232

3333
public string Version
3434
{
35-
get { return string.Format("{0}.{1}", Major, Minor); }
35+
get { return string.Format($"{Major}.{Minor}"); }
3636
}
3737

3838
public string Description

Rubberduck.VBEEditor/SafeComWrappers/VB6/VBProjects.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ public IVBProject Add(ProjectType type)
4848

4949
public void Remove(IVBProject project)
5050
{
51-
if (IsWrappingNullReference) return;
51+
if (IsWrappingNullReference)
52+
{
53+
return;
54+
}
5255
Target.Remove((VB.VBProject)project.Target);
5356
}
5457

Rubberduck.VBEEditor/SafeComWrappers/VBA/CodeModule.cs

Lines changed: 52 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,11 @@ public string GetLines(Selection selection)
6868
/// <param name="selection"></param>
6969
public void DeleteLines(Selection selection)
7070
{
71-
if (IsWrappingNullReference) return;
71+
if (IsWrappingNullReference)
72+
{
73+
return;
74+
}
75+
7276
DeleteLines(selection.StartLine, selection.LineCount);
7377
}
7478

@@ -78,6 +82,7 @@ public void DeleteLines(Selection selection)
7882
{
7983
return null;
8084
}
85+
8186
return CodePane.GetQualifiedSelection();
8287
}
8388

@@ -88,7 +93,11 @@ public string Content()
8893

8994
public void Clear()
9095
{
91-
if (IsWrappingNullReference) return;
96+
if (IsWrappingNullReference)
97+
{
98+
return;
99+
}
100+
92101
if (Target.CountOfLines > 0)
93102
{
94103
Target.DeleteLines(1, CountOfLines);
@@ -109,37 +118,60 @@ public string ContentHash()
109118

110119
public void AddFromString(string content)
111120
{
112-
if (IsWrappingNullReference) return;
121+
if (IsWrappingNullReference)
122+
{
123+
return;
124+
}
125+
113126
Target.AddFromString(content);
114127
}
115128

116129
public void AddFromFile(string path)
117130
{
118-
if (IsWrappingNullReference) return;
131+
if (IsWrappingNullReference)
132+
{
133+
return;
134+
}
135+
119136
Target.AddFromFile(path);
120137
}
121138

122139
public void InsertLines(int line, string content)
123140
{
124-
if (IsWrappingNullReference) return;
141+
if (IsWrappingNullReference)
142+
{
143+
return;
144+
}
145+
125146
Target.InsertLines(line, content);
126147
}
127148

128149
public void DeleteLines(int startLine, int count = 1)
129150
{
130-
if (IsWrappingNullReference) return;
151+
if (IsWrappingNullReference)
152+
{
153+
return;
154+
}
155+
131156
Target.DeleteLines(startLine, count);
132157
}
133158

134159
public void ReplaceLine(int line, string content)
135160
{
136-
if (IsWrappingNullReference) return;
161+
if (IsWrappingNullReference)
162+
{
163+
return;
164+
}
165+
137166
Target.ReplaceLine(line, content);
138167
}
139168

140169
public Selection? Find(string target, bool wholeWord = false, bool matchCase = false, bool patternSearch = false)
141170
{
142-
if (IsWrappingNullReference) return null;
171+
if (IsWrappingNullReference)
172+
{
173+
return null;
174+
}
143175

144176
var startLine = 0;
145177
var startColumn = 0;
@@ -168,16 +200,22 @@ public int GetProcCountLines(string procName, ProcKind procKind)
168200

169201
public string GetProcOfLine(int line)
170202
{
171-
if (IsWrappingNullReference) return string.Empty;
172-
vbext_ProcKind procKind;
173-
return Target.get_ProcOfLine(line, out procKind);
203+
if (IsWrappingNullReference)
204+
{
205+
return string.Empty;
206+
}
207+
208+
return Target.get_ProcOfLine(line, out vbext_ProcKind procKind);
174209
}
175210

176211
public ProcKind GetProcKindOfLine(int line)
177212
{
178-
if (IsWrappingNullReference) return 0;
179-
vbext_ProcKind procKind;
180-
Target.get_ProcOfLine(line, out procKind);
213+
if (IsWrappingNullReference)
214+
{
215+
return 0;
216+
}
217+
218+
Target.get_ProcOfLine(line, out vbext_ProcKind procKind);
181219
return (ProcKind)procKind;
182220
}
183221

Rubberduck.VBEEditor/SafeComWrappers/VBA/CodePane.cs

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,12 @@ public Selection Selection
5656

5757
private Selection GetSelection()
5858
{
59-
if (IsWrappingNullReference) return new Selection(0, 0, 0, 0);
59+
if (IsWrappingNullReference)
60+
{
61+
return new Selection(0, 0, 0, 0);
62+
}
6063

61-
int startLine;
62-
int startColumn;
63-
int endLine;
64-
int endColumn;
65-
Target.GetSelection(out startLine, out startColumn, out endLine, out endColumn);
64+
Target.GetSelection(out int startLine, out int startColumn, out int endLine, out int endColumn);
6665

6766
if (endLine > startLine && endColumn == 1)
6867
{
@@ -93,14 +92,22 @@ private Selection GetSelection()
9392

9493
private void SetSelection(int startLine, int startColumn, int endLine, int endColumn)
9594
{
96-
if (IsWrappingNullReference) return;
95+
if (IsWrappingNullReference)
96+
{
97+
return;
98+
}
99+
97100
Target.SetSelection(startLine, startColumn, endLine, endColumn);
98101
ForceFocus();
99102
}
100103

101104
private void ForceFocus()
102105
{
103-
if (IsWrappingNullReference) return;
106+
if (IsWrappingNullReference)
107+
{
108+
return;
109+
}
110+
104111
Show();
105112

106113
var window = VBE.MainWindow;
@@ -123,7 +130,11 @@ private void ForceFocus()
123130

124131
public void Show()
125132
{
126-
if (IsWrappingNullReference) return;
133+
if (IsWrappingNullReference)
134+
{
135+
return;
136+
}
137+
127138
Target.Show();
128139
}
129140

Rubberduck.VBEEditor/SafeComWrappers/VBA/LinkedWindows.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,21 @@ public IWindow this[object index]
3434

3535
public void Remove(IWindow window)
3636
{
37-
if (IsWrappingNullReference) return;
37+
if (IsWrappingNullReference)
38+
{
39+
return;
40+
}
41+
3842
Target.Remove(((Window)window).Target);
3943
}
4044

4145
public void Add(IWindow window)
4246
{
43-
if (IsWrappingNullReference) return;
47+
if (IsWrappingNullReference)
48+
{
49+
return;
50+
}
51+
4452
Target.Add(((Window)window).Target);
4553
}
4654

Rubberduck.VBEEditor/SafeComWrappers/VBA/Property.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@ public object GetIndexedValue(object index1, object index2 = null, object index3
5858

5959
public void SetIndexedValue(object value, object index1, object index2 = null, object index3 = null, object index4 = null)
6060
{
61-
if (!IsWrappingNullReference) Target.set_IndexedValue(index1, index2, index3, index4, value);
61+
if (!IsWrappingNullReference)
62+
{
63+
Target.set_IndexedValue(index1, index2, index3, index4, value);
64+
}
6265
}
6366

6467
/// <summary>

Rubberduck.VBEEditor/SafeComWrappers/VBA/References.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,20 @@ public IVBE VBE
6464
private void Target_ItemRemoved(Microsoft.Vbe.Interop.Reference reference)
6565
{
6666
var handler = ItemRemoved;
67-
if (handler == null) { return; }
67+
if (handler == null)
68+
{
69+
return;
70+
}
6871
handler.Invoke(this, new ReferenceEventArgs(new Reference(reference)));
6972
}
7073

7174
private void Target_ItemAdded(Microsoft.Vbe.Interop.Reference reference)
7275
{
7376
var handler = ItemAdded;
74-
if (handler == null) { return; }
77+
if (handler == null)
78+
{
79+
return;
80+
}
7581
handler.Invoke(this, new ReferenceEventArgs(new Reference(reference)));
7682
}
7783

@@ -92,7 +98,10 @@ public IReference AddFromFile(string path)
9298

9399
public void Remove(IReference reference)
94100
{
95-
if (IsWrappingNullReference) return;
101+
if (IsWrappingNullReference)
102+
{
103+
return;
104+
}
96105
Target.Remove(((ISafeComWrapper<VB.Reference>)reference).Target);
97106
}
98107

0 commit comments

Comments
 (0)