using System.ComponentModel.DataAnnotations;
using System.Collections.Generic;
public string UserName { get; set; }
public string Password { get; set; }
public string Name{get;set;}
public int Value{get;set;}
public static List<FieldLength> GenerateValidationModel<T>()
List<FieldLength> FieldVal= new List<FieldLength>();
foreach (var prop in typeof(T).GetProperties())
object[] attrs = prop.GetCustomAttributes(true);
if (attrs == null || attrs.Length == 0)
foreach (Attribute attr in attrs)
if (attr is MaxLengthAttribute)
conds += (attr as MaxLengthAttribute).Length;
FieldVal.Add(new FieldLength() { Name = prop.Name, Value = conds });
public static void Main()
var FieldVal = GenerateValidationModel<LoginModel>();
foreach(var item in FieldVal)
Console.WriteLine(item.Name + " "+item.Value );