[Key]//主键
[StringLength(maximumLength:100,MinimumLength =6)]//限定字符串长度
[EmailAddress]//识别邮箱格式
[Required]//属性不能为空
[Display(Name = "显示字段别名")]
可以通过特性类获取所有的方法并为按钮添加回调
public void TestMethod<T>() where T : class, new()
{
Type type = typeof(T);
//获取所有的方法及特性
MethodInfo[] methodInfos = type.GetMethods();
//遍历所有函数,并取到函数上的特性实例
foreach (MethodInfo methodInfo in methodInfos)
{
//取到函数上的所有特性实例
object[] objs = methodInfo.GetCustomAttributes(typeof(MethodTestAttribute), true);
if (objs.Length > 0)
{
//获取第一个特性
MethodTestAttribute attribute = objs[0] as MethodTestAttribute;
if (attribute != null)
{
button.transform.Find("Text").GetComponent<Text>().text = methodInfo.Name;
Button but = Instantiate(button, this.transform);
but.onClick.AddListener(() => { methodInfo.Invoke(new MyMethod(), null); });
}
}
}
}