Browse Source

Use compound assignment (#186)

* Used compound assignment

* -||-

* -||-
pull/1923/head
Simon Hjorthøj GitHub 3 years ago
parent
commit
ab8e56634b
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 22 additions and 22 deletions
  1. +1
    -1
      samples/02_commands_framework/Modules/PublicModule.cs
  2. +2
    -2
      src/Discord.Net.Commands/Builders/ModuleClassBuilder.cs
  3. +1
    -1
      src/Discord.Net.Commands/Builders/ParameterBuilder.cs
  4. +3
    -3
      src/Discord.Net.Commands/CommandService.cs
  5. +3
    -3
      src/Discord.Net.Commands/Info/CommandInfo.cs
  6. +2
    -2
      src/Discord.Net.Commands/Info/ParameterInfo.cs
  7. +6
    -6
      src/Discord.Net.Rest/DiscordRestApiClient.cs
  8. +1
    -1
      src/Discord.Net.Rest/DiscordRestClient.cs
  9. +1
    -1
      src/Discord.Net.Rest/Entities/Messages/MessageHelper.cs
  10. +1
    -1
      src/Discord.Net.WebSocket/DiscordSocketClient.cs
  11. +1
    -1
      test/Discord.Net.Analyzers.Tests/Helpers/DiagnosticVerifier.Helper.cs

+ 1
- 1
samples/02_commands_framework/Modules/PublicModule.cs View File

@@ -31,7 +31,7 @@ namespace _02_commands_framework.Modules
[Command("userinfo")] [Command("userinfo")]
public async Task UserInfoAsync(IUser user = null) public async Task UserInfoAsync(IUser user = null)
{ {
user = user ?? Context.User;
user ??= Context.User;


await ReplyAsync(user.ToString()); await ReplyAsync(user.ToString());
} }


+ 2
- 2
src/Discord.Net.Commands/Builders/ModuleClassBuilder.cs View File

@@ -116,7 +116,7 @@ namespace Discord.Commands
builder.AddAliases(alias.Aliases); builder.AddAliases(alias.Aliases);
break; break;
case GroupAttribute group: case GroupAttribute group:
builder.Name = builder.Name ?? group.Prefix;
builder.Name ??= group.Prefix;
builder.Group = group.Prefix; builder.Group = group.Prefix;
builder.AddAliases(group.Prefix); builder.AddAliases(group.Prefix);
break; break;
@@ -158,7 +158,7 @@ namespace Discord.Commands
case CommandAttribute command: case CommandAttribute command:
builder.AddAliases(command.Text); builder.AddAliases(command.Text);
builder.RunMode = command.RunMode; builder.RunMode = command.RunMode;
builder.Name = builder.Name ?? command.Text;
builder.Name ??= command.Text;
builder.IgnoreExtraArgs = command.IgnoreExtraArgs ?? service._ignoreExtraArgs; builder.IgnoreExtraArgs = command.IgnoreExtraArgs ?? service._ignoreExtraArgs;
break; break;
case NameAttribute name: case NameAttribute name:


+ 1
- 1
src/Discord.Net.Commands/Builders/ParameterBuilder.cs View File

@@ -131,7 +131,7 @@ namespace Discord.Commands.Builders


internal ParameterInfo Build(CommandInfo info) internal ParameterInfo Build(CommandInfo info)
{ {
if ((TypeReader ?? (TypeReader = GetReader(ParameterType))) == null)
if ((TypeReader ??= GetReader(ParameterType)) == null)
throw new InvalidOperationException($"No type reader found for type {ParameterType.Name}, one must be specified"); throw new InvalidOperationException($"No type reader found for type {ParameterType.Name}, one must be specified");


return new ParameterInfo(this, info, Command.Module.Service); return new ParameterInfo(this, info, Command.Module.Service);


+ 3
- 3
src/Discord.Net.Commands/CommandService.cs View File

@@ -189,7 +189,7 @@ namespace Discord.Commands
/// </returns> /// </returns>
public async Task<ModuleInfo> AddModuleAsync(Type type, IServiceProvider services) public async Task<ModuleInfo> AddModuleAsync(Type type, IServiceProvider services)
{ {
services = services ?? EmptyServiceProvider.Instance;
services ??= EmptyServiceProvider.Instance;


await _moduleLock.WaitAsync().ConfigureAwait(false); await _moduleLock.WaitAsync().ConfigureAwait(false);
try try
@@ -224,7 +224,7 @@ namespace Discord.Commands
/// </returns> /// </returns>
public async Task<IEnumerable<ModuleInfo>> AddModulesAsync(Assembly assembly, IServiceProvider services) public async Task<IEnumerable<ModuleInfo>> AddModulesAsync(Assembly assembly, IServiceProvider services)
{ {
services = services ?? EmptyServiceProvider.Instance;
services ??= EmptyServiceProvider.Instance;


await _moduleLock.WaitAsync().ConfigureAwait(false); await _moduleLock.WaitAsync().ConfigureAwait(false);
try try
@@ -507,7 +507,7 @@ namespace Discord.Commands
/// </returns> /// </returns>
public async Task<IResult> ExecuteAsync(ICommandContext context, string input, IServiceProvider services, MultiMatchHandling multiMatchHandling = MultiMatchHandling.Exception) public async Task<IResult> ExecuteAsync(ICommandContext context, string input, IServiceProvider services, MultiMatchHandling multiMatchHandling = MultiMatchHandling.Exception)
{ {
services = services ?? EmptyServiceProvider.Instance;
services ??= EmptyServiceProvider.Instance;


var searchResult = Search(input); var searchResult = Search(input);
if (!searchResult.IsSuccess) if (!searchResult.IsSuccess)


+ 3
- 3
src/Discord.Net.Commands/Info/CommandInfo.cs View File

@@ -123,7 +123,7 @@ namespace Discord.Commands


public async Task<PreconditionResult> CheckPreconditionsAsync(ICommandContext context, IServiceProvider services = null) public async Task<PreconditionResult> CheckPreconditionsAsync(ICommandContext context, IServiceProvider services = null)
{ {
services = services ?? EmptyServiceProvider.Instance;
services ??= EmptyServiceProvider.Instance;


async Task<PreconditionResult> CheckGroups(IEnumerable<PreconditionAttribute> preconditions, string type) async Task<PreconditionResult> CheckGroups(IEnumerable<PreconditionAttribute> preconditions, string type)
{ {
@@ -164,7 +164,7 @@ namespace Discord.Commands


public async Task<ParseResult> ParseAsync(ICommandContext context, int startIndex, SearchResult searchResult, PreconditionResult preconditionResult = null, IServiceProvider services = null) public async Task<ParseResult> ParseAsync(ICommandContext context, int startIndex, SearchResult searchResult, PreconditionResult preconditionResult = null, IServiceProvider services = null)
{ {
services = services ?? EmptyServiceProvider.Instance;
services ??= EmptyServiceProvider.Instance;


if (!searchResult.IsSuccess) if (!searchResult.IsSuccess)
return ParseResult.FromError(searchResult); return ParseResult.FromError(searchResult);
@@ -201,7 +201,7 @@ namespace Discord.Commands
} }
public async Task<IResult> ExecuteAsync(ICommandContext context, IEnumerable<object> argList, IEnumerable<object> paramList, IServiceProvider services) public async Task<IResult> ExecuteAsync(ICommandContext context, IEnumerable<object> argList, IEnumerable<object> paramList, IServiceProvider services)
{ {
services = services ?? EmptyServiceProvider.Instance;
services ??= EmptyServiceProvider.Instance;


try try
{ {


+ 2
- 2
src/Discord.Net.Commands/Info/ParameterInfo.cs View File

@@ -75,7 +75,7 @@ namespace Discord.Commands


public async Task<PreconditionResult> CheckPreconditionsAsync(ICommandContext context, object arg, IServiceProvider services = null) public async Task<PreconditionResult> CheckPreconditionsAsync(ICommandContext context, object arg, IServiceProvider services = null)
{ {
services = services ?? EmptyServiceProvider.Instance;
services ??= EmptyServiceProvider.Instance;


foreach (var precondition in Preconditions) foreach (var precondition in Preconditions)
{ {
@@ -89,7 +89,7 @@ namespace Discord.Commands


public async Task<TypeReaderResult> ParseAsync(ICommandContext context, string input, IServiceProvider services = null) public async Task<TypeReaderResult> ParseAsync(ICommandContext context, string input, IServiceProvider services = null)
{ {
services = services ?? EmptyServiceProvider.Instance;
services ??= EmptyServiceProvider.Instance;
return await _reader.ReadAsync(context, input, services).ConfigureAwait(false); return await _reader.ReadAsync(context, input, services).ConfigureAwait(false);
} }




+ 6
- 6
src/Discord.Net.Rest/DiscordRestApiClient.cs View File

@@ -177,7 +177,7 @@ namespace Discord.API
public async Task SendAsync(string method, string endpoint, public async Task SendAsync(string method, string endpoint,
BucketId bucketId = null, ClientBucketType clientBucket = ClientBucketType.Unbucketed, RequestOptions options = null) BucketId bucketId = null, ClientBucketType clientBucket = ClientBucketType.Unbucketed, RequestOptions options = null)
{ {
options = options ?? new RequestOptions();
options ??= new RequestOptions();
options.HeaderOnly = true; options.HeaderOnly = true;
options.BucketId = bucketId; options.BucketId = bucketId;


@@ -191,7 +191,7 @@ namespace Discord.API
public async Task SendJsonAsync(string method, string endpoint, object payload, public async Task SendJsonAsync(string method, string endpoint, object payload,
BucketId bucketId = null, ClientBucketType clientBucket = ClientBucketType.Unbucketed, RequestOptions options = null) BucketId bucketId = null, ClientBucketType clientBucket = ClientBucketType.Unbucketed, RequestOptions options = null)
{ {
options = options ?? new RequestOptions();
options ??= new RequestOptions();
options.HeaderOnly = true; options.HeaderOnly = true;
options.BucketId = bucketId; options.BucketId = bucketId;


@@ -206,7 +206,7 @@ namespace Discord.API
public async Task SendMultipartAsync(string method, string endpoint, IReadOnlyDictionary<string, object> multipartArgs, public async Task SendMultipartAsync(string method, string endpoint, IReadOnlyDictionary<string, object> multipartArgs,
BucketId bucketId = null, ClientBucketType clientBucket = ClientBucketType.Unbucketed, RequestOptions options = null) BucketId bucketId = null, ClientBucketType clientBucket = ClientBucketType.Unbucketed, RequestOptions options = null)
{ {
options = options ?? new RequestOptions();
options ??= new RequestOptions();
options.HeaderOnly = true; options.HeaderOnly = true;
options.BucketId = bucketId; options.BucketId = bucketId;


@@ -220,7 +220,7 @@ namespace Discord.API
public async Task<TResponse> SendAsync<TResponse>(string method, string endpoint, public async Task<TResponse> SendAsync<TResponse>(string method, string endpoint,
BucketId bucketId = null, ClientBucketType clientBucket = ClientBucketType.Unbucketed, RequestOptions options = null) where TResponse : class BucketId bucketId = null, ClientBucketType clientBucket = ClientBucketType.Unbucketed, RequestOptions options = null) where TResponse : class
{ {
options = options ?? new RequestOptions();
options ??= new RequestOptions();
options.BucketId = bucketId; options.BucketId = bucketId;


var request = new RestRequest(RestClient, method, endpoint, options); var request = new RestRequest(RestClient, method, endpoint, options);
@@ -233,7 +233,7 @@ namespace Discord.API
public async Task<TResponse> SendJsonAsync<TResponse>(string method, string endpoint, object payload, public async Task<TResponse> SendJsonAsync<TResponse>(string method, string endpoint, object payload,
BucketId bucketId = null, ClientBucketType clientBucket = ClientBucketType.Unbucketed, RequestOptions options = null) where TResponse : class BucketId bucketId = null, ClientBucketType clientBucket = ClientBucketType.Unbucketed, RequestOptions options = null) where TResponse : class
{ {
options = options ?? new RequestOptions();
options ??= new RequestOptions();
options.BucketId = bucketId; options.BucketId = bucketId;


string json = payload != null ? SerializeJson(payload) : null; string json = payload != null ? SerializeJson(payload) : null;
@@ -248,7 +248,7 @@ namespace Discord.API
public async Task<TResponse> SendMultipartAsync<TResponse>(string method, string endpoint, IReadOnlyDictionary<string, object> multipartArgs, public async Task<TResponse> SendMultipartAsync<TResponse>(string method, string endpoint, IReadOnlyDictionary<string, object> multipartArgs,
BucketId bucketId = null, ClientBucketType clientBucket = ClientBucketType.Unbucketed, RequestOptions options = null) BucketId bucketId = null, ClientBucketType clientBucket = ClientBucketType.Unbucketed, RequestOptions options = null)
{ {
options = options ?? new RequestOptions();
options ??= new RequestOptions();
options.BucketId = bucketId; options.BucketId = bucketId;


var request = new MultipartRestRequest(RestClient, method, endpoint, multipartArgs, options); var request = new MultipartRestRequest(RestClient, method, endpoint, multipartArgs, options);


+ 1
- 1
src/Discord.Net.Rest/DiscordRestClient.cs View File

@@ -62,7 +62,7 @@ namespace Discord.Rest


public async Task<RestApplication> GetApplicationInfoAsync(RequestOptions options = null) public async Task<RestApplication> GetApplicationInfoAsync(RequestOptions options = null)
{ {
return _applicationInfo ?? (_applicationInfo = await ClientHelper.GetApplicationInfoAsync(this, options).ConfigureAwait(false));
return _applicationInfo ??= await ClientHelper.GetApplicationInfoAsync(this, options).ConfigureAwait(false);
} }


public Task<RestChannel> GetChannelAsync(ulong id, RequestOptions options = null) public Task<RestChannel> GetChannelAsync(ulong id, RequestOptions options = null)


+ 1
- 1
src/Discord.Net.Rest/Entities/Messages/MessageHelper.cs View File

@@ -344,7 +344,7 @@ namespace Discord.Rest
tags.Add(new Tag<Emote>(TagType.Emoji, index, content.Length, emoji.Id, emoji)); tags.Add(new Tag<Emote>(TagType.Emoji, index, content.Length, emoji.Id, emoji));
else //Bad Tag else //Bad Tag
{ {
index = index + 1;
index++;
continue; continue;
} }
index = endIndex + 1; index = endIndex + 1;


+ 1
- 1
src/Discord.Net.WebSocket/DiscordSocketClient.cs View File

@@ -322,7 +322,7 @@ namespace Discord.WebSocket


/// <inheritdoc /> /// <inheritdoc />
public override async Task<RestApplication> GetApplicationInfoAsync(RequestOptions options = null) public override async Task<RestApplication> GetApplicationInfoAsync(RequestOptions options = null)
=> _applicationInfo ?? (_applicationInfo = await ClientHelper.GetApplicationInfoAsync(this, options ?? RequestOptions.Default).ConfigureAwait(false));
=> _applicationInfo ??= await ClientHelper.GetApplicationInfoAsync(this, options ?? RequestOptions.Default).ConfigureAwait(false);


/// <inheritdoc /> /// <inheritdoc />
public override SocketGuild GetGuild(ulong id) public override SocketGuild GetGuild(ulong id)


+ 1
- 1
test/Discord.Net.Analyzers.Tests/Helpers/DiagnosticVerifier.Helper.cs View File

@@ -187,7 +187,7 @@ namespace TestHelper


private static HashSet<Assembly> RecursiveReferencedAssemblies(Assembly a, HashSet<Assembly> assemblies = null) private static HashSet<Assembly> RecursiveReferencedAssemblies(Assembly a, HashSet<Assembly> assemblies = null)
{ {
assemblies = assemblies ?? new HashSet<Assembly>();
assemblies ??= new HashSet<Assembly>();
if (assemblies.Add(a)) if (assemblies.Add(a))
{ {
foreach (var referencedAssemblyName in a.GetReferencedAssemblies()) foreach (var referencedAssemblyName in a.GetReferencedAssemblies())


Loading…
Cancel
Save