/// <summary>
        /// <code>writeObject</code> for custom serialization.
        ///
        /// <para>This method writes this object's serialized form for
        /// this class as follows:
        ///
        /// </para>
        /// <para>The <code>writeObject</code> method is invoked on
        /// <code>out</code> passing this object's unique identifier
        /// (a <seealso cref="java.rmi.server.UID UID"/> instance) as the argument.
        ///
        /// </para>
        /// <para>Next, the {@link
        /// java.rmi.server.RemoteRef#getRefClass(java.io.ObjectOutput)
        /// getRefClass} method is invoked on the activator's
        /// <code>RemoteRef</code> instance to obtain its external ref
        /// type name.  Next, the <code>writeUTF</code> method is
        /// invoked on <code>out</code> with the value returned by
        /// <code>getRefClass</code>, and then the
        /// <code>writeExternal</code> method is invoked on the
        /// <code>RemoteRef</code> instance passing <code>out</code>
        /// as the argument.
        ///
        /// @serialData The serialized data for this class comprises a
        /// <code>java.rmi.server.UID</code> (written with
        /// <code>ObjectOutput.writeObject</code>) followed by the
        /// external ref type name of the activator's
        /// <code>RemoteRef</code> instance (a string written with
        /// <code>ObjectOutput.writeUTF</code>), followed by the
        /// external form of the <code>RemoteRef</code> instance as
        /// written by its <code>writeExternal</code> method.
        ///
        /// </para>
        /// <para>The external ref type name of the
        /// <code>RemoteRef</Code> instance is
        /// determined using the definitions of external ref type
        /// names specified in the {@link java.rmi.server.RemoteObject
        /// RemoteObject} <code>writeObject</code> method
        /// <b>serialData</b> specification.  Similarly, the data
        /// written by the <code>writeExternal</code> method and read
        /// by the <code>readExternal</code> method of
        /// <code>RemoteRef</code> implementation classes
        /// corresponding to each of the defined external ref type
        /// names is specified in the {@link
        /// java.rmi.server.RemoteObject RemoteObject}
        /// <code>writeObject</code> method <b>serialData</b>
        /// specification.
        ///
        /// </para>
        /// </summary>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException, ClassNotFoundException
        private void WriteObject(ObjectOutputStream @out)
        {
            @out.WriteObject(Uid);

            RemoteRef @ref;

            if (Activator is RemoteObject)
            {
                @ref = ((RemoteObject)Activator).Ref;
            }
            else if (Proxy.isProxyClass(Activator.GetType()))
            {
                InvocationHandler handler = Proxy.getInvocationHandler(Activator);
                if (!(handler is RemoteObjectInvocationHandler))
                {
                    throw new InvalidObjectException("unexpected invocation handler");
                }
                @ref = ((RemoteObjectInvocationHandler)handler).Ref;
            }
            else
            {
                throw new InvalidObjectException("unexpected activator type");
            }
            @out.WriteUTF(@ref.GetRefClass(@out));
            @ref.WriteExternal(@out);
        }