mark
mark

Reputation: 1428

Invoke Static Method of a .NET Generic Class in MATLAB?

How do you invoke a static method of a .NET generic class in MATLAB?

For example, how would I invoke the static method Create shown below?

public class A<T> {

    internal A() {      
    }

    public static A<T> Create() {
        return new A<T>();
    }
}

http://www.mathworks.com/help/techdoc/matlab_external/brz16z_-1.html talks about invoking a static generic method of a generic class, but it does not show how to invoke a static non-generic method of a generic class.

Upvotes: 2

Views: 910

Answers (2)

Wollmich
Wollmich

Reputation: 1646

The following code should work to invoke a static method of a generic non-static class:

c = NET.createGeneric('A',{'System.Double'});
d = c.Create()

Upvotes: 0

SwDevMan81
SwDevMan81

Reputation: 50028

So on that link you have, it says:

Invoke Generic Functions of a Generic Class If a generic method uses the same parameterized type as the generic class, you can call the function directly on the class object. If the generic uses a different type than the class, use the NET.invokeGenericMethod function.

So seems like you should be able to do:

genClsDef = NET.GenericClass('A','System.Double');
ret = NET.invokeGenericMethod(genClsDef,'A','System.Double');

Upvotes: 2

Related Questions