com.javonet.api

Class NType

  • java.lang.Object
    • com.javonet.api.NType

  • public class NType
    extends java.lang.Object
    A class representing any .NET type.

    Instances of NType exposes methods to perform operations on .NET types

    • calling static methods
    • getting or setting static fields and properties
    • creating instances of associated type

    Creating Instance of NType

    NType is initialized by calling Javonet.getType(String) method.

    This method loads to memory appropriate type on .NET side with unique identifier and returns
    instance of NType class associated to that identifier. This way all operation on NType class
    are transfered and executed on corresponding .NET type.

    Usage Sample

     
     NType dateTimeType = Javonet.getType("System.DateTime");
     String currenTime = dateTimeType.getRef("Now").invoke("ToString");
     
     
    Version:
    1.0


    • Constructor Summary

      Constructors 
      Constructor and Description
      NType(com.javonet.internal.IGateway gatewayManager,
      java.lang.Integer oid,
      java.lang.String typeName)
       



    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      NObject create()

      Creates new instance of associated .NET type using parameter-less constructor.
      NObject create(java.lang.Object... parameters)

      Creates new instance of associated .NET type using constructor with parameters.
      NGenericStaticMethod generic(NType... genericTypes)

      Initializes generic method invocation.
      <T> T get(java.lang.String fieldName)

      Returns value of static field or property of associated .NET type.
      java.lang.Integer getOid()

      Returns unique identifier of associated type loaded on .NET side.
      NObject getRef(java.lang.String fieldName)

      Returns value of static field or property of associated .NET type which return value is another .NET object.
      java.lang.String getTypeName()

      Returns name of associated .NET type
      <T> T invoke(java.lang.String methodName)

      Invokes any static method without parameters on associated .NET type and returns result.
      <T> T invoke(java.lang.String methodName,
      java.lang.Object... parameters)

      Invokes any static method with parameters on associated .NET type and returns result.
      void set(java.lang.String fieldName,
      java.lang.Object fieldValue)

      Sets value for any static field or property on associated .NET type.


      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait



    • Constructor Detail



      • NType

        public NType(com.javonet.internal.IGateway gatewayManager,
                     java.lang.Integer oid,
                     java.lang.String typeName)



    • Method Detail



      • create

        public NObject create()
                       throws JavonetException
        Creates new instance of associated .NET type using parameter-less constructor.

        This method returns new instance of NObject class associated to newly created object on .NET side.

        Returns:
        NObject instance associated to newly created object on .NET side
        Throws:
        JavonetException – If .NET exception occurs during initialization of .NET object



      • create

        public NObject create(java.lang.Object... parameters)
                       throws JavonetException
        Creates new instance of associated .NET type using constructor with parameters.

        Constructor is being matched by parameters count and type.

        Parameters can be specified as JAVA primitive types (string, integer, float..) or instances of NObject class for reference-type parameters.

        This method returns new instance of NObject class associated to newly created object on .NET side.

        Parameters:
        parameters – Parameters to be passed to constructor during creation of new instance of associated .NET type
        Returns:
        NObject instance associated to newly created object on .NET side
        Throws:
        JavonetException – If .NET exception occurs during initialization of .NET object



      • generic

        public NGenericStaticMethod generic(NType... genericTypes)
        Initializes generic method invocation. Following invocation on returned object
        should call invoke(methodName) or invoke(methodName,parameters) to perform generic
        invocation on .NET method.

        Sample usage

        To call (.NET): obj.MyMethod<String>(arg1);

        Use following instruction (JAVA): obj.generic(NType(“String”)).invoke(“MyMethod”,arg1);

        Parameters:
        genericTypes – List of NType objects attached to .NET types to be used as generic arguments
        Returns:
        Generic method execution instance. Before method is executed following invoke method must be called on this object.



      • get

        public <T> T get(java.lang.String fieldName)
                  throws JavonetException
        Returns value of static field or property of associated .NET type.

        If result is another .NET object a new instance of NObject class will be returned.

        Type Parameters:
        T – JAVA type to which the value returned from .NET field or property will be casted. Provide either JAVA value type like: integer, string, boolean or for reference type results please use NObject
        Parameters:
        fieldName – Name of the field or property which value needs to be retrieved
        Returns:
        Value of field or property retrieved from associated .NET object
        Throws:
        JavonetException – If .NET exception occurs within corresponding getter on .NET side



      • getOid

        public java.lang.Integer getOid()
        Returns unique identifier of associated type loaded on .NET side.
        Associated type is specified during initialization of NType class.
        Returns:
        Unique identifier of corresponding .NET type



      • getRef

        public NObject getRef(java.lang.String fieldName)
                       throws JavonetException
        Returns value of static field or property of associated .NET type which return value is another .NET object.

        This method should be used to simplify get calls for properties/fields with reference result.

        Result is an instance of new NObject class associated to returned .NET object.

        Alternatively generic T get with NType type might be used dateTimeType.<NObject>get("Now");

        Parameters:
        fieldName – Name of the field or property which value needs to be retrieved
        Returns:
        NObject instance associated to .NET class returned by specified field or property
        Throws:
        JavonetException – If .NET exception occurs within corresponding getter on .NET side



      • getTypeName

        public java.lang.String getTypeName()
        Returns name of associated .NET type
        Returns:
        Name of associated .NET type



      • invoke

        public <T> T invoke(java.lang.String methodName)
                     throws JavonetException
        Invokes any static method without parameters on associated .NET type and returns result.

        For primitive-type results appropriate JAVA primitive type will be returned (String, Integer, Float…)

        If reference-type results instance of another NObject will be returned associated to returned .NET object.

        For void results NULL will be returned.

        Type Parameters:
        T – JAVA type to which the result returned by invoked method will be casted. Provide either JAVA value type like: integer, string, boolean or for reference type results please use NObject
        Parameters:
        methodName – Name of the method to be invoked
        Returns:
        Result of method invocation. It can be JAVA primitive type (string, integer, float) or instance of another NObject
        Throws:
        JavonetException – If .NET exception occurs during method invocation



      • invoke

        public <T> T invoke(java.lang.String methodName,
                            java.lang.Object... parameters)
                     throws JavonetException
        Invokes any static method with parameters on associated .NET type and returns result.

        Parameters can be specified as any JAVA primitive type or instance of another NObject to pass reference to another .NET object.

        For primitive-type results appropriate JAVA primitive type will be returned (String, Integer, Float…)

        If reference-type results instance of another NObject will be returned associated to returned .NET object.

        For void results NULL will be returned.

        Type Parameters:
        T – JAVA type to which the result returned by invoked method will be casted. Provide either JAVA value type like: integer, string, boolean or for reference type results please use NObject
        Parameters:
        methodName – Name of the method to be invoked
        parameters – Input parameters for method to be invoked. It can be JAVA primitive types or NObject to pass .NET reference
        Returns:
        Result of method invocation. It can be JAVA primitive type (string, integer, float) or instance of another NObject
        Throws:
        JavonetException – If .NET exception occurs during method invocation



      • set

        public void set(java.lang.String fieldName,
                        java.lang.Object fieldValue)
                 throws JavonetException
        Sets value for any static field or property on associated .NET type.

        Value can be specified as any JAVA primitive type (integer, string, float etc…)
        or as NObject instance to pass reference to another instance of initialized .NET object.

        Parameters:
        fieldName – Name of the instance or static field or property
        fieldValue – Value to be set on selected field or property. Value can be any JAVA primitive type or instance of NObject to pass reference-type
        Throws:
        JavonetException – If .NET exception occurs within corresponding setter on .NET side