TypeExtensionsCanAcceptValue Method

Checks whether a value can be an instance of type when, for example, value is passed to a method with type parameter type.


Namespace: KGySoft.CoreLibraries
Assembly: KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 8.0.0
public static bool CanAcceptValue(
	this Type type,
	Object? value


type  Type
The type to check.
value  Object
The value, whose compatibility with the type is checked.

Return Value

if value can be an instance of type; otherwise, .

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).


type can be a NullableT type.

If type is passed by reference, then the element type is checked.

If either type or value is enum, then its underlying type is also accepted because both can be unboxed from an Object without casting errors.


See Also