Warum gibt das immer wahr zurück?DataAnnotations scheinen bei Werttypen mit einem Validator nicht korrekt zu funktionieren
class Program
{
static void Main(string[] args)
{
Person p = new Person();
p.Age = 24;
ICollection<ValidationResult> results = new Collection<ValidationResult>();
bool isValid = Validator.TryValidateObject(p, new ValidationContext(p, null, null), results);
Console.WriteLine("Valid = {0}",isValid);
foreach (var result in results)
{
Console.WriteLine(result.ErrorMessage);
}
Console.ReadKey();
}
}
public class Person
{
[Required(ErrorMessage = "You have to identify yourself!!")]
public int Id { get; set; }
public decimal Age { get; set; }
}
was ist falsch mit meiner Verwendung ??
@Erik Phillips: Dank den Titel für die Bearbeitung ... macht jetzt mehr Sinn – Perpetualcoder