@@ -9,14 +9,16 @@ namespace LinqToDB.LINQPad;
99/// Implements Linq To DB connection settings provider, which use data from JSON config.
1010/// Used as settings source for static data context.
1111/// </summary>
12- internal sealed class AppConfig : ILinqToDBSettings
12+ internal sealed class AppConfig ( IConnectionStringSettings [ ] connectionStrings ) : ILinqToDBSettings
1313{
14+ #pragma warning disable CA1859 // change return type
1415 public static ILinqToDBSettings LoadJson ( string configPath )
16+ #pragma warning restore CA1859 // change return type
1517 {
1618 var config = JsonSerializer . Deserialize < JsonConfig > ( File . ReadAllText ( configPath ) ) ;
1719
1820 if ( config ? . ConnectionStrings ? . Count is null or 0 )
19- return new AppConfig ( Array . Empty < IConnectionStringSettings > ( ) ) ;
21+ return new AppConfig ( [ ] ) ;
2022
2123 var connections = new Dictionary < string , ConnectionStringSettings > ( StringComparer . InvariantCultureIgnoreCase ) ;
2224 foreach ( var cn in config . ConnectionStrings )
@@ -40,15 +42,18 @@ public static ILinqToDBSettings LoadJson(string configPath)
4042 return new AppConfig ( connections . Values . ToArray ( ) ) ;
4143 }
4244
45+ #pragma warning disable CA1859 // change return type
4346 public static ILinqToDBSettings LoadAppConfig ( string configPath )
47+ #pragma warning restore CA1859 // change return type
4448 {
4549 var xml = new XmlDocument ( ) { XmlResolver = null } ;
46- xml . Load ( XmlReader . Create ( new StringReader ( File . ReadAllText ( configPath ) ) , new XmlReaderSettings ( ) { XmlResolver = null } ) ) ;
50+ using var reader = XmlReader . Create ( new StringReader ( File . ReadAllText ( configPath ) ) , new XmlReaderSettings ( ) { XmlResolver = null } ) ;
51+ xml . Load ( reader ) ;
4752
4853 var connections = xml . SelectNodes ( "/configuration/connectionStrings/add" ) ;
4954
5055 if ( connections ? . Count is null or 0 )
51- return new AppConfig ( Array . Empty < IConnectionStringSettings > ( ) ) ;
56+ return new AppConfig ( [ ] ) ;
5257
5358 var settings = new List < ConnectionStringSettings > ( ) ;
5459
@@ -65,36 +70,22 @@ public static ILinqToDBSettings LoadAppConfig(string configPath)
6570 return new AppConfig ( settings . ToArray ( ) ) ;
6671 }
6772
68- private readonly IConnectionStringSettings [ ] _connectionStrings ;
69-
70- public AppConfig ( IConnectionStringSettings [ ] connectionStrings )
71- {
72- _connectionStrings = connectionStrings ;
73- }
74-
75- IEnumerable < IDataProviderSettings > ILinqToDBSettings . DataProviders => Array . Empty < IDataProviderSettings > ( ) ;
73+ IEnumerable < IDataProviderSettings > ILinqToDBSettings . DataProviders => [ ] ;
7674 string ? ILinqToDBSettings . DefaultConfiguration => null ;
7775 string ? ILinqToDBSettings . DefaultDataProvider => null ;
78- IEnumerable < IConnectionStringSettings > ILinqToDBSettings . ConnectionStrings => _connectionStrings ;
76+ IEnumerable < IConnectionStringSettings > ILinqToDBSettings . ConnectionStrings => connectionStrings ;
7977
78+ #pragma warning disable CA1812 // Remove unused type
8079 private sealed class JsonConfig
80+ #pragma warning restore CA1812 // Remove unused type
8181 {
8282 public IDictionary < string , string > ? ConnectionStrings { get ; set ; }
8383 }
8484
85- private sealed class ConnectionStringSettings : IConnectionStringSettings
85+ private sealed class ConnectionStringSettings ( string name , string connectionString ) : IConnectionStringSettings
8686 {
87- private readonly string _name ;
88- private readonly string _connectionString ;
89-
90- public ConnectionStringSettings ( string name , string connectionString )
91- {
92- _name = name ;
93- _connectionString = connectionString ;
94- }
95-
96- string IConnectionStringSettings . ConnectionString => _connectionString ;
97- string IConnectionStringSettings . Name => _name ;
87+ string IConnectionStringSettings . ConnectionString => connectionString ;
88+ string IConnectionStringSettings . Name => name ;
9889 bool IConnectionStringSettings . IsGlobal => false ;
9990
10091 public string ? ProviderName { get ; set ; }
0 commit comments