Skip to content

Commit

Permalink
Use ArgumentNullException.ThrowIfNull
Browse files Browse the repository at this point in the history
  • Loading branch information
xPaw committed Nov 16, 2023
1 parent 3c35e4a commit 414e6e3
Show file tree
Hide file tree
Showing 44 changed files with 185 additions and 674 deletions.
20 changes: 4 additions & 16 deletions SteamKit2/SteamKit2/Base/ClientMsg.cs
Original file line number Diff line number Diff line change
Expand Up @@ -325,10 +325,7 @@ public ClientMsg( int payloadReserve = 64 )
public ClientMsg( MsgBase<ExtendedClientMsgHdr> 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;
Expand All @@ -342,10 +339,7 @@ public ClientMsg( MsgBase<ExtendedClientMsgHdr> 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 ) )
{
Expand Down Expand Up @@ -479,10 +473,7 @@ public Msg( int payloadReserve = 0 )
public Msg( MsgBase<MsgHdr> 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;
Expand All @@ -496,10 +487,7 @@ public Msg( MsgBase<MsgHdr> 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 ) )
{
Expand Down
25 changes: 5 additions & 20 deletions SteamKit2/SteamKit2/Base/GC/ClientMsgGC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,7 @@ public ClientGCMsgProtobuf( uint eMsg, int payloadReserve = 64 )
public ClientGCMsgProtobuf( uint eMsg, GCMsgBase<MsgGCHdrProtoBuf> 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;
Expand Down Expand Up @@ -142,10 +139,7 @@ public override byte[] Serialize()
/// <param name="data">The data representing a gc message.</param>
public override void Deserialize( byte[] data )
{
if ( data == null )
{
throw new ArgumentNullException( nameof(data) );
}
ArgumentNullException.ThrowIfNull( data );

using ( MemoryStream ms = new MemoryStream( data ) )
{
Expand Down Expand Up @@ -238,10 +232,7 @@ public ClientGCMsg( int payloadReserve = 64 )
public ClientGCMsg( GCMsgBase<MsgGCHdr> 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;
Expand All @@ -255,10 +246,7 @@ public ClientGCMsg( GCMsgBase<MsgGCHdr> 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!" );

Expand Down Expand Up @@ -288,10 +276,7 @@ public override byte[] Serialize()
/// <param name="data">The data representing a client message.</param>
public override void Deserialize( byte[] data )
{
if ( data == null )
{
throw new ArgumentNullException( nameof(data) );
}
ArgumentNullException.ThrowIfNull( data );

using ( MemoryStream ms = new MemoryStream( data ) )
{
Expand Down
10 changes: 2 additions & 8 deletions SteamKit2/SteamKit2/Base/GC/PacketBaseGC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,7 @@ public sealed class PacketClientGCMsgProtobuf : IPacketGCMsg
/// <param name="data">The data.</param>
public PacketClientGCMsgProtobuf( uint eMsg, byte[] data )
{
if ( data == null )
{
throw new ArgumentNullException( nameof(data) );
}
ArgumentNullException.ThrowIfNull( data );

MsgType = eMsg;
payload = data;
Expand Down Expand Up @@ -193,10 +190,7 @@ public sealed class PacketClientGCMsg : IPacketGCMsg
/// <param name="data">The data.</param>
public PacketClientGCMsg( uint eMsg, byte[] data )
{
if ( data == null )
{
throw new ArgumentNullException( nameof(data) );
}
ArgumentNullException.ThrowIfNull( data );

MsgType = eMsg;
payload = data;
Expand Down
10 changes: 2 additions & 8 deletions SteamKit2/SteamKit2/Base/MsgBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) );
}
Expand Down Expand Up @@ -420,10 +417,7 @@ public string ReadNullTermString()
/// /// <returns>The string.</returns>
public string ReadNullTermString( Encoding encoding )
{
if ( encoding == null )
{
throw new ArgumentNullException( nameof(encoding) );
}
ArgumentNullException.ThrowIfNull( encoding );

return Payload.ReadNullTermString( encoding );
}
Expand Down
15 changes: 3 additions & 12 deletions SteamKit2/SteamKit2/Base/PacketBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,7 @@ public sealed class PacketClientMsgProtobuf : IPacketMsg
/// <param name="data">The data.</param>
public PacketClientMsgProtobuf( EMsg eMsg, byte[] data )
{
if ( data == null )
{
throw new ArgumentNullException( nameof(data) );
}
ArgumentNullException.ThrowIfNull( data );

MsgType = eMsg;
payload = data;
Expand Down Expand Up @@ -215,10 +212,7 @@ public sealed class PacketClientMsg : IPacketMsg
/// <param name="data">The data.</param>
public PacketClientMsg( EMsg eMsg, byte[] data )
{
if ( data == null )
{
throw new ArgumentNullException( nameof(data) );
}
ArgumentNullException.ThrowIfNull( data );

MsgType = eMsg;
payload = data;
Expand Down Expand Up @@ -302,10 +296,7 @@ public sealed class PacketMsg : IPacketMsg
/// <param name="data">The data.</param>
public PacketMsg( EMsg eMsg, byte[] data )
{
if ( data == null )
{
throw new ArgumentNullException( nameof(data) );
}
ArgumentNullException.ThrowIfNull( data );

MsgType = eMsg;
payload = data;
Expand Down
10 changes: 2 additions & 8 deletions SteamKit2/SteamKit2/Steam/Authentication/SteamAuthentication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ public sealed class SteamAuthentication
/// <param name="steamClient">The <see cref="SteamClient"/> this instance will be associated with.</param>
internal SteamAuthentication( SteamClient steamClient )
{
if ( steamClient == null )
{
throw new ArgumentNullException( nameof( steamClient ) );
}
ArgumentNullException.ThrowIfNull( steamClient );

Client = steamClient;

Expand Down Expand Up @@ -134,10 +131,7 @@ public async Task<QrAuthSession> BeginAuthSessionViaQRAsync( AuthSessionDetails
/// <exception cref="ArgumentException">Username or password are not set within <paramref name="details"/>.</exception>
public async Task<CredentialsAuthSession> BeginAuthSessionViaCredentialsAsync( AuthSessionDetails details )
{
if ( details == null )
{
throw new ArgumentNullException( nameof( details ) );
}
ArgumentNullException.ThrowIfNull( details );

if ( string.IsNullOrEmpty( details.Username ) || string.IsNullOrEmpty( details.Password ) )
{
Expand Down
20 changes: 4 additions & 16 deletions SteamKit2/SteamKit2/Steam/CDN/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@ public sealed class Client : IDisposable
/// The SteamClient instance must be connected and logged onto Steam.</param>
public Client( SteamClient steamClient )
{
if ( steamClient == null )
{
throw new ArgumentNullException( nameof( steamClient ) );
}
ArgumentNullException.ThrowIfNull( steamClient );

this.httpClient = steamClient.Configuration.HttpClientFactory();
}
Expand Down Expand Up @@ -70,10 +67,7 @@ public void Dispose()
/// <exception cref="SteamKitWebRequestException">A network error occurred when performing the request.</exception>
public async Task<DepotManifest> 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;
Expand Down Expand Up @@ -127,15 +121,9 @@ public async Task<DepotManifest> DownloadManifestAsync( uint depotId, ulong mani
/// <exception cref="SteamKitWebRequestException">A network error occurred when performing the request.</exception>
public async Task<DepotChunk> 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 )
{
Expand Down
15 changes: 3 additions & 12 deletions SteamKit2/SteamKit2/Steam/CDN/DepotChunk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,9 @@ public sealed class DepotChunk
/// <param name="data">The underlying data for this chunk.</param>
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;
Expand All @@ -61,10 +55,7 @@ public DepotChunk( DepotManifest.ChunkData info, byte[] data )
/// <exception cref="System.IO.InvalidDataException">Thrown if the processed data does not match the expected checksum given in it's chunk information.</exception>
public void Process( byte[] depotKey )
{
if ( depotKey == null )
{
throw new ArgumentNullException( nameof( depotKey ) );
}
ArgumentNullException.ThrowIfNull( depotKey );

if ( IsProcessed )
{
Expand Down
2 changes: 1 addition & 1 deletion SteamKit2/SteamKit2/Steam/CMClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,7 @@ public Task<IEnumerable<ServerRecord>> FetchServerListAsync()
/// <returns>Awaitable task for write completion</returns>
public Task UpdateServerListAsync(IEnumerable<ServerRecord> endpoints)
{
if (endpoints == null)
{
throw new ArgumentNullException(nameof(endpoints));
}
ArgumentNullException.ThrowIfNull( endpoints );

return Task.Run(() =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,7 @@ public Task<IEnumerable<ServerRecord>> FetchServerListAsync()
/// <returns>Awaitable task for write completion</returns>
public Task UpdateServerListAsync(IEnumerable<ServerRecord> endpoints)
{
if (endpoints == null)
{
throw new ArgumentNullException(nameof(endpoints));
}
ArgumentNullException.ThrowIfNull( endpoints );

return Task.Run(() =>
{
Expand Down
5 changes: 1 addition & 4 deletions SteamKit2/SteamKit2/Steam/Discovery/ServerRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,7 @@ public static bool TryCreateSocketServer(string address, [NotNullWhen(true)] out
/// <returns>A new <see cref="ServerRecord"/> instance</returns>
public static ServerRecord CreateWebSocketServer(string address)
{
if (address == null)
{
throw new ArgumentNullException(nameof(address));
}
ArgumentNullException.ThrowIfNull( address );

EndPoint endPoint;
const int DefaultPort = 443;
Expand Down
5 changes: 1 addition & 4 deletions SteamKit2/SteamKit2/Steam/Discovery/SmartCMServerList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,7 @@ public void ResetOldScores()
/// <param name="endpointList">The <see cref="ServerRecord"/>s to use for this <see cref="SmartCMServerList"/>.</param>
public void ReplaceList( IEnumerable<ServerRecord> endpointList )
{
if ( endpointList == null )
{
throw new ArgumentNullException( nameof(endpointList) );
}
ArgumentNullException.ThrowIfNull( endpointList );

lock ( listLock )
{
Expand Down
20 changes: 4 additions & 16 deletions SteamKit2/SteamKit2/Steam/Handlers/SteamApps/SteamApps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,15 +204,9 @@ public AsyncJobMultiple<PICSProductInfoCallback> PICSGetProductInfo( PICSRequest
/// <returns>The Job ID of the request. This can be used to find the appropriate <see cref="PICSProductInfoCallback"/>.</returns>
public AsyncJobMultiple<PICSProductInfoCallback> PICSGetProductInfo( IEnumerable<PICSRequest> apps, IEnumerable<PICSRequest> 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<CMsgClientPICSProductInfoRequest>( EMsg.ClientPICSProductInfoRequest );
request.SourceJobID = Client.GetNextJobID();
Expand Down Expand Up @@ -287,10 +281,7 @@ public AsyncJob<FreeLicenseCallback> RequestFreeLicense( uint app )
/// <returns>The Job ID of the request. This can be used to find the appropriate <see cref="FreeLicenseCallback"/>.</returns>
public AsyncJob<FreeLicenseCallback> RequestFreeLicense( IEnumerable<uint> apps )
{
if ( apps == null )
{
throw new ArgumentNullException( nameof(apps) );
}
ArgumentNullException.ThrowIfNull( apps );

var request = new ClientMsgProtobuf<CMsgClientRequestFreeLicense>( EMsg.ClientRequestFreeLicense );
request.SourceJobID = Client.GetNextJobID();
Expand Down Expand Up @@ -344,10 +335,7 @@ public AsyncJob<LegacyGameKeyCallback> GetLegacyGameKey( uint appid )
/// <param name="packetMsg">The packet message that contains the data.</param>
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 ) )
{
Expand Down
Loading

0 comments on commit 414e6e3

Please sign in to comment.