OPC Studio User's Guide and Reference
AsObject Method (InteropHelper)



OpcLabs.BaseLib Assembly > OpcLabs.BaseLib.ComInterop Namespace > InteropHelper Class : AsObject Method
The object to be cast.

The value of this parameter can be null (Nothing in Visual Basic).

Casts the input argument to an System.Object.
Syntax
'Declaration
 
<CanBeNullAttribute()>
Public Function AsObject( _
   ByVal obj As Object _
) As Object
'Usage
 
Dim instance As InteropHelper
Dim obj As Object
Dim value As Object
 
value = instance.AsObject(obj)
[CanBeNull()]
public object AsObject( 
   object obj
)
[CanBeNull()]
public:
Object^ AsObject( 
   Object^ obj
) 

Parameters

obj
The object to be cast.

The value of this parameter can be null (Nothing in Visual Basic).

Return Value

Returns the input argument, cast to an System.Object.

This method can return null (Nothing in Visual Basic).

Remarks

This method is useful in some COM tools (such as PHP) that do not allow to navigate between COM interfaces of an object, or provide an "amalgamated" set of members from multiple interfaces, when a specific interface is returned by a property or method. This leads to a problem if you want to downcast the object you have to a derived type. By passing the object through this method, the consuming COM tool is forced to use late binding, allowing the intended members be accessed.

Requirements

Target Platforms: .NET Framework: Windows 10 (selected versions), Windows 11 (selected versions), Windows Server 2016, Windows Server 2022; .NET: Linux, macOS, Microsoft Windows

See Also