A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://docs.microsoft.com/en-us/dotnet/api/microsoft.visualbasic.conversion.ctypedynamic below:

Conversion.CTypeDynamic Method (Microsoft.VisualBasic) | Microsoft Learn

Conversion.CTypeDynamic Method Definition Overloads CTypeDynamic(Object, Type)
Source:
Conversion.vb
Source:
Conversion.vb
Source:
Conversion.vb
Source:
Conversion.vb

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
Expression
Object

The object to convert.

TargetType
Type

The type to which to convert the object.

Returns

An object whose type at run time is the requested target type.

Examples

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

See also CTypeDynamic<TargetType>(Object)
Source:
Conversion.vb
Source:
Conversion.vb
Source:
Conversion.vb
Source:
Conversion.vb

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
TargetType

The type to which to convert the object.

Parameters
Expression
Object

The object to convert.

Returns

TargetType

An object statically typed as the requested generic type.

Examples

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

See also

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 article

Was 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