TypesExtensionsGetClosedTypeOf Method

Simple Injector
Gets the single closed version of genericTypeDefinition that the current type is assignable from. In case none or multiple matching closed types are found, and exception is thrown. Example: When type is a type class X : IX<int>, IFoo<string> and genericTypeDefinition is type IX<T>: this method will return type IX<int>.

Namespace:  SimpleInjector
Assembly:  SimpleInjector (in SimpleInjector.dll) Version: 4.0.0
Syntax

public static Type GetClosedTypeOf(
	this Type type,
	Type genericTypeDefinition
)

Parameters

type
Type: SystemType
The type to check.
genericTypeDefinition
Type: SystemType
The generic type definition to match.

Return Value

Type: Type
The matching closed type.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type Type. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).
Exceptions

ExceptionCondition
ArgumentNullExceptionThrown when one of the arguments is a null reference.
ArgumentExceptionThrown when genericTypeDefinition is not a generic type or when none of the base classes or implemented interfaces of
InvalidOperationExceptionThrown when multiple matching closed generic types are found.
See Also

Reference