Skip to content

Commit 89cc90c

Browse files
Use collection initializers
1 parent cece3a1 commit 89cc90c

File tree

12 files changed

+43
-43
lines changed

12 files changed

+43
-43
lines changed

examples/AspNet/OData/SomeOpenApiODataWebApiExample/BooksController.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414
[RoutePrefix( "api/books" )]
1515
public class BooksController : ApiController
1616
{
17-
private static readonly Book[] books = new Book[]
18-
{
17+
private static readonly Book[] books =
18+
[
1919
new() { Id = "9781847490599", Title = "Anna Karenina", Author = "Leo Tolstoy", Published = 1878 },
2020
new() { Id = "9780198800545", Title = "War and Peace", Author = "Leo Tolstoy", Published = 1869 },
2121
new() { Id = "9780684801520", Title = "The Great Gatsby", Author = "F. Scott Fitzgerald", Published = 1925 },
2222
new() { Id = "9780486280615", Title = "The Adventures of Huckleberry Finn", Author = "Mark Twain", Published = 1884 },
2323
new() { Id = "9780140430820", Title = "Moby Dick", Author = "Herman Melville", Published = 1851 },
2424
new() { Id = "9780060934347", Title = "Don Quixote", Author = "Miguel de Cervantes", Published = 1605 },
25-
};
25+
];
2626

2727
/// <summary>
2828
/// Gets all books.

examples/AspNetCore/OData/SomeODataOpenApiExample/BooksController.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@
1313
[Route( "api/[controller]" )]
1414
public class BooksController : ControllerBase
1515
{
16-
private static readonly Book[] books = new Book[]
17-
{
16+
private static readonly Book[] books =
17+
[
1818
new() { Id = "9781847490599", Title = "Anna Karenina", Author = "Leo Tolstoy", Published = 1878 },
1919
new() { Id = "9780198800545", Title = "War and Peace", Author = "Leo Tolstoy", Published = 1869 },
2020
new() { Id = "9780684801520", Title = "The Great Gatsby", Author = "F. Scott Fitzgerald", Published = 1925 },
2121
new() { Id = "9780486280615", Title = "The Adventures of Huckleberry Finn", Author = "Mark Twain", Published = 1884 },
2222
new() { Id = "9780140430820", Title = "Moby Dick", Author = "Herman Melville", Published = 1851 },
2323
new() { Id = "9780060934347", Title = "Don Quixote", Author = "Miguel de Cervantes", Published = 1605 },
24-
};
24+
];
2525

2626
/// <summary>
2727
/// Gets all books.

src/Abstractions/test/Asp.Versioning.Abstractions.Tests/ApiVersionTest.cs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -595,27 +595,27 @@ public void api_version_1_ge_api_version_2_should_return_expected_result( string
595595
}
596596

597597
public static IEnumerable<object[]> FormatData =>
598-
new[]
598+
new object[][]
599599
{
600-
new[] { null, "2013-08-06.1.1-Alpha", "2013-08-06.1.1-Alpha" },
601-
new[] { "", "2013-08-06.1.1-Alpha", "2013-08-06.1.1-Alpha" },
602-
new[] { "F", "2013-08-06.1.1-Alpha", "2013-08-06.1.1-Alpha" },
603-
new[] { "G", "2013-08-06", "2013-08-06" },
604-
new[] { "GG", "2013-08-06-Alpha", "2013-08-06-Alpha" },
605-
new[] { "G", "1.1", "" },
606-
new[] { "G", "1.1-Alpha", "" },
607-
new[] { "G", "2013-08-06.1.1", "2013-08-06" },
608-
new[] { "GG", "2013-08-06.1.1-Alpha", "2013-08-06-Alpha" },
609-
new[] { "V", "2013-08-06", "" },
610-
new[] { "VVVV", "2013-08-06-Alpha", "" },
611-
new[] { "VV", "1.1", "1.1" },
612-
new[] { "VVVV", "1.1-Alpha", "1.1-Alpha" },
613-
new[] { "VV", "2013-08-06.1.1", "1.1" },
614-
new[] { "VVVV", "2013-08-06.1.1-Alpha", "1.1-Alpha" },
615-
new[] { "S", "1.1-Alpha", "Alpha" },
616-
new[] { "'v'VVV", "1.1", "v1.1" },
617-
new[] { "'Major': %V, 'Minor': %v", "1.1", "Major: 1, Minor: 1" },
618-
new[] { "MMM yyyy '('S')'", "2013-08-06-preview.1", "Aug 2013 (preview.1)" },
600+
[null, "2013-08-06.1.1-Alpha", "2013-08-06.1.1-Alpha"],
601+
["", "2013-08-06.1.1-Alpha", "2013-08-06.1.1-Alpha"],
602+
["F", "2013-08-06.1.1-Alpha", "2013-08-06.1.1-Alpha"],
603+
["G", "2013-08-06", "2013-08-06"],
604+
["GG", "2013-08-06-Alpha", "2013-08-06-Alpha"],
605+
["G", "1.1", ""],
606+
["G", "1.1-Alpha", ""],
607+
["G", "2013-08-06.1.1", "2013-08-06"],
608+
["GG", "2013-08-06.1.1-Alpha", "2013-08-06-Alpha"],
609+
["V", "2013-08-06", ""],
610+
["VVVV", "2013-08-06-Alpha", ""],
611+
["VV", "1.1", "1.1"],
612+
["VVVV", "1.1-Alpha", "1.1-Alpha"],
613+
["VV", "2013-08-06.1.1", "1.1"],
614+
["VVVV", "2013-08-06.1.1-Alpha", "1.1-Alpha"],
615+
["S", "1.1-Alpha", "Alpha"],
616+
["'v'VVV", "1.1", "v1.1"],
617+
["'Major': %V, 'Minor': %v", "1.1", "Major: 1, Minor: 1"],
618+
["MMM yyyy '('S')'", "2013-08-06-preview.1", "Aug 2013 (preview.1)"],
619619
};
620620

621621
#if NETFRAMEWORK

src/AspNet/OData/test/Asp.Versioning.WebApi.OData.ApiExplorer.Tests/Simulators/V1/BooksController.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ namespace Asp.Versioning.Simulators.V1;
1717
[RoutePrefix( "api/books" )]
1818
public class BooksController : ApiController
1919
{
20-
private static readonly Book[] books = new Book[]
21-
{
20+
private static readonly Book[] books =
21+
[
2222
new() { Id = "9781847490599", Title = "Anna Karenina", Author = "Leo Tolstoy", Published = 1878 },
2323
new() { Id = "9780198800545", Title = "War and Peace", Author = "Leo Tolstoy", Published = 1869 },
2424
new() { Id = "9780684801520", Title = "The Great Gatsby", Author = "F. Scott Fitzgerald", Published = 1925 },
2525
new() { Id = "9780486280615", Title = "The Adventures of Huckleberry Finn", Author = "Mark Twain", Published = 1884 },
2626
new() { Id = "9780140430820", Title = "Moby Dick", Author = "Herman Melville", Published = 1851 },
2727
new() { Id = "9780060934347", Title = "Don Quixote", Author = "Miguel de Cervantes", Published = 1605 },
28-
};
28+
];
2929

3030
/// <summary>
3131
/// Gets all books.

src/AspNet/OData/test/Asp.Versioning.WebApi.OData.ApiExplorer.Tests/System.Web.Http/Description/ApiDescriptionExtensionsTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ private static VersionedApiDescription CreateApiDescription( IEdmModel model )
6868
{
6969
var configuration = new HttpConfiguration();
7070
var controllerType = typeof( Asp.Versioning.Simulators.V1.OrdersController );
71-
var actionMethod = controllerType.GetRuntimeMethod( "Get", new[] { typeof( int ) } );
71+
var actionMethod = controllerType.GetRuntimeMethod( "Get", [typeof( int )] );
7272
var controllerDescriptor = new HttpControllerDescriptor( configuration, "Orders", controllerType );
7373
var actionDescriptor = new ReflectedHttpActionDescriptor( controllerDescriptor, actionMethod );
7474
var apiDescription = new VersionedApiDescription()

src/AspNet/OData/test/Asp.Versioning.WebApi.OData.Tests/System.Web.Http/HttpConfigurationExtensionsTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public void map_versioned_odata_route_should_return_expected_result( string rout
4646
var selector = GetODataRootContainer( configuration, routeName ).GetRequiredService<IEdmModelSelector>();
4747
var routingConventions = GetRoutingConventions( configuration, route );
4848

49-
selector.ApiVersions.Should().Equal( new ApiVersion[] { new( 1, 0 ), new( 2, 0 ) } );
49+
selector.ApiVersions.Should().Equal( [new( 1, 0 ), new( 2, 0 )] );
5050
routingConventions[0].Should().BeOfType<VersionedAttributeRoutingConvention>();
5151
routingConventions[1].Should().BeOfType<VersionedMetadataRoutingConvention>();
5252
routingConventions.OfType<MetadataRoutingConvention>().Should().BeEmpty();

src/AspNet/WebApi/test/Asp.Versioning.WebApi.ApiExplorer.Tests/Description/InternalTypeExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ internal static void EnsureInitialized( this IHttpRoute route, Func<IReadOnlyCol
2020
Debug.Assert( route.GetType().Name == "RouteCollectionRoute", "Extension method only intended to support testing RouteCollectionRoute.EnsureInitialized" );
2121

2222
var type = route.GetType();
23-
var method = type.GetRuntimeMethod( nameof( EnsureInitialized ), new[] { initializer.GetType() } );
23+
var method = type.GetRuntimeMethod( nameof( EnsureInitialized ), [initializer.GetType()] );
2424

25-
method.Invoke( route, new object[] { initializer } );
25+
method.Invoke( route, [initializer] );
2626
}
2727

2828
internal static IDirectRouteBuilder NewDirectRouteBuilder( IReadOnlyCollection<HttpActionDescriptor> actions, bool targetIsAction )

src/AspNetCore/OData/test/Asp.Versioning.OData.ApiExplorer.Tests/Simulators/V1/BooksController.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ namespace Asp.Versioning.Simulators.V1;
1616
[Route( "api/[controller]" )]
1717
public class BooksController : ControllerBase
1818
{
19-
private static readonly Book[] books = new Book[]
20-
{
19+
private static readonly Book[] books =
20+
[
2121
new() { Id = "9781847490599", Title = "Anna Karenina", Author = "Leo Tolstoy", Published = 1878 },
2222
new() { Id = "9780198800545", Title = "War and Peace", Author = "Leo Tolstoy", Published = 1869 },
2323
new() { Id = "9780684801520", Title = "The Great Gatsby", Author = "F. Scott Fitzgerald", Published = 1925 },
2424
new() { Id = "9780486280615", Title = "The Adventures of Huckleberry Finn", Author = "Mark Twain", Published = 1884 },
2525
new() { Id = "9780140430820", Title = "Moby Dick", Author = "Herman Melville", Published = 1851 },
2626
new() { Id = "9780060934347", Title = "Don Quixote", Author = "Miguel de Cervantes", Published = 1605 },
27-
};
27+
];
2828

2929
/// <summary>
3030
/// Gets all books.

src/AspNetCore/OData/test/Asp.Versioning.OData.Tests/OData/ModelConfigurationFeatureProviderTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public void populate_feature_should_discover_valid_model_configurations()
2828
provider.PopulateFeature( partManager.ApplicationParts, feature );
2929

3030
// assert
31-
feature.ModelConfigurations.Should().Equal( new[] { typeof( PublicModelConfiguration ) } );
31+
feature.ModelConfigurations.Should().Equal( [typeof( PublicModelConfiguration )] );
3232
}
3333
}
3434

src/AspNetCore/WebApi/test/Asp.Versioning.Http.Tests/Routing/ApiVersionMatcherPolicyTest.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public async Task apply_should_have_candidate_for_matched_api_version()
9797
var model = new ApiVersionModel( new ApiVersion( 1, 0 ) );
9898
var items = new object[] { new ApiVersionMetadata( model, model ) };
9999
var endpoint = new Endpoint( Limbo, new( items ), default );
100-
var candidates = new CandidateSet( new[] { endpoint }, new[] { new RouteValueDictionary() }, new[] { 0 } );
100+
var candidates = new CandidateSet( new[] { endpoint }, new[] { new RouteValueDictionary() }, [0] );
101101
var policy = NewApiVersionMatcherPolicy();
102102

103103
feature.SetupProperty( f => f.RequestedApiVersion, new ApiVersion( 1, 0 ) );
@@ -125,7 +125,7 @@ public async Task apply_should_use_400_endpoint_for_unmatched_api_version()
125125
var model = new ApiVersionModel( new ApiVersion( 1, 0 ) );
126126
var items = new object[] { new ApiVersionMetadata( model, model ) };
127127
var endpoint = new Endpoint( Limbo, new( items ), default );
128-
var candidates = new CandidateSet( new[] { endpoint }, new[] { new RouteValueDictionary() }, new[] { 0 } );
128+
var candidates = new CandidateSet( new[] { endpoint }, new[] { new RouteValueDictionary() }, [0] );
129129
var httpContext = NewHttpContext( feature );
130130

131131
// act
@@ -192,7 +192,7 @@ public async Task apply_should_use_400_endpoint_for_unspecified_api_version()
192192
var model = new ApiVersionModel( new ApiVersion( 1, 0 ) );
193193
var items = new object[] { new ApiVersionMetadata( model, model ) };
194194
var endpoint = new Endpoint( Limbo, new( items ), "Test" );
195-
var candidates = new CandidateSet( new[] { endpoint }, new[] { new RouteValueDictionary() }, new[] { 0 } );
195+
var candidates = new CandidateSet( new[] { endpoint }, new[] { new RouteValueDictionary() }, [0] );
196196
var httpContext = NewHttpContext( feature );
197197

198198
// act
@@ -210,7 +210,7 @@ public async Task apply_should_have_candidate_for_unspecified_api_version()
210210
var model = new ApiVersionModel( new ApiVersion( 1, 0 ) );
211211
var items = new object[] { new ApiVersionMetadata( model, model ) };
212212
var endpoint = new Endpoint( Limbo, new( items ), default );
213-
var candidates = new CandidateSet( new[] { endpoint }, new[] { new RouteValueDictionary() }, new[] { 0 } );
213+
var candidates = new CandidateSet( new[] { endpoint }, new[] { new RouteValueDictionary() }, [0] );
214214
var options = new ApiVersioningOptions() { AssumeDefaultVersionWhenUnspecified = true };
215215
var policy = NewApiVersionMatcherPolicy( options );
216216

src/AspNetCore/WebApi/test/Asp.Versioning.Mvc.ApiExplorer.Tests/TestActionDescriptorCollectionProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public TestActionDescriptorCollectionProvider( ActionDescriptor action, params A
1717

1818
if ( otherActions.Length == 0 )
1919
{
20-
actions = new ActionDescriptor[] { action };
20+
actions = [action];
2121
}
2222
else
2323
{

src/Common/test/Common.OData.ApiExplorer.Tests/OData/DefaultModelTypeBuilderTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ public void substitute_should_get_attributes_from_property_that_has_attributes_t
383383
var property = substitutionType.GetRuntimeProperty( "Salary" );
384384
var attributeWithParams = property.GetCustomAttribute<AllowedRolesAttribute>();
385385

386-
attributeWithParams.AllowedRoles.Should().BeEquivalentTo( new[] { "Manager", "Employer" } );
386+
attributeWithParams.AllowedRoles.Should().BeEquivalentTo( ["Manager", "Employer"] );
387387
}
388388

389389
[Fact]

0 commit comments

Comments
 (0)