C# 7.0 syntax sugars

This commit is contained in:
Bruno Logerfo
2017-03-14 08:20:29 -03:00
parent 6c8a123b68
commit f8b2fcda7a
14 changed files with 62 additions and 150 deletions

View File

@@ -41,13 +41,7 @@ namespace ArchiSteamFarm {
internal DateTime LastPacketReceived { get; private set; } = DateTime.MinValue; internal DateTime LastPacketReceived { get; private set; } = DateTime.MinValue;
internal ArchiHandler(ArchiLogger archiLogger) { internal ArchiHandler(ArchiLogger archiLogger) => ArchiLogger = archiLogger ?? throw new ArgumentNullException(nameof(archiLogger));
if (archiLogger == null) {
throw new ArgumentNullException(nameof(archiLogger));
}
ArchiLogger = archiLogger;
}
public override void HandleMsg(IPacketMsg packetMsg) { public override void HandleMsg(IPacketMsg packetMsg) {
if (packetMsg == null) { if (packetMsg == null) {

View File

@@ -69,12 +69,7 @@ namespace ArchiSteamFarm {
private ulong SteamID; private ulong SteamID;
internal ArchiWebHandler(Bot bot) { internal ArchiWebHandler(Bot bot) {
if (bot == null) { Bot = bot ?? throw new ArgumentNullException(nameof(bot));
throw new ArgumentNullException(nameof(bot));
}
Bot = bot;
WebBrowser = new WebBrowser(bot.ArchiLogger); WebBrowser = new WebBrowser(bot.ArchiLogger);
} }
@@ -417,8 +412,7 @@ namespace ArchiSteamFarm {
return null; return null;
} }
uint steamID3; if (!uint.TryParse(miniProfile, out uint steamID3) || (steamID3 == 0)) {
if (!uint.TryParse(miniProfile, out steamID3) || (steamID3 == 0)) {
Bot.ArchiLogger.LogNullError(nameof(steamID3)); Bot.ArchiLogger.LogNullError(nameof(steamID3));
return null; return null;
} }
@@ -466,8 +460,7 @@ namespace ArchiSteamFarm {
return null; return null;
} }
uint appID; if (!uint.TryParse(appNode.InnerText, out uint appID)) {
if (!uint.TryParse(appNode.InnerText, out appID)) {
Bot.ArchiLogger.LogNullError(nameof(appID)); Bot.ArchiLogger.LogNullError(nameof(appID));
return null; return null;
} }
@@ -515,8 +508,7 @@ namespace ArchiSteamFarm {
continue; continue;
} }
ulong classID; if (!ulong.TryParse(classIDString, out ulong classID) || (classID == 0)) {
if (!ulong.TryParse(classIDString, out classID) || (classID == 0)) {
Bot.ArchiLogger.LogNullError(nameof(classID)); Bot.ArchiLogger.LogNullError(nameof(classID));
continue; continue;
} }
@@ -579,8 +571,7 @@ namespace ArchiSteamFarm {
steamItem.AppID = Steam.Item.SteamAppID; steamItem.AppID = Steam.Item.SteamAppID;
steamItem.ContextID = Steam.Item.SteamCommunityContextID; steamItem.ContextID = Steam.Item.SteamCommunityContextID;
Tuple<uint, Steam.Item.EType> description; if (descriptionMap.TryGetValue(steamItem.ClassID, out Tuple<uint, Steam.Item.EType> description)) {
if (descriptionMap.TryGetValue(steamItem.ClassID, out description)) {
steamItem.RealAppID = description.Item1; steamItem.RealAppID = description.Item1;
steamItem.Type = description.Item2; steamItem.Type = description.Item2;
} }
@@ -592,13 +583,11 @@ namespace ArchiSteamFarm {
result.Add(steamItem); result.Add(steamItem);
} }
bool more; if (!bool.TryParse(jObject["more"]?.ToString(), out bool more) || !more) {
if (!bool.TryParse(jObject["more"]?.ToString(), out more) || !more) {
break; // OK, last page break; // OK, last page
} }
uint nextPage; if (!uint.TryParse(jObject["more_start"]?.ToString(), out uint nextPage) || (nextPage <= currentPage)) {
if (!uint.TryParse(jObject["more_start"]?.ToString(), out nextPage) || (nextPage <= currentPage)) {
Bot.ArchiLogger.LogNullError(nameof(nextPage)); Bot.ArchiLogger.LogNullError(nameof(nextPage));
return null; return null;
} }
@@ -738,8 +727,7 @@ namespace ArchiSteamFarm {
text = text.Substring(0, index); text = text.Substring(0, index);
byte holdDuration; if (byte.TryParse(text, out byte holdDuration)) {
if (byte.TryParse(text, out holdDuration)) {
return holdDuration; return holdDuration;
} }
@@ -1193,8 +1181,7 @@ namespace ArchiSteamFarm {
return 0; return 0;
} }
uint appID; return uint.TryParse(hashName.Substring(0, index), out uint appID) ? appID : 0;
return uint.TryParse(hashName.Substring(0, index), out appID) ? appID : 0;
} }
private static Steam.Item.EType GetItemType(string name) { private static Steam.Item.EType GetItemType(string name) {
@@ -1287,8 +1274,7 @@ namespace ArchiSteamFarm {
uint realAppID = appID; uint realAppID = appID;
Steam.Item.EType type = Steam.Item.EType.Unknown; Steam.Item.EType type = Steam.Item.EType.Unknown;
Tuple<uint, Steam.Item.EType> description; if (descriptions.TryGetValue(classID, out Tuple<uint, Steam.Item.EType> description)) {
if (descriptions.TryGetValue(classID, out description)) {
realAppID = description.Item1; realAppID = description.Item1;
type = description.Item2; type = description.Item2;
} }

View File

@@ -347,8 +347,7 @@ namespace ArchiSteamFarm {
} }
foreach (Dictionary<uint, SteamApps.PICSProductInfoCallback.PICSProductInfo> productInfoApps in productInfoResultSet.Results.Select(result => result.Apps)) { foreach (Dictionary<uint, SteamApps.PICSProductInfoCallback.PICSProductInfo> productInfoApps in productInfoResultSet.Results.Select(result => result.Apps)) {
SteamApps.PICSProductInfoCallback.PICSProductInfo productInfoApp; if (!productInfoApps.TryGetValue(appID, out SteamApps.PICSProductInfoCallback.PICSProductInfo productInfoApp)) {
if (!productInfoApps.TryGetValue(appID, out productInfoApp)) {
continue; continue;
} }
@@ -418,8 +417,7 @@ namespace ArchiSteamFarm {
string[] dlcAppIDsString = listOfDlc.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); string[] dlcAppIDsString = listOfDlc.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
foreach (string dlcAppIDString in dlcAppIDsString) { foreach (string dlcAppIDString in dlcAppIDsString) {
uint dlcAppID; if (!uint.TryParse(dlcAppIDString, out uint dlcAppID) || (dlcAppID == 0)) {
if (!uint.TryParse(dlcAppIDString, out dlcAppID) || (dlcAppID == 0)) {
ArchiLogger.LogNullError(nameof(dlcAppID)); ArchiLogger.LogNullError(nameof(dlcAppID));
break; break;
} }
@@ -784,8 +782,7 @@ namespace ArchiSteamFarm {
Task.Run(() => Stop()).Forget(); Task.Run(() => Stop()).Forget();
} }
Bot ignored; Bots.TryRemove(BotName, out Bot ignored);
Bots.TryRemove(BotName, out ignored);
} }
private void Disconnect() { private void Disconnect() {
@@ -832,8 +829,7 @@ namespace ArchiSteamFarm {
if (botName.Contains("..")) { if (botName.Contains("..")) {
string[] botRange = botName.Split(new[] { ".." }, StringSplitOptions.RemoveEmptyEntries); string[] botRange = botName.Split(new[] { ".." }, StringSplitOptions.RemoveEmptyEntries);
if (botRange.Length == 2) { if (botRange.Length == 2) {
Bot firstBot, lastBot; if (Bots.TryGetValue(botRange[0], out Bot firstBot) && Bots.TryGetValue(botRange[1], out Bot lastBot)) {
if (Bots.TryGetValue(botRange[0], out firstBot) && Bots.TryGetValue(botRange[1], out lastBot)) {
bool inRange = false; bool inRange = false;
foreach (Bot bot in Bots.OrderBy(bot => bot.Key).Select(bot => bot.Value)) { foreach (Bot bot in Bots.OrderBy(bot => bot.Key).Select(bot => bot.Value)) {
@@ -855,8 +851,7 @@ namespace ArchiSteamFarm {
} }
} }
Bot targetBot; if (!Bots.TryGetValue(botName, out Bot targetBot)) {
if (!Bots.TryGetValue(botName, out targetBot)) {
continue; continue;
} }
@@ -1947,8 +1942,7 @@ namespace ArchiSteamFarm {
HashSet<uint> gamesToRedeem = new HashSet<uint>(); HashSet<uint> gamesToRedeem = new HashSet<uint>();
foreach (string game in gameIDs) { foreach (string game in gameIDs) {
uint gameID; if (!uint.TryParse(game, out uint gameID) || (gameID == 0)) {
if (!uint.TryParse(game, out gameID) || (gameID == 0)) {
return FormatBotResponse(string.Format(Strings.ErrorParsingObject, nameof(gameID))); return FormatBotResponse(string.Format(Strings.ErrorParsingObject, nameof(gameID)));
} }
@@ -2108,8 +2102,7 @@ namespace ArchiSteamFarm {
return FormatBotResponse(Strings.ErrorFunctionOnlyInHeadlessMode); return FormatBotResponse(Strings.ErrorFunctionOnlyInHeadlessMode);
} }
ASF.EUserInputType inputType; if (!Enum.TryParse(propertyName, true, out ASF.EUserInputType inputType) || (inputType == ASF.EUserInputType.Unknown)) {
if (!Enum.TryParse(propertyName, true, out inputType) || (inputType == ASF.EUserInputType.Unknown)) {
return FormatBotResponse(string.Format(Strings.ErrorIsInvalid, nameof(inputType))); return FormatBotResponse(string.Format(Strings.ErrorIsInvalid, nameof(inputType)));
} }
@@ -2310,15 +2303,13 @@ namespace ArchiSteamFarm {
foreach (string game in games) { foreach (string game in games) {
// Check if this is gameID // Check if this is gameID
uint gameID; if (uint.TryParse(game, out uint gameID) && (gameID != 0)) {
if (uint.TryParse(game, out gameID) && (gameID != 0)) {
if (OwnedPackageIDs.Contains(gameID)) { if (OwnedPackageIDs.Contains(gameID)) {
response.Append(FormatBotResponse(string.Format(Strings.BotOwnedAlready, gameID))); response.Append(FormatBotResponse(string.Format(Strings.BotOwnedAlready, gameID)));
continue; continue;
} }
string ownedName; response.Append(FormatBotResponse(ownedGames.TryGetValue(gameID, out string ownedName) ? string.Format(Strings.BotOwnedAlreadyWithName, gameID, ownedName) : string.Format(Strings.BotNotOwnedYet, gameID)));
response.Append(FormatBotResponse(ownedGames.TryGetValue(gameID, out ownedName) ? string.Format(Strings.BotOwnedAlreadyWithName, gameID, ownedName) : string.Format(Strings.BotNotOwnedYet, gameID)));
continue; continue;
} }
@@ -2509,8 +2500,7 @@ namespace ArchiSteamFarm {
HashSet<uint> gamesToPlay = new HashSet<uint>(); HashSet<uint> gamesToPlay = new HashSet<uint>();
foreach (string game in gameIDs) { foreach (string game in gameIDs) {
uint gameID; if (!uint.TryParse(game, out uint gameID)) {
if (!uint.TryParse(game, out gameID)) {
return FormatBotResponse(string.Format(Strings.ErrorParsingObject, nameof(gameID))); return FormatBotResponse(string.Format(Strings.ErrorParsingObject, nameof(gameID)));
} }

View File

@@ -33,7 +33,7 @@ namespace ArchiSteamFarm {
private readonly object FileLock = new object(); private readonly object FileLock = new object();
internal string LoginKey { internal string LoginKey {
get { return _LoginKey; } get => _LoginKey;
set { set {
if (_LoginKey == value) { if (_LoginKey == value) {
@@ -46,7 +46,7 @@ namespace ArchiSteamFarm {
} }
internal MobileAuthenticator MobileAuthenticator { internal MobileAuthenticator MobileAuthenticator {
get { return _MobileAuthenticator; } get => _MobileAuthenticator;
set { set {
if (_MobileAuthenticator == value) { if (_MobileAuthenticator == value) {

View File

@@ -69,11 +69,7 @@ namespace ArchiSteamFarm {
private bool StickyPause; private bool StickyPause;
internal CardsFarmer(Bot bot) { internal CardsFarmer(Bot bot) {
if (bot == null) { Bot = bot ?? throw new ArgumentNullException(nameof(bot));
throw new ArgumentNullException(nameof(bot));
}
Bot = bot;
if (Program.GlobalConfig.IdleFarmingPeriod > 0) { if (Program.GlobalConfig.IdleFarmingPeriod > 0) {
IdleFarmingTimer = new Timer( IdleFarmingTimer = new Timer(
@@ -340,8 +336,7 @@ namespace ArchiSteamFarm {
appIDString = appIDSplitted[4]; appIDString = appIDSplitted[4];
uint appID; if (!uint.TryParse(appIDString, out uint appID) || (appID == 0)) {
if (!uint.TryParse(appIDString, out appID) || (appID == 0)) {
Bot.ArchiLogger.LogNullError(nameof(appID)); Bot.ArchiLogger.LogNullError(nameof(appID));
continue; continue;
} }
@@ -351,8 +346,7 @@ namespace ArchiSteamFarm {
continue; continue;
} }
DateTime lastPICSReport; if (IgnoredAppIDs.TryGetValue(appID, out DateTime lastPICSReport)) {
if (IgnoredAppIDs.TryGetValue(appID, out lastPICSReport)) {
if (lastPICSReport.AddHours(HoursToIgnore) < DateTime.UtcNow) { if (lastPICSReport.AddHours(HoursToIgnore) < DateTime.UtcNow) {
// This game served its time as being ignored // This game served its time as being ignored
IgnoredAppIDs.TryRemove(appID, out lastPICSReport); IgnoredAppIDs.TryRemove(appID, out lastPICSReport);
@@ -409,8 +403,7 @@ namespace ArchiSteamFarm {
continue; continue;
} }
ushort cardsEarned; if (!ushort.TryParse(cardsEarnedMatch.Value, out ushort cardsEarned)) {
if (!ushort.TryParse(cardsEarnedMatch.Value, out cardsEarned)) {
Bot.ArchiLogger.LogNullError(nameof(cardsEarned)); Bot.ArchiLogger.LogNullError(nameof(cardsEarned));
continue; continue;
} }
@@ -681,8 +674,7 @@ namespace ArchiSteamFarm {
return 0; return 0;
} }
ushort cardsRemaining; if (ushort.TryParse(match.Value, out ushort cardsRemaining) && (cardsRemaining != 0)) {
if (ushort.TryParse(match.Value, out cardsRemaining) && (cardsRemaining != 0)) {
return cardsRemaining; return cardsRemaining;
} }

View File

@@ -46,7 +46,7 @@ namespace ArchiSteamFarm {
private readonly object FileLock = new object(); private readonly object FileLock = new object();
internal uint CellID { internal uint CellID {
get { return _CellID; } get => _CellID;
set { set {
if ((value == 0) || (_CellID == value)) { if ((value == 0) || (_CellID == value)) {
return; return;

View File

@@ -178,7 +178,7 @@ namespace ArchiSteamFarm.JSON {
} }
internal MobileAuthenticator.Confirmation Confirmation { internal MobileAuthenticator.Confirmation Confirmation {
get { return _Confirmation; } get => _Confirmation;
set { set {
if (value == null) { if (value == null) {
@@ -237,7 +237,7 @@ namespace ArchiSteamFarm.JSON {
[JsonProperty(PropertyName = "amount", Required = Required.Always)] [JsonProperty(PropertyName = "amount", Required = Required.Always)]
[SuppressMessage("ReSharper", "UnusedMember.Local")] [SuppressMessage("ReSharper", "UnusedMember.Local")]
private string AmountString { private string AmountString {
get { return Amount.ToString(); } get => Amount.ToString();
set { set {
if (string.IsNullOrEmpty(value)) { if (string.IsNullOrEmpty(value)) {
@@ -245,8 +245,7 @@ namespace ArchiSteamFarm.JSON {
return; return;
} }
uint amount; if (!uint.TryParse(value, out uint amount) || (amount == 0)) {
if (!uint.TryParse(value, out amount) || (amount == 0)) {
ASF.ArchiLogger.LogNullError(nameof(amount)); ASF.ArchiLogger.LogNullError(nameof(amount));
return; return;
} }
@@ -258,7 +257,7 @@ namespace ArchiSteamFarm.JSON {
[JsonProperty(PropertyName = "appid", Required = Required.DisallowNull)] [JsonProperty(PropertyName = "appid", Required = Required.DisallowNull)]
[SuppressMessage("ReSharper", "UnusedMember.Local")] [SuppressMessage("ReSharper", "UnusedMember.Local")]
private string AppIDString { private string AppIDString {
get { return AppID.ToString(); } get => AppID.ToString();
set { set {
if (string.IsNullOrEmpty(value)) { if (string.IsNullOrEmpty(value)) {
@@ -266,8 +265,7 @@ namespace ArchiSteamFarm.JSON {
return; return;
} }
uint appID; if (!uint.TryParse(value, out uint appID) || (appID == 0)) {
if (!uint.TryParse(value, out appID) || (appID == 0)) {
ASF.ArchiLogger.LogNullError(nameof(appID)); ASF.ArchiLogger.LogNullError(nameof(appID));
return; return;
} }
@@ -278,7 +276,7 @@ namespace ArchiSteamFarm.JSON {
[JsonProperty(PropertyName = "assetid", Required = Required.DisallowNull)] [JsonProperty(PropertyName = "assetid", Required = Required.DisallowNull)]
private string AssetIDString { private string AssetIDString {
get { return AssetID.ToString(); } get => AssetID.ToString();
set { set {
if (string.IsNullOrEmpty(value)) { if (string.IsNullOrEmpty(value)) {
@@ -286,8 +284,7 @@ namespace ArchiSteamFarm.JSON {
return; return;
} }
ulong assetID; if (!ulong.TryParse(value, out ulong assetID) || (assetID == 0)) {
if (!ulong.TryParse(value, out assetID) || (assetID == 0)) {
ASF.ArchiLogger.LogNullError(nameof(assetID)); ASF.ArchiLogger.LogNullError(nameof(assetID));
return; return;
} }
@@ -299,7 +296,7 @@ namespace ArchiSteamFarm.JSON {
[JsonProperty(PropertyName = "classid", Required = Required.DisallowNull)] [JsonProperty(PropertyName = "classid", Required = Required.DisallowNull)]
[SuppressMessage("ReSharper", "UnusedMember.Local")] [SuppressMessage("ReSharper", "UnusedMember.Local")]
private string ClassIDString { private string ClassIDString {
get { return ClassID.ToString(); } get => ClassID.ToString();
set { set {
if (string.IsNullOrEmpty(value)) { if (string.IsNullOrEmpty(value)) {
@@ -307,8 +304,7 @@ namespace ArchiSteamFarm.JSON {
return; return;
} }
ulong classID; if (!ulong.TryParse(value, out ulong classID) || (classID == 0)) {
if (!ulong.TryParse(value, out classID) || (classID == 0)) {
return; return;
} }
@@ -319,7 +315,7 @@ namespace ArchiSteamFarm.JSON {
[JsonProperty(PropertyName = "contextid", Required = Required.DisallowNull)] [JsonProperty(PropertyName = "contextid", Required = Required.DisallowNull)]
[SuppressMessage("ReSharper", "UnusedMember.Local")] [SuppressMessage("ReSharper", "UnusedMember.Local")]
private string ContextIDString { private string ContextIDString {
get { return ContextID.ToString(); } get => ContextID.ToString();
set { set {
if (string.IsNullOrEmpty(value)) { if (string.IsNullOrEmpty(value)) {
@@ -327,8 +323,7 @@ namespace ArchiSteamFarm.JSON {
return; return;
} }
ulong contextID; if (!ulong.TryParse(value, out ulong contextID) || (contextID == 0)) {
if (!ulong.TryParse(value, out contextID) || (contextID == 0)) {
ASF.ArchiLogger.LogNullError(nameof(contextID)); ASF.ArchiLogger.LogNullError(nameof(contextID));
return; return;
} }
@@ -340,8 +335,8 @@ namespace ArchiSteamFarm.JSON {
[JsonProperty(PropertyName = "id", Required = Required.DisallowNull)] [JsonProperty(PropertyName = "id", Required = Required.DisallowNull)]
[SuppressMessage("ReSharper", "UnusedMember.Local")] [SuppressMessage("ReSharper", "UnusedMember.Local")]
private string ID { private string ID {
get { return AssetIDString; } get => AssetIDString;
set { AssetIDString = value; } set => AssetIDString = value;
} }
// Constructed from trades being received // Constructed from trades being received
@@ -440,13 +435,11 @@ namespace ArchiSteamFarm.JSON {
internal bool IsFairTypesExchange() { internal bool IsFairTypesExchange() {
Dictionary<uint, Dictionary<Item.EType, uint>> itemsToGivePerGame = new Dictionary<uint, Dictionary<Item.EType, uint>>(); Dictionary<uint, Dictionary<Item.EType, uint>> itemsToGivePerGame = new Dictionary<uint, Dictionary<Item.EType, uint>>();
foreach (Item item in ItemsToGive) { foreach (Item item in ItemsToGive) {
Dictionary<Item.EType, uint> itemsPerType; if (!itemsToGivePerGame.TryGetValue(item.RealAppID, out Dictionary<Item.EType, uint> itemsPerType)) {
if (!itemsToGivePerGame.TryGetValue(item.RealAppID, out itemsPerType)) {
itemsPerType = new Dictionary<Item.EType, uint> { [item.Type] = item.Amount }; itemsPerType = new Dictionary<Item.EType, uint> { [item.Type] = item.Amount };
itemsToGivePerGame[item.RealAppID] = itemsPerType; itemsToGivePerGame[item.RealAppID] = itemsPerType;
} else { } else {
uint amount; if (itemsPerType.TryGetValue(item.Type, out uint amount)) {
if (itemsPerType.TryGetValue(item.Type, out amount)) {
itemsPerType[item.Type] = amount + item.Amount; itemsPerType[item.Type] = amount + item.Amount;
} else { } else {
itemsPerType[item.Type] = item.Amount; itemsPerType[item.Type] = item.Amount;
@@ -456,16 +449,14 @@ namespace ArchiSteamFarm.JSON {
Dictionary<uint, Dictionary<Item.EType, uint>> itemsToReceivePerGame = new Dictionary<uint, Dictionary<Item.EType, uint>>(); Dictionary<uint, Dictionary<Item.EType, uint>> itemsToReceivePerGame = new Dictionary<uint, Dictionary<Item.EType, uint>>();
foreach (Item item in ItemsToReceive) { foreach (Item item in ItemsToReceive) {
Dictionary<Item.EType, uint> itemsPerType; if (!itemsToReceivePerGame.TryGetValue(item.RealAppID, out Dictionary<Item.EType, uint> itemsPerType)) {
if (!itemsToReceivePerGame.TryGetValue(item.RealAppID, out itemsPerType)) {
itemsPerType = new Dictionary<Item.EType, uint> { itemsPerType = new Dictionary<Item.EType, uint> {
{ item.Type, item.Amount } { item.Type, item.Amount }
}; };
itemsToReceivePerGame[item.RealAppID] = itemsPerType; itemsToReceivePerGame[item.RealAppID] = itemsPerType;
} else { } else {
uint amount; if (itemsPerType.TryGetValue(item.Type, out uint amount)) {
if (itemsPerType.TryGetValue(item.Type, out amount)) {
itemsPerType[item.Type] = amount + item.Amount; itemsPerType[item.Type] = amount + item.Amount;
} else { } else {
itemsPerType[item.Type] = item.Amount; itemsPerType[item.Type] = item.Amount;
@@ -475,14 +466,12 @@ namespace ArchiSteamFarm.JSON {
// Ensure that amount of items to give is at least amount of items to receive (per game and per type) // Ensure that amount of items to give is at least amount of items to receive (per game and per type)
foreach (KeyValuePair<uint, Dictionary<Item.EType, uint>> itemsPerGame in itemsToGivePerGame) { foreach (KeyValuePair<uint, Dictionary<Item.EType, uint>> itemsPerGame in itemsToGivePerGame) {
Dictionary<Item.EType, uint> otherItemsPerType; if (!itemsToReceivePerGame.TryGetValue(itemsPerGame.Key, out Dictionary<Item.EType, uint> otherItemsPerType)) {
if (!itemsToReceivePerGame.TryGetValue(itemsPerGame.Key, out otherItemsPerType)) {
return false; return false;
} }
foreach (KeyValuePair<Item.EType, uint> itemsPerType in itemsPerGame.Value) { foreach (KeyValuePair<Item.EType, uint> itemsPerType in itemsPerGame.Value) {
uint otherAmount; if (!otherItemsPerType.TryGetValue(itemsPerType.Key, out uint otherAmount)) {
if (!otherItemsPerType.TryGetValue(itemsPerType.Key, out otherAmount)) {
return false; return false;
} }

View File

@@ -154,8 +154,7 @@ namespace ArchiSteamFarm {
return null; return null;
} }
uint id; if (!uint.TryParse(idString, out uint id) || (id == 0)) {
if (!uint.TryParse(idString, out id) || (id == 0)) {
Bot.ArchiLogger.LogNullError(nameof(id)); Bot.ArchiLogger.LogNullError(nameof(id));
return null; return null;
} }
@@ -166,8 +165,7 @@ namespace ArchiSteamFarm {
return null; return null;
} }
ulong key; if (!ulong.TryParse(keyString, out ulong key) || (key == 0)) {
if (!ulong.TryParse(keyString, out key) || (key == 0)) {
Bot.ArchiLogger.LogNullError(nameof(key)); Bot.ArchiLogger.LogNullError(nameof(key));
return null; return null;
} }
@@ -248,13 +246,7 @@ namespace ArchiSteamFarm {
} }
} }
internal void Init(Bot bot) { internal void Init(Bot bot) => Bot = bot ?? throw new ArgumentNullException(nameof(bot));
if (bot == null) {
throw new ArgumentNullException(nameof(bot));
}
Bot = bot;
}
internal static async Task OnTimeChanged() { internal static async Task OnTimeChanged() {
await TimeSemaphore.WaitAsync().ConfigureAwait(false); await TimeSemaphore.WaitAsync().ConfigureAwait(false);

View File

@@ -48,13 +48,7 @@ namespace ArchiSteamFarm {
private string LastNickname; private string LastNickname;
private bool ShouldSendHeartBeats; private bool ShouldSendHeartBeats;
internal Statistics(Bot bot) { internal Statistics(Bot bot) => Bot = bot ?? throw new ArgumentNullException(nameof(bot));
if (bot == null) {
throw new ArgumentNullException(nameof(bot));
}
Bot = bot;
}
public void Dispose() => Semaphore.Dispose(); public void Dispose() => Semaphore.Dispose();

View File

@@ -43,13 +43,7 @@ namespace ArchiSteamFarm {
private bool ParsingScheduled; private bool ParsingScheduled;
internal Trading(Bot bot) { internal Trading(Bot bot) => Bot = bot ?? throw new ArgumentNullException(nameof(bot));
if (bot == null) {
throw new ArgumentNullException(nameof(bot));
}
Bot = bot;
}
public void Dispose() => TradesSemaphore.Dispose(); public void Dispose() => TradesSemaphore.Dispose();
@@ -269,8 +263,7 @@ namespace ArchiSteamFarm {
// Now let's create a map which maps items to their amount in our EQ // Now let's create a map which maps items to their amount in our EQ
Dictionary<ulong, uint> amountMap = new Dictionary<ulong, uint>(); Dictionary<ulong, uint> amountMap = new Dictionary<ulong, uint>();
foreach (Steam.Item item in inventory) { foreach (Steam.Item item in inventory) {
uint amount; if (amountMap.TryGetValue(item.ClassID, out uint amount)) {
if (amountMap.TryGetValue(item.ClassID, out amount)) {
amountMap[item.ClassID] = amount + item.Amount; amountMap[item.ClassID] = amount + item.Amount;
} else { } else {
amountMap[item.ClassID] = item.Amount; amountMap[item.ClassID] = item.Amount;
@@ -281,8 +274,7 @@ namespace ArchiSteamFarm {
List<uint> amountsToGive = new List<uint>(tradeOffer.ItemsToGive.Count); List<uint> amountsToGive = new List<uint>(tradeOffer.ItemsToGive.Count);
Dictionary<ulong, uint> amountMapToGive = new Dictionary<ulong, uint>(amountMap); Dictionary<ulong, uint> amountMapToGive = new Dictionary<ulong, uint>(amountMap);
foreach (ulong key in tradeOffer.ItemsToGive.Select(item => item.ClassID)) { foreach (ulong key in tradeOffer.ItemsToGive.Select(item => item.ClassID)) {
uint amount; if (!amountMapToGive.TryGetValue(key, out uint amount)) {
if (!amountMapToGive.TryGetValue(key, out amount)) {
amountsToGive.Add(0); amountsToGive.Add(0);
continue; continue;
} }
@@ -298,8 +290,7 @@ namespace ArchiSteamFarm {
List<uint> amountsToReceive = new List<uint>(tradeOffer.ItemsToReceive.Count); List<uint> amountsToReceive = new List<uint>(tradeOffer.ItemsToReceive.Count);
Dictionary<ulong, uint> amountMapToReceive = new Dictionary<ulong, uint>(amountMap); Dictionary<ulong, uint> amountMapToReceive = new Dictionary<ulong, uint>(amountMap);
foreach (ulong key in tradeOffer.ItemsToReceive.Select(item => item.ClassID)) { foreach (ulong key in tradeOffer.ItemsToReceive.Select(item => item.ClassID)) {
uint amount; if (!amountMapToReceive.TryGetValue(key, out uint amount)) {
if (!amountMapToReceive.TryGetValue(key, out amount)) {
amountsToReceive.Add(0); amountsToReceive.Add(0);
continue; continue;
} }

View File

@@ -46,11 +46,7 @@ namespace ArchiSteamFarm {
private readonly HttpClient HttpClient; private readonly HttpClient HttpClient;
internal WebBrowser(ArchiLogger archiLogger) { internal WebBrowser(ArchiLogger archiLogger) {
if (archiLogger == null) { ArchiLogger = archiLogger ?? throw new ArgumentNullException(nameof(archiLogger));
throw new ArgumentNullException(nameof(archiLogger));
}
ArchiLogger = archiLogger;
HttpClientHandler httpClientHandler = new HttpClientHandler { HttpClientHandler httpClientHandler = new HttpClientHandler {
AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip, AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip,

View File

@@ -31,11 +31,7 @@ namespace ConfigGenerator {
internal readonly ASFConfig ASFConfig; internal readonly ASFConfig ASFConfig;
internal ConfigPage(ASFConfig config) { internal ConfigPage(ASFConfig config) {
if (config == null) { ASFConfig = config ?? throw new ArgumentNullException(nameof(config));
throw new ArgumentNullException(nameof(config));
}
ASFConfig = config;
RefreshText(); RefreshText();

View File

@@ -30,11 +30,7 @@ namespace ConfigGenerator {
private readonly ASFConfig ASFConfig; private readonly ASFConfig ASFConfig;
internal EnhancedPropertyGrid(ASFConfig config) { internal EnhancedPropertyGrid(ASFConfig config) {
if (config == null) { ASFConfig = config ?? throw new ArgumentNullException(nameof(config));
throw new ArgumentNullException(nameof(config));
}
ASFConfig = config;
SelectedObject = config; SelectedObject = config;
Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top; Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top;

View File

@@ -11,11 +11,7 @@ namespace ArchiSteamFarm {
private readonly Bot Bot; private readonly Bot Bot;
internal BotStatusForm(Bot bot) { internal BotStatusForm(Bot bot) {
if (bot == null) { Bot = bot ?? throw new ArgumentNullException(nameof(bot));
throw new ArgumentNullException(nameof(bot));
}
Bot = bot;
BotForms[bot.BotName] = this; BotForms[bot.BotName] = this;