.NET/Link API Version 1.7 USE FRAMES

IKernelLink.PutReference Method (Object, Type)

Sends the object cast as a parent type or interface.

[Visual Basic]
Sub PutReference( _
   ByVal obj As Object, _
   ByVal t As Type _
)
[C#]
void PutReference(
   object obj,
   Type t
);

Parameters

obj
The object to send by reference.
t
The type the object will be seen as in Mathematica.

Remarks

Use this form of PutReference if you want to "upcast" the object so that it is seen in Mathematica as an instance of a parent class or interface. You would want to do this if you needed to call from Mathematica an inherited version of a method that was hidden by a "new" declaration lower in the inheritance hierarchy. For example, consider the following classes:

public class Parent {
    public virtual string Foo() { return "parent foo"; }
}

public class Child {
    public new string Foo() { return "child foo"; }
}
In C# code, if you had an object of type Child and you wanted to call the Parent version of Foo(), you would upcast the object like this:
Child childObject = new Child();
string result = ((Parent) childObject).Foo();
This PutReference() method is the equivalent for Mathematica programmers. You would send the object to Mathematica typed as Parent, so that when you called the Foo() method you would get the version from the Parent class.

An alternative is to use the other signature of PutReference() to send the object to Mathematica as its normal type and then call the Mathematica function CastNETObject[] to upcast it to a parent type.

For more examples of when you would want to use this method, see the .NET/Link User Guide for its discussion of the CastNETObject Mathematica function.

This method is virtually never used as a "downcast". Downcasting is generally irrelevant in .NET/Link because objects are normally sent to Mathematica as their true runtime type (there is no lower-down type to cast to). It is only useful to upcast to a parent type or interface. The one exception to this is if you have an object that you have previously upcast to a parent type and you want to downcast it back to its true runtime type.

Exceptions

Exception Type Condition
MathLinkException On any MathLink error.
InvalidCastException If the object cannot be cast to the given type.

See Also

IKernelLink Interface | Wolfram.NETLink Namespace | IKernelLink.PutReference Overload List | EnableObjectReferences | GetObject