com.javonet.api

Class NDelegateWithResult

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

  • public class NDelegateWithResult
    extends java.lang.Object
    A class that represents the .NET delegate object. This class can be used to create the
    instance of .NET delegate and pass that instance as method/constructor argument or set on field
    or property of .NET object.

    NDelegate object should be initialized with the name of the type of delegate it will represent.
    After initialization it can be passed to .NET side and the “delegateCalled” method will be
    invoked every time the delegate is called on .NET side. All arguments passed from .NET to delegate
    during invocation will be routed to “delegateCalled” method and provided in Object array.

    Arguments passed in Object array to “delegateCalled” method can be any JAVA primitive types
    (integer, string, float..) or instances of NObject class for reference-type arguments.

    Usage

    Use this object to pass the JAVA logic as handler for .NET delegate.
    Code below represents the sample of passing JAVA code to .NET method delegate argument.

    .NET code method signature is: void Execute(VoidCallback callBack);

    To invoke that method from JAVA use this code:

     
     NObject sample = Javonet.New("ClassWithDel");
    
     sample.invoke("Execute",new NDelegate("VoidCallback") {
             @Override
            public void delegateCalled(Object[] arguments) {
                    System.out.println("Delegate Called on JAVA Side arg1:"+arguments[0]);
            }
     });
     
     

    You can also pass NDelegate as argument to constructor for example while initializing System.Thread.Thread object.

     
     NObject thread = Javonet.New("Thread", new NDelegate("ThreadStart") {
             @Override
            public void delegateCalled(Object[] arguments) {
                    //Your JAVA code to be invoked when .NET thread is started
            }
     });
     thread.invoke("Start");
     
     
    Since:
    1.4hf14
    Version:
    1.4hf14


    • Constructor Summary

      Constructors 
      Constructor and Description
      NDelegateWithResult(NType delegateType)

      Creates new instance of delegate with result handler using delegate type provided as NType.
      NDelegateWithResult(java.lang.String delegateType)

      Creates new instance of delegate with result handler using delegate type provided as string.



    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      static java.lang.Object CallDelegate(java.lang.String objectId,
      java.lang.Object[] arguments)

      Internal method used to route the delegate call.
      java.lang.Object delegateCalled(java.lang.Object[] arguments)

      Method called when .NET code invokes delegate on which this instance of NDelegate
      was assigned.
      java.lang.String getDelegateType()

      Returns the type of delegate used to initialize this delegate handler.
      NType getDelegateTypeObj()

      Returns the type of delegate used to initialize this delegate handler.
      java.lang.String getOid()

      Returns unique identifier of delegate instance.


      • Methods inherited from class java.lang.Object

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



    • Constructor Detail



      • NDelegateWithResult

        public NDelegateWithResult(NType delegateType)
        Creates new instance of delegate with result handler using delegate type provided as NType.
        Parameters:
        delegateType – delegate type provided as NType object.



      • NDelegateWithResult

        public NDelegateWithResult(java.lang.String delegateType)
        Creates new instance of delegate with result handler using delegate type provided as string.
        Parameters:
        delegateType – delegate type name with or without namespace.



    • Method Detail



      • CallDelegate

        public static java.lang.Object CallDelegate(java.lang.String objectId,
                                                    java.lang.Object[] arguments)
        Internal method used to route the delegate call. Do not use this method from your code.
        Parameters:
        objectId – unique identifier of NDelegate instance
        arguments – arguments passed during the invocation of delegate on .NET side.
        Returns:
        delegate invocation result



      • delegateCalled

        public java.lang.Object delegateCalled(java.lang.Object[] arguments)
        Method called when .NET code invokes delegate on which this instance of NDelegate
        was assigned.

        If you pass this instance of NDelegate as argument to .NET method expecting delegate
        once this delegate will be invoked the call will be routed to this method.

        Override this method method to execute your custom logic when delegate is invoked
        and process the arguments passed to delegate from .NET side.

        Parameters:
        arguments – arguments passed to delegate on .NET side when delegate was invoked. Arguments are stored in Object array in the same sequence as they were passed to delegate. These can be any JAVA primitive types (integer, string, float..) or instances of NObject class for reference-type arguments.
        Returns:
        return the result that should be passed to .NET side as delegate call result



      • getDelegateType

        public java.lang.String getDelegateType()
        Returns the type of delegate used to initialize this delegate handler.
        This class can be set on field or passed as argument to method or constructor
        expecting type of delegate returned by this method.

        For example the NDelegate class initialized with type “ThreadStart” can be passed
        as argument to .NET “Thread” object.

          
         NObject thread = Javonet.New("Thread", new NDelegate("ThreadStart") {
         	{@literal @}Override
         	public void delegateCalled(Object[] arguments) {
         		//Your JAVA code that will be execute when .NET Thread is started
         	}
         });
         
        Returns:
        The name of delegate type used to initialize this instance of NDelegate



      • getDelegateTypeObj

        public NType getDelegateTypeObj()
        Returns the type of delegate used to initialize this delegate handler.
        Returns:
        NType object representing the .NET type of delegate associated with this NDelegate instance.
        Since:
        1.5



      • getOid

        public java.lang.String getOid()
        Returns unique identifier of delegate instance. This identifier is used to bind
        delegate method implementation to callbacks raised from .NET side.
        Returns:
        Unique identifier of delegate instance.