From e3534f4440dc3ad3616e85a204304a155f399847 Mon Sep 17 00:00:00 2001 From: JustArchi Date: Sat, 1 Oct 2016 00:36:48 +0200 Subject: [PATCH] Code review --- ArchiSteamFarm/ArchiWebHandler.cs | 8 ++++---- ArchiSteamFarm/JSON/Steam.cs | 30 +++++++----------------------- 2 files changed, 11 insertions(+), 27 deletions(-) diff --git a/ArchiSteamFarm/ArchiWebHandler.cs b/ArchiSteamFarm/ArchiWebHandler.cs index 51d5da00f..fa69b7d26 100644 --- a/ArchiSteamFarm/ArchiWebHandler.cs +++ b/ArchiSteamFarm/ArchiWebHandler.cs @@ -138,7 +138,7 @@ namespace ArchiSteamFarm { return false; } - uint realAppID = 0; + uint realAppID = appID; Steam.Item.EType type = Steam.Item.EType.Unknown; Tuple description; @@ -820,12 +820,12 @@ namespace ArchiSteamFarm { } bool more; - if (!bool.TryParse(jObject["more"].ToString(), out more) || !more) { + if (!bool.TryParse(jObject["more"]?.ToString(), out more) || !more) { break; // OK, last page } uint nextPage; - if (!uint.TryParse(jObject["more_start"].ToString(), out nextPage) || (nextPage <= currentPage)) { + if (!uint.TryParse(jObject["more_start"]?.ToString(), out nextPage) || (nextPage <= currentPage)) { Logging.LogNullError(nameof(nextPage), Bot.BotName); return null; } @@ -867,7 +867,7 @@ namespace ArchiSteamFarm { itemID = 0; } - singleTrade.ItemsToGive.Assets.Add(new Steam.Item(Steam.Item.SteamAppID, Steam.Item.SteamCommunityContextID, item.AssetID, item.Amount)); + singleTrade.ItemsToGive.Assets.Add(item); itemID++; } diff --git a/ArchiSteamFarm/JSON/Steam.cs b/ArchiSteamFarm/JSON/Steam.cs index 73f30de0e..1ecc33720 100644 --- a/ArchiSteamFarm/JSON/Steam.cs +++ b/ArchiSteamFarm/JSON/Steam.cs @@ -101,7 +101,7 @@ namespace ArchiSteamFarm.JSON { } } - internal ulong AssetID { get; private set; } + private ulong AssetID; [JsonProperty(PropertyName = "assetid", Required = Required.DisallowNull)] private string AssetIDString { @@ -184,38 +184,22 @@ namespace ArchiSteamFarm.JSON { internal uint RealAppID { get; set; } internal EType Type { get; set; } - // This constructor is used for constructing items in trades being sent - internal Item(uint appID, ulong contextID, ulong assetID, uint amount) : this(appID, contextID, amount) { - if (assetID == 0) { - throw new ArgumentNullException(nameof(assetID)); - } - - AssetID = assetID; - } - // This constructor is used for constructing items in trades being received - internal Item(uint appID, ulong contextID, ulong classID, uint amount, uint realAppID, EType type) : this(appID, contextID, amount) { - if (classID == 0) { - throw new ArgumentNullException(nameof(classID)); + internal Item(uint appID, ulong contextID, ulong classID, uint amount, uint realAppID, EType type) { + if ((appID == 0) || (contextID == 0) || (classID == 0) || (amount == 0) || (realAppID == 0)) { + throw new ArgumentNullException(nameof(classID) + " || " + nameof(contextID) + " || " + nameof(classID) + " || " + nameof(amount) + " || " + nameof(realAppID)); } + AppID = appID; + ContextID = contextID; ClassID = classID; + Amount = amount; RealAppID = realAppID; Type = type; } [SuppressMessage("ReSharper", "UnusedMember.Local")] private Item() { } - - private Item(uint appID, ulong contextID, uint amount) { - if ((appID == 0) || (contextID == 0) || (amount == 0)) { - throw new ArgumentNullException(nameof(appID) + " || " + nameof(contextID) + " || " + nameof(amount)); - } - - AppID = appID; - ContextID = contextID; - Amount = amount; - } } internal sealed class TradeOffer { // REF: https://developer.valvesoftware.com/wiki/Steam_Web_API/IEconService#CEcon_TradeOffer | Constructed from code