Skip to content

Commit

Permalink
Merge branch 'main' into alanwest/otlp-array-values
Browse files Browse the repository at this point in the history
  • Loading branch information
cijothomas authored Apr 29, 2022
2 parents f0cb67d + b8aaf1a commit 289e68b
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/OpenTelemetry.Api/Internal/Guard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public CallerArgumentExpressionAttribute(string parameterName)
}
#endif

#nullable enable

#pragma warning disable SA1403 // File may only contain a single namespace
namespace OpenTelemetry.Internal
#pragma warning restore SA1403 // File may only contain a single namespace
Expand All @@ -65,7 +67,7 @@ internal static class Guard
/// <param name="paramName">The parameter name to use in the thrown exception.</param>
[DebuggerHidden]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void ThrowIfNull(object value, [CallerArgumentExpression("value")] string paramName = null)
public static void ThrowIfNull(object value, [CallerArgumentExpression("value")] string? paramName = null)
{
if (value is null)
{
Expand All @@ -80,7 +82,7 @@ public static void ThrowIfNull(object value, [CallerArgumentExpression("value")]
/// <param name="paramName">The parameter name to use in the thrown exception.</param>
[DebuggerHidden]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void ThrowIfNullOrEmpty(string value, [CallerArgumentExpression("value")] string paramName = null)
public static void ThrowIfNullOrEmpty(string value, [CallerArgumentExpression("value")] string? paramName = null)
{
if (string.IsNullOrEmpty(value))
{
Expand All @@ -95,7 +97,7 @@ public static void ThrowIfNullOrEmpty(string value, [CallerArgumentExpression("v
/// <param name="paramName">The parameter name to use in the thrown exception.</param>
[DebuggerHidden]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void ThrowIfNullOrWhitespace(string value, [CallerArgumentExpression("value")] string paramName = null)
public static void ThrowIfNullOrWhitespace(string value, [CallerArgumentExpression("value")] string? paramName = null)
{
if (string.IsNullOrWhiteSpace(value))
{
Expand All @@ -111,7 +113,7 @@ public static void ThrowIfNullOrWhitespace(string value, [CallerArgumentExpressi
/// <param name="paramName">The parameter name to use in the thrown exception.</param>
[DebuggerHidden]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void ThrowIfZero(int value, string message = "Must not be zero", [CallerArgumentExpression("value")] string paramName = null)
public static void ThrowIfZero(int value, string message = "Must not be zero", [CallerArgumentExpression("value")] string? paramName = null)
{
if (value == 0)
{
Expand All @@ -126,7 +128,7 @@ public static void ThrowIfZero(int value, string message = "Must not be zero", [
/// <param name="paramName">The parameter name to use in the thrown exception.</param>
[DebuggerHidden]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void ThrowIfInvalidTimeout(int value, [CallerArgumentExpression("value")] string paramName = null)
public static void ThrowIfInvalidTimeout(int value, [CallerArgumentExpression("value")] string? paramName = null)
{
ThrowIfOutOfRange(value, paramName, min: Timeout.Infinite, message: $"Must be non-negative or '{nameof(Timeout)}.{nameof(Timeout.Infinite)}'");
}
Expand All @@ -143,7 +145,7 @@ public static void ThrowIfInvalidTimeout(int value, [CallerArgumentExpression("v
/// <param name="message">An optional custom message to use in the thrown exception.</param>
[DebuggerHidden]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void ThrowIfOutOfRange(int value, [CallerArgumentExpression("value")] string paramName = null, int min = int.MinValue, int max = int.MaxValue, string minName = null, string maxName = null, string message = null)
public static void ThrowIfOutOfRange(int value, [CallerArgumentExpression("value")] string? paramName = null, int min = int.MinValue, int max = int.MaxValue, string? minName = null, string? maxName = null, string? message = null)
{
Range(value, paramName, min, max, minName, maxName, message);
}
Expand All @@ -160,7 +162,7 @@ public static void ThrowIfOutOfRange(int value, [CallerArgumentExpression("value
/// <param name="message">An optional custom message to use in the thrown exception.</param>
[DebuggerHidden]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void ThrowIfOutOfRange(double value, [CallerArgumentExpression("value")] string paramName = null, double min = double.MinValue, double max = double.MaxValue, string minName = null, string maxName = null, string message = null)
public static void ThrowIfOutOfRange(double value, [CallerArgumentExpression("value")] string? paramName = null, double min = double.MinValue, double max = double.MaxValue, string? minName = null, string? maxName = null, string? message = null)
{
Range(value, paramName, min, max, minName, maxName, message);
}
Expand All @@ -174,7 +176,7 @@ public static void ThrowIfOutOfRange(double value, [CallerArgumentExpression("va
/// <returns>The value casted to the specified type.</returns>
[DebuggerHidden]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T ThrowIfNotOfType<T>(object value, [CallerArgumentExpression("value")] string paramName = null)
public static T ThrowIfNotOfType<T>(object value, [CallerArgumentExpression("value")] string? paramName = null)
{
if (value is not T result)
{
Expand All @@ -186,7 +188,7 @@ public static T ThrowIfNotOfType<T>(object value, [CallerArgumentExpression("val

[DebuggerHidden]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static void Range<T>(T value, string paramName, T min, T max, string minName, string maxName, string message)
private static void Range<T>(T value, string? paramName, T min, T max, string? minName, string? maxName, string? message)
where T : IComparable<T>
{
if (value.CompareTo(min) < 0 || value.CompareTo(max) > 0)
Expand Down

0 comments on commit 289e68b

Please sign in to comment.