Converts an object to the specified type.
public:
static System::Object ^ CTypeDynamic(System::Object ^ Expression, Type ^ TargetType);
public static object CTypeDynamic(object? Expression, Type TargetType);
public static object CTypeDynamic(object Expression, Type TargetType);
static member CTypeDynamic : obj * Type -> obj
Public Function CTypeDynamic (Expression As Object, TargetType As Type) As Object
Parameters
The object to convert.
The type to which to convert the object.
ReturnsAn object whose type at run time is the requested target type.
ExamplesThe following example uses the CTypeDynamic
method to convert a dynamic object to a string by using the conversion defined by the dynamic object.
Imports System.Dynamic
Module Module1
Sub Main()
Dim dyn As Object = New SampleDynamicObject
Dim sampleString = CTypeDynamic(dyn, GetType(String))
Console.WriteLine(sampleString)
End Sub
End Module
Class SampleDynamicObject
Inherits DynamicObject
Public Overrides Function TryConvert(ByVal binder As ConvertBinder,
ByRef result As Object) As Boolean
If binder.Type = GetType(String) Then
result = "Sample String"
Return True
End If
Return False
End Function
End Class
Remarks
The CTypeDynamic
method converts the object passed as the Expression
parameter to the type specified by the TargetType
parameter. If the object is a dynamic object, the CTypeDynamic
method applies available dynamic conversions.
The CTypeDynamic
method applies dynamic conversions in accordance with the conversion semantics defined by the object itself. If a dynamic object inherits from DynamicObject, the CTypeDynamic
method first attempts to perform the conversion by using a user-defined, static conversion. If the user-defined, static conversion fails, the CTypeDynamic
method attempts to perform the conversion by using dynamic conversions. If a dynamic object implements IDynamicMetaObjectProvider, the CTypeDynamic
method gives precedence to dynamic conversions over user-defined, static conversions.
Converts an object to the specified generic type.
public:
generic <typename TargetType>
static TargetType CTypeDynamic(System::Object ^ Expression);
public static TargetType CTypeDynamic<TargetType>(object? Expression);
public static TargetType CTypeDynamic<TargetType>(object Expression);
static member CTypeDynamic : obj -> 'argetType
Public Function CTypeDynamic(Of TargetType) (Expression As Object) As TargetType
Type Parameters
The type to which to convert the object.
ParametersThe object to convert.
ReturnsTargetType
An object statically typed as the requested generic type.
ExamplesThe following example uses the CTypeDynamic
method to convert a dynamic object to a string by using the conversion defined by the dynamic object.
Imports System.Dynamic
Module Module1
Sub Main()
Dim dyn As Object = New SampleDynamicObject
Dim str = CTypeDynamic(Of String)(dyn)
Console.WriteLine(str)
End Sub
End Module
Class SampleDynamicObject
Inherits DynamicObject
Public Overrides Function TryConvert(ByVal binder As ConvertBinder,
ByRef result As Object) As Boolean
If binder.Type = GetType(String) Then
result = "Sample String"
Return True
End If
Return False
End Function
End Class
Remarks
The CTypeDynamic
method converts the object passed as the Expression
parameter to the type specified by the type of the generic parameter. If the object is a dynamic object, the CTypeDynamic
method applies available dynamic conversions.
The CTypeDynamic
method applies dynamic conversions in accordance with the conversion semantics defined by the object itself. If a dynamic object inherits from DynamicObject, the CTypeDynamic
method first attempts to perform the conversion by using a user-defined, static conversion. If the user-defined, static conversion fails, the CTypeDynamic
method attempts to perform the conversion by using dynamic conversions. If a dynamic object implements IDynamicMetaObjectProvider, the CTypeDynamic
method gives precedence to dynamic conversions over user-defined, static conversions.
Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide. In this articleWas this page helpful?
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4