C#:实体类中做数据验证
2010-02-26 13:34
218 查看
主要是在实体类中验证
using System;
namespace Jone.Function.attribute
{
/// <summary>
/// 附加在数据实体用于描述如何验证合法性
/// </summary>
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
public sealed class ValidateAttribute : Attribute
{
private bool _allowNull = true;
private string _regEx;
private string _description;
private string _ValidateType;
private string _instruction;
#region 方法
public ValidateAttribute()
{
}
public ValidateAttribute(bool AllowNull)
{
_allowNull = AllowNull;
}
public ValidateAttribute(bool AllowNull, string ValidateType)
{
_allowNull = AllowNull;
_ValidateType = ValidateType;
}
#endregion
#region 属性
/// <summary>
/// 描述
/// </summary>
public string Description
{
get { return _description; }
set { _description = value; }
}
/// <summary>
/// 验证类型
/// </summary>
public string ValidateType
{
get
{
return _ValidateType;
}
set
{
_ValidateType = value;
}
}
/// <summary>
/// 是否可以空
/// </summary>
public bool AllowNull
{
get
{
return _allowNull;
}
set
{
_allowNull = value;
}
}
/// <summary>
/// 用于验证的正则表达式
/// </summary>
public string RegEx
{
get
{
return _regEx;
}
set
{
_regEx = value;
}
}
/// <summary>
/// 对于正确格式的描述
/// </summary>
public string Instruction
{
get
{
return _instruction;
}
set
{
_instruction = value;
}
}
#endregion
}
#region 使用示例
//public class 使用示例
//{
// public 使用示例()
// {
// }
// private int _id;
// private string _name;
// //[Validate(RegEx = "^\\d{17}(http://www.cnblogs.com/luomingui/admin/file:///d|x)$", Description = "身份证号码")]
// [Validate(RegEx = "", Description = "")]
// public int id
// {
// set { _id = value; }
// get { return _id; }
// }
// [Validate(AllowNull = false, Description = "姓名")]
// public string name
// {
// set { _name = value; }
// get { return _name; }
// }
//}
#endregion
}
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/luomingui/archive/2008/09/14/2874588.aspx
using System;
namespace Jone.Function.attribute
{
/// <summary>
/// 附加在数据实体用于描述如何验证合法性
/// </summary>
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
public sealed class ValidateAttribute : Attribute
{
private bool _allowNull = true;
private string _regEx;
private string _description;
private string _ValidateType;
private string _instruction;
#region 方法
public ValidateAttribute()
{
}
public ValidateAttribute(bool AllowNull)
{
_allowNull = AllowNull;
}
public ValidateAttribute(bool AllowNull, string ValidateType)
{
_allowNull = AllowNull;
_ValidateType = ValidateType;
}
#endregion
#region 属性
/// <summary>
/// 描述
/// </summary>
public string Description
{
get { return _description; }
set { _description = value; }
}
/// <summary>
/// 验证类型
/// </summary>
public string ValidateType
{
get
{
return _ValidateType;
}
set
{
_ValidateType = value;
}
}
/// <summary>
/// 是否可以空
/// </summary>
public bool AllowNull
{
get
{
return _allowNull;
}
set
{
_allowNull = value;
}
}
/// <summary>
/// 用于验证的正则表达式
/// </summary>
public string RegEx
{
get
{
return _regEx;
}
set
{
_regEx = value;
}
}
/// <summary>
/// 对于正确格式的描述
/// </summary>
public string Instruction
{
get
{
return _instruction;
}
set
{
_instruction = value;
}
}
#endregion
}
#region 使用示例
//public class 使用示例
//{
// public 使用示例()
// {
// }
// private int _id;
// private string _name;
// //[Validate(RegEx = "^\\d{17}(http://www.cnblogs.com/luomingui/admin/file:///d|x)$", Description = "身份证号码")]
// [Validate(RegEx = "", Description = "")]
// public int id
// {
// set { _id = value; }
// get { return _id; }
// }
// [Validate(AllowNull = false, Description = "姓名")]
// public string name
// {
// set { _name = value; }
// get { return _name; }
// }
//}
#endregion
}
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/luomingui/archive/2008/09/14/2874588.aspx
相关文章推荐
- C#:实体类中做数据验证
- C# WPF 快速开发18封装数据验证逻辑
- C#实体类中在数据类型后面添加问号是什么意思
- 常用的正则表达式(转)及在C#代码中用正则表达式验证数据(转)
- c# winform控件数据验证
- 表单提交数据的方式 怎么在服务器获取 服务器控件 html服务器控件 提交服务器之前的验证 前台网页编写c#代码
- C#提高知识 ADO.NET实体数据模型(1)
- 利用反射实现ASP.NET控件和数据实体之间的双向绑定,并且在客户端自动验证输入的内容是否合法
- 采用一个自创的"验证框架"实现对数据实体的验证[设计篇]
- Smark.Data实体成员数据验证
- C# 实体model验证输出
- C#中将DataTable数据转为实体对象
- C#提高知识 ADO.NET实体数据模型 (2)
- 在C#中使用正则表达式验证数据格式
- C#提高知识 ADO.NET实体数据模型(1)
- C#验证输入数据的字节数包括中文和英文
- c#基类 常用数据验证的封装,数字,字符,邮箱的验证
- MVC验证(自动在基类中验证实体的数据有效性),本人最满意的作品之一
- C#验证输入数据的字节数包括中文和英文
- C# Windows Form下的控件的Validator(数据验证)