ObjectExtensionsTryConvertTTarget(Object, CultureInfo, TTarget) Method
Namespace: KGySoft.CoreLibrariesAssembly: KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 9.0.0-preview.1
public static bool TryConvert<TTarget>(
this Object? obj,
CultureInfo culture,
out TTarget value
)
<ExtensionAttribute>
Public Shared Function TryConvert(Of TTarget) (
obj As Object,
culture As CultureInfo,
<OutAttribute> ByRef value As TTarget
) As Boolean
public:
[ExtensionAttribute]
generic<typename TTarget>
static bool TryConvert(
Object^ obj,
CultureInfo^ culture,
[OutAttribute] TTarget% value
)
[<ExtensionAttribute>]
static member TryConvert :
obj : Object *
culture : CultureInfo *
value : 'TTarget byref -> bool
- obj Object
- The object to convert.
- culture CultureInfo
- The culture to use for the conversion. If , then the InvariantCulture will be used.
- value TTarget
- When this method returns with result, then this parameter contains the result of the conversion.
- TTarget
- The desired type of the returned value.
Boolean, if
obj could be converted to
TTarget, which is returned in the
value parameter; otherwise,
.In Visual Basic and C#, you can call this method as an instance method on any object of type
Object. 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).
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.
The registered conversions are tried to be used for intermediate conversion steps if possible. For example, if a conversion is registered from
DateTime to
Int64,
then conversions from
DateTime to
Double becomes automatically available using the
Int64 type as an intermediate conversion step.