Salesforce

DNCast (Magic xpa 4.x)

« Go Back

Information

 
Created BySalesforce Service User
Approval Process StatusPublished
Objective
Description

DNCast (Magic xpa 4.x)

Casts data from Magic xpa to .NET. Use this function whenever you need to implicitly cast a value to a .NET type.

A possible use for this function is to select an overloaded method.

Another use for the DNCast() function is to cast a .NET variable of type Object to a specific object type, so you will be able to access its methods. See the second example below.

Syntax:

DNCast (value, type)

Parameters:

value: a value of any type to cast the data from

type: the .NET type to cast the data to

Returns:

A value according to a .NET type.

Example:

  • Let's take the following scenario: you have two .NET methods with the same name, one receives a parameter of type Int16 and the other of type Double. In this case, it is not legal to send a Magic xpa numeric value to this method, since Magic xpa cannot know which method to use.

    So the proper way is to implicitly specify the .NET type to use, for example:
    DNCast(5, DotNet.System.Int16)

  • When defining a handler for a .NET event, in most cases (depending on the event) two arguments ('sender' and 'e') are added to the handler. The 'sender' is the object that raises the event and the 'e' is the event arguments. Now, the 'sender' has a .NET type of 'Object'. This is a generic object, and it is not easy to manipulate it.
    Using DNCast() to cast the object type into a specific .NET object, such a: 'System.Windows.Forms.TextBox' will let you refer to this object and get all the properties/methods of 'System.Windows.Forms.TextBox'.
    You can even use them directly after the DNCast function, for example: DNCast(A,DotNet.System.Windows.Forms.TextBox).Text

Exceptions:

This function is not supported in Web Client tasks.

Platform specific:

This function is not supported for mobile devices.

See also:

Dot Net Tutorial sample project

Reference
Attachment 
Attachment