Skip to content

Commit 2709f16

Browse files
Chris Martinezcommonsensesoftware
authored andcommitted
Fix issues from improved code analysis
1 parent 9fc324e commit 2709f16

File tree

15 files changed

+33
-28
lines changed

15 files changed

+33
-28
lines changed

src/Common/CollectionExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ internal static void AddRange<T>( this ICollection<T> collection, IEnumerable<T>
5757
}
5858
}
5959

60-
internal static string EnsureZeroOrOneApiVersions( this ICollection<string> apiVersions )
60+
internal static string? EnsureZeroOrOneApiVersions( this ICollection<string> apiVersions )
6161
{
6262
if ( apiVersions.Count < 2 )
6363
{

src/Common/Versioning/ApiVersionFormatProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ protected virtual string FormatStatusPart( ApiVersion apiVersion, string format,
489489
/// <returns>A <see cref="string">string</see> representing the formatted argument.</returns>
490490
public virtual string Format( string? format, object? arg, IFormatProvider? formatProvider )
491491
{
492-
if ( !( arg is ApiVersion value ) )
492+
if ( arg is not ApiVersion value )
493493
{
494494
return GetDefaultFormat( format, arg, formatProvider );
495495
}

src/Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer/ApiVersionModelMetadata.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public ApiVersionModelMetadata( IModelMetadataProvider modelMetadataProvider, st
6868
public override string EditFormatString => inner.EditFormatString;
6969

7070
/// <inheritdoc />
71-
public override ModelMetadata ElementMetadata => inner.ElementMetadata;
71+
public override ModelMetadata? ElementMetadata => inner.ElementMetadata;
7272

7373
/// <inheritdoc />
7474
public override IEnumerable<KeyValuePair<EnumGroupAndName, string>> EnumGroupedDisplayNamesAndValues => inner.EnumGroupedDisplayNamesAndValues;

src/Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer/ApiVersionParameterDescriptionContext.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,12 @@ where constraints.OfType<ApiVersionRouteConstraint>().Any()
173173
parameter.DefaultValue = ApiVersion.ToString();
174174
parameter.ModelMetadata = ModelMetadata;
175175
parameter.Type = ModelMetadata.ModelType;
176-
parameter.RouteInfo.IsOptional = false;
177-
parameter.RouteInfo.DefaultValue = parameter.DefaultValue;
176+
177+
if ( parameter.RouteInfo != null )
178+
{
179+
parameter.RouteInfo.IsOptional = false;
180+
parameter.RouteInfo.DefaultValue = parameter.DefaultValue;
181+
}
178182

179183
if ( parameter.ParameterDescriptor == null )
180184
{

src/Microsoft.AspNetCore.Mvc.Versioning/Abstractions/ActionDescriptorExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ public static ApiVersionMapping MappingTo( this ActionDescriptor action, ApiVers
9696

9797
internal static string ExpandSignature( this ActionDescriptor action )
9898
{
99-
if ( !( action is ControllerActionDescriptor controllerAction ) )
99+
if ( action is not ControllerActionDescriptor controllerAction )
100100
{
101-
return action.DisplayName;
101+
return action.DisplayName ?? string.Empty;
102102
}
103103

104104
var signature = new StringBuilder();

src/Microsoft.AspNetCore.Mvc.Versioning/Microsoft.Extensions.DependencyInjection/IServiceCollectionExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ static object CreateInstance( this IServiceProvider services, ServiceDescriptor
9696
return descriptor.ImplementationFactory( services );
9797
}
9898

99-
return ActivatorUtilities.GetServiceOrCreateInstance( services, descriptor.ImplementationType );
99+
return ActivatorUtilities.GetServiceOrCreateInstance( services, descriptor.ImplementationType! );
100100
}
101101

102102
// REF: https://github.com/dotnet/runtime/blob/master/src/libraries/Microsoft.Extensions.DependencyInjection.Abstractions/src/ServiceDescriptor.cs#L125

src/Microsoft.AspNetCore.Mvc.Versioning/Routing/ApiVersionMatcherPolicy.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ static bool MatchesApiVersion( CandidateSet candidates, ApiVersion? apiVersion )
158158
return true;
159159
case 1:
160160
ref var candidate = ref candidates[bestMatches[0]];
161-
var action = candidate.Endpoint.Metadata.GetMetadata<ActionDescriptor>();
161+
var action = candidate.Endpoint.Metadata.GetMetadata<ActionDescriptor>()!;
162162
var model = action.GetApiVersionModel();
163163

164164
if ( model.IsApiVersionNeutral )

src/Microsoft.AspNetCore.Mvc.Versioning/Routing/ApiVersionRouteConstraint.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public sealed class ApiVersionRouteConstraint : IRouteConstraint
2323
/// <param name="values">The current <see cref="RouteValueDictionary">collection</see> of route values.</param>
2424
/// <param name="routeDirection">The <see cref="RouteDirection">route direction</see> to match.</param>
2525
/// <returns>True if the route constraint is matched; otherwise, false.</returns>
26-
public bool Match( HttpContext httpContext, IRouter route, string routeKey, RouteValueDictionary values, RouteDirection routeDirection )
26+
public bool Match( HttpContext? httpContext, IRouter? route, string routeKey, RouteValueDictionary values, RouteDirection routeDirection )
2727
{
2828
if ( values == null )
2929
{

src/Microsoft.AspNetCore.Mvc.Versioning/Routing/ApiVersionUrlHelper.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public ApiVersionUrlHelper( ActionContext actionContext, IUrlHelper url )
4646
public ActionContext ActionContext { get; }
4747

4848
/// <inheritdoc />
49-
public virtual string Action( UrlActionContext actionContext )
49+
public virtual string? Action( UrlActionContext actionContext )
5050
{
5151
if ( actionContext == null )
5252
{
@@ -58,20 +58,20 @@ public virtual string Action( UrlActionContext actionContext )
5858
}
5959

6060
/// <inheritdoc />
61-
public virtual string Content( string contentPath ) => Url.Content( contentPath );
61+
public virtual string? Content( string? contentPath ) => Url.Content( contentPath );
6262

6363
/// <inheritdoc />
6464
#pragma warning disable CA1054 // URI-like parameters should not be strings
65-
public virtual bool IsLocalUrl( string url ) => Url.IsLocalUrl( url );
65+
public virtual bool IsLocalUrl( string? url ) => Url.IsLocalUrl( url );
6666
#pragma warning restore CA1054
6767

6868
/// <inheritdoc />
69-
public virtual string Link( string routeName, object values ) =>
69+
public virtual string? Link( string? routeName, object? values ) =>
7070
Url.Link( routeName, AddApiVersionRouteValueIfNecessary( values ) );
7171

7272
/// <inheritdoc />
7373
#pragma warning disable CA1055 // URI-like return values should not be strings
74-
public virtual string RouteUrl( UrlRouteContext routeContext )
74+
public virtual string? RouteUrl( UrlRouteContext routeContext )
7575
#pragma warning restore CA1055
7676
{
7777
if ( routeContext == null )
@@ -83,7 +83,7 @@ public virtual string RouteUrl( UrlRouteContext routeContext )
8383
return Url.RouteUrl( routeContext );
8484
}
8585

86-
object AddApiVersionRouteValueIfNecessary( object current )
86+
object? AddApiVersionRouteValueIfNecessary( object? current )
8787
{
8888
var key = RouteParameter;
8989

@@ -99,7 +99,7 @@ object AddApiVersionRouteValueIfNecessary( object current )
9999
return current;
100100
}
101101

102-
if ( !( current is RouteValueDictionary values ) )
102+
if ( current is not RouteValueDictionary values )
103103
{
104104
values = current == null ? new RouteValueDictionary() : new RouteValueDictionary( current );
105105
}

src/Microsoft.AspNetCore.Mvc.Versioning/Routing/ClientErrorBuilder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ internal RequestHandler Build()
3636
var method = request.Method;
3737
var requestedVersion = feature.RawRequestedApiVersion;
3838
var parsedVersion = feature.RequestedApiVersion;
39-
var actionNames = new Lazy<string>( () => Join( NewLine, Candidates.Select( a => a.DisplayName ) ) );
39+
var actionNames = new Lazy<string>( () => Join( NewLine, Candidates!.Select( a => a.DisplayName ) ) );
4040
var allowedMethods = new Lazy<HashSet<string>>( () => AllowedMethodsFromCandidates( Candidates!, parsedVersion ) );
41-
var apiVersions = new Lazy<ApiVersionModel>( Candidates.Select( a => a.GetApiVersionModel() ).Aggregate );
41+
var apiVersions = new Lazy<ApiVersionModel>( Candidates!.Select( a => a.GetApiVersionModel() ).Aggregate );
4242
var handlerContext = new RequestHandlerContext( ErrorResponseProvider, ApiVersionReporter!, apiVersions );
4343
var url = new Uri( request.GetDisplayUrl() ).SafeFullPath();
4444

0 commit comments

Comments
 (0)