Created
September 22, 2020 15:25
-
-
Save smailliwcs/0d13f8a9b13297d2de34aba09b25886e to your computer and use it in GitHub Desktop.
Nonempty collection validation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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