Skip to content

Commit e26826a

Browse files
Chris Martinezcommonsensesoftware
authored andcommitted
Refactor to C# 8.0 features
1 parent 446204e commit e26826a

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
}

0 commit comments

Comments
 (0)