void Check(object objValue, string parameterName);
public CheckIsNullOrEmptyAttribute(){} public void Check(object objValue,string parameterName){
if (objValue == null) throw new ArgumentNullException(parameterName);
}
private int _minValue; private int _maxValue; public CheckLengthAttribute(int minValue,int maxValue){
this._minValue=minValue; this._maxValue=maxValue;
this._minValue=minValue;
this._maxValue=maxValue;
} public void Check(object objValue, string parameterName){
if (objValue == null) throw new ArgumentNullException(parameterName, "The object can't be null."); int len = objValue.ToString().Length; if (len<this._minValue||len>this._maxValue) throw new ArgumentOutOfRangeException(parameterName, string.Format("The value length must be between {0} and {1}", this._minValue,this._maxValue));
if (objValue == null) throw new ArgumentNullException(parameterName, "The object can't be null.");
int len = objValue.ToString().Length;
if (len<this._minValue||len>this._maxValue)
throw new ArgumentOutOfRangeException(parameterName,
string.Format("The value length must be between {0} and {1}",
this._minValue,this._maxValue));
void CheckPower([CheckIsNullOrEmpty]string uName, [CheckLength(6, 10)]string pwd);
public LoginClass() { } public void CheckPower(string uName, string pwd) {
try{ Console.WriteLine("Pass...\n"); } catch (Exception error) { Console.WriteLine("An Error:{0}\n",error.Message); }
try{
Console.WriteLine("Pass...\n");
catch (Exception error)
{
Console.WriteLine("An Error:{0}\n",error.Message);
static void Main(string[] args){ LoginClass lc = new LoginClass(); lc.CheckPower(null, "123456"); lc.CheckPower("Test", "123"); Console.ReadKey(true); }
LoginClass lc = new LoginClass();
lc.CheckPower(null, "123456");
lc.CheckPower("Test", "123");
Console.ReadKey(true);