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")]
public async Task UserInfoAsync(IUser user = null)
{
user = user ?? Context.User;
user ??= Context.User;

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);
break;
case GroupAttribute group:
builder.Name = builder.Name ?? group.Prefix;
builder.Name ??= group.Prefix;
builder.Group = group.Prefix;
builder.AddAliases(group.Prefix);
break;
@@ -158,7 +158,7 @@ namespace Discord.Commands
case CommandAttribute command:
builder.AddAliases(command.Text);
builder.RunMode = command.RunMode;
builder.Name = builder.Name ?? command.Text;
builder.Name ??= command.Text;
builder.IgnoreExtraArgs = command.IgnoreExtraArgs ?? service._ignoreExtraArgs;
break;
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)
{
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");

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>
public async Task<ModuleInfo> AddModuleAsync(Type type, IServiceProvider services)
{
services = services ?? EmptyServiceProvider.Instance;
services ??= EmptyServiceProvider.Instance;

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

await _moduleLock.WaitAsync().ConfigureAwait(false);
try
@@ -507,7 +507,7 @@ namespace Discord.Commands
/// </returns>
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);
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)
{
services = services ?? EmptyServiceProvider.Instance;
services ??= EmptyServiceProvider.Instance;

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)
{
services = services ?? EmptyServiceProvider.Instance;
services ??= EmptyServiceProvider.Instance;

if (!searchResult.IsSuccess)
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)
{
services = services ?? EmptyServiceProvider.Instance;
services ??= EmptyServiceProvider.Instance;

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)
{
services = services ?? EmptyServiceProvider.Instance;
services ??= EmptyServiceProvider.Instance;

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

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);
}



+ 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,
BucketId bucketId = null, ClientBucketType clientBucket = ClientBucketType.Unbucketed, RequestOptions options = null)
{
options = options ?? new RequestOptions();
options ??= new RequestOptions();
options.HeaderOnly = true;
options.BucketId = bucketId;

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

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

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

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,
BucketId bucketId = null, ClientBucketType clientBucket = ClientBucketType.Unbucketed, RequestOptions options = null) where TResponse : class
{
options = options ?? new RequestOptions();
options ??= new RequestOptions();
options.BucketId = bucketId;

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,
BucketId bucketId = null, ClientBucketType clientBucket = ClientBucketType.Unbucketed, RequestOptions options = null)
{
options = options ?? new RequestOptions();
options ??= new RequestOptions();
options.BucketId = bucketId;

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)
{
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)


+ 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));
else //Bad Tag
{
index = index + 1;
index++;
continue;
}
index = endIndex + 1;


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

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

/// <inheritdoc />
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 />
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)
{
assemblies = assemblies ?? new HashSet<Assembly>();
assemblies ??= new HashSet<Assembly>();
if (assemblies.Add(a))
{
foreach (var referencedAssemblyName in a.GetReferencedAssemblies())


Loading…
Cancel
Save