Код: Выделить всё
public class Config {
static Dictionary dictionary = new Dictionary() {
{ 0, new Handler() },
{ 1, new Handler() },
{ 2, new SecondHandler() }
};
public static IHandler Get(int id) { return dictionary[id].handler; }
}
interface IHandler {
void Execute(SqlConnection sqlConnection, SqlTransaction transaction, List data);
}
class Handler : IHandler {
public void Execute(SqlConnection sqlConnection, SqlTransaction transaction, List data) {
...
}
}
interface IHandlerSecond {
void Execute(SqlConnection sqlConnection, IConnection connection, SqlTransaction transaction, List data);
}
class SecondHandler : Handler, IHandlerSecond {
public void Execute(SqlConnection sqlConnection, IConnection connection, SqlTransaction transaction, List data) {
base.Execute(sqlConnection, connection, transaction);
...
}
}
void Main(IConnect connect) {
// Some code
var handler = Config.Get(num);
if(handler is IHandlerSecond) {
(handler as IHandlerSecond).Execute(connect, iconnection, transaction, data);
}
else if (handler is IHandler) {
(handler as IHandler).Execute(connect, transaction, data);
}
}
Код: Выделить всё
void Execute(SqlConnection sqlConnection, SqlTransaction transaction, List data);
Моей лучшей идеей было просто создать еще один интерфейс и проверьте тип в основной функции, но это выглядит немного грязно
Подробнее здесь: https://stackoverflow.com/questions/784 ... -signature