void PutReference(
Object obj,
Type t
)
Sub PutReference (
obj As Object,
t As Type
)
void PutReference(
Object^ obj,
Type^ t
)
abstract PutReference :
obj : Object *
t : Type -> unit
public class Parent {
public virtual string Foo() { return "parent foo"; }
}
public class Child {
public new string Foo() { return "child foo"; }
}
Child childObject = new Child();
string result = ((Parent) childObject).Foo();
An alternative is to use the other signature of PutReference() to send the object to the Wolfram Language as its normal type and then call the Wolfram Language 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 Wolfram Language function.This method is virtually never used as a "downcast". Downcasting is generally irrelevant in .NET/Link because objects are normally sent to the Wolfram session 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.
MathLinkException | On any MathLink error. |
InvalidCastException | If the object cannot be cast to the given type. |