Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collection expressions (IDE0300) #6726

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,11 @@ public class EntitiesResolverTests
var representations = new List<Representation>
{
new("FederatedTypeWithRequiredDetail",
new ObjectValueNode(new[]
{
new ObjectValueNode(
[
new ObjectFieldNode("detail",
new ObjectValueNode(new[] { new ObjectFieldNode("id", "testId") })),
})),
new ObjectValueNode([new ObjectFieldNode("id", "testId")])),
])),
};

var result = await EntitiesResolver.ResolveAsync(schema, representations, context);
Expand All @@ -215,8 +215,8 @@ public class EntitiesResolverTests
var representations = new List<Representation>
{
new("FederatedTypeWithOptionalDetail",
new ObjectValueNode(new[]
{
new ObjectValueNode(
[
new ObjectFieldNode("detail",
new ObjectValueNode(new[]
{
Expand Down
8 changes: 4 additions & 4 deletions src/HotChocolate/AspNetCore/src/AspNetCore/ContentType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ internal static class ContentType
public const string Html = $"{Types.Text}/{SubTypes.Html}";

private static readonly char[] _jsonArray =
{
[
'a', 'p', 'p', 'l', 'i', 'c', 'a', 't', 'i', 'o', 'n', '/', 'j', 's', 'o', 'n',
};
];

private static readonly char[] _multiPartFormArray =
{
[
'm', 'u', 'l', 't', 'i', 'p', 'a', 'r', 't', '/', 'f', 'o', 'r', 'm', '-', 'd', 'a',
't', 'a',
};
];

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ReadOnlySpan<char> JsonSpan() => _jsonArray;
Expand Down
4 changes: 2 additions & 2 deletions src/HotChocolate/AspNetCore/src/AspNetCore/HeaderUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ internal static class HeaderUtilities
new(StringComparer.Ordinal);

public static readonly AcceptMediaType[] GraphQLResponseContentTypes =
{
[
new AcceptMediaType(
ContentType.Types.Application,
ContentType.SubTypes.GraphQLResponse,
null,
StringSegment.Empty),
};
];

/// <summary>
/// Gets the parsed accept header values from a request.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ namespace HotChocolate.AspNetCore;
public sealed class HttpGetSchemaMiddleware : MiddlewareBase
{
private static readonly AcceptMediaType[] _mediaTypes =
{
[
new AcceptMediaType(
ContentType.Types.Application,
ContentType.SubTypes.GraphQLResponse,
null,
default),
};
];
private readonly MiddlewareRoutingType _routing;
private readonly IServerDiagnosticEvents _diagnosticEvents;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace HotChocolate.AspNetCore.Subscriptions.Protocols.Apollo;
internal static class Utf8MessageBodies
{
private static readonly byte[] _keepAlive =
{
[
(byte)'{',
(byte)'"',
(byte)'t',
Expand All @@ -17,7 +17,7 @@ internal static class Utf8MessageBodies
(byte)'a',
(byte)'"',
(byte)'}',
};
];

public static ReadOnlyMemory<byte> KeepAlive => _keepAlive;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace HotChocolate.AspNetCore.Subscriptions.Protocols.GraphQLOverWebSocket;
internal static class Utf8MessageBodies
{
private static readonly byte[] _defaultPong =
{
[
(byte)'{',
(byte)'"',
(byte)'t',
Expand All @@ -19,10 +19,10 @@ internal static class Utf8MessageBodies
(byte)'g',
(byte)'"',
(byte)'}',
};
];

private static readonly byte[] _defaultPing =
{
[
(byte)'{',
(byte)'"',
(byte)'t',
Expand All @@ -38,7 +38,7 @@ internal static class Utf8MessageBodies
(byte)'g',
(byte)'"',
(byte)'}',
};
];

public static ReadOnlyMemory<byte> DefaultPing => _defaultPing;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ private static void CollectFile(
}
else
{
list = new[] { path };
list = [path];
files.Add(file, list);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ namespace HotChocolate.Transport.Sockets.Client;
public sealed class SocketClient : ISocket
{
private static readonly IProtocolHandler[] _protocolHandlers =
{
[
new GraphQLOverWebSocketProtocolHandler(),
};
];

private readonly CancellationTokenSource _cts = new();
private readonly CancellationToken _ct;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ public class Query
[Authorize(Policy = Policies.HasDefinedAge)]
public string GetAge() => "foo";

[Authorize(Roles = new[] { "a" })]
[Authorize(Roles = ["a"])]
public string GetRoles() => "foo";

[Authorize(Roles = new[] { "a", "b" })]
[Authorize(Roles = ["a", "b"])]
[GraphQLName("roles_ab")]
public string GetRolesAb() => "foo";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ public class Query
[Authorize("HasAgeDefined", ApplyPolicy.BeforeResolver)]
public string? GetAge() => "foo";

[Authorize(ApplyPolicy.BeforeResolver, Roles = new[] { "a" })]
[Authorize(ApplyPolicy.BeforeResolver, Roles = ["a"])]
public string? GetRoles() => "foo";

[Authorize(ApplyPolicy.BeforeResolver, Roles = new[] { "a", "b" })]
[Authorize(ApplyPolicy.BeforeResolver, Roles = ["a", "b"])]
[GraphQLName("roles_ab")]
public string? GetRolesAb() => "foo";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public void TypeAuth_WithRoles()
.AddQueryType(
c => c
.Name("Query")
.Authorize(new[] { "MyRole" })
.Authorize(["MyRole"])
.Field("foo")
.Resolve("bar"))
.AddAuthorizeDirectiveType()
Expand All @@ -169,7 +169,7 @@ public void TypeAuth_WithRoles_DescriptorNull()
// arrange
// act
void Action()
=> AuthorizeObjectTypeDescriptorExtensions.Authorize(null!, new[] { "MyRole" });
=> AuthorizeObjectTypeDescriptorExtensions.Authorize(null!, ["MyRole"]);

// assert
Assert.Throws<ArgumentNullException>(Action);
Expand Down Expand Up @@ -399,7 +399,7 @@ public async Task FieldAuth_WithRoles()
c => c
.Name("Query")
.Field("foo")
.Authorize(new[] { "MyRole" })
.Authorize(["MyRole"])
.Resolve("bar"))
.AddAuthorization()
.BuildSchemaAsync();
Expand All @@ -415,7 +415,7 @@ public void FieldAuth_WithRoles_DescriptorNull()
// act
Action action = () =>
AuthorizeObjectFieldDescriptorExtensions
.Authorize(null!, new[] { "MyRole" });
.Authorize(null!, ["MyRole"]);

// assert
Assert.Throws<ArgumentNullException>(action);
Expand Down
2 changes: 1 addition & 1 deletion src/HotChocolate/Core/src/Abstractions/GraphQLException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public GraphQLException(IError error)
{
Errors = error is null
? Array.Empty<IError>()
: new[] { error };
: [error];
}

public GraphQLException(params IError[] errors)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public IOperation Compile(
var rootPath = SelectionPath.Root;
var id = GetOrCreateSelectionSetRefId(operationDefinition.SelectionSet, rootPath);
var variants = GetOrCreateSelectionVariants(id);
SelectionSetInfo[] infos = { new(operationDefinition.SelectionSet, 0) };
SelectionSetInfo[] infos = [new(operationDefinition.SelectionSet, 0)];

var context = new CompilerContext(schema, document, enableNullBubbling);
context.Initialize(operationType, variants, infos, rootPath, rootOptimizers);
Expand Down Expand Up @@ -522,7 +522,7 @@ selection.SelectionSet is not null
arguments: CoerceArgumentValues(field, selection, responseName),
includeConditions: includeCondition == 0
? null
: new[] { includeCondition });
: [includeCondition]);

context.Fields.Add(responseName, preparedSelection);

Expand All @@ -531,7 +531,7 @@ selection.SelectionSet is not null
var selectionSetInfo = new SelectionSetInfo(
selection.SelectionSet!,
includeCondition);
_selectionLookup.Add(preparedSelection, new[] { selectionSetInfo });
_selectionLookup.Add(preparedSelection, [selectionSetInfo]);
}
}
}
Expand Down Expand Up @@ -843,7 +843,7 @@ internal void RegisterNewSelection(Selection newSelection)
if (newSelection.SyntaxNode.SelectionSet is not null)
{
var selectionSetInfo = new SelectionSetInfo(newSelection.SelectionSet!, 0);
_selectionLookup.Add(newSelection, new[] { selectionSetInfo });
_selectionLookup.Add(newSelection, [selectionSetInfo]);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,28 @@ namespace HotChocolate.Execution.Serialization;
public sealed partial class MultiPartResultFormatter
{
private static byte[] ContentType { get; } =
{
[
(byte)'C', (byte)'o', (byte)'n', (byte)'t', (byte)'e', (byte)'n', (byte)'t',
(byte)'-', (byte)'T', (byte)'y', (byte)'p', (byte)'e', (byte)':', (byte)' ',
(byte)'a', (byte)'p', (byte)'p', (byte)'l', (byte)'i', (byte)'c', (byte)'a',
(byte)'t', (byte)'i', (byte)'o', (byte)'n', (byte)'/', (byte)'j', (byte)'s',
(byte)'o', (byte)'n', (byte)';', (byte)' ', (byte)'c', (byte)'h', (byte)'a',
(byte)'r', (byte)'s', (byte)'e', (byte)'t', (byte)'=', (byte)'u', (byte)'t',
(byte)'f', (byte)'-', (byte)'8',
};
];

private static byte[] Start { get; } =
{
[
(byte)'-', (byte)'-', (byte)'-',
};
];

private static byte[] End { get; } =
{
[
(byte)'-', (byte)'-', (byte)'-', (byte)'-', (byte)'-',
};
];

private static byte[] CrLf { get; } =
{
[
(byte)'\r', (byte)'\n',
};
];
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ namespace HotChocolate.Types.Analyzers;
public class TypeModuleGenerator : IIncrementalGenerator
{
private static readonly ISyntaxInspector[] _inspectors =
{
[
new TypeAttributeInspector(),
new ClassBaseClassInspector(),
new ModuleInspector(),
new DataLoaderInspector(),
new DataLoaderDefaultsInspector(),
};
];

private static readonly ISyntaxGenerator[] _generators =
{
[
new ModuleGenerator(),
new DataLoaderGenerator(),
};
];

public void Initialize(IncrementalGeneratorInitializationContext context)
{
Expand Down
4 changes: 2 additions & 2 deletions src/HotChocolate/Core/src/Types.Scalars/PostalCodeType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class PostalCodeType : StringType
/// Different validation patterns for postal codes.
/// </summary>
private static readonly Regex[] _validationPatterns =
{
[
CreateRegexUs(),
CreateRegexUk(),
CreateRegexDe(),
Expand All @@ -37,7 +37,7 @@ public class PostalCodeType : StringType
CreateRegexPt(),
CreateRegexCh(),
CreateRegexLu(),
};
];

#if DISABLED_DUE_TO_COMPILER_ISSUE
[GeneratedRegex(PostalCodePatterns.US, RegexOptions.IgnoreCase, DefaultRegexTimeoutInMs)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public override bool TryInferType(
return false;
}

schemaTypeRefs = new[] { schemaType };
schemaTypeRefs = [schemaType];
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ namespace HotChocolate.Configuration.Validation;
internal static class SchemaValidator
{
private static readonly ISchemaValidationRule[] _rules =
{
[
new ObjectTypeValidationRule(),
new InterfaceTypeValidationRule(),
new InputObjectTypeValidationRule(),
new DirectiveValidationRule(),
new InterfaceHasAtLeastOneImplementationRule(),
};
];

public static IReadOnlyCollection<ISchemaError> Validate(
IEnumerable<ITypeSystemObject> typeSystemObjects,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ internal static void UsePooledService(
Type serviceType)
=> _usePooledService
.MakeGenericMethod(serviceType)
.Invoke(null, new object?[] { definition });
.Invoke(null, [definition]);

internal static void UsePooledService<TService>(
ObjectFieldDefinition definition)
Expand Down Expand Up @@ -71,7 +71,7 @@ internal static void UseResolverService(
Type serviceType)
=> _useResolverService
.MakeGenericMethod(serviceType)
.Invoke(null, new object?[] { definition });
.Invoke(null, [definition]);

private static void UseResolverServiceInternal<TService>(
ObjectFieldDefinition definition)
Expand Down Expand Up @@ -136,7 +136,7 @@ internal static void UseResolverKeyedService(
string key)
=> _useResolverKeyedService
.MakeGenericMethod(serviceType)
.Invoke(null, new object?[] { definition, key });
.Invoke(null, [definition, key]);

private static void UseResolverKeyedServiceInternal<TService>(
ObjectFieldDefinition definition,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static FieldMiddleware Create(
{
return (FieldMiddleware)_createGeneric
.MakeGenericMethod(middlewareType)
.Invoke(null, new object[] { services });
.Invoke(null, [services]);
}

public static FieldMiddleware Create<TMiddleware>(
Expand Down
Loading
Loading