Skip to content

Commit feb3fbf

Browse files
committed
Get used to null propagation
1 parent 0b06df4 commit feb3fbf

File tree

11 files changed

+28
-79
lines changed

11 files changed

+28
-79
lines changed

ArchiSteamFarm.sln.DotSettings

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=FS/@EntryIndexedValue">FS</s:String>
1111
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=HTML/@EntryIndexedValue">HTML</s:String>
1212
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=ID/@EntryIndexedValue">ID</s:String>
13+
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=IP/@EntryIndexedValue">IP</s:String>
1314
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=OK/@EntryIndexedValue">OK</s:String>
1415
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=PIN/@EntryIndexedValue">PIN</s:String>
1516
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=SC/@EntryIndexedValue">SC</s:String>

ArchiSteamFarm/ArchiWebHandler.cs

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -377,11 +377,8 @@ internal async Task<Dictionary<uint, string>> GetOwnedGames() {
377377
string request = SteamCommunityURL + "/my/games/?xml=1";
378378

379379
XmlDocument response = await WebBrowser.UrlGetToXMLRetry(request).ConfigureAwait(false);
380-
if (response == null) {
381-
return null;
382-
}
383380

384-
XmlNodeList xmlNodeList = response.SelectNodes("gamesList/games/game");
381+
XmlNodeList xmlNodeList = response?.SelectNodes("gamesList/games/game");
385382
if ((xmlNodeList == null) || (xmlNodeList.Count == 0)) {
386383
return null;
387384
}
@@ -492,11 +489,8 @@ internal uint GetServerTime() {
492489
string request = SteamCommunityURL + "/tradeoffer/" + tradeID + "?l=english";
493490

494491
HtmlDocument htmlDocument = await WebBrowser.UrlGetToHtmlDocumentRetry(request).ConfigureAwait(false);
495-
if (htmlDocument == null) {
496-
return null;
497-
}
498492

499-
HtmlNode htmlNode = htmlDocument.DocumentNode.SelectSingleNode("//div[@class='pagecontent']/script");
493+
HtmlNode htmlNode = htmlDocument?.DocumentNode.SelectSingleNode("//div[@class='pagecontent']/script");
500494
if (htmlNode == null) { // Trade can be no longer valid
501495
return null;
502496
}
@@ -713,11 +707,8 @@ internal bool DeclineTradeOffer(ulong tradeID) {
713707
string request = SteamCommunityURL + "/my/inventory/json/" + Steam.Item.SteamAppID + "/" + Steam.Item.SteamContextID + "?trading=" + (tradable ? "1" : "0") + "&start=" + currentPage;
714708

715709
JObject jObject = await WebBrowser.UrlGetToJObjectRetry(request).ConfigureAwait(false);
716-
if (jObject == null) {
717-
return null;
718-
}
719710

720-
IEnumerable<JToken> descriptions = jObject.SelectTokens("$.rgDescriptions.*");
711+
IEnumerable<JToken> descriptions = jObject?.SelectTokens("$.rgDescriptions.*");
721712
if (descriptions == null) {
722713
return null; // OK, empty inventory
723714
}
@@ -913,11 +904,7 @@ internal async Task<bool> MarkInventory() {
913904
string request = SteamCommunityURL + "/my/videos";
914905

915906
Uri uri = await WebBrowser.UrlHeadToUriRetry(request).ConfigureAwait(false);
916-
if (uri == null) {
917-
return null;
918-
}
919-
920-
return !uri.AbsolutePath.StartsWith("/login", StringComparison.Ordinal);
907+
return !uri?.AbsolutePath.StartsWith("/login", StringComparison.Ordinal);
921908
}
922909

923910
private async Task<bool> RefreshSessionIfNeeded() {

ArchiSteamFarm/Bot.cs

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -252,25 +252,11 @@ public void Dispose() {
252252
LoginSemaphore.Dispose();
253253
HandledGifts.Dispose();
254254

255-
if (AcceptConfirmationsTimer != null) {
256-
AcceptConfirmationsTimer.Dispose();
257-
}
258-
259-
if (ArchiWebHandler != null) {
260-
ArchiWebHandler.Dispose();
261-
}
262-
263-
if (CardsFarmer != null) {
264-
CardsFarmer.Dispose();
265-
}
266-
267-
if (SendItemsTimer != null) {
268-
SendItemsTimer.Dispose();
269-
}
270-
271-
if (Trading != null) {
272-
Trading.Dispose();
273-
}
255+
AcceptConfirmationsTimer?.Dispose();
256+
ArchiWebHandler?.Dispose();
257+
CardsFarmer?.Dispose();
258+
SendItemsTimer?.Dispose();
259+
Trading?.Dispose();
274260
}
275261

276262
internal async Task AcceptConfirmations(bool accept, Steam.ConfirmationDetails.EType acceptedType = Steam.ConfirmationDetails.EType.Unknown, ulong acceptedSteamID = 0, HashSet<ulong> acceptedTradeIDs = null) {
@@ -333,7 +319,7 @@ internal async Task<bool> RefreshSession() {
333319
return false;
334320
}
335321

336-
if ((callback == null) || string.IsNullOrEmpty(callback.Nonce)) {
322+
if (string.IsNullOrEmpty(callback?.Nonce)) {
337323
Start().Forget();
338324
return false;
339325
}
@@ -1609,7 +1595,7 @@ private void OnFreeLicense(SteamApps.FreeLicenseCallback callback) {
16091595
}
16101596

16111597
private async void OnGuestPassList(SteamApps.GuestPassListCallback callback) {
1612-
if ((callback == null) || (callback.GuestPasses == null)) {
1598+
if (callback?.GuestPasses == null) {
16131599
Logging.LogNullError(nameof(callback) + " || " + nameof(callback.GuestPasses), BotName);
16141600
return;
16151601
}
@@ -1647,7 +1633,7 @@ private async void OnGuestPassList(SteamApps.GuestPassListCallback callback) {
16471633
}
16481634

16491635
private void OnChatInvite(SteamFriends.ChatInviteCallback callback) {
1650-
if ((callback == null) || (callback.ChatRoomID == null) || (callback.PatronID == null)) {
1636+
if ((callback?.ChatRoomID == null) || (callback.PatronID == null)) {
16511637
Logging.LogNullError(nameof(callback) + " || " + nameof(callback.ChatRoomID) + " || " + nameof(callback.PatronID), BotName);
16521638
return;
16531639
}
@@ -1689,7 +1675,7 @@ private async void OnChatMsg(SteamFriends.ChatMsgCallback callback) {
16891675
}
16901676

16911677
private void OnFriendsList(SteamFriends.FriendsListCallback callback) {
1692-
if ((callback == null) || (callback.FriendList == null)) {
1678+
if (callback?.FriendList == null) {
16931679
Logging.LogNullError(nameof(callback) + " || " + nameof(callback.FriendList), BotName);
16941680
return;
16951681
}
@@ -1722,7 +1708,7 @@ private async void OnFriendMsg(SteamFriends.FriendMsgCallback callback) {
17221708
}
17231709

17241710
private async void OnFriendMsgHistory(SteamFriends.FriendMsgHistoryCallback callback) {
1725-
if ((callback == null) || (callback.Messages == null) || (callback.SteamID == null)) {
1711+
if ((callback?.Messages == null) || (callback.SteamID == null)) {
17261712
Logging.LogNullError(nameof(callback) + " || " + nameof(callback.Messages) + " || " + nameof(callback.SteamID), BotName);
17271713
return;
17281714
}
@@ -1865,7 +1851,7 @@ private async void OnLoggedOn(SteamUser.LoggedOnCallback callback) {
18651851
}
18661852

18671853
private void OnLoginKey(SteamUser.LoginKeyCallback callback) {
1868-
if ((callback == null) || string.IsNullOrEmpty(callback.LoginKey)) {
1854+
if (string.IsNullOrEmpty(callback?.LoginKey)) {
18691855
Logging.LogNullError(nameof(callback) + " || " + nameof(callback.LoginKey), BotName);
18701856
return;
18711857
}

ArchiSteamFarm/CardsFarmer.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,7 @@ public void Dispose() {
7575
FarmResetEvent.Dispose();
7676
FarmingSemaphore.Dispose();
7777

78-
if (Timer != null) {
79-
Timer.Dispose();
80-
}
78+
Timer?.Dispose();
8179
}
8280

8381
internal async Task SwitchToManualMode(bool manualMode) {

ArchiSteamFarm/ConcurrentEnumerator.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,6 @@ internal ConcurrentEnumerator(ICollection<T> collection, ReaderWriterLockSlim rw
5050
public bool MoveNext() => Enumerator.MoveNext();
5151
public void Reset() => Enumerator.Reset();
5252

53-
public void Dispose() {
54-
if (Lock != null) {
55-
Lock.ExitReadLock();
56-
}
57-
}
53+
public void Dispose() => Lock?.ExitReadLock();
5854
}
5955
}

ArchiSteamFarm/ConcurrentHashSet.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,7 @@ public bool Remove(T item) {
100100
}
101101
}
102102

103-
public void Dispose() {
104-
if (Lock != null) {
105-
Lock.Dispose();
106-
}
107-
}
103+
public void Dispose() => Lock?.Dispose();
108104

109105
public void CopyTo(T[] array, int arrayIndex) {
110106
Lock.EnterReadLock();

ArchiSteamFarm/GlobalDatabase.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,7 @@ internal static GlobalDatabase Load(string filePath) {
9191
return globalDatabase;
9292
}
9393

94-
private void OnServerListUpdated(object sender, EventArgs e) {
95-
if ((sender == null) || (e == null)) {
96-
Logging.LogNullError(nameof(sender) + " || " + nameof(e));
97-
return;
98-
}
99-
100-
Save();
101-
}
94+
private void OnServerListUpdated(object sender, EventArgs e) => Save();
10295

10396
// This constructor is used when creating new database
10497
private GlobalDatabase(string filePath) : this() {

ArchiSteamFarm/MobileAuthenticator.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,8 @@ internal async Task<HashSet<Confirmation>> GetConfirmations() {
173173
}
174174

175175
HtmlDocument htmlDocument = await Bot.ArchiWebHandler.GetConfirmations(DeviceID, confirmationHash, time).ConfigureAwait(false);
176-
if (htmlDocument == null) {
177-
return null;
178-
}
179176

180-
HtmlNodeCollection confirmationNodes = htmlDocument.DocumentNode.SelectNodes("//div[@class='mobileconf_list_entry']");
177+
HtmlNodeCollection confirmationNodes = htmlDocument?.DocumentNode.SelectNodes("//div[@class='mobileconf_list_entry']");
181178
if (confirmationNodes == null) {
182179
return null;
183180
}

ArchiSteamFarm/Program.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -437,17 +437,17 @@ private static void ParseArgs(IEnumerable<string> args) {
437437
}
438438

439439
private static void UnhandledExceptionHandler(object sender, UnhandledExceptionEventArgs args) {
440-
if ((sender == null) || (args == null) || (args.ExceptionObject == null)) {
441-
Logging.LogNullError(nameof(sender) + " || " + nameof(args) + " || " + nameof(args.ExceptionObject));
440+
if (args?.ExceptionObject == null) {
441+
Logging.LogNullError(nameof(args) + " || " + nameof(args.ExceptionObject));
442442
return;
443443
}
444444

445445
Logging.LogFatalException((Exception) args.ExceptionObject);
446446
}
447447

448448
private static void UnobservedTaskExceptionHandler(object sender, UnobservedTaskExceptionEventArgs args) {
449-
if ((sender == null) || (args == null) || (args.Exception == null)) {
450-
Logging.LogNullError(nameof(sender) + " || " + nameof(args) + " || " + nameof(args.Exception));
449+
if (args?.Exception == null) {
450+
Logging.LogNullError(nameof(args) + " || " + nameof(args.Exception));
451451
return;
452452
}
453453

ArchiSteamFarm/WCF.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,8 @@ public string HandleCommand(string input) {
7575
}
7676

7777
public void Dispose() {
78-
if (ServiceHost != null) {
79-
ServiceHost.Close();
80-
}
81-
82-
if (Client != null) {
83-
Client.Close();
84-
}
78+
ServiceHost?.Close();
79+
Client?.Close();
8580
}
8681

8782
internal bool IsServerRunning() => ServiceHost != null;

0 commit comments

Comments
 (0)