Returns the element corresponding to the specified key as an instance of a custom class.

Namespace: Sfs2X.Entities.Data
Assembly: SmartFox2X (in SmartFox2X.dll) Version: 1.7.0.0 (1.7.0)

Syntax

C#
Object GetClass(
	string key
)

Parameters

key
Type: System..::..String
The key whose associated value is to be returned.

Return Value

Type: Object
The element of this object as a generic object type to be casted to the target class definition.

Remarks

This advanced feature allows the transmission of specific object instances between client-side C# and server-side Java provided that:
- the respective class definitions on both sides have the same package name
- the following code is executed right after creating the SmartFox object: DefaultSFSDataSerializer.RunningAssembly = Assembly.GetExecutingAssembly(); (requires System.Reflection and Sfs2X.Protocol.Serialization)

IMPORTANT: class serialization is not supported in Unity WebGL.

Examples

The following example shows the same class on the client and server sides, which can be transferred back and forth with the GetClass(String) and PutClass(String, Object) methods.

The server-side Java definition of a SpaceShip class is:

 Copy imageCopy
package my.game.spacecombat
public class SpaceShip
{
    private String type;
    private String name;
    private int firePower;
    private int maxSpeed;
    private List<String> weapons;
    public SpaceShip(String name, String type)
    {
        this.name = name;
        this.type = type;
    }
    // ... Getters / Setters ...
}

The client-side C# definition of the SpaceShip class is:

 Copy imageCopy
namespace my.game.spacecombat
{
    public class SpaceShip
    {
        private string _type;
        private string _name;
        private int _firePower;
        private int _maxSpeed;
        private Array _weapons;
        public SpaceShip(string name, string type)
        {
            _name = name
            _type = type
        }
        // ... Getters / Setters ...
    }
}

The SpaceShip instance is sent by the server to the client. This is how to retrieve it:

 Copy imageCopy
SpaceShip myShipData = (SpaceShip)sfsObject.GetClass(key);

See Also