Skip to content

Instantly share code, notes, and snippets.

@smailliwcs
Created September 22, 2020 15:25
Show Gist options
  • Save smailliwcs/0d13f8a9b13297d2de34aba09b25886e to your computer and use it in GitHub Desktop.
Save smailliwcs/0d13f8a9b13297d2de34aba09b25886e to your computer and use it in GitHub Desktop.
Nonempty collection validation
using System;
using System.Collections;
using System.ComponentModel.DataAnnotations;
[AttributeUsage(AttributeTargets.Property)]
public sealed class NotEmptyAttribute : RequiredAttribute
{
public override bool IsValid(object value)
{
ICollection valueCollection = value as ICollection;
return valueCollection != null && valueCollection.Count > 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment