Skip to content

Commit 54e05d4

Browse files
committed
Rewrote some null checks.
1 parent a3adad5 commit 54e05d4

11 files changed

+22
-67
lines changed

DataExchange/ReClassNetFile.Read.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,10 +214,7 @@ public static Tuple<List<ClassNode>, List<BaseNode>> ReadNodes(Stream input, ReC
214214

215215
using (var project = new ReClassNetProject())
216216
{
217-
if (templateProject != null)
218-
{
219-
templateProject.Classes.ForEach(project.AddClass);
220-
}
217+
templateProject?.Classes.ForEach(project.AddClass);
221218

222219
var file = new ReClassNetFile(project);
223220
file.Load(input, logger);

Debugger/HardwareBreakpoint.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,9 @@ public void Handler(ref DebugEvent evt)
7373
public override bool Equals(object obj)
7474
{
7575
var hwbp = obj as HardwareBreakpoint;
76-
if (hwbp == null)
77-
{
78-
return false;
79-
}
8076

8177
// Two hardware breakpoints are equal if they use the same register.
82-
return Register == hwbp.Register;
78+
return hwbp?.Register == Register;
8379
}
8480

8581
public override int GetHashCode()

Debugger/RemoteDebugger.Handler.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,11 @@ private void HandleExceptionEvent(ref DebugEvent evt)
1111
foreach (var bp in breakpoints)
1212
{
1313
var hwbp = bp as HardwareBreakpoint;
14-
if (hwbp != null)
14+
if (hwbp?.Register == causedBy)
1515
{
16-
if (causedBy == hwbp.Register)
17-
{
18-
hwbp.Handler(ref evt);
16+
hwbp.Handler(ref evt);
1917

20-
break;
21-
}
18+
break;
2219
}
2320
}
2421
}

Debugger/RemoteDebugger.Thread.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,7 @@ private void Terminate(bool join)
107107
{
108108
lock (syncThread)
109109
{
110-
if (thread != null)
111-
{
112-
thread.Join();
113-
}
110+
thread?.Join();
114111
}
115112
}
116113
}

Forms/FoundCodeForm.cs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -184,16 +184,8 @@ private void closeButton_Click(object sender, EventArgs e)
184184
private FoundCodeInfo GetSelectedInfo()
185185
{
186186
var row = foundCodeDataGridView.SelectedRows.Cast<DataGridViewRow>().FirstOrDefault();
187-
if (row != null)
188-
{
189-
var view = row.DataBoundItem as DataRowView;
190-
if (view != null)
191-
{
192-
return view["info"] as FoundCodeInfo;
193-
}
194-
}
195-
196-
return null;
187+
var view = row?.DataBoundItem as DataRowView;
188+
return view?["info"] as FoundCodeInfo;
197189
}
198190

199191
private void StopRecording()

Forms/MainForm.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -654,10 +654,7 @@ private void LoadFileFromPath(string filePath, ref ReClassNetProject project)
654654
Program.Logger.Log(LogLevel.Error, $"The file '{filePath}' has an unknown type.");
655655
break;
656656
}
657-
if (import != null)
658-
{
659-
import.Load(filePath, Program.Logger);
660-
}
657+
import?.Load(filePath, Program.Logger);
661658
}
662659

663660
/// <summary>Loads all symbols for the current process and displays the progress status.</summary>

Forms/ProcessInfoForm.cs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -254,21 +254,13 @@ private Control GetToolStripSourceControl(object sender)
254254
private Module GetSelectedModule()
255255
{
256256
var row = modulesDataGridView.SelectedRows.Cast<DataGridViewRow>().FirstOrDefault()?.DataBoundItem as DataRowView;
257-
if (row != null)
258-
{
259-
return row["module"] as Module;
260-
}
261-
return null;
257+
return row?["module"] as Module;
262258
}
263259

264260
private Section GetSelectedSection()
265261
{
266262
var row = sectionsDataGridView.SelectedRows.Cast<DataGridViewRow>().FirstOrDefault()?.DataBoundItem as DataRowView;
267-
if (row != null)
268-
{
269-
return row["section"] as Section;
270-
}
271-
return null;
263+
return row?["section"] as Section;
272264
}
273265
}
274266
}

Nodes/BaseHexCommentNode.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,10 @@ protected int AddComment(ViewInfo view, int x, int y, float fvalue, IntPtr ivalu
4848
if (module != null)
4949
{
5050
var symbols = view.Memory.Process.Symbols.GetSymbolsForModule(module);
51-
if (symbols != null)
51+
var symbol = symbols?.GetSymbolString(ivalue, module);
52+
if (!string.IsNullOrEmpty(symbol))
5253
{
53-
var symbol = symbols.GetSymbolString(ivalue, module);
54-
if (!string.IsNullOrEmpty(symbol))
55-
{
56-
x = AddText(view, x, y, view.Settings.OffsetColor, HotSpot.ReadOnlyId, symbol) + view.Font.Width;
57-
}
54+
x = AddText(view, x, y, view.Settings.OffsetColor, HotSpot.ReadOnlyId, symbol) + view.Font.Width;
5855
}
5956
}
6057
}

Symbols/SymbolStore.cs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -96,18 +96,15 @@ private void ResolveSearchPath()
9696
{
9797
using (var debuggerKey = vsKey.OpenSubKey($@"{subKeyName}\Debugger"))
9898
{
99-
if (debuggerKey != null)
99+
var symbolCacheDir = debuggerKey?.GetValue("SymbolCacheDir") as string;
100+
if (symbolCacheDir != null)
100101
{
101-
var symbolCacheDir = debuggerKey.GetValue("SymbolCacheDir") as string;
102-
if (symbolCacheDir != null)
102+
if (Directory.Exists(symbolCacheDir))
103103
{
104-
if (Directory.Exists(symbolCacheDir))
105-
{
106-
SymbolCachePath = symbolCacheDir;
107-
}
108-
109-
return;
104+
SymbolCachePath = symbolCacheDir;
110105
}
106+
107+
return;
111108
}
112109
}
113110
}

UI/ClassNodeView.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -282,10 +282,7 @@ private void deleteClassToolStripMenuItem_Click(object sender, EventArgs e)
282282
private void renameClassToolStripMenuItem_Click(object sender, EventArgs e)
283283
{
284284
var treeNode = classesTreeView.SelectedNode;
285-
if (treeNode != null)
286-
{
287-
treeNode.BeginEdit();
288-
}
285+
treeNode?.BeginEdit();
289286
}
290287

291288
private void classesTreeView_AfterLabelEdit(object sender, NodeLabelEditEventArgs e)

UI/MemoryViewControl.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -690,12 +690,8 @@ private void repaintTimer_Tick(object sender, EventArgs e)
690690
private void editBox_Committed(object sender, EventArgs e)
691691
{
692692
var hotspotTextBox = sender as HotSpotTextBox;
693-
if (hotspotTextBox == null)
694-
{
695-
return;
696-
}
697693

698-
var hotSpot = hotspotTextBox.HotSpot;
694+
var hotSpot = hotspotTextBox?.HotSpot;
699695
if (hotSpot != null)
700696
{
701697
try

0 commit comments

Comments
 (0)