Tip
public static Object? Convert(
this Object? obj,
Type targetType,
CultureInfo culture = null
)
<ExtensionAttribute>
Public Shared Function Convert (
obj As Object,
targetType As Type,
Optional culture As CultureInfo = Nothing
) As Object
public:
[ExtensionAttribute]
static Object^ Convert(
Object^ obj,
Type^ targetType,
CultureInfo^ culture = nullptr
)
[<ExtensionAttribute>]
static member Convert :
obj : Object *
targetType : Type *
?culture : CultureInfo
(* Defaults:
let _culture = defaultArg culture null
*)
-> Object
The method firstly tries to use registered direct conversions between source and target types, then attempts to perform the conversion via IConvertible types and registered TypeConverters. If these attempts fail, then the registered conversions tried to be used for intermediate steps, if possible. As an ultimate fallback, the String type is attempted to be used as intermediate conversion.
New conversions can be registered by the RegisterConversion extension methods.
targetType can be even a collection type if obj is also an IEnumerable implementation. The target collection type must have either a default constructor or a constructor that can accept a list, array or dictionary as an initializer collection.
ArgumentException | obj cannot be converted to targetType. |