Выделить абстрактный класс - C#
Формулировка задачи:
Здравствуйте, подскажите пожалуйста как можно "выделить" абстрактный класс из этих классов:
public class NoProblemCommand: Command
{
public override string Name => Problems.ProblemTypes.noProblem.ToString();
public override async void Execute(Message message, TelegramBotClient client)
{
if(!message.Text.Contains(this.Name))
return;
await client.SendTextMessageAsync(message.From.Id, Problems.GetProblemResult(Problems.ProblemTypes.noProblem));
}
} public class PcProblemCommand: Command
{
public override string Name => Problems.ProblemTypes.pc.ToString();
public override async void Execute(Message message, TelegramBotClient client)
{
if (!message.Text.Contains(this.Name))
return;
await client.SendTextMessageAsync(message.From.Id, Problems.GetProblemResult(Problems.ProblemTypes.pc));
}
}
Вот мой:
public abstract class Command
{
public abstract string Name { get; }
public abstract void Execute(Message message, TelegramBotClient client);
public bool Contains(string command)
{
return command.Contains(this.Name)
&& command.Contains(CustomConfigRetriever.GetConfig<TelegramBotConfigurationSection>().Name);
}
}
Хотелось бы добавить в класс Command привязку к Problems.ProblemTypes
Потому что таких классов планируется много
Решение задачи: «Выделить абстрактный класс»
textual
Листинг программы
public class Command
{
public ProblemTypes ProblemType { get; }
public virtual string Name {get { return ProblemType.ToString(); } }
public virtual async void Execute(Message message, TelegramBotClient client)
{
if (!message.Text.Contains(this.Name))
return;
await client.SendTextMessageAsync(message.From.Id, Problems.GetProblemResult(ProblemType));
}
public bool Contains(string command)
{
return command.Contains(this.Name)
&& command.Contains(CustomConfigRetriever.GetConfig<TelegramBotConfigurationSection>().Name);
}
}