c# - Private Constructor in SqlConnection class Takes Parameter SqlConnection class -


i inspection sqlconnection .net reflector.

i noticed there private constructor, interestingly takes parameter sqlconnection class.

the main question wonder * why sqlconnection takes sqlconnection class? * , use of private constructors?

private sqlconnection(sqlconnection connection) {     this._reconnectlock = new object();     this._originalconnectionid = guid.empty;     this.objectid = interlocked.increment(ref _objecttypecount);     gc.suppressfinalize(this);     this.copyfrom(connection);     this._connectionstring = connection._connectionstring;     if (connection._credential != null)     {         securestring password = connection._credential.password.copy();         password.makereadonly();         this._credential = new sqlcredential(connection._credential.userid, password);     } }  public sqlconnection() {     this._reconnectlock = new object();     this._originalconnectionid = guid.empty;     this.objectid = interlocked.increment(ref _objecttypecount);     gc.suppressfinalize(this);     this._innerconnection = dbconnectionclosedneveropened.singletoninstance; } 

update: guide of hvd's answer found 1 usage:

object icloneable.clone() {   sqlconnection sqlconnection = new sqlconnection(this);   bid.trace("<sc.sqlconnection.clone|api> %d#, clone=%d#\n", this.objectid, sqlconnection.objectid);   return (object) sqlconnection; } 

you don't need use reflector that, source code freely available online.

what's more, freely available online version of source code shows point of constructor is: it's used in sqlconnection's implementation of icloneable.clone. new connection's properties supposed match old connection's properties, , easiest way copying properties. class designers decided shouldn't attempt clone sqlconnection creating new sqlconnection, clearly, some new connection object needs created, , other public constructors aren't match implementation of clone. so, new constructor created, , access restricted not (mis)used others.


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -