Skip to content

Commit 8c0568f

Browse files
author
Chris Martinez
committed
Refactor to C# 8.0 features
1 parent 246e0bc commit 8c0568f

File tree

311 files changed

+2828
-3894
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

311 files changed

+2828
-3894
lines changed

SECURITY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ If you believe you have found a security vulnerability in any Microsoft-owned re
1212

1313
Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://msrc.microsoft.com/create-report).
1414

15-
If you prefer to submit without logging in, send email to [secure@microsoft.com](mailto:secure@microsoft.com). If possible, encrypt your message with our PGP key; please download it from the the [Microsoft Security Response Center PGP Key page](https://www.microsoft.com/en-us/msrc/pgp-key-msrc).
15+
If you prefer to submit without logging in, send email to [secure@microsoft.com](mailto:secure@microsoft.com). If possible, encrypt your message with our PGP key; please download it from the [Microsoft Security Response Center PGP Key page](https://www.microsoft.com/en-us/msrc/pgp-key-msrc).
1616

1717
You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://www.microsoft.com/msrc).
1818

build/code-analysis.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
</ItemGroup>
1717

1818
<ItemGroup Label="NuGet">
19-
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.6.2" PrivateAssets="All" />
20-
<PackageReference Include="StyleCop.Analyzers" Version="1.1.1-beta.61" PrivateAssets="All" />
19+
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.6" PrivateAssets="All" />
20+
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.66" PrivateAssets="All" />
2121
</ItemGroup>
2222

2323
</Project>

build/nuget.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33

44
<PropertyGroup Label="NuGet">
5+
<IsPackable>true</IsPackable>
56
<RepositoryType>git</RepositoryType>
67
<RepositoryUrl>https://github.com/Microsoft/aspnet-api-versioning</RepositoryUrl>
78
<PackageIconUrl>http://go.microsoft.com/fwlink/?LinkID=288890</PackageIconUrl>

samples/aspnetcore/ODataBasicSample/ODataBasicSample.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
<PropertyGroup>
44
<TargetFramework>netcoreapp2.2</TargetFramework>
5-
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
65
<RootNamespace>Microsoft.Examples</RootNamespace>
76
</PropertyGroup>
87

samples/aspnetcore/SwaggerODataSample/SwaggerODataSample.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
<PropertyGroup>
44
<TargetFramework>netcoreapp2.2</TargetFramework>
5-
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
65
<RootNamespace>Microsoft.Examples</RootNamespace>
76
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\$(MSBuildThisFileName).xml</DocumentationFile>
87
</PropertyGroup>

samples/directory.build.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<PropertyGroup>
55
<LangVersion>latest</LangVersion>
66
<IsTestProject>false</IsTestProject>
7+
<IsPackable>false</IsPackable>
78
</PropertyGroup>
89

910
</Project>

src/Common.ApiExplorer/ApiExplorerOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public partial class ApiExplorerOptions
2525
/// <remarks>For information about API version formatting, review <see cref="ApiVersionFormatProvider"/>
2626
/// as well as the <see cref="ApiVersion.ToString(string)"/> and <see cref="ApiVersion.ToString(string, IFormatProvider)"/>
2727
/// methods.</remarks>
28-
public string GroupNameFormat { get; set; }
28+
public string GroupNameFormat { get; set; } = string.Empty;
2929

3030
/// <summary>
3131
/// Gets or sets the format used to format the API version value substituted in route templates.

src/Common.OData.ApiExplorer/AspNet.OData/Builder/DefaultODataQueryOptionDescriptionProvider.cs

Lines changed: 38 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using Microsoft.AspNet.OData.Query;
44
using System;
55
using System.Collections.Generic;
6-
using System.Diagnostics.Contracts;
76
using System.Text;
87
using static Microsoft.AspNet.OData.Query.AllowedArithmeticOperators;
98
using static Microsoft.AspNet.OData.Query.AllowedLogicalOperators;
@@ -23,8 +22,6 @@ public class DefaultODataQueryOptionDescriptionProvider : IODataQueryOptionDescr
2322
/// <inheritdoc />
2423
public virtual string Describe( AllowedQueryOptions queryOption, ODataQueryOptionDescriptionContext context )
2524
{
26-
Arg.NotNull( context, nameof( context ) );
27-
2825
if ( ( queryOption < Filter || queryOption > Supported ) || ( queryOption != Filter && ( (int) queryOption % 2 != 0 ) ) )
2926
{
3027
throw new ArgumentException( SR.MultipleQueryOptionsNotAllowed, nameof( queryOption ) );
@@ -41,8 +38,8 @@ public virtual string Describe( AllowedQueryOptions queryOption, ODataQueryOptio
4138
Count => DescribeCount( context ),
4239
#pragma warning disable CA1308 // Normalize strings to uppercase
4340
_ => throw new ArgumentException( SR.UnsupportedQueryOption.FormatDefault( queryOption.ToString().ToLowerInvariant() ), nameof( queryOption ) ),
44-
};
4541
#pragma warning restore CA1308
42+
};
4643
}
4744

4845
/// <summary>
@@ -52,8 +49,10 @@ public virtual string Describe( AllowedQueryOptions queryOption, ODataQueryOptio
5249
/// <returns>The query option description.</returns>
5350
protected virtual string DescribeFilter( ODataQueryOptionDescriptionContext context )
5451
{
55-
Arg.NotNull( context, nameof( context ) );
56-
Contract.Ensures( !string.IsNullOrEmpty( Contract.Result<string>() ) );
52+
if ( context == null )
53+
{
54+
throw new ArgumentNullException( nameof( context ) );
55+
}
5756

5857
var description = new StringBuilder();
5958

@@ -84,8 +83,10 @@ protected virtual string DescribeFilter( ODataQueryOptionDescriptionContext cont
8483
/// <returns>The query option description.</returns>
8584
protected virtual string DescribeExpand( ODataQueryOptionDescriptionContext context )
8685
{
87-
Arg.NotNull( context, nameof( context ) );
88-
Contract.Ensures( !string.IsNullOrEmpty( Contract.Result<string>() ) );
86+
if ( context == null )
87+
{
88+
throw new ArgumentNullException( nameof( context ) );
89+
}
8990

9091
var description = new StringBuilder();
9192

@@ -114,8 +115,10 @@ protected virtual string DescribeExpand( ODataQueryOptionDescriptionContext cont
114115
/// <returns>The query option description.</returns>
115116
protected virtual string DescribeSelect( ODataQueryOptionDescriptionContext context )
116117
{
117-
Arg.NotNull( context, nameof( context ) );
118-
Contract.Ensures( !string.IsNullOrEmpty( Contract.Result<string>() ) );
118+
if ( context == null )
119+
{
120+
throw new ArgumentNullException( nameof( context ) );
121+
}
119122

120123
var description = new StringBuilder();
121124

@@ -138,8 +141,10 @@ protected virtual string DescribeSelect( ODataQueryOptionDescriptionContext cont
138141
/// <returns>The query option description.</returns>
139142
protected virtual string DescribeOrderBy( ODataQueryOptionDescriptionContext context )
140143
{
141-
Arg.NotNull( context, nameof( context ) );
142-
Contract.Ensures( !string.IsNullOrEmpty( Contract.Result<string>() ) );
144+
if ( context == null )
145+
{
146+
throw new ArgumentNullException( nameof( context ) );
147+
}
143148

144149
var description = new StringBuilder();
145150

@@ -168,8 +173,10 @@ protected virtual string DescribeOrderBy( ODataQueryOptionDescriptionContext con
168173
/// <returns>The query option description.</returns>
169174
protected virtual string DescribeTop( ODataQueryOptionDescriptionContext context )
170175
{
171-
Arg.NotNull( context, nameof( context ) );
172-
Contract.Ensures( !string.IsNullOrEmpty( Contract.Result<string>() ) );
176+
if ( context == null )
177+
{
178+
throw new ArgumentNullException( nameof( context ) );
179+
}
173180

174181
var description = new StringBuilder();
175182

@@ -191,8 +198,10 @@ protected virtual string DescribeTop( ODataQueryOptionDescriptionContext context
191198
/// <returns>The query option description.</returns>
192199
protected virtual string DescribeSkip( ODataQueryOptionDescriptionContext context )
193200
{
194-
Arg.NotNull( context, nameof( context ) );
195-
Contract.Ensures( !string.IsNullOrEmpty( Contract.Result<string>() ) );
201+
if ( context == null )
202+
{
203+
throw new ArgumentNullException( nameof( context ) );
204+
}
196205

197206
var description = new StringBuilder();
198207

@@ -212,19 +221,10 @@ protected virtual string DescribeSkip( ODataQueryOptionDescriptionContext contex
212221
/// </summary>
213222
/// <param name="context">The current <see cref="ODataQueryOptionDescriptionContext">description context</see>.</param>
214223
/// <returns>The query option description.</returns>
215-
protected virtual string DescribeCount( ODataQueryOptionDescriptionContext context )
216-
{
217-
Arg.NotNull( context, nameof( context ) );
218-
Contract.Ensures( !string.IsNullOrEmpty( Contract.Result<string>() ) );
219-
220-
return SR.CountQueryOptionDesc;
221-
}
224+
protected virtual string DescribeCount( ODataQueryOptionDescriptionContext context ) => SR.CountQueryOptionDesc;
222225

223226
static void AppendAllowedOptions( StringBuilder description, ODataQueryOptionDescriptionContext context )
224227
{
225-
Contract.Requires( description != null );
226-
Contract.Requires( context != null );
227-
228228
if ( context.AllowedLogicalOperators != AllowedLogicalOperators.None &&
229229
context.AllowedLogicalOperators != AllowedLogicalOperators.All )
230230
{
@@ -336,28 +336,24 @@ static IEnumerable<string> EnumerateArithmeticOperators( AllowedArithmeticOperat
336336

337337
static string ToCommaSeparatedValues( IEnumerable<string> values )
338338
{
339-
Contract.Requires( values != null );
340-
Contract.Ensures( Contract.Result<string>() != null );
339+
using var iterator = values.GetEnumerator();
341340

342-
using ( var iterator = values.GetEnumerator() )
341+
if ( !iterator.MoveNext() )
343342
{
344-
if ( !iterator.MoveNext() )
345-
{
346-
return string.Empty;
347-
}
348-
349-
var csv = new StringBuilder();
343+
return string.Empty;
344+
}
350345

351-
csv.Append( iterator.Current );
346+
var csv = new StringBuilder();
352347

353-
while ( iterator.MoveNext() )
354-
{
355-
csv.Append( ", " );
356-
csv.Append( iterator.Current );
357-
}
348+
csv.Append( iterator.Current );
358349

359-
return csv.ToString();
350+
while ( iterator.MoveNext() )
351+
{
352+
csv.Append( ", " );
353+
csv.Append( iterator.Current );
360354
}
355+
356+
return csv.ToString();
361357
}
362358
}
363359
}

src/Common.OData.ApiExplorer/AspNet.OData/Builder/IODataActionQueryOptionsConventionBuilder{T}.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@
1414
[CLSCompliant( false )]
1515
#endif
1616
public interface IODataActionQueryOptionsConventionBuilder<T>
17+
where T : notnull
1718
#if WEBAPI
18-
where T : IHttpController
19+
#pragma warning disable SA1001 // Commas should be spaced correctly
20+
, IHttpController
21+
#pragma warning restore SA1001 // Commas should be spaced correctly
1922
#endif
2023
{
2124
/// <summary>

src/Common.OData.ApiExplorer/AspNet.OData/Builder/ODataActionQueryOptionConventionLookup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
using System;
44
using System.Reflection;
55

6-
delegate bool ODataActionQueryOptionConventionLookup( MethodInfo action, ODataQueryOptionSettings settings, out IODataQueryOptionsConvention convention );
6+
delegate bool ODataActionQueryOptionConventionLookup( MethodInfo action, ODataQueryOptionSettings settings, out IODataQueryOptionsConvention? convention );
77
}

src/Common.OData.ApiExplorer/AspNet.OData/Builder/ODataActionQueryOptionsConventionBuilder.cs

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System;
55
using System.Collections.Generic;
66
using System.ComponentModel;
7-
using System.Diagnostics.Contracts;
87
using System.Reflection;
98
using static Microsoft.AspNet.OData.Query.AllowedFunctions;
109
using static Microsoft.AspNet.OData.Query.AllowedQueryOptions;
@@ -23,11 +22,8 @@ public class ODataActionQueryOptionsConventionBuilder : ODataActionQueryOptionsC
2322
/// </summary>
2423
/// <param name="controllerBuilder">The <see cref="ODataActionQueryOptionsConventionBuilder">controller builder</see>
2524
/// the action builder belongs to.</param>
26-
public ODataActionQueryOptionsConventionBuilder( ODataControllerQueryOptionsConventionBuilder controllerBuilder )
27-
{
28-
Arg.NotNull( controllerBuilder, nameof( controllerBuilder ) );
25+
public ODataActionQueryOptionsConventionBuilder( ODataControllerQueryOptionsConventionBuilder controllerBuilder ) =>
2926
ControllerBuilder = controllerBuilder;
30-
}
3127

3228
/// <summary>
3329
/// Gets the controller builder the action builder belongs to.
@@ -56,8 +52,10 @@ public ODataActionQueryOptionsConventionBuilder( ODataControllerQueryOptionsConv
5652
/// <returns>The original <see cref="ODataActionQueryOptionsConventionBuilder"/>.</returns>
5753
public virtual ODataActionQueryOptionsConventionBuilder Use( ODataValidationSettings validationSettings )
5854
{
59-
Arg.NotNull( validationSettings, nameof( validationSettings ) );
60-
Contract.Ensures( Contract.Result<ODataActionQueryOptionsConventionBuilder>() != null );
55+
if ( validationSettings == null )
56+
{
57+
throw new ArgumentNullException( nameof( validationSettings ) );
58+
}
6159

6260
ValidationSettings.CopyFrom( validationSettings );
6361
return this;
@@ -70,8 +68,6 @@ public virtual ODataActionQueryOptionsConventionBuilder Use( ODataValidationSett
7068
/// <returns>The original <see cref="ODataActionQueryOptionsConventionBuilder"/>.</returns>
7169
public virtual ODataActionQueryOptionsConventionBuilder Allow( AllowedArithmeticOperators arithmeticOperators )
7270
{
73-
Contract.Ensures( Contract.Result<ODataActionQueryOptionsConventionBuilder>() != null );
74-
7571
ValidationSettings.AllowedArithmeticOperators |= arithmeticOperators;
7672
return this;
7773
}
@@ -83,8 +79,6 @@ public virtual ODataActionQueryOptionsConventionBuilder Allow( AllowedArithmetic
8379
/// <returns>The original <see cref="ODataActionQueryOptionsConventionBuilder"/>.</returns>
8480
public virtual ODataActionQueryOptionsConventionBuilder Allow( AllowedFunctions functions )
8581
{
86-
Contract.Ensures( Contract.Result<ODataActionQueryOptionsConventionBuilder>() != null );
87-
8882
ValidationSettings.AllowedFunctions |= functions;
8983
return this;
9084
}
@@ -96,8 +90,6 @@ public virtual ODataActionQueryOptionsConventionBuilder Allow( AllowedFunctions
9690
/// <returns>The original <see cref="ODataActionQueryOptionsConventionBuilder"/>.</returns>
9791
public virtual ODataActionQueryOptionsConventionBuilder Allow( AllowedLogicalOperators logicalOperators )
9892
{
99-
Contract.Ensures( Contract.Result<ODataActionQueryOptionsConventionBuilder>() != null );
100-
10193
ValidationSettings.AllowedLogicalOperators |= logicalOperators;
10294
return this;
10395
}
@@ -109,8 +101,6 @@ public virtual ODataActionQueryOptionsConventionBuilder Allow( AllowedLogicalOpe
109101
/// <returns>The original <see cref="ODataActionQueryOptionsConventionBuilder"/>.</returns>
110102
public virtual ODataActionQueryOptionsConventionBuilder Allow( AllowedQueryOptions queryOptions )
111103
{
112-
Contract.Ensures( Contract.Result<ODataActionQueryOptionsConventionBuilder>() != null );
113-
114104
ValidationSettings.AllowedQueryOptions |= queryOptions;
115105
return this;
116106
}
@@ -122,9 +112,6 @@ public virtual ODataActionQueryOptionsConventionBuilder Allow( AllowedQueryOptio
122112
/// <returns>The original <see cref="ODataActionQueryOptionsConventionBuilder"/>.</returns>
123113
public virtual ODataActionQueryOptionsConventionBuilder AllowSkip( int max )
124114
{
125-
Arg.GreaterThanOrEqualTo( max, 0, nameof( max ) );
126-
Contract.Ensures( Contract.Result<ODataActionQueryOptionsConventionBuilder>() != null );
127-
128115
ValidationSettings.AllowedQueryOptions |= Skip;
129116

130117
if ( max != default )
@@ -142,9 +129,6 @@ public virtual ODataActionQueryOptionsConventionBuilder AllowSkip( int max )
142129
/// <returns>The original <see cref="ODataActionQueryOptionsConventionBuilder"/>.</returns>
143130
public virtual ODataActionQueryOptionsConventionBuilder AllowTop( int max )
144131
{
145-
Arg.GreaterThanOrEqualTo( max, 0, nameof( max ) );
146-
Contract.Ensures( Contract.Result<ODataActionQueryOptionsConventionBuilder>() != null );
147-
148132
ValidationSettings.AllowedQueryOptions |= Top;
149133

150134
if ( max != default )
@@ -162,9 +146,6 @@ public virtual ODataActionQueryOptionsConventionBuilder AllowTop( int max )
162146
/// <returns>The original <see cref="ODataActionQueryOptionsConventionBuilder"/>.</returns>
163147
public virtual ODataActionQueryOptionsConventionBuilder AllowExpand( int maxDepth )
164148
{
165-
Arg.GreaterThanOrEqualTo( maxDepth, 0, nameof( maxDepth ) );
166-
Contract.Ensures( Contract.Result<ODataActionQueryOptionsConventionBuilder>() != null );
167-
168149
ValidationSettings.AllowedQueryOptions |= Expand;
169150

170151
if ( maxDepth != default )
@@ -182,9 +163,6 @@ public virtual ODataActionQueryOptionsConventionBuilder AllowExpand( int maxDept
182163
/// <returns>The original <see cref="ODataActionQueryOptionsConventionBuilder"/>.</returns>
183164
public virtual ODataActionQueryOptionsConventionBuilder AllowAnyAll( int maxExpressionDepth )
184165
{
185-
Arg.GreaterThanOrEqualTo( maxExpressionDepth, 0, nameof( maxExpressionDepth ) );
186-
Contract.Ensures( Contract.Result<ODataActionQueryOptionsConventionBuilder>() != null );
187-
188166
ValidationSettings.AllowedFunctions |= Any | AllowedFunctions.All;
189167
ValidationSettings.AllowedQueryOptions |= Filter;
190168

@@ -203,9 +181,6 @@ public virtual ODataActionQueryOptionsConventionBuilder AllowAnyAll( int maxExpr
203181
/// <returns>The original <see cref="ODataActionQueryOptionsConventionBuilder"/>.</returns>
204182
public virtual ODataActionQueryOptionsConventionBuilder AllowFilter( int maxNodeCount )
205183
{
206-
Arg.GreaterThanOrEqualTo( maxNodeCount, 0, nameof( maxNodeCount ) );
207-
Contract.Ensures( Contract.Result<ODataActionQueryOptionsConventionBuilder>() != null );
208-
209184
ValidationSettings.AllowedQueryOptions |= Filter;
210185

211186
if ( maxNodeCount != default )
@@ -225,9 +200,10 @@ public virtual ODataActionQueryOptionsConventionBuilder AllowFilter( int maxNode
225200
/// <returns>The original <see cref="ODataActionQueryOptionsConventionBuilder"/>.</returns>
226201
public virtual ODataActionQueryOptionsConventionBuilder AllowOrderBy( int maxNodeCount, IEnumerable<string> properties )
227202
{
228-
Arg.NotNull( properties, nameof( properties ) );
229-
Arg.GreaterThanOrEqualTo( maxNodeCount, 0, nameof( maxNodeCount ) );
230-
Contract.Ensures( Contract.Result<ODataActionQueryOptionsConventionBuilder>() != null );
203+
if ( properties == null )
204+
{
205+
throw new ArgumentNullException( nameof( properties ) );
206+
}
231207

232208
ValidationSettings.AllowedQueryOptions |= OrderBy;
233209

0 commit comments

Comments
 (0)