using System; using System.Collections; using System.ComponentModel.DataAnnotations; namespace EPAServeur.Attributes { /// /// Specifies that a collection of a specified type must have at least one element. /// [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false)] public sealed class CannotBeEmptyAttribute : RequiredAttribute { public override bool IsValid(object value) { var list = value as IEnumerable; return list != null && list.GetEnumerator().MoveNext(); } } }