I got a problem using a Validation Attribute in a non CSLA property. The test code follow below.
[Serializable]
public class Foo : BusinessBase<Foo>
{
public static readonly PropertyInfo<string> NameProperty = RegisterProperty<string>(c => c.Name);
public string Name
{
get { return GetProperty(NameProperty); }
set { SetProperty(NameProperty, value); }
}
public static readonly PropertyInfo<int> IdProperty = RegisterProperty<int>(c => c.Id);
public int Id
{
get { return GetProperty(IdProperty); }
set { SetProperty(IdProperty, value); }
}
[Required]
public int Code { get; set; }
}
privatevoid AddDataAnnotationsFromType(Type metadataType)
{
var attList = metadataType.GetCustomAttributes(typeof(System.ComponentModel.DataAnnotations.ValidationAttribute),true);
foreach (var att in attList)
AddRule(new CommonRules.DataAnnotation(null, (System.ComponentModel.DataAnnotations.ValidationAttribute)att));
// attributes on properties
var propList = metadataType.GetProperties();
foreach (var prop in propList)
{
attList = prop.GetCustomAttributes(typeof(System.ComponentModel.DataAnnotations.ValidationAttribute),true);
foreach (var att in attList)
{
var target = (IManageProperties)_target;
var pi = target.GetManagedProperties().First(c => c.Name == prop.Name);
AddRule(new CommonRules.DataAnnotation(pi, (System.ComponentModel.DataAnnotations.ValidationAttribute)att));
}
}
}