You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Digitalisation_EPA_Serveur/EPAServeur/Attributes/CannotBeEmptyAttribute.cs

20 lines
638 B

using System;
using System.Collections;
using System.ComponentModel.DataAnnotations;
namespace EPAServeur.Attributes
{
/// <summary>
/// Specifies that a collection of a specified type must have at least one element.
/// </summary>
[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();
}
}
}