Skip to content

Commit eb97519

Browse files
authored
Merge pull request #1388 from SimonCropp/cleanup-exception-handling
cleanup exception handling
2 parents 22c7a3d + bb0f507 commit eb97519

Some content is hidden

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

54 files changed

+125
-431
lines changed

src/Microsoft.OpenApi/Attributes/DisplayAttribute.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,7 @@ public class DisplayAttribute : Attribute
1717
/// <param name="name">The display name.</param>
1818
public DisplayAttribute(string name)
1919
{
20-
if (string.IsNullOrWhiteSpace(name))
21-
{
22-
throw Error.ArgumentNullOrWhiteSpace(nameof(name));
23-
}
24-
25-
Name = name;
20+
Name = Utils.CheckArgumentNullOrEmpty(name);
2621
}
2722

2823
/// <summary>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#if !NETCOREAPP3_1_OR_GREATER
2+
using System.Diagnostics;
3+
using System.Diagnostics.CodeAnalysis;
4+
5+
namespace System.Runtime.CompilerServices;
6+
7+
[ExcludeFromCodeCoverage]
8+
[DebuggerNonUserCode]
9+
[AttributeUsage(AttributeTargets.Parameter)]
10+
sealed class CallerArgumentExpressionAttribute :
11+
Attribute
12+
{
13+
public CallerArgumentExpressionAttribute(string parameterName) =>
14+
ParameterName = parameterName;
15+
16+
public string ParameterName { get; }
17+
}
18+
#endif

src/Microsoft.OpenApi/Error.cs

Lines changed: 0 additions & 98 deletions
This file was deleted.

src/Microsoft.OpenApi/Expressions/BodyExpression.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,7 @@ public BodyExpression()
3333
public BodyExpression(JsonPointer pointer)
3434
: base(pointer?.ToString())
3535
{
36-
if (pointer == null)
37-
{
38-
throw Error.ArgumentNull(nameof(pointer));
39-
}
36+
Utils.CheckArgumentNull(pointer);
4037
}
4138

4239
/// <summary>

src/Microsoft.OpenApi/Expressions/HeaderExpression.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@ public class HeaderExpression : SourceExpression
2020
public HeaderExpression(string token)
2121
: base(token)
2222
{
23-
if (string.IsNullOrWhiteSpace(token))
24-
{
25-
throw Error.ArgumentNullOrWhiteSpace(nameof(token));
26-
}
23+
Utils.CheckArgumentNullOrEmpty(token);
2724
}
2825

2926
/// <summary>

src/Microsoft.OpenApi/Expressions/PathExpression.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@ public sealed class PathExpression : SourceExpression
2020
public PathExpression(string name)
2121
: base(name)
2222
{
23-
if (string.IsNullOrWhiteSpace(name))
24-
{
25-
throw Error.ArgumentNullOrWhiteSpace(nameof(name));
26-
}
23+
Utils.CheckArgumentNullOrEmpty(name);
2724
}
2825

2926
/// <summary>

src/Microsoft.OpenApi/Expressions/QueryExpression.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@ public sealed class QueryExpression : SourceExpression
2020
public QueryExpression(string name)
2121
: base(name)
2222
{
23-
if (string.IsNullOrWhiteSpace(name))
24-
{
25-
throw Error.ArgumentNullOrWhiteSpace(nameof(name));
26-
}
23+
Utils.CheckArgumentNullOrEmpty(name);
2724
}
2825

2926
/// <summary>

src/Microsoft.OpenApi/Expressions/RequestExpression.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public sealed class RequestExpression : RuntimeExpression
1919
/// <param name="source">The source of the request.</param>
2020
public RequestExpression(SourceExpression source)
2121
{
22-
Source = source ?? throw Error.ArgumentNull(nameof(source));
22+
Source = Utils.CheckArgumentNull(source);
2323
}
2424

2525
/// <summary>

src/Microsoft.OpenApi/Expressions/ResponseExpression.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public sealed class ResponseExpression : RuntimeExpression
1919
/// <param name="source">The source of the response.</param>
2020
public ResponseExpression(SourceExpression source)
2121
{
22-
Source = source ?? throw Error.ArgumentNull(nameof(source));
22+
Source = Utils.CheckArgumentNull(source);
2323
}
2424

2525
/// <summary>

src/Microsoft.OpenApi/Expressions/RuntimeExpression.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,7 @@ public abstract class RuntimeExpression : IEquatable<RuntimeExpression>
2929
/// <returns>The built runtime expression object.</returns>
3030
public static RuntimeExpression Build(string expression)
3131
{
32-
if (string.IsNullOrWhiteSpace(expression))
33-
{
34-
throw Error.ArgumentNullOrWhiteSpace(nameof(expression));
35-
}
32+
Utils.CheckArgumentNullOrEmpty(expression);
3633

3734
if (!expression.StartsWith(Prefix))
3835
{

0 commit comments

Comments
 (0)