TelegramBotFramework/TelegramBotBase/Base/SimpleStartFormFactory.cs
Victor bab69b593e Migrate start form creation from generics to a factory method pattern
Add SimpleStartFormFactory.cs that encloses old behavior
2021-10-11 14:23:27 +03:00

25 lines
730 B
C#

using System;
using Telegram.Bot.Exceptions;
using TelegramBotBase.Form;
using TelegramBotBase.Interfaces;
namespace TelegramBotBase.Base
{
public class SimpleStartFormFactory : IStartFormFactory
{
private readonly Type _startFormClass;
public SimpleStartFormFactory(Type startFormClass)
{
if (!typeof(FormBase).IsAssignableFrom(startFormClass))
throw new ArgumentException("startFormClass argument must be a FormBase type");
_startFormClass = startFormClass;
}
public FormBase CreateForm()
{
return _startFormClass.GetConstructor(new Type[] { })?.Invoke(new object[] { }) as FormBase;
}
}
}