ArcFM Responder Mobile Developer Guide
TryCast<T> Method






The type of the value to be returned.
The object to be cast.
The default value to be returned if the object to be cast is null or DBNull.
Trys to casts an object to the type of the given default value. If the object cannot be cast, the default value specified will be returned. If the object is convertable to the type of the default value, the explicit conversion will be performed.
Syntax
'Declaration
 
Public Shared Function TryCast(Of T)( _
   ByVal obj As System.Object, _
   ByVal defaultValue As T _
) As T
'Usage
 
Dim obj As System.Object
Dim defaultValue As T
Dim value As T
 
value = ProvidersHelper.TryCast(Of T)(obj, defaultValue)
public static T TryCast<T>( 
   System.object obj,
   T defaultValue
)
public function TryCast( 
    obj: System.TObject;
    defaultValue: T
): T; static; 
public static function TryCast( 
   obj : System.Object,
   defaultValue : T
) : T;
public: static T* TryCast<T>( 
   System.Object* obj,
   T* defaultValue
) 
public:
static T^ TryCastgeneric<typename T>
( 
   System.Object^ obj,
   T^ defaultValue
) 

Parameters

obj
The object to be cast.
defaultValue
The default value to be returned if the object to be cast is null or DBNull.

Type Parameters

T
The type of the value to be returned.

Return Value

The value of the object cast to the type of the default value.
Exceptions
ExceptionDescription
System.InvalidCastExceptionThrown if the type of the object cannot be cast to the type of the default value.
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

ProvidersHelper Class
ProvidersHelper Members

Send Feedback