Show / Hide Table of Contents

Class CollectionHaveAnyAttribute

Check if the collection have any item.

Inheritance
System.Object
CollectionHaveAnyAttribute
Namespace: StoneCo.Framework.Common.Attributes
Assembly: cs.temp.dll.dll
Syntax
public class CollectionHaveAnyAttribute : ValidationAttribute

Constructors

CollectionHaveAnyAttribute(Boolean)

Constructor for set required.

Declaration
public CollectionHaveAnyAttribute(bool required = false)
Parameters
Type Name Description
System.Boolean required

Value true for required or false to ignore required.

Methods

IsValid(Object)

Determines whether the collection have any item.

note

If object is null and not set required true on the constructor, the return is true, because the field may be not required.

warning

The provided object must interfaced of ICollection.

Declaration
public override bool IsValid(object value)
Parameters
Type Name Description
System.Object value

The value to validate.

Returns
Type Description
System.Boolean

True if the specified value is valid, otherwise, false.

Examples

Example to default ignore required collection.

public class CollectionMessage
{
    [CollectionHaveAny]
    public List<string> ListOfString { get; set; }
}

Example to set collection is required.

public class CollectionMessage
{
    [CollectionHaveAny(true)]
    public List<string> ListOfString { get; set; }
}
Back to top Generated by DocFX