Skip to content

Commit 72364c5

Browse files
committed
Add utilities library
1 parent 5869a55 commit 72364c5

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

src/Microsoft.OpenApi/Utils.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license.
3+
4+
using System;
5+
6+
namespace Microsoft.OpenApi
7+
{
8+
/// <summary>
9+
/// Utilities methods
10+
/// </summary>
11+
public static class Utils
12+
{
13+
/// <summary>
14+
/// Check whether the input argument value is null or not.
15+
/// </summary>
16+
/// <typeparam name="T">The input value type.</typeparam>
17+
/// <param name="value">The input value.</param>
18+
/// <param name="parameterName">The input parameter name.</param>
19+
/// <returns>The input value.</returns>
20+
internal static T CheckArgumentNull<T>(T value, string parameterName) where T : class
21+
{
22+
return value ?? throw new ArgumentNullException(parameterName, $"Value cannot be null: {parameterName}");
23+
}
24+
25+
/// <summary>
26+
/// Check whether the input string value is null or empty.
27+
/// </summary>
28+
/// <param name="value">The input string value.</param>
29+
/// <param name="parameterName">The input parameter name.</param>
30+
/// <returns>The input value.</returns>
31+
internal static string CheckArgumentNullOrEmpty(string value, string parameterName)
32+
{
33+
return string.IsNullOrEmpty(value) ? throw new ArgumentNullException(parameterName, $"Value cannot be null or empty: {parameterName}") : value;
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)