diff --git a/SteamKit2/SteamKit2/Base/ClientMsg.cs b/SteamKit2/SteamKit2/Base/ClientMsg.cs index 689cc556e..3edc970af 100644 --- a/SteamKit2/SteamKit2/Base/ClientMsg.cs +++ b/SteamKit2/SteamKit2/Base/ClientMsg.cs @@ -325,10 +325,7 @@ public ClientMsg( int payloadReserve = 64 ) public ClientMsg( MsgBase msg, int payloadReserve = 64 ) : this( payloadReserve ) { - if ( msg == null ) - { - throw new ArgumentNullException( nameof(msg) ); - } + ArgumentNullException.ThrowIfNull( msg ); // our target is where the message came from Header.TargetJobID = msg.Header.SourceJobID; @@ -342,10 +339,7 @@ public ClientMsg( MsgBase msg, int payloadReserve = 64 ) public ClientMsg( IPacketMsg msg ) : this() { - if ( msg == null ) - { - throw new ArgumentNullException( nameof(msg) ); - } + ArgumentNullException.ThrowIfNull( msg ); if ( !( msg is PacketClientMsg packetMsg ) ) { @@ -479,10 +473,7 @@ public Msg( int payloadReserve = 0 ) public Msg( MsgBase msg, int payloadReserve = 0 ) : this( payloadReserve ) { - if ( msg == null ) - { - throw new ArgumentNullException( nameof(msg) ); - } + ArgumentNullException.ThrowIfNull( msg ); // our target is where the message came from Header.TargetJobID = msg.Header.SourceJobID; @@ -496,10 +487,7 @@ public Msg( MsgBase msg, int payloadReserve = 0 ) public Msg( IPacketMsg msg ) : this() { - if ( msg == null ) - { - throw new ArgumentNullException( nameof(msg) ); - } + ArgumentNullException.ThrowIfNull( msg ); if ( !( msg is PacketMsg packetMsg ) ) { diff --git a/SteamKit2/SteamKit2/Base/GC/ClientMsgGC.cs b/SteamKit2/SteamKit2/Base/GC/ClientMsgGC.cs index 88f48eed0..9710ce51e 100644 --- a/SteamKit2/SteamKit2/Base/GC/ClientMsgGC.cs +++ b/SteamKit2/SteamKit2/Base/GC/ClientMsgGC.cs @@ -97,10 +97,7 @@ public ClientGCMsgProtobuf( uint eMsg, int payloadReserve = 64 ) public ClientGCMsgProtobuf( uint eMsg, GCMsgBase msg, int payloadReserve = 64 ) : this( eMsg, payloadReserve ) { - if ( msg == null ) - { - throw new ArgumentNullException( nameof(msg) ); - } + ArgumentNullException.ThrowIfNull( msg ); // our target is where the message came from Header.Proto.job_id_target = msg.Header.Proto.job_id_source; @@ -142,10 +139,7 @@ public override byte[] Serialize() /// The data representing a gc message. public override void Deserialize( byte[] data ) { - if ( data == null ) - { - throw new ArgumentNullException( nameof(data) ); - } + ArgumentNullException.ThrowIfNull( data ); using ( MemoryStream ms = new MemoryStream( data ) ) { @@ -238,10 +232,7 @@ public ClientGCMsg( int payloadReserve = 64 ) public ClientGCMsg( GCMsgBase msg, int payloadReserve = 64 ) : this( payloadReserve ) { - if ( msg == null ) - { - throw new ArgumentNullException( nameof(msg) ); - } + ArgumentNullException.ThrowIfNull( msg ); // our target is where the message came from Header.TargetJobID = msg.Header.SourceJobID; @@ -255,10 +246,7 @@ public ClientGCMsg( GCMsgBase msg, int payloadReserve = 64 ) public ClientGCMsg( IPacketGCMsg msg ) : this() { - if ( msg == null ) - { - throw new ArgumentNullException( nameof(msg) ); - } + ArgumentNullException.ThrowIfNull( msg ); DebugLog.Assert( !msg.IsProto, "ClientGCMsg", "ClientGCMsg used for proto message!" ); @@ -288,10 +276,7 @@ public override byte[] Serialize() /// The data representing a client message. public override void Deserialize( byte[] data ) { - if ( data == null ) - { - throw new ArgumentNullException( nameof(data) ); - } + ArgumentNullException.ThrowIfNull( data ); using ( MemoryStream ms = new MemoryStream( data ) ) { diff --git a/SteamKit2/SteamKit2/Base/GC/PacketBaseGC.cs b/SteamKit2/SteamKit2/Base/GC/PacketBaseGC.cs index c403458e3..864dff0f5 100644 --- a/SteamKit2/SteamKit2/Base/GC/PacketBaseGC.cs +++ b/SteamKit2/SteamKit2/Base/GC/PacketBaseGC.cs @@ -116,10 +116,7 @@ public sealed class PacketClientGCMsgProtobuf : IPacketGCMsg /// The data. public PacketClientGCMsgProtobuf( uint eMsg, byte[] data ) { - if ( data == null ) - { - throw new ArgumentNullException( nameof(data) ); - } + ArgumentNullException.ThrowIfNull( data ); MsgType = eMsg; payload = data; @@ -193,10 +190,7 @@ public sealed class PacketClientGCMsg : IPacketGCMsg /// The data. public PacketClientGCMsg( uint eMsg, byte[] data ) { - if ( data == null ) - { - throw new ArgumentNullException( nameof(data) ); - } + ArgumentNullException.ThrowIfNull( data ); MsgType = eMsg; payload = data; diff --git a/SteamKit2/SteamKit2/Base/MsgBase.cs b/SteamKit2/SteamKit2/Base/MsgBase.cs index a3b66c012..39609cf27 100644 --- a/SteamKit2/SteamKit2/Base/MsgBase.cs +++ b/SteamKit2/SteamKit2/Base/MsgBase.cs @@ -216,10 +216,7 @@ public void Write( string data, Encoding encoding ) return; } - if ( encoding == null ) - { - throw new ArgumentNullException( nameof(encoding) ); - } + ArgumentNullException.ThrowIfNull( encoding ); Write( encoding.GetBytes( data ) ); } @@ -420,10 +417,7 @@ public string ReadNullTermString() /// /// The string. public string ReadNullTermString( Encoding encoding ) { - if ( encoding == null ) - { - throw new ArgumentNullException( nameof(encoding) ); - } + ArgumentNullException.ThrowIfNull( encoding ); return Payload.ReadNullTermString( encoding ); } diff --git a/SteamKit2/SteamKit2/Base/PacketBase.cs b/SteamKit2/SteamKit2/Base/PacketBase.cs index a4648d292..e285b16c2 100644 --- a/SteamKit2/SteamKit2/Base/PacketBase.cs +++ b/SteamKit2/SteamKit2/Base/PacketBase.cs @@ -128,10 +128,7 @@ public sealed class PacketClientMsgProtobuf : IPacketMsg /// The data. public PacketClientMsgProtobuf( EMsg eMsg, byte[] data ) { - if ( data == null ) - { - throw new ArgumentNullException( nameof(data) ); - } + ArgumentNullException.ThrowIfNull( data ); MsgType = eMsg; payload = data; @@ -215,10 +212,7 @@ public sealed class PacketClientMsg : IPacketMsg /// The data. public PacketClientMsg( EMsg eMsg, byte[] data ) { - if ( data == null ) - { - throw new ArgumentNullException( nameof(data) ); - } + ArgumentNullException.ThrowIfNull( data ); MsgType = eMsg; payload = data; @@ -302,10 +296,7 @@ public sealed class PacketMsg : IPacketMsg /// The data. public PacketMsg( EMsg eMsg, byte[] data ) { - if ( data == null ) - { - throw new ArgumentNullException( nameof(data) ); - } + ArgumentNullException.ThrowIfNull( data ); MsgType = eMsg; payload = data; diff --git a/SteamKit2/SteamKit2/Steam/Authentication/SteamAuthentication.cs b/SteamKit2/SteamKit2/Steam/Authentication/SteamAuthentication.cs index ada8ecee2..d35371862 100644 --- a/SteamKit2/SteamKit2/Steam/Authentication/SteamAuthentication.cs +++ b/SteamKit2/SteamKit2/Steam/Authentication/SteamAuthentication.cs @@ -25,10 +25,7 @@ public sealed class SteamAuthentication /// The this instance will be associated with. internal SteamAuthentication( SteamClient steamClient ) { - if ( steamClient == null ) - { - throw new ArgumentNullException( nameof( steamClient ) ); - } + ArgumentNullException.ThrowIfNull( steamClient ); Client = steamClient; @@ -134,10 +131,7 @@ public async Task BeginAuthSessionViaQRAsync( AuthSessionDetails /// Username or password are not set within . public async Task BeginAuthSessionViaCredentialsAsync( AuthSessionDetails details ) { - if ( details == null ) - { - throw new ArgumentNullException( nameof( details ) ); - } + ArgumentNullException.ThrowIfNull( details ); if ( string.IsNullOrEmpty( details.Username ) || string.IsNullOrEmpty( details.Password ) ) { diff --git a/SteamKit2/SteamKit2/Steam/CDN/Client.cs b/SteamKit2/SteamKit2/Steam/CDN/Client.cs index 5ca6824b8..8b422894a 100644 --- a/SteamKit2/SteamKit2/Steam/CDN/Client.cs +++ b/SteamKit2/SteamKit2/Steam/CDN/Client.cs @@ -36,10 +36,7 @@ public sealed class Client : IDisposable /// The SteamClient instance must be connected and logged onto Steam. public Client( SteamClient steamClient ) { - if ( steamClient == null ) - { - throw new ArgumentNullException( nameof( steamClient ) ); - } + ArgumentNullException.ThrowIfNull( steamClient ); this.httpClient = steamClient.Configuration.HttpClientFactory(); } @@ -70,10 +67,7 @@ public void Dispose() /// A network error occurred when performing the request. public async Task DownloadManifestAsync( uint depotId, ulong manifestId, ulong manifestRequestCode, Server server, byte[]? depotKey = null, Server? proxyServer = null ) { - if ( server == null ) - { - throw new ArgumentNullException( nameof( server ) ); - } + ArgumentNullException.ThrowIfNull( server ); const uint MANIFEST_VERSION = 5; string url; @@ -127,15 +121,9 @@ public async Task DownloadManifestAsync( uint depotId, ulong mani /// A network error occurred when performing the request. public async Task DownloadDepotChunkAsync( uint depotId, DepotManifest.ChunkData chunk, Server server, byte[]? depotKey = null, Server? proxyServer = null ) { - if ( server == null ) - { - throw new ArgumentNullException( nameof( server ) ); - } + ArgumentNullException.ThrowIfNull( server ); - if ( chunk == null ) - { - throw new ArgumentNullException( nameof( chunk ) ); - } + ArgumentNullException.ThrowIfNull( chunk ); if ( chunk.ChunkID == null ) { diff --git a/SteamKit2/SteamKit2/Steam/CDN/DepotChunk.cs b/SteamKit2/SteamKit2/Steam/CDN/DepotChunk.cs index d5ba38d11..dc233b96e 100644 --- a/SteamKit2/SteamKit2/Steam/CDN/DepotChunk.cs +++ b/SteamKit2/SteamKit2/Steam/CDN/DepotChunk.cs @@ -39,15 +39,9 @@ public sealed class DepotChunk /// The underlying data for this chunk. public DepotChunk( DepotManifest.ChunkData info, byte[] data ) { - if ( info is null ) - { - throw new ArgumentNullException( nameof( info ) ); - } + ArgumentNullException.ThrowIfNull( info ); - if ( data is null ) - { - throw new ArgumentNullException( nameof( data ) ); - } + ArgumentNullException.ThrowIfNull( data ); ChunkInfo = info; Data = data; @@ -61,10 +55,7 @@ public DepotChunk( DepotManifest.ChunkData info, byte[] data ) /// Thrown if the processed data does not match the expected checksum given in it's chunk information. public void Process( byte[] depotKey ) { - if ( depotKey == null ) - { - throw new ArgumentNullException( nameof( depotKey ) ); - } + ArgumentNullException.ThrowIfNull( depotKey ); if ( IsProcessed ) { diff --git a/SteamKit2/SteamKit2/Steam/CMClient.cs b/SteamKit2/SteamKit2/Steam/CMClient.cs index a6ae55d32..05df46cd3 100644 --- a/SteamKit2/SteamKit2/Steam/CMClient.cs +++ b/SteamKit2/SteamKit2/Steam/CMClient.cs @@ -139,7 +139,7 @@ public CMClient( SteamConfiguration configuration, string identifier ) { Configuration = configuration ?? throw new ArgumentNullException( nameof( configuration ) ); - if ( identifier is null ) throw new ArgumentNullException( nameof( identifier ) ); + ArgumentNullException.ThrowIfNull( identifier ); if ( identifier.Length == 0 ) throw new ArgumentException( "Identifer must not be empty.", nameof( identifier ) ); ID = identifier; diff --git a/SteamKit2/SteamKit2/Steam/Discovery/FileStorageServerListProvider.cs b/SteamKit2/SteamKit2/Steam/Discovery/FileStorageServerListProvider.cs index e46683191..d196e2bb3 100644 --- a/SteamKit2/SteamKit2/Steam/Discovery/FileStorageServerListProvider.cs +++ b/SteamKit2/SteamKit2/Steam/Discovery/FileStorageServerListProvider.cs @@ -54,10 +54,7 @@ public Task> FetchServerListAsync() /// Awaitable task for write completion public Task UpdateServerListAsync(IEnumerable endpoints) { - if (endpoints == null) - { - throw new ArgumentNullException(nameof(endpoints)); - } + ArgumentNullException.ThrowIfNull( endpoints ); return Task.Run(() => { diff --git a/SteamKit2/SteamKit2/Steam/Discovery/IsolatedStorageServerListProvider.cs b/SteamKit2/SteamKit2/Steam/Discovery/IsolatedStorageServerListProvider.cs index fc7a53342..dabaec3b0 100644 --- a/SteamKit2/SteamKit2/Steam/Discovery/IsolatedStorageServerListProvider.cs +++ b/SteamKit2/SteamKit2/Steam/Discovery/IsolatedStorageServerListProvider.cs @@ -57,10 +57,7 @@ public Task> FetchServerListAsync() /// Awaitable task for write completion public Task UpdateServerListAsync(IEnumerable endpoints) { - if (endpoints == null) - { - throw new ArgumentNullException(nameof(endpoints)); - } + ArgumentNullException.ThrowIfNull( endpoints ); return Task.Run(() => { diff --git a/SteamKit2/SteamKit2/Steam/Discovery/ServerRecord.cs b/SteamKit2/SteamKit2/Steam/Discovery/ServerRecord.cs index 6fc4281ef..5e8b1e153 100644 --- a/SteamKit2/SteamKit2/Steam/Discovery/ServerRecord.cs +++ b/SteamKit2/SteamKit2/Steam/Discovery/ServerRecord.cs @@ -93,10 +93,7 @@ public static bool TryCreateSocketServer(string address, [NotNullWhen(true)] out /// A new instance public static ServerRecord CreateWebSocketServer(string address) { - if (address == null) - { - throw new ArgumentNullException(nameof(address)); - } + ArgumentNullException.ThrowIfNull( address ); EndPoint endPoint; const int DefaultPort = 443; diff --git a/SteamKit2/SteamKit2/Steam/Discovery/SmartCMServerList.cs b/SteamKit2/SteamKit2/Steam/Discovery/SmartCMServerList.cs index 49a7cd8b3..cc5eaad16 100644 --- a/SteamKit2/SteamKit2/Steam/Discovery/SmartCMServerList.cs +++ b/SteamKit2/SteamKit2/Steam/Discovery/SmartCMServerList.cs @@ -156,10 +156,7 @@ public void ResetOldScores() /// The s to use for this . public void ReplaceList( IEnumerable endpointList ) { - if ( endpointList == null ) - { - throw new ArgumentNullException( nameof(endpointList) ); - } + ArgumentNullException.ThrowIfNull( endpointList ); lock ( listLock ) { diff --git a/SteamKit2/SteamKit2/Steam/Handlers/SteamApps/SteamApps.cs b/SteamKit2/SteamKit2/Steam/Handlers/SteamApps/SteamApps.cs index 6e0921d17..97c397860 100644 --- a/SteamKit2/SteamKit2/Steam/Handlers/SteamApps/SteamApps.cs +++ b/SteamKit2/SteamKit2/Steam/Handlers/SteamApps/SteamApps.cs @@ -204,15 +204,9 @@ public AsyncJobMultiple PICSGetProductInfo( PICSRequest /// The Job ID of the request. This can be used to find the appropriate . public AsyncJobMultiple PICSGetProductInfo( IEnumerable apps, IEnumerable packages, bool metaDataOnly = false ) { - if ( apps == null ) - { - throw new ArgumentNullException( nameof(apps) ); - } + ArgumentNullException.ThrowIfNull( apps ); - if ( packages == null ) - { - throw new ArgumentNullException( nameof(packages) ); - } + ArgumentNullException.ThrowIfNull( packages ); var request = new ClientMsgProtobuf( EMsg.ClientPICSProductInfoRequest ); request.SourceJobID = Client.GetNextJobID(); @@ -287,10 +281,7 @@ public AsyncJob RequestFreeLicense( uint app ) /// The Job ID of the request. This can be used to find the appropriate . public AsyncJob RequestFreeLicense( IEnumerable apps ) { - if ( apps == null ) - { - throw new ArgumentNullException( nameof(apps) ); - } + ArgumentNullException.ThrowIfNull( apps ); var request = new ClientMsgProtobuf( EMsg.ClientRequestFreeLicense ); request.SourceJobID = Client.GetNextJobID(); @@ -344,10 +335,7 @@ public AsyncJob GetLegacyGameKey( uint appid ) /// The packet message that contains the data. public override void HandleMsg( IPacketMsg packetMsg ) { - if ( packetMsg == null ) - { - throw new ArgumentNullException( nameof(packetMsg) ); - } + ArgumentNullException.ThrowIfNull( packetMsg ); if ( !dispatchMap.TryGetValue( packetMsg.MsgType, out var handlerFunc ) ) { diff --git a/SteamKit2/SteamKit2/Steam/Handlers/SteamCloud/SteamCloud.cs b/SteamKit2/SteamKit2/Steam/Handlers/SteamCloud/SteamCloud.cs index 62d652ae6..9cc81215d 100644 --- a/SteamKit2/SteamKit2/Steam/Handlers/SteamCloud/SteamCloud.cs +++ b/SteamKit2/SteamKit2/Steam/Handlers/SteamCloud/SteamCloud.cs @@ -38,10 +38,7 @@ internal SteamCloud() /// The Job ID of the request. This can be used to find the appropriate . public AsyncJob RequestUGCDetails( UGCHandle ugcId ) { - if ( ugcId == null ) - { - throw new ArgumentNullException( nameof(ugcId) ); - } + ArgumentNullException.ThrowIfNull( ugcId ); var request = new ClientMsgProtobuf( EMsg.ClientUFSGetUGCDetails ); request.SourceJobID = Client.GetNextJobID(); @@ -101,10 +98,7 @@ public AsyncJob ShareFile( uint appid, string filename ) /// The packet message that contains the data. public override void HandleMsg( IPacketMsg packetMsg ) { - if ( packetMsg == null ) - { - throw new ArgumentNullException( nameof(packetMsg) ); - } + ArgumentNullException.ThrowIfNull( packetMsg ); if ( !dispatchMap.TryGetValue( packetMsg.MsgType, out var handlerFunc ) ) { diff --git a/SteamKit2/SteamKit2/Steam/Handlers/SteamFriends/SteamFriends.cs b/SteamKit2/SteamKit2/Steam/Handlers/SteamFriends/SteamFriends.cs index 67d8d52a5..b58d24cda 100644 --- a/SteamKit2/SteamKit2/Steam/Handlers/SteamFriends/SteamFriends.cs +++ b/SteamKit2/SteamKit2/Steam/Handlers/SteamFriends/SteamFriends.cs @@ -139,10 +139,7 @@ public SteamID GetFriendByIndex( int index ) /// The name. public string? GetFriendPersonaName( SteamID steamId ) { - if ( steamId == null ) - { - throw new ArgumentNullException( nameof(steamId) ); - } + ArgumentNullException.ThrowIfNull( steamId ); return cache.GetUser( steamId ).Name; } @@ -153,10 +150,7 @@ public SteamID GetFriendByIndex( int index ) /// The persona state. public EPersonaState GetFriendPersonaState( SteamID steamId ) { - if ( steamId == null ) - { - throw new ArgumentNullException( nameof(steamId) ); - } + ArgumentNullException.ThrowIfNull( steamId ); return cache.GetUser( steamId ).PersonaState; } @@ -167,10 +161,7 @@ public EPersonaState GetFriendPersonaState( SteamID steamId ) /// The relationship of the friend to the local user. public EFriendRelationship GetFriendRelationship( SteamID steamId ) { - if ( steamId == null ) - { - throw new ArgumentNullException( nameof(steamId) ); - } + ArgumentNullException.ThrowIfNull( steamId ); return cache.GetUser( steamId ).Relationship; } @@ -181,10 +172,7 @@ public EFriendRelationship GetFriendRelationship( SteamID steamId ) /// The game name of a friend playing a game, or null if they haven't been cached yet. public string? GetFriendGamePlayedName( SteamID steamId ) { - if ( steamId == null ) - { - throw new ArgumentNullException( nameof(steamId) ); - } + ArgumentNullException.ThrowIfNull( steamId ); return cache.GetUser( steamId ).GameName; } @@ -195,10 +183,7 @@ public EFriendRelationship GetFriendRelationship( SteamID steamId ) /// The gameid of a friend playing a game, or 0 if they haven't been cached yet. public GameID GetFriendGamePlayed( SteamID steamId ) { - if ( steamId == null ) - { - throw new ArgumentNullException( nameof(steamId) ); - } + ArgumentNullException.ThrowIfNull( steamId ); return cache.GetUser( steamId ).GameID; } @@ -209,10 +194,7 @@ public GameID GetFriendGamePlayed( SteamID steamId ) /// A byte array representing a SHA-1 hash of the friend's avatar. public byte[]? GetFriendAvatar( SteamID steamId ) { - if ( steamId == null ) - { - throw new ArgumentNullException( nameof(steamId) ); - } + ArgumentNullException.ThrowIfNull( steamId ); return cache.GetUser( steamId ).AvatarHash; } @@ -251,10 +233,7 @@ public SteamID GetClanByIndex( int index ) /// The name. public string? GetClanName( SteamID steamId ) { - if ( steamId == null ) - { - throw new ArgumentNullException( nameof(steamId) ); - } + ArgumentNullException.ThrowIfNull( steamId ); return cache.Clans.GetAccount( steamId ).Name; } @@ -265,10 +244,7 @@ public SteamID GetClanByIndex( int index ) /// The relationship of the clan to the local user. public EClanRelationship GetClanRelationship( SteamID steamId ) { - if ( steamId == null ) - { - throw new ArgumentNullException( nameof(steamId) ); - } + ArgumentNullException.ThrowIfNull( steamId ); return cache.Clans.GetAccount( steamId ).Relationship; } @@ -279,10 +255,7 @@ public EClanRelationship GetClanRelationship( SteamID steamId ) /// A byte array representing a SHA-1 hash of the clan's avatar, or null if the clan could not be found. public byte[]? GetClanAvatar( SteamID steamId ) { - if ( steamId == null ) - { - throw new ArgumentNullException( nameof(steamId) ); - } + ArgumentNullException.ThrowIfNull( steamId ); return cache.Clans.GetAccount( steamId ).AvatarHash; } @@ -295,15 +268,9 @@ public EClanRelationship GetClanRelationship( SteamID steamId ) /// The message to send. public void SendChatMessage( SteamID target, EChatEntryType type, string message ) { - if ( target == null ) - { - throw new ArgumentNullException( nameof(target) ); - } + ArgumentNullException.ThrowIfNull( target ); - if ( message == null ) - { - throw new ArgumentNullException( nameof(message) ); - } + ArgumentNullException.ThrowIfNull( message ); var chatMsg = new ClientMsgProtobuf( EMsg.ClientFriendMsg ); @@ -320,10 +287,7 @@ public void SendChatMessage( SteamID target, EChatEntryType type, string message /// The account name or email of the user. public void AddFriend( string accountNameOrEmail ) { - if ( accountNameOrEmail == null ) - { - throw new ArgumentNullException( nameof(accountNameOrEmail) ); - } + ArgumentNullException.ThrowIfNull( accountNameOrEmail ); var addFriend = new ClientMsgProtobuf( EMsg.ClientAddFriend ); @@ -337,10 +301,7 @@ public void AddFriend( string accountNameOrEmail ) /// The SteamID of the friend to add. public void AddFriend( SteamID steamId ) { - if ( steamId == null ) - { - throw new ArgumentNullException( nameof(steamId) ); - } + ArgumentNullException.ThrowIfNull( steamId ); var addFriend = new ClientMsgProtobuf( EMsg.ClientAddFriend ); @@ -354,10 +315,7 @@ public void AddFriend( SteamID steamId ) /// The SteamID of the friend to remove. public void RemoveFriend( SteamID steamId ) { - if ( steamId == null ) - { - throw new ArgumentNullException( nameof(steamId) ); - } + ArgumentNullException.ThrowIfNull( steamId ); var removeFriend = new ClientMsgProtobuf( EMsg.ClientRemoveFriend ); @@ -373,10 +331,7 @@ public void RemoveFriend( SteamID steamId ) /// The SteamID of the chat room. public void JoinChat( SteamID steamId ) { - if ( steamId == null ) - { - throw new ArgumentNullException( nameof(steamId) ); - } + ArgumentNullException.ThrowIfNull( steamId ); SteamID chatId = steamId.ConvertToUInt64(); // copy the steamid so we don't modify it @@ -398,10 +353,7 @@ public void JoinChat( SteamID steamId ) /// The SteamID of the chat room. public void LeaveChat( SteamID steamId ) { - if ( steamId == null ) - { - throw new ArgumentNullException( nameof(steamId) ); - } + ArgumentNullException.ThrowIfNull( steamId ); SteamID chatId = steamId.ConvertToUInt64(); // copy the steamid so we don't modify it @@ -434,15 +386,9 @@ public void LeaveChat( SteamID steamId ) /// The message. public void SendChatRoomMessage( SteamID steamIdChat, EChatEntryType type, string message ) { - if ( steamIdChat == null ) - { - throw new ArgumentNullException( nameof(steamIdChat) ); - } + ArgumentNullException.ThrowIfNull( steamIdChat ); - if ( message == null ) - { - throw new ArgumentNullException( nameof(message) ); - } + ArgumentNullException.ThrowIfNull( message ); SteamID chatId = steamIdChat.ConvertToUInt64(); // copy the steamid so we don't modify it @@ -472,15 +418,9 @@ public void SendChatRoomMessage( SteamID steamIdChat, EChatEntryType type, strin /// The SteamID of the chat room to invite the user to. public void InviteUserToChat( SteamID steamIdUser, SteamID steamIdChat ) { - if ( steamIdUser == null ) - { - throw new ArgumentNullException( nameof(steamIdUser) ); - } + ArgumentNullException.ThrowIfNull( steamIdUser ); - if ( steamIdChat == null ) - { - throw new ArgumentNullException( nameof(steamIdChat) ); - } + ArgumentNullException.ThrowIfNull( steamIdChat ); SteamID chatId = steamIdChat.ConvertToUInt64(); // copy the steamid so we don't modify it @@ -509,15 +449,9 @@ public void InviteUserToChat( SteamID steamIdUser, SteamID steamIdChat ) /// The SteamID of the member to kick from the chat. public void KickChatMember( SteamID steamIdChat, SteamID steamIdMember ) { - if ( steamIdChat == null ) - { - throw new ArgumentNullException( nameof(steamIdChat) ); - } + ArgumentNullException.ThrowIfNull( steamIdChat ); - if ( steamIdMember == null ) - { - throw new ArgumentNullException( nameof(steamIdMember) ); - } + ArgumentNullException.ThrowIfNull( steamIdMember ); SteamID chatId = steamIdChat.ConvertToUInt64(); // copy the steamid so we don't modify it @@ -545,15 +479,9 @@ public void KickChatMember( SteamID steamIdChat, SteamID steamIdMember ) /// The SteamID of the member to ban from the chat. public void BanChatMember( SteamID steamIdChat, SteamID steamIdMember ) { - if ( steamIdChat == null ) - { - throw new ArgumentNullException( nameof(steamIdChat) ); - } + ArgumentNullException.ThrowIfNull( steamIdChat ); - if ( steamIdMember == null ) - { - throw new ArgumentNullException( nameof(steamIdMember) ); - } + ArgumentNullException.ThrowIfNull( steamIdMember ); SteamID chatId = steamIdChat.ConvertToUInt64(); // copy the steamid so we don't modify it @@ -580,15 +508,9 @@ public void BanChatMember( SteamID steamIdChat, SteamID steamIdMember ) /// The SteamID of the member to unban from the chat. public void UnbanChatMember( SteamID steamIdChat, SteamID steamIdMember ) { - if ( steamIdChat == null ) - { - throw new ArgumentNullException( nameof(steamIdChat) ); - } + ArgumentNullException.ThrowIfNull( steamIdChat ); - if ( steamIdMember == null ) - { - throw new ArgumentNullException( nameof(steamIdMember) ); - } + ArgumentNullException.ThrowIfNull( steamIdMember ); SteamID chatId = steamIdChat.ConvertToUInt64(); // copy the steamid so we don't modify it @@ -617,10 +539,7 @@ public void UnbanChatMember( SteamID steamIdChat, SteamID steamIdMember ) /// The requested info flags. If none specified, this uses . public void RequestFriendInfo( IEnumerable steamIdList, EClientPersonaStateFlag requestedInfo = default ) { - if ( steamIdList == null ) - { - throw new ArgumentNullException( nameof(steamIdList) ); - } + ArgumentNullException.ThrowIfNull( steamIdList ); if ( requestedInfo == default ) { @@ -642,10 +561,7 @@ public void UnbanChatMember( SteamID steamIdChat, SteamID steamIdMember ) /// The requested info flags. If none specified, this uses . public void RequestFriendInfo( SteamID steamId, EClientPersonaStateFlag requestedInfo = 0 ) { - if ( steamId == null ) - { - throw new ArgumentNullException( nameof(steamId) ); - } + ArgumentNullException.ThrowIfNull( steamId ); RequestFriendInfo( new SteamID[] { steamId }, requestedInfo ); } @@ -660,10 +576,7 @@ public void RequestFriendInfo( SteamID steamId, EClientPersonaStateFlag requeste /// The Job ID of the request. This can be used to find the appropriate . public AsyncJob IgnoreFriend( SteamID steamId, bool setIgnore = true ) { - if ( steamId == null ) - { - throw new ArgumentNullException( nameof(steamId) ); - } + ArgumentNullException.ThrowIfNull( steamId ); var ignore = new ClientMsg(); ignore.SourceJobID = Client.GetNextJobID(); @@ -687,10 +600,7 @@ public AsyncJob IgnoreFriend( SteamID steamId, bool setIgn /// The Job ID of the request. This can be used to find the appropriate . public AsyncJob RequestProfileInfo( SteamID steamId ) { - if ( steamId == null ) - { - throw new ArgumentNullException( nameof(steamId) ); - } + ArgumentNullException.ThrowIfNull( steamId ); var request = new ClientMsgProtobuf( EMsg.ClientFriendProfileInfo ); request.SourceJobID = Client.GetNextJobID(); @@ -709,10 +619,7 @@ public AsyncJob RequestProfileInfo( SteamID steamId ) /// SteamID of the friend public void RequestMessageHistory( SteamID steamId ) { - if ( steamId == null ) - { - throw new ArgumentNullException( nameof(steamId) ); - } + ArgumentNullException.ThrowIfNull( steamId ); var request = new ClientMsgProtobuf( EMsg.ClientChatGetFriendMessageHistory ); @@ -740,10 +647,7 @@ public void RequestOfflineMessages() /// The packet message that contains the data. public override void HandleMsg( IPacketMsg packetMsg ) { - if ( packetMsg == null ) - { - throw new ArgumentNullException( nameof(packetMsg) ); - } + ArgumentNullException.ThrowIfNull( packetMsg ); if ( !dispatchMap.TryGetValue( packetMsg.MsgType, out var handlerFunc ) ) { diff --git a/SteamKit2/SteamKit2/Steam/Handlers/SteamGameCoordinator/SteamGameCoordinator.cs b/SteamKit2/SteamKit2/Steam/Handlers/SteamGameCoordinator/SteamGameCoordinator.cs index 44f691df5..ed634fe57 100644 --- a/SteamKit2/SteamKit2/Steam/Handlers/SteamGameCoordinator/SteamGameCoordinator.cs +++ b/SteamKit2/SteamKit2/Steam/Handlers/SteamGameCoordinator/SteamGameCoordinator.cs @@ -28,10 +28,7 @@ internal SteamGameCoordinator() /// The app id of the game coordinator to send to. public void Send( IClientGCMsg msg, uint appId ) { - if ( msg == null ) - { - throw new ArgumentNullException( nameof(msg) ); - } + ArgumentNullException.ThrowIfNull( msg ); var clientMsg = new ClientMsgProtobuf( EMsg.ClientToGC ); @@ -51,10 +48,7 @@ public void Send( IClientGCMsg msg, uint appId ) /// The packet message that contains the data. public override void HandleMsg( IPacketMsg packetMsg ) { - if ( packetMsg == null ) - { - throw new ArgumentNullException( nameof(packetMsg) ); - } + ArgumentNullException.ThrowIfNull( packetMsg ); if ( !dispatchMap.TryGetValue( packetMsg.MsgType, out var handlerFunc ) ) { diff --git a/SteamKit2/SteamKit2/Steam/Handlers/SteamGameServer/SteamGameServer.cs b/SteamKit2/SteamKit2/Steam/Handlers/SteamGameServer/SteamGameServer.cs index 27007f777..f59236782 100644 --- a/SteamKit2/SteamKit2/Steam/Handlers/SteamGameServer/SteamGameServer.cs +++ b/SteamKit2/SteamKit2/Steam/Handlers/SteamGameServer/SteamGameServer.cs @@ -96,10 +96,7 @@ internal SteamGameServer() /// Username or password are not set within . public void LogOn( LogOnDetails details ) { - if ( details == null ) - { - throw new ArgumentNullException( nameof(details) ); - } + ArgumentNullException.ThrowIfNull( details ); if ( string.IsNullOrEmpty( details.Token ) ) { @@ -183,10 +180,7 @@ public void LogOff() /// A object containing the server's status. public void SendStatus(StatusDetails details) { - if (details == null) - { - throw new ArgumentNullException( nameof(details) ); - } + ArgumentNullException.ThrowIfNull( details ); if (details.Address != null && details.Address.AddressFamily != AddressFamily.InterNetwork) { @@ -215,10 +209,7 @@ public void SendStatus(StatusDetails details) /// The packet message that contains the data. public override void HandleMsg( IPacketMsg packetMsg ) { - if ( packetMsg == null ) - { - throw new ArgumentNullException( nameof(packetMsg) ); - } + ArgumentNullException.ThrowIfNull( packetMsg ); if ( !dispatchMap.TryGetValue( packetMsg.MsgType, out var handlerFunc ) ) { diff --git a/SteamKit2/SteamKit2/Steam/Handlers/SteamMasterServer/SteamMasterServer.cs b/SteamKit2/SteamKit2/Steam/Handlers/SteamMasterServer/SteamMasterServer.cs index 7d699b480..abbf11985 100644 --- a/SteamKit2/SteamKit2/Steam/Handlers/SteamMasterServer/SteamMasterServer.cs +++ b/SteamKit2/SteamKit2/Steam/Handlers/SteamMasterServer/SteamMasterServer.cs @@ -68,10 +68,7 @@ internal SteamMasterServer() /// The Job ID of the request. This can be used to find the appropriate . public AsyncJob ServerQuery( QueryDetails details ) { - if ( details == null ) - { - throw new ArgumentNullException( nameof(details) ); - } + ArgumentNullException.ThrowIfNull( details ); var query = new ClientMsgProtobuf( EMsg.ClientGMSServerQuery ); query.SourceJobID = Client.GetNextJobID(); @@ -100,10 +97,7 @@ public AsyncJob ServerQuery( QueryDetails details ) /// The packet message that contains the data. public override void HandleMsg( IPacketMsg packetMsg ) { - if ( packetMsg == null ) - { - throw new ArgumentNullException( nameof(packetMsg) ); - } + ArgumentNullException.ThrowIfNull( packetMsg ); if ( !dispatchMap.TryGetValue( packetMsg.MsgType, out var handlerFunc ) ) { diff --git a/SteamKit2/SteamKit2/Steam/Handlers/SteamMatchmaking/SteamMatchmaking.cs b/SteamKit2/SteamKit2/Steam/Handlers/SteamMatchmaking/SteamMatchmaking.cs index 5468fe548..947fefe8e 100644 --- a/SteamKit2/SteamKit2/Steam/Handlers/SteamMatchmaking/SteamMatchmaking.cs +++ b/SteamKit2/SteamKit2/Steam/Handlers/SteamMatchmaking/SteamMatchmaking.cs @@ -324,10 +324,7 @@ public void InviteToLobby( uint appId, SteamID lobbySteamId, SteamID userSteamId /// The ID of the app this message pertains to. public void Send( ClientMsgProtobuf msg, uint appId ) { - if ( msg == null ) - { - throw new ArgumentNullException( nameof(msg) ); - } + ArgumentNullException.ThrowIfNull( msg ); msg.ProtoHeader.routing_appid = appId; Client.Send( msg ); @@ -339,10 +336,7 @@ public void Send( ClientMsgProtobuf msg, uint appId ) /// The packet message that contains the data. public override void HandleMsg( IPacketMsg packetMsg ) { - if ( packetMsg == null ) - { - throw new ArgumentNullException( nameof(packetMsg) ); - } + ArgumentNullException.ThrowIfNull( packetMsg ); if ( dispatchMap.TryGetValue( packetMsg.MsgType, out var handler ) ) { diff --git a/SteamKit2/SteamKit2/Steam/Handlers/SteamNetworking/SteamNetworking.cs b/SteamKit2/SteamKit2/Steam/Handlers/SteamNetworking/SteamNetworking.cs index 90610cbca..85d56007b 100644 --- a/SteamKit2/SteamKit2/Steam/Handlers/SteamNetworking/SteamNetworking.cs +++ b/SteamKit2/SteamKit2/Steam/Handlers/SteamNetworking/SteamNetworking.cs @@ -30,10 +30,7 @@ internal SteamNetworking() /// The Job ID of the request. This can be used to find the appropriate . public AsyncJob RequestNetworkingCertificate( uint appId, byte[] publicKey ) { - if ( publicKey == null ) - { - throw new ArgumentNullException( nameof( publicKey ) ); - } + ArgumentNullException.ThrowIfNull( publicKey ); var msg = new ClientMsgProtobuf( EMsg.ClientNetworkingCertRequest ); msg.SourceJobID = Client.GetNextJobID(); @@ -52,10 +49,7 @@ public AsyncJob RequestNetworkingCertificate( uin /// The packet message that contains the data. public override void HandleMsg( IPacketMsg packetMsg ) { - if ( packetMsg == null ) - { - throw new ArgumentNullException( nameof( packetMsg ) ); - } + ArgumentNullException.ThrowIfNull( packetMsg ); if ( !dispatchMap.TryGetValue( packetMsg.MsgType, out var handlerFunc ) ) { diff --git a/SteamKit2/SteamKit2/Steam/Handlers/SteamScreenshots/SteamScreenshots.cs b/SteamKit2/SteamKit2/Steam/Handlers/SteamScreenshots/SteamScreenshots.cs index c43d2b1b4..f72d4926d 100644 --- a/SteamKit2/SteamKit2/Steam/Handlers/SteamScreenshots/SteamScreenshots.cs +++ b/SteamKit2/SteamKit2/Steam/Handlers/SteamScreenshots/SteamScreenshots.cs @@ -101,10 +101,7 @@ internal SteamScreenshots() /// The Job ID of the request. This can be used to find the appropriate . public AsyncJob AddScreenshot( ScreenshotDetails details ) { - if ( details == null ) - { - throw new ArgumentNullException( nameof(details) ); - } + ArgumentNullException.ThrowIfNull( details ); var msg = new ClientMsgProtobuf( EMsg.ClientUCMAddScreenshot ); msg.SourceJobID = Client.GetNextJobID(); @@ -134,10 +131,7 @@ public AsyncJob AddScreenshot( ScreenshotDetails detail /// The packet message that contains the data. public override void HandleMsg( IPacketMsg packetMsg ) { - if ( packetMsg == null ) - { - throw new ArgumentNullException( nameof(packetMsg) ); - } + ArgumentNullException.ThrowIfNull( packetMsg ); if ( !dispatchMap.TryGetValue( packetMsg.MsgType, out var handlerFunc ) ) { diff --git a/SteamKit2/SteamKit2/Steam/Handlers/SteamTrading/SteamTrading.cs b/SteamKit2/SteamKit2/Steam/Handlers/SteamTrading/SteamTrading.cs index 211bf40b5..268bcd0cd 100644 --- a/SteamKit2/SteamKit2/Steam/Handlers/SteamTrading/SteamTrading.cs +++ b/SteamKit2/SteamKit2/Steam/Handlers/SteamTrading/SteamTrading.cs @@ -35,10 +35,7 @@ internal SteamTrading() /// The client to trade. public void Trade( SteamID user ) { - if ( user == null ) - { - throw new ArgumentNullException( nameof(user) ); - } + ArgumentNullException.ThrowIfNull( user ); var tradeReq = new ClientMsgProtobuf( EMsg.EconTrading_InitiateTradeRequest ); @@ -68,10 +65,7 @@ public void RespondToTrade( uint tradeId, bool acceptTrade ) /// The user. public void CancelTrade( SteamID user ) { - if ( user == null ) - { - throw new ArgumentNullException( nameof(user) ); - } + ArgumentNullException.ThrowIfNull( user ); var cancelTrade = new ClientMsgProtobuf( EMsg.EconTrading_CancelTradeRequest ); @@ -87,10 +81,7 @@ public void CancelTrade( SteamID user ) /// The packet message that contains the data. public override void HandleMsg( IPacketMsg packetMsg ) { - if ( packetMsg == null ) - { - throw new ArgumentNullException( nameof(packetMsg) ); - } + ArgumentNullException.ThrowIfNull( packetMsg ); if ( !dispatchMap.TryGetValue( packetMsg.MsgType, out var handlerFunc ) ) { diff --git a/SteamKit2/SteamKit2/Steam/Handlers/SteamUnifiedMessages/SteamUnifiedMessages.cs b/SteamKit2/SteamKit2/Steam/Handlers/SteamUnifiedMessages/SteamUnifiedMessages.cs index 6410d357c..dbca68c61 100644 --- a/SteamKit2/SteamKit2/Steam/Handlers/SteamUnifiedMessages/SteamUnifiedMessages.cs +++ b/SteamKit2/SteamKit2/Steam/Handlers/SteamUnifiedMessages/SteamUnifiedMessages.cs @@ -60,10 +60,7 @@ public void SendNotification( Expression> e AsyncJob? SendMessageOrNotification( Expression> expr, bool isNotification ) { - if ( expr == null ) - { - throw new ArgumentNullException( nameof( expr ) ); - } + ArgumentNullException.ThrowIfNull( expr ); var call = ExtractMethodCallExpression( expr, nameof( expr ) ); var methodInfo = call.Method; @@ -204,10 +201,7 @@ public UnifiedService CreateService() /// The packet message that contains the data. public override void HandleMsg( IPacketMsg packetMsg ) { - if ( packetMsg == null ) - { - throw new ArgumentNullException( nameof( packetMsg ) ); - } + ArgumentNullException.ThrowIfNull( packetMsg ); if ( !dispatchMap.TryGetValue( packetMsg.MsgType, out var handlerFunc ) ) { diff --git a/SteamKit2/SteamKit2/Steam/Handlers/SteamUser/SteamUser.cs b/SteamKit2/SteamKit2/Steam/Handlers/SteamUser/SteamUser.cs index 3d39715c9..9f8c7808e 100644 --- a/SteamKit2/SteamKit2/Steam/Handlers/SteamUser/SteamUser.cs +++ b/SteamKit2/SteamKit2/Steam/Handlers/SteamUser/SteamUser.cs @@ -197,10 +197,7 @@ internal SteamUser() /// Username or password are not set within . public void LogOn( LogOnDetails details ) { - if ( details == null ) - { - throw new ArgumentNullException( nameof( details ) ); - } + ArgumentNullException.ThrowIfNull( details ); if ( string.IsNullOrEmpty( details.Username ) || ( string.IsNullOrEmpty( details.Password ) && string.IsNullOrEmpty( details.AccessToken ) ) ) { @@ -282,10 +279,7 @@ public void LogOnAnonymous() /// The details to use for logging on. public void LogOnAnonymous( AnonymousLogOnDetails details ) { - if ( details == null ) - { - throw new ArgumentNullException( nameof( details ) ); - } + ArgumentNullException.ThrowIfNull( details ); if ( !this.Client.IsConnected ) { @@ -328,10 +322,7 @@ public void LogOff() /// The packet message that contains the data. public override void HandleMsg( IPacketMsg packetMsg ) { - if ( packetMsg == null ) - { - throw new ArgumentNullException( nameof( packetMsg ) ); - } + ArgumentNullException.ThrowIfNull( packetMsg ); if ( !dispatchMap.TryGetValue( packetMsg.MsgType, out var handlerFunc ) ) { diff --git a/SteamKit2/SteamKit2/Steam/Handlers/SteamUserStats/SteamUserStats.cs b/SteamKit2/SteamKit2/Steam/Handlers/SteamUserStats/SteamUserStats.cs index c0889d8e4..710586850 100644 --- a/SteamKit2/SteamKit2/Steam/Handlers/SteamUserStats/SteamUserStats.cs +++ b/SteamKit2/SteamKit2/Steam/Handlers/SteamUserStats/SteamUserStats.cs @@ -135,10 +135,7 @@ public AsyncJob GetLeaderboardEntries( uint appId, i /// The instance containing the event data. public override void HandleMsg( IPacketMsg packetMsg ) { - if ( packetMsg == null ) - { - throw new ArgumentNullException( nameof(packetMsg) ); - } + ArgumentNullException.ThrowIfNull( packetMsg ); if (! dispatchMap.TryGetValue( packetMsg.MsgType, out var handlerFunc ) ) { diff --git a/SteamKit2/SteamKit2/Steam/Handlers/SteamWorkshop/SteamWorkshop.cs b/SteamKit2/SteamKit2/Steam/Handlers/SteamWorkshop/SteamWorkshop.cs index f7df12edc..15cb7bdd5 100644 --- a/SteamKit2/SteamKit2/Steam/Handlers/SteamWorkshop/SteamWorkshop.cs +++ b/SteamKit2/SteamKit2/Steam/Handlers/SteamWorkshop/SteamWorkshop.cs @@ -65,10 +65,7 @@ public sealed class EnumerationUserDetails /// The Job ID of the request. This can be used to find the appropriate . public AsyncJob EnumeratePublishedFilesByUserAction( EnumerationUserDetails details ) { - if ( details == null ) - { - throw new ArgumentNullException( nameof(details) ); - } + ArgumentNullException.ThrowIfNull( details ); var enumRequest = new ClientMsgProtobuf( EMsg.ClientUCMEnumeratePublishedFilesByUserAction ); enumRequest.SourceJobID = Client.GetNextJobID(); @@ -88,10 +85,7 @@ public AsyncJob EnumeratePublishedFilesByUserA /// The packet message that contains the data. public override void HandleMsg( IPacketMsg packetMsg ) { - if ( packetMsg == null ) - { - throw new ArgumentNullException( nameof(packetMsg) ); - } + ArgumentNullException.ThrowIfNull( packetMsg ); if (!dispatchMap.TryGetValue(packetMsg.MsgType, out var handlerFunc)) { diff --git a/SteamKit2/SteamKit2/Steam/SteamClient/CallbackMgr/CallbackMgr.cs b/SteamKit2/SteamKit2/Steam/SteamClient/CallbackMgr/CallbackMgr.cs index b488b1d48..e8de4f91f 100644 --- a/SteamKit2/SteamKit2/Steam/SteamClient/CallbackMgr/CallbackMgr.cs +++ b/SteamKit2/SteamKit2/Steam/SteamClient/CallbackMgr/CallbackMgr.cs @@ -30,10 +30,7 @@ public sealed class CallbackManager : ICallbackMgrInternals /// The instance to handle the callbacks of. public CallbackManager( SteamClient client ) { - if ( client == null ) - { - throw new ArgumentNullException( nameof(client) ); - } + ArgumentNullException.ThrowIfNull( client ); registeredCallbacks = new List(); @@ -101,15 +98,9 @@ public void RunWaitCallbacks() public IDisposable Subscribe( JobID jobID, Action callbackFunc ) where TCallback : class, ICallbackMsg { - if ( jobID == null ) - { - throw new ArgumentNullException( nameof(jobID) ); - } + ArgumentNullException.ThrowIfNull( jobID ); - if ( callbackFunc == null ) - { - throw new ArgumentNullException( nameof(callbackFunc) ); - } + ArgumentNullException.ThrowIfNull( callbackFunc ); #pragma warning disable CA2000 // Not implicitly disposed var callback = new Internal.Callback( callbackFunc, this, jobID ); diff --git a/SteamKit2/SteamKit2/Steam/SteamClient/Configuration/SteamConfiguration.cs b/SteamKit2/SteamKit2/Steam/SteamClient/Configuration/SteamConfiguration.cs index 168c1399b..59509edaf 100644 --- a/SteamKit2/SteamKit2/Steam/SteamClient/Configuration/SteamConfiguration.cs +++ b/SteamKit2/SteamKit2/Steam/SteamClient/Configuration/SteamConfiguration.cs @@ -39,10 +39,7 @@ internal SteamConfiguration(SteamConfigurationState state) /// A configuration object. public static SteamConfiguration Create(Action configurator) { - if (configurator == null) - { - throw new ArgumentNullException(nameof(configurator)); - } + ArgumentNullException.ThrowIfNull( configurator ); var builder = new SteamConfigurationBuilder(); configurator(builder); diff --git a/SteamKit2/SteamKit2/Steam/SteamClient/SteamClient.cs b/SteamKit2/SteamKit2/Steam/SteamClient/SteamClient.cs index 6337bdabb..2b01ab99e 100644 --- a/SteamKit2/SteamKit2/Steam/SteamClient/SteamClient.cs +++ b/SteamKit2/SteamKit2/Steam/SteamClient/SteamClient.cs @@ -131,10 +131,7 @@ public SteamClient( SteamConfiguration configuration, string identifier ) /// A handler of that type is already registered. public void AddHandler( ClientMsgHandler handler ) { - if ( handler is null ) - { - throw new ArgumentNullException( nameof( handler ) ); - } + ArgumentNullException.ThrowIfNull( handler ); if ( handlers.Contains( handler.GetType() ) ) { diff --git a/SteamKit2/SteamKit2/Steam/WebAPI/ContentServerDirectoryService.cs b/SteamKit2/SteamKit2/Steam/WebAPI/ContentServerDirectoryService.cs index cd8706e55..eed287144 100644 --- a/SteamKit2/SteamKit2/Steam/WebAPI/ContentServerDirectoryService.cs +++ b/SteamKit2/SteamKit2/Steam/WebAPI/ContentServerDirectoryService.cs @@ -55,10 +55,7 @@ public static class ContentServerDirectoryService static async Task> LoadCoreAsync( SteamConfiguration configuration, int? cellId, int? maxNumServers, CancellationToken cancellationToken ) { - if ( configuration == null ) - { - throw new ArgumentNullException( nameof( configuration ) ); - } + ArgumentNullException.ThrowIfNull( configuration ); using var directory = configuration.GetAsyncWebAPIInterface( "IContentServerDirectoryService" ); var args = new Dictionary(); diff --git a/SteamKit2/SteamKit2/Steam/WebAPI/SteamConfigurationWebAPIExtensions.cs b/SteamKit2/SteamKit2/Steam/WebAPI/SteamConfigurationWebAPIExtensions.cs index dd7849e5f..c6c87dc00 100644 --- a/SteamKit2/SteamKit2/Steam/WebAPI/SteamConfigurationWebAPIExtensions.cs +++ b/SteamKit2/SteamKit2/Steam/WebAPI/SteamConfigurationWebAPIExtensions.cs @@ -16,10 +16,7 @@ public static class SteamConfigurationWebAPIExtensions /// A dynamic object to interact with the Web API. public static WebAPI.Interface GetWebAPIInterface(this SteamConfiguration config, string iface) { - if (config == null) - { - throw new ArgumentNullException(nameof(config)); - } + ArgumentNullException.ThrowIfNull( config ); return new WebAPI.Interface(config.GetHttpClientForWebAPI(), iface, config.WebAPIKey); } @@ -32,10 +29,7 @@ public static WebAPI.Interface GetWebAPIInterface(this SteamConfiguration config /// A dynamic object to interact with the Web API. public static WebAPI.AsyncInterface GetAsyncWebAPIInterface(this SteamConfiguration config, string iface) { - if (config == null) - { - throw new ArgumentNullException(nameof(config)); - } + ArgumentNullException.ThrowIfNull( config ); return new WebAPI.AsyncInterface(config.GetHttpClientForWebAPI(), iface, config.WebAPIKey); } diff --git a/SteamKit2/SteamKit2/Steam/WebAPI/SteamDirectory.cs b/SteamKit2/SteamKit2/Steam/WebAPI/SteamDirectory.cs index 4284cf3b9..e144e8fd0 100644 --- a/SteamKit2/SteamKit2/Steam/WebAPI/SteamDirectory.cs +++ b/SteamKit2/SteamKit2/Steam/WebAPI/SteamDirectory.cs @@ -42,10 +42,7 @@ public static Task> LoadAsync( SteamConfigurat static async Task> LoadCoreAsync( SteamConfiguration configuration, int? maxNumServers, CancellationToken cancellationToken ) { - if ( configuration == null ) - { - throw new ArgumentNullException( nameof(configuration) ); - } + ArgumentNullException.ThrowIfNull( configuration ); using var directory = configuration.GetAsyncWebAPIInterface( "ISteamDirectory" ); var args = new Dictionary diff --git a/SteamKit2/SteamKit2/Steam/WebAPI/WebAPI.cs b/SteamKit2/SteamKit2/Steam/WebAPI/WebAPI.cs index 902099e74..f189de0a0 100644 --- a/SteamKit2/SteamKit2/Steam/WebAPI/WebAPI.cs +++ b/SteamKit2/SteamKit2/Steam/WebAPI/WebAPI.cs @@ -264,15 +264,9 @@ public async Task> CallProtobufAsync CallAsync( HttpMethod method, string func, int versi private async Task CallAsyncInternal( HttpMethod method, string func, int version, Dictionary? args, string expectedFormat ) { - if ( method == null ) - { - throw new ArgumentNullException( nameof( method ) ); - } + ArgumentNullException.ThrowIfNull( method ); - if ( func == null ) - { - throw new ArgumentNullException( nameof( func ) ); - } + ArgumentNullException.ThrowIfNull( func ); var formatProvided = false; @@ -564,15 +552,9 @@ public override bool TryInvokeMember( InvokeMemberBinder binder, object?[]? args /// A dynamic object to interact with the Web API. public static Interface GetInterface( Uri baseAddress, string iface, string apiKey = "" ) { - if ( baseAddress == null ) - { - throw new ArgumentNullException( nameof( baseAddress ) ); - } + ArgumentNullException.ThrowIfNull( baseAddress ); - if ( iface == null ) - { - throw new ArgumentNullException( nameof( iface ) ); - } + ArgumentNullException.ThrowIfNull( iface ); return new Interface( CreateDefaultHttpClient( baseAddress ), iface, apiKey ); } @@ -585,10 +567,7 @@ public static Interface GetInterface( Uri baseAddress, string iface, string apiK /// A dynamic object to interact with the Web API. public static Interface GetInterface( string iface, string apiKey = "" ) { - if ( iface == null ) - { - throw new ArgumentNullException( nameof( iface ) ); - } + ArgumentNullException.ThrowIfNull( iface ); return new Interface( CreateDefaultHttpClient( DefaultBaseAddress ), iface, apiKey ); } @@ -601,10 +580,7 @@ public static Interface GetInterface( string iface, string apiKey = "" ) /// A dynamic object to interact with the Web API. public static AsyncInterface GetAsyncInterface( string iface, string apiKey = "" ) { - if ( iface == null ) - { - throw new ArgumentNullException( nameof( iface ) ); - } + ArgumentNullException.ThrowIfNull( iface ); return new AsyncInterface( CreateDefaultHttpClient( DefaultBaseAddress ), iface, apiKey ); } @@ -618,15 +594,9 @@ public static AsyncInterface GetAsyncInterface( string iface, string apiKey = "" /// A dynamic object to interact with the Web API. public static AsyncInterface GetAsyncInterface( Uri baseAddress, string iface, string apiKey = "" ) { - if ( baseAddress == null ) - { - throw new ArgumentNullException( nameof( baseAddress ) ); - } + ArgumentNullException.ThrowIfNull( baseAddress ); - if ( iface == null ) - { - throw new ArgumentNullException( nameof( iface ) ); - } + ArgumentNullException.ThrowIfNull( iface ); return new AsyncInterface( CreateDefaultHttpClient( baseAddress ), iface, apiKey ); } diff --git a/SteamKit2/SteamKit2/Types/GameID.cs b/SteamKit2/SteamKit2/Types/GameID.cs index ec77e443d..7181f0559 100644 --- a/SteamKit2/SteamKit2/Types/GameID.cs +++ b/SteamKit2/SteamKit2/Types/GameID.cs @@ -122,10 +122,7 @@ public ulong ToUInt64() /// public static implicit operator string( GameID? gid ) { - if ( gid is null ) - { - throw new ArgumentNullException( nameof(gid) ); - } + ArgumentNullException.ThrowIfNull( gid ); return gid.gameid.Data.ToString(); } @@ -139,10 +136,7 @@ public static implicit operator string( GameID? gid ) /// public static implicit operator UInt64( GameID? gid ) { - if ( gid is null ) - { - throw new ArgumentNullException( nameof(gid) ); - } + ArgumentNullException.ThrowIfNull( gid ); return gid.gameid.Data; } diff --git a/SteamKit2/SteamKit2/Types/GlobalID.cs b/SteamKit2/SteamKit2/Types/GlobalID.cs index 2d5f94c7d..e98b356ea 100644 --- a/SteamKit2/SteamKit2/Types/GlobalID.cs +++ b/SteamKit2/SteamKit2/Types/GlobalID.cs @@ -48,10 +48,7 @@ public GlobalID( ulong gid ) /// public static implicit operator ulong( GlobalID gid ) { - if ( gid == null ) - { - throw new ArgumentNullException( nameof(gid) ); - } + ArgumentNullException.ThrowIfNull( gid ); return gid.gidBits.Data; } @@ -269,10 +266,7 @@ public UGCHandle( ulong ugcId ) /// public static implicit operator ulong( UGCHandle handle ) { - if ( handle == null ) - { - throw new ArgumentNullException( nameof(handle) ); - } + ArgumentNullException.ThrowIfNull( handle ); return handle.Value; } diff --git a/SteamKit2/SteamKit2/Types/JobID.cs b/SteamKit2/SteamKit2/Types/JobID.cs index 4379e6a01..10528dfb5 100644 --- a/SteamKit2/SteamKit2/Types/JobID.cs +++ b/SteamKit2/SteamKit2/Types/JobID.cs @@ -49,10 +49,7 @@ public JobID( ulong jobId ) /// public static implicit operator ulong ( JobID jobId ) { - if ( jobId == null ) - { - throw new ArgumentNullException( nameof(jobId) ); - } + ArgumentNullException.ThrowIfNull( jobId ); return jobId.Value; } @@ -78,10 +75,7 @@ public static implicit operator JobID( ulong jobId ) /// public static implicit operator JobID( AsyncJob asyncJob ) { - if ( asyncJob == null ) - { - throw new ArgumentNullException( nameof(asyncJob) ); - } + ArgumentNullException.ThrowIfNull( asyncJob ); return asyncJob.JobID; } @@ -114,15 +108,9 @@ internal bool IsTimedout internal AsyncJob( SteamClient client, JobID jobId ) { - if ( client == null ) - { - throw new ArgumentNullException( nameof(client) ); - } - - if ( jobId == null ) - { - throw new ArgumentNullException( nameof(jobId) ); - } + ArgumentNullException.ThrowIfNull( client ); + + ArgumentNullException.ThrowIfNull( jobId ); jobStart = ValueStopwatch.StartNew(); JobID = jobId; @@ -213,10 +201,7 @@ public TaskAwaiter GetAwaiter() /// Always true. internal override bool AddResult( CallbackMsg callback ) { - if ( callback == null ) - { - throw new ArgumentNullException( nameof( callback ) ); - } + ArgumentNullException.ThrowIfNull( callback ); // we're complete with just this callback tcs.TrySetResult( (T)callback ); @@ -327,10 +312,7 @@ public TaskAwaiter GetAwaiter() /// true if this result completes the set; otherwise, false. internal override bool AddResult( CallbackMsg callback ) { - if ( callback == null ) - { - throw new ArgumentNullException( nameof( callback ) ); - } + ArgumentNullException.ThrowIfNull( callback ); T callbackMsg = (T)callback; diff --git a/SteamKit2/SteamKit2/Types/KeyValue.cs b/SteamKit2/SteamKit2/Types/KeyValue.cs index 9c977d50c..e039a4686 100644 --- a/SteamKit2/SteamKit2/Types/KeyValue.cs +++ b/SteamKit2/SteamKit2/Types/KeyValue.cs @@ -273,10 +273,7 @@ public KeyValue this[ string key ] { get { - if ( key == null ) - { - throw new ArgumentNullException( nameof(key) ); - } + ArgumentNullException.ThrowIfNull( key ); var child = this.Children .FirstOrDefault( c => string.Equals( c.Name, key, StringComparison.OrdinalIgnoreCase ) ); @@ -290,10 +287,7 @@ public KeyValue this[ string key ] } set { - if ( key == null ) - { - throw new ArgumentNullException( nameof(key) ); - } + ArgumentNullException.ThrowIfNull( key ); var existingChild = this.Children .FirstOrDefault( c => string.Equals( c.Name, key, StringComparison.OrdinalIgnoreCase ) ); @@ -567,10 +561,7 @@ public static bool TryLoadAsBinary( string path, [NotNullWhen(true)] out KeyValu /// public static KeyValue? LoadFromString( string input ) { - if ( input == null ) - { - throw new ArgumentNullException( nameof(input) ); - } + ArgumentNullException.ThrowIfNull( input ); byte[] bytes = Encoding.UTF8.GetBytes( input ); @@ -599,10 +590,7 @@ public static bool TryLoadAsBinary( string path, [NotNullWhen(true)] out KeyValu /// true if the read was successful; otherwise, false. public bool ReadAsText( Stream input ) { - if ( input == null ) - { - throw new ArgumentNullException( nameof(input) ); - } + ArgumentNullException.ThrowIfNull( input ); this.Children = new List(); @@ -707,10 +695,7 @@ public void SaveToFile( string path, bool asBinary ) /// If set to true, saves this instance as binary. public void SaveToStream( Stream stream, bool asBinary ) { - if ( stream == null ) - { - throw new ArgumentNullException( nameof(stream) ); - } + ArgumentNullException.ThrowIfNull( stream ); if (asBinary) { @@ -811,11 +796,8 @@ static void WriteString( Stream stream, string str, bool quote = false ) /// true if the read was successful; otherwise, false. public bool TryReadAsBinary( Stream input ) { - if ( input == null ) - { - throw new ArgumentNullException( nameof(input) ); - } - + ArgumentNullException.ThrowIfNull( input ); + return TryReadAsBinaryCore( input, this, null ); } diff --git a/SteamKit2/SteamKit2/Types/Manifest.cs b/SteamKit2/SteamKit2/Types/Manifest.cs index 0100ccfc6..6bcc33a42 100644 --- a/SteamKit2/SteamKit2/Types/Manifest.cs +++ b/SteamKit2/SteamKit2/Types/Manifest.cs @@ -112,10 +112,7 @@ internal void Deserialize( BinaryReader ds ) public Steam3Manifest(byte[] data) { - if (data == null) - { - throw new ArgumentNullException(nameof(data)); - } + ArgumentNullException.ThrowIfNull( data ); Deserialize(data); } diff --git a/SteamKit2/SteamKit2/Types/MessageObject.cs b/SteamKit2/SteamKit2/Types/MessageObject.cs index b7b9be8de..35b5aa29e 100644 --- a/SteamKit2/SteamKit2/Types/MessageObject.cs +++ b/SteamKit2/SteamKit2/Types/MessageObject.cs @@ -23,10 +23,7 @@ public class MessageObject /// The KeyValue backing store for this message object. public MessageObject( KeyValue keyValues ) { - if ( keyValues == null ) - { - throw new ArgumentNullException( nameof(keyValues) ); - } + ArgumentNullException.ThrowIfNull( keyValues ); this.KeyValues = keyValues; } @@ -46,10 +43,7 @@ public MessageObject() /// true on success; otherwise, false. public bool ReadFromStream( Stream stream ) { - if ( stream == null ) - { - throw new ArgumentNullException( nameof(stream) ); - } + ArgumentNullException.ThrowIfNull( stream ); return KeyValues.TryReadAsBinary( stream ); } @@ -60,10 +54,7 @@ public bool ReadFromStream( Stream stream ) /// The stream to write to. public void WriteToStream( Stream stream ) { - if ( stream == null ) - { - throw new ArgumentNullException( nameof(stream) ); - } + ArgumentNullException.ThrowIfNull( stream ); KeyValues.SaveToStream( stream, true ); } diff --git a/SteamKit2/SteamKit2/Types/PubFile.cs b/SteamKit2/SteamKit2/Types/PubFile.cs index 78cbd2db2..966480301 100644 --- a/SteamKit2/SteamKit2/Types/PubFile.cs +++ b/SteamKit2/SteamKit2/Types/PubFile.cs @@ -126,10 +126,7 @@ public PublishedFileID( ulong fileId = ulong.MaxValue ) /// public static implicit operator ulong( PublishedFileID? file ) { - if ( file is null ) - { - throw new ArgumentNullException( nameof(file) ); - } + ArgumentNullException.ThrowIfNull( file ); return file.Value; } diff --git a/SteamKit2/SteamKit2/Types/SteamID.cs b/SteamKit2/SteamKit2/Types/SteamID.cs index 057692ec5..ac4c504b4 100644 --- a/SteamKit2/SteamKit2/Types/SteamID.cs +++ b/SteamKit2/SteamKit2/Types/SteamID.cs @@ -657,10 +657,7 @@ string RenderSteam3() /// public static implicit operator ulong( SteamID sid ) { - if ( sid is null ) - { - throw new ArgumentNullException( nameof(sid) ); - } + ArgumentNullException.ThrowIfNull( sid ); return sid.steamid.Data; } diff --git a/SteamKit2/SteamKit2/Util/CryptoHelper.cs b/SteamKit2/SteamKit2/Util/CryptoHelper.cs index a71d912cb..ee43a955e 100644 --- a/SteamKit2/SteamKit2/Util/CryptoHelper.cs +++ b/SteamKit2/SteamKit2/Util/CryptoHelper.cs @@ -30,10 +30,7 @@ public class RSACrypto : IDisposable /// The public key to encrypt with. public RSACrypto( byte[] key ) { - if ( key == null ) - { - throw new ArgumentNullException( nameof(key) ); - } + ArgumentNullException.ThrowIfNull( key ); rsa = RSA.Create(); rsa.ImportSubjectPublicKeyInfo( key, out _ ); @@ -46,10 +43,7 @@ public RSACrypto( byte[] key ) /// The input to encrypt. public byte[] Encrypt( byte[] input ) { - if ( input == null ) - { - throw new ArgumentNullException( nameof(input) ); - } + ArgumentNullException.ThrowIfNull( input ); return rsa.Encrypt( input, RSAEncryptionPadding.OaepSHA1 ); } @@ -73,10 +67,7 @@ public static class CryptoHelper /// public static byte[] SHAHash( byte[] input ) { - if ( input == null ) - { - throw new ArgumentNullException( nameof(input) ); - } + ArgumentNullException.ThrowIfNull( input ); using ( var sha = SHA1.Create() ) { @@ -89,20 +80,11 @@ public static byte[] SHAHash( byte[] input ) /// public static byte[] AESEncrypt( byte[] input, byte[] key, byte[] iv ) { - if ( input == null ) - { - throw new ArgumentNullException( nameof(input) ); - } - - if ( key == null ) - { - throw new ArgumentNullException( nameof(key) ); - } - - if ( iv == null ) - { - throw new ArgumentNullException( nameof(iv) ); - } + ArgumentNullException.ThrowIfNull( input ); + + ArgumentNullException.ThrowIfNull( key ); + + ArgumentNullException.ThrowIfNull( iv ); using ( var aes = Aes.Create() ) { @@ -129,20 +111,11 @@ public static byte[] AESEncrypt( byte[] input, byte[] key, byte[] iv ) /// public static byte[] AESDecrypt( byte[] input, byte[] key, byte[] iv ) { - if ( input == null ) - { - throw new ArgumentNullException( nameof(input) ); - } - - if ( key == null ) - { - throw new ArgumentNullException( nameof(key) ); - } - - if ( iv == null ) - { - throw new ArgumentNullException( nameof(iv) ); - } + ArgumentNullException.ThrowIfNull( input ); + + ArgumentNullException.ThrowIfNull( key ); + + ArgumentNullException.ThrowIfNull( iv ); using ( var aes = Aes.Create() ) { @@ -174,20 +147,11 @@ public static byte[] AESDecrypt( byte[] input, byte[] key, byte[] iv ) /// public static byte[] SymmetricEncryptWithIV( byte[] input, byte[] key, byte[] iv ) { - if ( input == null ) - { - throw new ArgumentNullException( nameof(input) ); - } - - if ( key == null ) - { - throw new ArgumentNullException( nameof(key) ); - } - - if ( iv == null ) - { - throw new ArgumentNullException( nameof(iv) ); - } + ArgumentNullException.ThrowIfNull( input ); + + ArgumentNullException.ThrowIfNull( key ); + + ArgumentNullException.ThrowIfNull( iv ); DebugLog.Assert( key.Length == 32, "CryptoHelper", "SymmetricEncrypt used with non 32 byte key!" ); @@ -236,15 +200,9 @@ public static byte[] SymmetricEncryptWithIV( byte[] input, byte[] key, byte[] iv /// public static byte[] SymmetricEncrypt( byte[] input, byte[] key ) { - if ( input == null ) - { - throw new ArgumentNullException( nameof(input) ); - } - - if ( key == null ) - { - throw new ArgumentNullException( nameof(key) ); - } + ArgumentNullException.ThrowIfNull( input ); + + ArgumentNullException.ThrowIfNull( key ); var iv = GenerateRandomBlock( 16 ); return SymmetricEncryptWithIV( input, key, iv ); @@ -255,20 +213,11 @@ public static byte[] SymmetricEncrypt( byte[] input, byte[] key ) /// public static byte[] SymmetricEncryptWithHMACIV( byte[] input, byte[] key, byte[] hmacSecret ) { - if ( input == null ) - { - throw new ArgumentNullException( nameof(input) ); - } - - if ( key == null ) - { - throw new ArgumentNullException( nameof(key) ); - } - - if ( hmacSecret == null ) - { - throw new ArgumentNullException( nameof(hmacSecret) ); - } + ArgumentNullException.ThrowIfNull( input ); + + ArgumentNullException.ThrowIfNull( key ); + + ArgumentNullException.ThrowIfNull( hmacSecret ); // IV is HMAC-SHA1(Random(3) + Plaintext) + Random(3). (Same random values for both) var iv = new byte[ 16 ]; @@ -294,16 +243,10 @@ public static byte[] SymmetricEncryptWithHMACIV( byte[] input, byte[] key, byte[ /// public static byte[] SymmetricDecrypt( byte[] input, byte[] key ) { - if ( input == null ) - { - throw new ArgumentNullException( nameof(input) ); - } - - if ( key == null ) - { - throw new ArgumentNullException( nameof(key) ); - } - + ArgumentNullException.ThrowIfNull( input ); + + ArgumentNullException.ThrowIfNull( key ); + return SymmetricDecrypt( input, key, out _ ); } @@ -312,20 +255,11 @@ public static byte[] SymmetricDecrypt( byte[] input, byte[] key ) /// public static byte[] SymmetricDecryptHMACIV( byte[] input, byte[] key, byte[] hmacSecret ) { - if ( input == null ) - { - throw new ArgumentNullException( nameof(input) ); - } - - if ( key == null ) - { - throw new ArgumentNullException( nameof(key) ); - } - - if ( hmacSecret == null ) - { - throw new ArgumentNullException( nameof(hmacSecret) ); - } + ArgumentNullException.ThrowIfNull( input ); + + ArgumentNullException.ThrowIfNull( key ); + + ArgumentNullException.ThrowIfNull( hmacSecret ); DebugLog.Assert( key.Length >= 16, "CryptoHelper", "SymmetricDecryptHMACIV used with a key smaller than 16 bytes." ); var truncatedKeyForHmac = new byte[ 16 ]; @@ -358,15 +292,9 @@ public static byte[] SymmetricDecryptHMACIV( byte[] input, byte[] key, byte[] hm /// static byte[] SymmetricDecrypt( byte[] input, byte[] key, out byte[] iv ) { - if ( input == null ) - { - throw new ArgumentNullException( nameof(input) ); - } - - if ( key == null ) - { - throw new ArgumentNullException( nameof(key) ); - } + ArgumentNullException.ThrowIfNull( input ); + + ArgumentNullException.ThrowIfNull( key ); DebugLog.Assert( key.Length == 32, "CryptoHelper", "SymmetricDecrypt used with non 32 byte key!" ); @@ -419,15 +347,9 @@ static byte[] SymmetricDecrypt( byte[] input, byte[] key, out byte[] iv ) /// public static byte[]? VerifyAndDecryptPassword( byte[] input, string password ) { - if ( input == null ) - { - throw new ArgumentNullException( nameof(input) ); - } - - if ( password == null ) - { - throw new ArgumentNullException( nameof(password) ); - } + ArgumentNullException.ThrowIfNull( input ); + + ArgumentNullException.ThrowIfNull( password ); byte[] key, hash; using( var sha256 = SHA256.Create() ) @@ -455,16 +377,10 @@ static byte[] SymmetricDecrypt( byte[] input, byte[] key, out byte[] iv ) /// public static byte[] SymmetricDecryptECB( byte[] input, byte[] key ) { - if ( input == null ) - { - throw new ArgumentNullException( nameof(input) ); - } - - if ( key == null ) - { - throw new ArgumentNullException( nameof(key) ); - } - + ArgumentNullException.ThrowIfNull( input ); + + ArgumentNullException.ThrowIfNull( key ); + DebugLog.Assert( key.Length == 32, "CryptoHelper", "SymmetricDecryptECB used with non 32 byte key!" ); using ( var aes = Aes.Create() ) @@ -488,10 +404,7 @@ public static byte[] SymmetricDecryptECB( byte[] input, byte[] key ) /// public static byte[] CRCHash( byte[] input ) { - if ( input == null ) - { - throw new ArgumentNullException( nameof(input) ); - } + ArgumentNullException.ThrowIfNull( input ); using ( var crc = new Crc32() ) { @@ -507,11 +420,8 @@ public static byte[] CRCHash( byte[] input ) /// public static byte[] AdlerHash( byte[] input ) { - if ( input == null ) - { - throw new ArgumentNullException( nameof(input) ); - } - + ArgumentNullException.ThrowIfNull( input ); + uint a = 0, b = 0; for ( int i = 0 ; i < input.Length ; i++ ) { diff --git a/SteamKit2/SteamKit2/Util/DebugLog.cs b/SteamKit2/SteamKit2/Util/DebugLog.cs index 765ddbae8..160f07a5f 100644 --- a/SteamKit2/SteamKit2/Util/DebugLog.cs +++ b/SteamKit2/SteamKit2/Util/DebugLog.cs @@ -76,11 +76,8 @@ static DebugLog() /// The listener. public static void AddListener( IDebugListener listener ) { - if ( listener == null ) - { - throw new ArgumentNullException( nameof(listener) ); - } - + ArgumentNullException.ThrowIfNull( listener ); + listeners.Add( listener ); } ///