Skip to content

Commit 8f86407

Browse files
Use CompositeFormat where possible
1 parent e3913cc commit 8f86407

25 files changed

+129
-37
lines changed

src/Abstractions/src/Asp.Versioning.Abstractions/ApiVersionParser.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,11 +336,11 @@ public virtual bool TryParse( Text text, [MaybeNullWhen( false )] out ApiVersion
336336

337337
[MethodImpl( MethodImplOptions.AggressiveInlining )]
338338
private static FormatException InvalidGroupVersion( string value ) =>
339-
new( string.Format( CultureInfo.CurrentCulture, SR.ApiVersionBadGroupVersion, value ) );
339+
new( string.Format( CultureInfo.CurrentCulture, Format.ApiVersionBadGroupVersion, value ) );
340340

341341
[MethodImpl( MethodImplOptions.AggressiveInlining )]
342342
private static FormatException InvalidStatus( string value ) =>
343-
new( string.Format( CultureInfo.CurrentCulture, SR.ApiVersionBadStatus, value ) );
343+
new( string.Format( CultureInfo.CurrentCulture, Format.ApiVersionBadStatus, value ) );
344344

345345
private static bool IsDateLike( Text value )
346346
{
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) .NET Foundation and contributors. All rights reserved.
2+
3+
namespace Asp.Versioning;
4+
5+
#if NET
6+
using System.Text;
7+
#endif
8+
9+
internal static class Format
10+
{
11+
#if NETSTANDARD
12+
internal static readonly string ApiVersionBadStatus = SR.ApiVersionBadStatus;
13+
internal static readonly string ApiVersionBadGroupVersion = SR.ApiVersionBadGroupVersion;
14+
#else
15+
internal static readonly CompositeFormat ApiVersionBadStatus = CompositeFormat.Parse( SR.ApiVersionBadStatus );
16+
internal static readonly CompositeFormat ApiVersionBadGroupVersion = CompositeFormat.Parse( SR.ApiVersionBadGroupVersion );
17+
#endif
18+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright (c) .NET Foundation and contributors. All rights reserved.
2+
3+
namespace Asp.Versioning;
4+
5+
using System.Text;
6+
7+
internal static class Format
8+
{
9+
internal static readonly CompositeFormat UnsupportedQueryOption = CompositeFormat.Parse( ODataExpSR.UnsupportedQueryOption );
10+
internal static readonly CompositeFormat MaxExpressionDesc = CompositeFormat.Parse( ODataExpSR.MaxExpressionDesc );
11+
internal static readonly CompositeFormat AllowedPropertiesDesc = CompositeFormat.Parse( ODataExpSR.AllowedPropertiesDesc );
12+
internal static readonly CompositeFormat MaxDepthDesc = CompositeFormat.Parse( ODataExpSR.MaxDepthDesc );
13+
internal static readonly CompositeFormat MaxValueDesc = CompositeFormat.Parse( ODataExpSR.MaxValueDesc );
14+
internal static readonly CompositeFormat AllowedLogicalOperatorsDesc = CompositeFormat.Parse( ODataExpSR.AllowedLogicalOperatorsDesc );
15+
internal static readonly CompositeFormat AllowedArithmeticOperatorsDesc = CompositeFormat.Parse( ODataExpSR.AllowedArithmeticOperatorsDesc );
16+
internal static readonly CompositeFormat AmbiguousActionMethod = CompositeFormat.Parse( ODataExpSR.AmbiguousActionMethod );
17+
internal static readonly CompositeFormat InvalidActionMethodExpression = CompositeFormat.Parse( ODataExpSR.InvalidActionMethodExpression );
18+
internal static readonly CompositeFormat ActionMethodNotFound = CompositeFormat.Parse( ODataExpSR.ActionMethodNotFound );
19+
internal static readonly CompositeFormat AllowedFunctionsDesc = CompositeFormat.Parse( ODataExpSR.AllowedFunctionsDesc );
20+
internal static readonly CompositeFormat RequiredInterfaceNotImplemented = CompositeFormat.Parse( ODataExpSR.RequiredInterfaceNotImplemented );
21+
internal static readonly CompositeFormat ConventionStyleMismatch = CompositeFormat.Parse( ODataExpSR.ConventionStyleMismatch );
22+
}

src/AspNetCore/OData/src/Asp.Versioning.OData/DependencyInjection/IApiVersioningBuilderExtensions.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,13 @@ private static void TryRemoveODataService( this IServiceCollection services, Typ
102102
}
103103
}
104104

105-
var message = string.Format( CultureInfo.CurrentCulture, SR.UnableToFindServices, nameof( IMvcBuilder ), "AddOData", "ConfigureServices(...)" );
105+
var message = string.Format(
106+
CultureInfo.CurrentCulture,
107+
Format.UnableToFindServices,
108+
nameof( IMvcBuilder ),
109+
"AddOData",
110+
"ConfigureServices(...)" );
111+
106112
throw new InvalidOperationException( message );
107113
}
108114

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Copyright (c) .NET Foundation and contributors. All rights reserved.
2+
3+
namespace Asp.Versioning;
4+
5+
using System.Text;
6+
7+
internal static class Format
8+
{
9+
internal static readonly CompositeFormat UnableToFindServices = CompositeFormat.Parse( SR.UnableToFindServices );
10+
}

