|
using System;
namespace MixModes.Synergy.Utilities
{
/// <summary>
/// Validation class
/// </summary>
public static class Validate
{
/// <summary>
/// Validates that a parameter is not null
/// </summary>
/// <param name="param">Parameter to verify</param>
/// <param name="paramName">Name of the parameter</param>
/// <exception cref="ArgumentNullException">Parameter is null</exception>
public static void NotNull(object param, string paramName)
{
if (param == null)
{
throw new ArgumentNullException(paramName);
}
}
/// <summary>
/// Validates that a string parameter is not null or empty
/// </summary>
/// <param name="param">String parameter to verify</param>
/// <param name="paramName">Name of the string parameter</param>
/// <exception cref="ArgumentOutOfRangeException">String parameter is null or empty</exception>
public static void StringNotNullOrEmpty(string param, string paramName)
{
NotNull(param, paramName);
if (string.IsNullOrEmpty(param))
{
throw new ArgumentOutOfRangeException(paramName);
}
}
/// <summary>
/// Asserts the specified condition
/// </summary>
/// <typeparam name="E">Type of exception to throw if assertion fails</typeparam>
/// <param name="condition">Assertion condition</param>
/// <exception cref="E">Condition evaluates to false</exception>
public static void Assert<E>(bool condition) where E : Exception, new()
{
if (!condition)
{
throw new E();
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Ashish worked for Microsoft for a number of years in Microsoft Visual Studio (Architect edition) and Windows Live division as a developer. Before that he was a developer consultant mainly involved in distributed service development / architecture. His main interests are distributed software architecture, patterns and practices and mobile device development.
Currently Ashish serves as a Technical Lead at RIM leading next generation BlackBerry media experience and also runs his own company MixModes Inc. specializing in .NET / WPF / Silverlight technologies. You can visit MixModes at http://mixmodes.com or follow it on Twitter @MixModes
In his free time he is an avid painter, hockey player and enjoys travelling. His blog is at: http://ashishkaila.serveblog.net