Open sandboxFocus

Method MustBeInstanceOfType

MustBeInstanceOfType<T>(IEligibilityBuilder<T>, Type)

Requires the validated object to be of a certain type of metadata object, e.g. an IField or IMethod. To check the type of a field, property or parameter, use code like builder.Type().MustBeConvertibleTo(typeof(string)); instead.

Declaration
public static void MustBeInstanceOfType<T>(this IEligibilityBuilder<T> eligibilityBuilder, Type type) where T : class
Parameters
Type Name Description
IEligibilityBuilder<T> eligibilityBuilder

The eligibility builder.

Type type

The metadata type that the declaration must be an instance of (e.g., typeof(IMethod), typeof(IProperty)).

Type Parameters
Name Description
T

The type of declaration being validated.

Remarks

Note that this validates the object itself, not the declaration that it represents. For instance, if the object is an IParameter and the type parameter is set to typeof(string), this method will fail with an exception, because no conversion exists from IParameter to string.

On the other hand, code like builder.MustBeInstanceOfType(typeof(IProperty)); will correctly check that a declaration is a property.