Novell.Directory.Ldap.LdapConnection.Clone C# (CSharp) Method

Clone() public method

Returns a copy of the object with a private context, but sharing the network connection if there is one. The network connection remains open until all clones have disconnected or gone out of scope. Any connection opened after cloning is private to the object making the connection. The clone can issue requests and freely modify options and search constraints, and , without affecting the source object or other clones. If the clone disconnects or reconnects, it is completely dissociated from the source object and other clones. Reauthenticating in a clone, however, is a global operation which will affect the source object and all associated clones, because it applies to the single shared physical connection. Any request by an associated object after one has reauthenticated will carry the new identity.
public Clone ( ) : Object
return System.Object
        public System.Object Clone()
        {
            LdapConnection newClone;
            System.Object newObj;
            try
            {
                newObj = base.MemberwiseClone();
                newClone = (LdapConnection) newObj;
            }
            catch (System.Exception ce)
            {
                throw new System.SystemException("Internal error, cannot create clone");
            }
            newClone.conn = conn; // same underlying connection

            //now just duplicate the defSearchCons and responseCtls
            if (defSearchCons != null)
            {
                newClone.defSearchCons = (LdapSearchConstraints) defSearchCons.Clone();
            }
            else
            {
                newClone.defSearchCons = null;
            }
            if (responseCtls != null)
            {
                newClone.responseCtls = new LdapControl[responseCtls.Length];
                for (int i = 0; i < responseCtls.Length; i++)
                {
                    newClone.responseCtls[i] = (LdapControl) responseCtls[i].Clone();
                }
            }
            else
            {
                newClone.responseCtls = null;
            }
            conn.incrCloneCount(); // Increment the count of clones
            return newObj;
        }