Skip to content

Commit 26da64f

Browse files
committed
Cross Migration Added & bug Fixes
1 parent 30a286b commit 26da64f

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

Factory/QueryGeneratorFactory.cs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using DbSyncKit.DB.Enum;
2+
using DbSyncKit.DB.Interface;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
9+
namespace DbSyncKit.DB.Factory
10+
{
11+
/// <summary>
12+
/// Factory class for creating instances of <see cref="IQueryGenerator"/> based on the specified <see cref="DatabaseProvider"/>.
13+
/// </summary>
14+
public static class QueryGeneratorFactory
15+
{
16+
/// <summary>
17+
/// Gets an instance of <see cref="IQueryGenerator"/> based on the specified <paramref name="provider"/>.
18+
/// </summary>
19+
/// <param name="provider">The database provider for which to get the query generator.</param>
20+
/// <returns>An instance of <see cref="IQueryGenerator"/> for the specified database provider.</returns>
21+
/// <exception cref="ArgumentException">Thrown if the <paramref name="provider"/> is not supported.</exception>
22+
/// <exception cref="TypeLoadException">Thrown if the type for the specified database provider is not found.</exception>
23+
public static IQueryGenerator GetQueryGenerator(DatabaseProvider provider)
24+
{
25+
string namespacePrefix; // Adjust this to your actual namespace
26+
string className = "QueryGenerator";
27+
28+
switch (provider)
29+
{
30+
case DatabaseProvider.MSSQL:
31+
namespacePrefix = "DbSyncKit.MSSQL";
32+
break;
33+
case DatabaseProvider.MySQL:
34+
namespacePrefix = "DbSyncKit.MySQL";
35+
break;
36+
// Add cases for other providers as needed
37+
default:
38+
throw new ArgumentException("Unsupported database provider", nameof(provider));
39+
}
40+
41+
string fullClassName = $"{namespacePrefix}.{className}, {namespacePrefix}";
42+
43+
// Use reflection to create an instance of the specified class
44+
Type queryGeneratorType = Type.GetType(fullClassName)!;
45+
if (queryGeneratorType == null)
46+
throw new TypeLoadException($"Type {fullClassName} not found.");
47+
48+
return (IQueryGenerator)Activator.CreateInstance(queryGeneratorType)!;
49+
}
50+
}
51+
52+
}

0 commit comments

Comments
 (0)