com.javonet.api.keywords

Class NOut

  • java.lang.Object
    • com.javonet.api.keywords.NOut
  • Direct Known Subclasses:
    NRef

    public class NOut
    extends java.lang.Object
    A class that represents .NET out keyword @see http://msdn.microsoft.com/en-us/library/ee332485.aspx

    The out keyword causes an argument to be passed by reference, not by value. This is like ref see NRef keyword, except that ref requires that the variable
    be initialized before it is passed.

    To use a out parameter, both the method definition and the calling method must explicitly use the out keyword, as shown in the following example:

    .NET class with method expecting argument passed by reference

      
     class OutExample
     {
     	public void Method(out int i)
     	{
     		i = 44;
     	}
     } 
     
     

    Sample usage on JAVA side

    To call this method from JAVA using Javonet method argument must be explicitly wrapped with NOut class.
    Both primitive types or primitive types arrays and other .NET objects (NObject) or NObject arrays might be passed by reference.
    Because Java does not support passing by reference, primitive types must be wrapped in “AtomicReference<?>” class.

      
     NObject outEx = Javonet.New("OutExample");
     //Wrap Java integer in AtomicReference to allow passing by reference
     AtomicReference{@literal <}Integer{@literal >} myInt = new AtomicReference{@literal <}Integer{@literal >}(); //We do not provide initial value myInt value equals null
     		
     outEx.invoke("Method",new NOut(myInt));
     
     System.out.println(myInt.get());
     //Output will display number "44" because int passed by reference has been initialized with value "44" within the method body.
     
     

    You can use passing by reference for any JAVA primitive type (String, Integer, Float, Boolean, etc…) and arrays of these objects as well as NObject variables and arrays of NObject.

    Passing arguments with out keyword is supported both for instance and static methods.

    Usage Sample

      
     String strNumber = "4";
     AtomicReference{@literal <}Integer{@literal >} myInt=new AtomicReference{@literal <}Integer{@literal >}();
    
     //NOut constructor with argument type is used because myInt has NULL value. Without specifying explicitly 
     //argument type .NET would not be able to locate proper method to execute.
     if (Javonet.getType("Int32").invoke("TryParse",strNumber,new NOut(myInt,"System.Int32")))
     {
     	System.out.println(myInt.get());
     }
     
     

    .NET equivalent:

      
     String strNumber = "4";
     Integer myInt = null;
    
     if (Int32.TryParse(strNumber,out myInt)
     {
     	Console.Out.WriteLine(myInt);
     }
     
     
    Version:
    1.2


    • Constructor Summary

      Constructors 
      Constructor and Description
      NOut(java.util.concurrent.atomic.AtomicReference<?> argument)

      Constructor used to wrap primitive type argument with “out” keyword.
      NOut(java.util.concurrent.atomic.AtomicReference<?> argument,
      java.lang.String dotNetType)

      Constructor used to wrap primitive type argument with “out” keyword.
      NOut(NEnum argument)

      Since 1.4hf14

      Constructor used to wrap NObject argument with “out” keyword.

      NOut(NObject argument)

      Constructor used to wrap NObject argument with “out” keyword.
      NOut(NObject[] argument)

      Constructor used to wrap NObject array argument with “out” keyword.
      NOut(NObject[] argument,
      java.lang.String dotNetType)

      Constructor used to wrap NObject array argument with “out” keyword.
      NOut(NObject argument,
      java.lang.String dotNetType)

      Constructor used to wrap NObject argument with “out” keyword.



    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      java.lang.Object getArgument()

      Internal method to retrieve argument value.
      java.lang.String getDotNetType()

      Internal method to retrieve .NET type of NULL argument
      void setArgument(java.lang.Object argument)

      Internal method to set argument value.


      • Methods inherited from class java.lang.Object

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



    • Constructor Detail



      • NOut

        public NOut(java.util.concurrent.atomic.AtomicReference<?> argument)
             throws JavonetException
        Constructor used to wrap primitive type argument with “out” keyword.
        Parameters:
        argument – AtomicReference instance that wraps argument variable for call with “out” keyword.
        Throws:
        JavonetException – if wrong argument is passed



      • NOut

        public NOut(java.util.concurrent.atomic.AtomicReference<?> argument,
                    java.lang.String dotNetType)
        Constructor used to wrap primitive type argument with “out” keyword.

        This constructor is dedicated for case when argument variable is not yet initialized and AtomicReference<?> contains null value.

        Parameters:
        argument – AtomicReference instance that wraps argument variable for call with “out” keyword.
        dotNetType – type of .NET class expected in the argument where null NOut will be passed (required to properly discover correct method overload)



      • NOut

        public NOut(NEnum argument)
             throws com.javonet.internal.commons.lang.NullArgumentException
        Since 1.4hf14

        Constructor used to wrap NObject argument with “out” keyword.

        Parameters:
        argument – Argument to be passed to method with “out” keyword.
        Throws:
        com.javonet.internal.commons.lang.NullArgumentException – if wrong argument is passed



      • NOut

        public NOut(NObject argument)
             throws JavonetException
        Constructor used to wrap NObject argument with “out” keyword.
        Parameters:
        argument – Argument to be passed to method with “out” keyword.
        Throws:
        JavonetException – if wrong argument is passed



      • NOut

        public NOut(NObject[] argument)
             throws JavonetException
        Constructor used to wrap NObject array argument with “out” keyword.
        Parameters:
        argument – Argument to be passed to method with “out” keyword.
        Throws:
        JavonetException – if wrong argument is passed



      • NOut

        public NOut(NObject[] argument,
                    java.lang.String dotNetType)
        Constructor used to wrap NObject array argument with “out” keyword.

        This constructor is dedicated for case when NObject array variable is not yet initialized and contains null value.

        Parameters:
        argument – Argument to be passed to method with “out” keyword.
        dotNetType – type of .NET class expected in the argument where null NOut will be passed (required to properly discover correct method overload)



      • NOut

        public NOut(NObject argument,
                    java.lang.String dotNetType)
        Constructor used to wrap NObject argument with “out” keyword.

        This constructor is dedicated for case when NObject variable is not yet initialized and contains null value.

        Provide the name of the .NET class of which null value will be passed as “out” argument to target method.

        Parameters:
        argument – Argument to be passed to method with “out” keyword.
        dotNetType – type of .NET class expected in the argument where null NOut will be passed (required to properly discover correct method overload)



    • Method Detail



      • getArgument

        public java.lang.Object getArgument()
        Internal method to retrieve argument value.
        Returns:
        Argument value



      • getDotNetType

        public java.lang.String getDotNetType()
        Internal method to retrieve .NET type of NULL argument
        Returns:
        .NET type of NULL argument



      • setArgument

        public void setArgument(java.lang.Object argument)
        Internal method to set argument value.
        Parameters:
        argument – New argument value