CollectionBase.OnValidate Method (Object)

 

Performs additional custom processes when validating a value.

Namespace:   System.Collections
Assembly:  mscorlib (in mscorlib.dll)

abstract OnValidate : 
        value:Object -> unit
override OnValidate : 
        value:Object -> unit

Parameters

value
Type: System.Object

The object to validate.

Exception Condition
ArgumentNullException

value is null.

The default implementation of this method determines whether value is null, and, if so, throws ArgumentNullException. It is intended to be overridden by a derived class to perform additional action when the specified element is validated.

The On* methods are invoked only on the instance returned by the List property, but not on the instance returned by the InnerList property.

The default implementation of this method is an O(1) operation.

Notes to Implementers:

This method allows implementers to define processes that must be performed when executing the standard behavior of the underlying System.Collections.ArrayList. By defining this method, implementers can add functionality to inherited methods without having to override all other methods.

OnValidate can be used to impose restrictions on the type of objects that are accepted into the collection. The default implementation prevents null from being added to or removed from the underlying System.Collections.ArrayList.

OnValidate is called prior to OnInsert, OnRemove, and OnSet.

The following code example implements the CollectionBase class and uses that implementation to create a collection of Int16 objects.

No code example is currently available or this language may not be supported.

Universal Windows Platform
Available since 10
.NET Framework
Available since 1.1
Return to top
Show: