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: 5.3.0
Syntax
Parameters
- type
- Type: SystemType
The type to check. - genericTypeDefinition
- Type: SystemType
The generic type definition to match.
Return Value
Type: TypeThe 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
Exception | Condition |
---|---|
ArgumentNullException | Thrown when one of the arguments is a null reference. |
ArgumentException | Thrown when genericTypeDefinition is not a generic type or when none of the base classes or implemented interfaces of type are closed-versions of genericTypeDefinition. |
InvalidOperationException | Thrown when multiple matching closed generic types are found. |
See Also