Main Content

NET.interfaceView

Explicit interface view of .NET object

Since R2023b

    Description

    example

    view = NET.interfaceView(obj,typename) creates an explicit view of a .NET object as one of its implemented interfaces. Use view to access members of the .NET interface type typename that are explicitly implemented by obj. For more information, see the MSDN® article Explicit Interface Implementation.

    Examples

    collapse all

    Inspect methods of the System.IConvertible interface of a System.String object.

    Create an IConvertible interface object from System.String.

    str = System.String("Hello, world!");
    itf = NET.interfaceView(str,"System.IConvertible");
    

    System.String has methods such as ToLower which manipulate strings. The interface object has conversion methods to cast the object to different types, such as the datetime type using the ToDateTime method. Compare the output of these commands:

    str.To<tab>
    itf.To<tab>

    Input Arguments

    collapse all

    Object to view, specified as a .NET object that implements an interface.

    Namespace-qualified name of a .NET interface type, specified as a string or a character vector.

    Example: "System.IConvertible"

    Version History

    Introduced in R2023b