C# Class NFluent.Helpers.IsInstanceHelper

Helper class related to Is(Not)Instance methods (used like a traits).
Mostra file Open project: tpierrain/NFluent

Public Methods

Method Description
BuildErrorMessage ( object value, Type typeOperand, bool isSameType ) : string

Builds the error message related to the type comparison. This should be called only if the test failed (no matter it is negated or not). Warning: Should not call this method with nullable types. Indeed, the Nullable types are treated specially by CLR and it is impossible to have a boxed instance of a nullable type. Instead, boxing a nullable type will result in a null reference (if HasValue is false), or the boxed value (if there is a value).

BuildErrorMessageForNullable ( Type instanceType, Type expectedType, object value, bool isSameType ) : string
InheritsFrom ( IChecker checker, Type expectedBaseType ) : void

Checks that an instance is in the inheritance hierarchy of a specified type.

IsDifferentType ( Type instanceType, Type expectedType, object value ) : void

Checks that a type is not the expected one.

IsInstanceOf ( object instance, Type expectedType ) : void

Checks that an instance is of the given expected type.

IsNotInstanceOf ( object instance, Type typeNotExpected ) : void

Checks that an instance is not of the given expected type.

IsSameType ( Type instanceType, Type expectedType, object value ) : void

Checks that a type is the same as the expected one.

Method Details

BuildErrorMessage() public static method

Builds the error message related to the type comparison. This should be called only if the test failed (no matter it is negated or not). Warning: Should not call this method with nullable types. Indeed, the Nullable types are treated specially by CLR and it is impossible to have a boxed instance of a nullable type. Instead, boxing a nullable type will result in a null reference (if HasValue is false), or the boxed value (if there is a value).
public static BuildErrorMessage ( object value, Type typeOperand, bool isSameType ) : string
value object The checked value.
typeOperand System.Type The other type operand.
isSameType bool A value indicating whether the two types are identical or not. true if they are equal; false otherwise.
return string

BuildErrorMessageForNullable() public static method

public static BuildErrorMessageForNullable ( Type instanceType, Type expectedType, object value, bool isSameType ) : string
instanceType System.Type
expectedType System.Type
value object
isSameType bool
return string

InheritsFrom() public static method

Checks that an instance is in the inheritance hierarchy of a specified type.
The instance is not in the inheritance hierarchy of the specified type.
public static InheritsFrom ( IChecker checker, Type expectedBaseType ) : void
checker IChecker The instance to be checked.
expectedBaseType System.Type The Type which is expected to be a base Type of the instance.
return void

IsDifferentType() public static method

Checks that a type is not the expected one.
public static IsDifferentType ( Type instanceType, Type expectedType, object value ) : void
instanceType System.Type The type of the instance to be checked.
expectedType System.Type The expected type for the instance to be checked.
value object The value of the instance to be checked (may be a nullable instance).
return void

IsInstanceOf() public static method

Checks that an instance is of the given expected type.
The instance is not of the expected type.
public static IsInstanceOf ( object instance, Type expectedType ) : void
instance object The instance to be checked.
expectedType System.Type The expected type.
return void

IsNotInstanceOf() public static method

Checks that an instance is not of the given expected type.
The instance is of the type not expected.
public static IsNotInstanceOf ( object instance, Type typeNotExpected ) : void
instance object The instance to be checked.
typeNotExpected System.Type The type not expected.
return void

IsSameType() public static method

Checks that a type is the same as the expected one.
public static IsSameType ( Type instanceType, Type expectedType, object value ) : void
instanceType System.Type The type of the instance to be checked.
expectedType System.Type The expected type for the instance to be checked.
value object The value of the instance to be checked (may be a nullable instance).
return void