要给出部分答案,可以检查ClientInfoView是否具有属性。一些对我有用的小演示。仍在尝试查找为什么我无法在ClientInfoViewmetaData单个属性中访问那些属性的原因
static void Main(string[] args) { TypeDescriptor.AddProviderTransparent( new AssociatedmetadataTypeTypeDescriptionProvider(typeof(ClientInfoView), typeof(ClientInfoViewmetaData)), typeof(ClientInfoView)); ClientInfoView cv1 = new ClientInfoView() { ID = 1 }; var df = cv1.GetType().GetCustomAttributes(true); var dfd = cv1.ID.GetType().GetCustomAttributes(typeof(DisplayNameAttribute), true); var context = new ValidationContext(cv1, null, null); var results = new List<ValidationResult>(); var isValid = Validator.TryValidateObject( cv1,context, results, true); }} [metadataType(typeof(ClientInfoViewmetaData))] public partial class ClientInfoView { public int ID { get; set; } public string Login { get; set; } }public class ClientInfoViewmetaData{ [Required] [Category("Main Data"), DisplayName("Client ID")] public int ID { get; set; } [Required] [Category("Main Data"), DisplayName("Login")] public string Login { get; set; }}


