@@ -80,14 +80,19 @@ public SqlTargetDatabase(object obj)
8080 /// <paramref name="connectionString"/> is <see langword="null"/>.
8181 /// </exception>
8282 public SqlTargetDatabase (
83- string connectionString ,
84- NetworkCredential ? credential = null ,
85- string ? serverDisplayName = null ,
86- string ? databaseDisplayName = null )
83+ string connectionString ,
84+ PSCredential ? credential = null ,
85+ string ? serverDisplayName = null ,
86+ string ? databaseDisplayName = null )
8787 {
8888 // Null checked by inner Target constructor
8989
90- _target = new ( connectionString , credential , serverDisplayName , databaseDisplayName ) ;
90+ _target = new (
91+ connectionString ,
92+ credential ? . GetNetworkCredential ( ) ,
93+ serverDisplayName ,
94+ databaseDisplayName
95+ ) ;
9196
9297 Credential = credential ;
9398 }
@@ -107,7 +112,7 @@ public SqlTargetDatabase(
107112 /// if a credential is required and not present in the
108113 /// <see cref="ConnectionString"/>.
109114 /// </summary>
110- public NetworkCredential ? Credential { get ; }
115+ public PSCredential ? Credential { get ; }
111116
112117 /// <summary>
113118 /// Gets a display name for the database server. This name might be a
@@ -139,13 +144,16 @@ private static bool IsSqlContext(object obj, out Type type)
139144 && name . EndsWith ( "SqlContext" , StringComparison . Ordinal ) ;
140145 }
141146
142- private static ( E . Target , NetworkCredential ? ) InterpretSqlContext ( ObjectTypePair source )
147+ private static ( E . Target , PSCredential ? ) InterpretSqlContext ( ObjectTypePair source )
143148 {
144149 return TryGetConnectionString ( source , out var connectionString ) // string
145150 && TryGetCredential ( source , out var credential ) // NetworkCredential?
146151 && TryGetServerResourceName ( source , out var serverDisplayName ) // string?
147- ? ( new ( connectionString , credential , serverDisplayName ) , credential )
148- : throw new ArgumentException (
152+ ? (
153+ new ( connectionString , credential ? . GetNetworkCredential ( ) , serverDisplayName ) ,
154+ credential
155+ )
156+ : throw new ArgumentException (
149157 "The object does not conform to the expected API surface of PSql.SqlContext."
150158 ) ;
151159 }
@@ -189,7 +197,7 @@ const string
189197 return true ;
190198 }
191199
192- private static bool TryGetCredential ( ObjectTypePair source , out NetworkCredential ? value )
200+ private static bool TryGetCredential ( ObjectTypePair source , out PSCredential ? value )
193201 {
194202 const string PropertyName = "Credential" ;
195203
@@ -204,7 +212,7 @@ private static bool TryGetCredential(ObjectTypePair source, out NetworkCredentia
204212 if ( property . GetValue ( source . Object ) is not { } objectValue )
205213 return true ; // property value is null; normal when credential is not required
206214
207- if ( objectValue is not NetworkCredential typedValue )
215+ if ( objectValue is not PSCredential typedValue )
208216 return false ; // property value is of wrong type
209217
210218 value = typedValue ;
0 commit comments