src/AspNetCore/WebApi/src/Asp.Versioning.Http/ApiVersioningFeature.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ private static AmbiguousApiVersionException NewAmbiguousApiVersionException( IRe
115115
new(
116116
string.Format(
117117
CultureInfo.CurrentCulture,
118-
CommonSR.MultipleDifferentApiVersionsRequested,
118+
Format.MultipleDifferentApiVersionsRequested,
119119
string.Join( ", ", [.. values], 0, values.Count ) ),
120120
values );
121121
}

src/AspNetCore/WebApi/src/Asp.Versioning.Http/Builder/EndpointBuilderFinalizer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ private static RequestDelegate EnsureRequestDelegate( RequestDelegate? current,
267267
throw new InvalidOperationException(
268268
string.Format(
269269
CultureInfo.CurrentCulture,
270-
SR.UnsetRequestDelegate,
270+
Format.UnsetRequestDelegate,
271271
nameof( RequestDelegate ),
272272
nameof( RouteEndpoint ) ) );
273273

src/AspNetCore/WebApi/src/Asp.Versioning.Http/Builder/IEndpointConventionBuilderExtensions.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ namespace Microsoft.AspNetCore.Builder;
77
using Microsoft.AspNetCore.Http;
88
using System.Collections;
99
using System.Globalization;
10+
using System.Runtime.Serialization;
1011
using static Asp.Versioning.ApiVersionProviderOptions;
1112

1213
/// <summary>
@@ -439,7 +440,7 @@ private static void AddMetadata( EndpointBuilder builder, object item )
439440
throw new InvalidOperationException(
440441
string.Format(
441442
CultureInfo.CurrentCulture,
442-
SR.NoVersionSet,
443+
Format.NoVersionSet,
443444
builder.DisplayName,
444445
nameof( IEndpointRouteBuilderExtensions.NewVersionedApi ),
445446
nameof( IEndpointRouteBuilderExtensions.WithApiVersionSet ) ) );
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright (c) .NET Foundation and contributors. All rights reserved.
2+
3+
namespace Asp.Versioning;
4+
5+
using System.Text;
6+
7+
internal static class Format
8+
{
9+
internal static readonly CompositeFormat MultipleDifferentApiVersionsRequested = CompositeFormat.Parse( CommonSR.MultipleDifferentApiVersionsRequested );
10+
internal static readonly CompositeFormat NoVersionSet = CompositeFormat.Parse( SR.NoVersionSet );
11+
internal static readonly CompositeFormat InvalidMediaTypeTemplate = CompositeFormat.Parse( CommonSR.InvalidMediaTypeTemplate );
12+
internal static readonly CompositeFormat UnsetRequestDelegate = CompositeFormat.Parse( SR.UnsetRequestDelegate );
13+
internal static readonly CompositeFormat VersionedResourceNotSupported = CompositeFormat.Parse( SR.VersionedResourceNotSupported );
14+
internal static readonly CompositeFormat InvalidDefaultApiVersion = CompositeFormat.Parse( SR.InvalidDefaultApiVersion );
15+
internal static readonly CompositeFormat InvalidPolicyKey = CompositeFormat.Parse( CommonSR.InvalidPolicyKey );
16+
}

src/AspNetCore/WebApi/src/Asp.Versioning.Http/MediaTypeApiVersionReaderBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public partial class MediaTypeApiVersionReaderBuilder
3434

3535
if ( string.IsNullOrEmpty( parameterName ) && routePattern.Parameters.Count > 1 )
3636
{
37-
var message = string.Format( CultureInfo.CurrentCulture, CommonSR.InvalidMediaTypeTemplate, template );
37+
var message = string.Format( CultureInfo.CurrentCulture, Format.InvalidMediaTypeTemplate, template );
3838
throw new ArgumentException( message, nameof( template ) );
3939
}
4040

0 commit comments

Comments
 (0)