Newtonsoft之Utilities=>ValidationUtils

来源:互联网 发布:windows xp软件功能 编辑:程序博客网 时间:2024/05/21 17:28

一、先看源码

namespace Newtonsoft.Json.Utilities{    //静态验证类,主要验证参数是否为空,是否为枚举,最后进行异常抛出    internal static class ValidationUtils    {        public static void ArgumentNotNullOrEmpty(string value, string parameterName)        {            if (value == null)                throw new ArgumentNullException(parameterName);            if (value.Length == 0)                throw new ArgumentException("'{0}' cannot be empty.".FormatWith(CultureInfo.InvariantCulture, parameterName), parameterName);        }        public static void ArgumentTypeIsEnum(Type enumType, string parameterName)        {            ArgumentNotNull(enumType, "enumType");            if (!enumType.IsEnum())                throw new ArgumentException("Type {0} is not an Enum.".FormatWith(CultureInfo.InvariantCulture, enumType), parameterName);        }        public static void ArgumentNotNull(object value, string parameterName)        {            if (value == null)                throw new ArgumentNullException(parameterName);        }    }}
二、该类的意义

主要是在其他业务进行前,提前验证参数问题,起到过滤的作用


0 0
原创粉丝点击