-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hook up ProviderRepository to FactoryTools
- Loading branch information
Martin Willey
committed
Mar 10, 2016
1 parent
e12586a
commit ace54f7
Showing
3 changed files
with
142 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,49 @@ | ||
using System; | ||
using System.Data; | ||
using System.Data.Common; | ||
|
||
namespace DatabaseSchemaReader.Utilities | ||
{ | ||
/// <summary> | ||
/// Tools to help with DbProviderFactory | ||
/// </summary> | ||
public static class FactoryTools | ||
{ | ||
private static DbProviderFactory _manualProviderFactory; | ||
|
||
/// <summary> | ||
/// Finds the factory. | ||
/// </summary> | ||
/// <param name="providerName">Name of the provider.</param> | ||
/// <returns></returns> | ||
public static DbProviderFactory GetFactory(string providerName) | ||
{ | ||
//a simple static manual override. | ||
if (_manualProviderFactory != null) return _manualProviderFactory; | ||
return DbProviderFactories.GetFactory(providerName); | ||
} | ||
|
||
|
||
/// <summary> | ||
/// Adds an existing factory. Call this before creating the DatabaseReader or SchemaReader. Use with care! | ||
/// </summary> | ||
/// <param name="factory">The factory.</param> | ||
/// <exception cref="System.ArgumentNullException">schemaReader</exception> | ||
public static void AddFactory(DbProviderFactory factory) | ||
{ | ||
if (factory == null) throw new ArgumentNullException("factory"); | ||
_manualProviderFactory = factory; | ||
} | ||
|
||
|
||
/// <summary> | ||
/// List of all the valid Providers. Use the ProviderInvariantName to fill ProviderName property | ||
/// </summary> | ||
/// <returns></returns> | ||
public static DataTable Providers() | ||
{ | ||
return DbProviderFactories.GetFactoryClasses(); | ||
} | ||
} | ||
} | ||
using System; | ||
using System.Data; | ||
using System.Data.Common; | ||
|
||
namespace DatabaseSchemaReader.Utilities | ||
{ | ||
/// <summary> | ||
/// Tools to help with DbProviderFactory | ||
/// </summary> | ||
public static class FactoryTools | ||
{ | ||
/// <summary> | ||
/// Finds the factory. You can override with <see cref="P:SingleProviderFactory"/> (simple) or <see cref="P:ProviderRespository"/> | ||
/// </summary> | ||
/// <param name="providerName">Name of the provider.</param> | ||
/// <returns></returns> | ||
public static DbProviderFactory GetFactory(string providerName) | ||
{ | ||
//a simple static manual override. | ||
if (SingleProviderFactory != null) return SingleProviderFactory; | ||
if (ProviderRepository != null) return ProviderRepository.GetFactory(providerName); | ||
return DbProviderFactories.GetFactory(providerName); | ||
} | ||
|
||
|
||
/// <summary> | ||
/// Adds an existing factory. Call this before creating the DatabaseReader or SchemaReader. Use with care! | ||
/// </summary> | ||
public static DbProviderFactory SingleProviderFactory { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets a provider repository. | ||
/// </summary> | ||
/// <value> | ||
/// The provider repository. | ||
/// </value> | ||
public static DbProviderFactoryRepository ProviderRepository { get; set; } | ||
|
||
|
||
/// <summary> | ||
/// List of all the valid Providers. Use the ProviderInvariantName to fill ProviderName property | ||
/// </summary> | ||
/// <returns></returns> | ||
public static DataTable Providers() | ||
{ | ||
return DbProviderFactories.GetFactoryClasses(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters