using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using Microsoft.Msagl.Core.Layout;
namespace Microsoft.Msagl.Core
{
///
/// Helper class for validating parameter arguments.
///
internal static class ValidateArg
{
///
/// Throws ArgumentNullException if the argument is null.
///
/// The argument to check.
/// The parameter name of the argument.
///
/// The ValidatedNotNullAttribute lets FxCop know that this method null-checks the argument.
///
[DebuggerStepThrough]
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification = "This is shared source. This method may not be called in the current assembly.")]
public static void IsNotNull([ValidatedNotNull] object arg, string parameterName)
{
if (arg == null)
{
throw new ArgumentNullException(parameterName);
}
}
///
/// Throws ArgumentOutOfRangeException if the argument is less than 0.
///
/// The argument to check.
/// The parameter name of the argument.
///
/// The ValidatedNotNullAttribute lets FxCop know that this method null-checks the argument.
///
[DebuggerStepThrough]
public static void IsPositive(double value, string parameterName)
{
if (value < 0)
{
throw new ArgumentOutOfRangeException(parameterName, "The argument must be positive");
}
}
///
/// throws ArgumentException if the enumerable is empty
///
///
///
///
public static void IsNotEmpty(IEnumerable enumerable, string parameterName)
{
if (enumerable == null)
{
throw new ArgumentNullException(parameterName);
}
if (!enumerable.Any())
{
throw new ArgumentException("The argument enumerable must not be empty", parameterName);
}
}
///
/// Marks the parameter as being validated by the method.
///
///
/// StyleCop uses this to determine whether the calling method has validated a parameter.
///
[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = true)]
private sealed class ValidatedNotNullAttribute : Attribute { }
}
}