From 57f2139dba81593931faecb4dc7d0564148ee1e8 Mon Sep 17 00:00:00 2001 From: Florian Zevedei Date: Fri, 2 Feb 2024 13:42:00 +0100 Subject: [PATCH] Extracting static extension methods into separate file --- .../Actions/EndsWithAction.Extensions.cs | 13 ++++ .../ActionManager/Actions/EndsWithAction.cs | 8 --- .../Actions/GuidAction.Extensions.cs | 13 ++++ .../ActionManager/Actions/GuidAction.cs | 9 --- .../Actions/StartWithAction.Extensions.cs | 13 ++++ .../ActionManager/Actions/StartWithAction.cs | 8 --- .../EndsWithNavigation.Extensions.cs | 63 +++++++++++++++++++ .../Navigation/EndsWithNavigation.cs | 60 +----------------- .../Navigation/GuidNavigation.Extensions.cs | 63 +++++++++++++++++++ .../Navigation/GuidNavigation.cs | 61 +----------------- .../StartWithNavigation.Extensions.cs | 63 +++++++++++++++++++ .../Navigation/StartWithNavigation.cs | 60 +----------------- 12 files changed, 231 insertions(+), 203 deletions(-) create mode 100644 Experiments/ExternalActionManager/TelegramBotBase.Experiments/ActionManager/Actions/EndsWithAction.Extensions.cs create mode 100644 Experiments/ExternalActionManager/TelegramBotBase.Experiments/ActionManager/Actions/GuidAction.Extensions.cs create mode 100644 Experiments/ExternalActionManager/TelegramBotBase.Experiments/ActionManager/Actions/StartWithAction.Extensions.cs create mode 100644 Experiments/ExternalActionManager/TelegramBotBase.Experiments/ActionManager/Navigation/EndsWithNavigation.Extensions.cs create mode 100644 Experiments/ExternalActionManager/TelegramBotBase.Experiments/ActionManager/Navigation/GuidNavigation.Extensions.cs create mode 100644 Experiments/ExternalActionManager/TelegramBotBase.Experiments/ActionManager/Navigation/StartWithNavigation.Extensions.cs diff --git a/Experiments/ExternalActionManager/TelegramBotBase.Experiments/ActionManager/Actions/EndsWithAction.Extensions.cs b/Experiments/ExternalActionManager/TelegramBotBase.Experiments/ActionManager/Actions/EndsWithAction.Extensions.cs new file mode 100644 index 0000000..4153b84 --- /dev/null +++ b/Experiments/ExternalActionManager/TelegramBotBase.Experiments/ActionManager/Actions/EndsWithAction.Extensions.cs @@ -0,0 +1,13 @@ +using TelegramBotBase.Base; + +namespace TelegramBotBase.Experiments.ActionManager.Actions +{ + public static class EndsWithAction_Extensions + { + public static void AddEndsWithAction(this ExternalActionManager manager, string value, Func action) + { + manager.Add(new EndsWithAction(value, action)); + } + } + +} diff --git a/Experiments/ExternalActionManager/TelegramBotBase.Experiments/ActionManager/Actions/EndsWithAction.cs b/Experiments/ExternalActionManager/TelegramBotBase.Experiments/ActionManager/Actions/EndsWithAction.cs index 1494c7e..8fb98d7 100644 --- a/Experiments/ExternalActionManager/TelegramBotBase.Experiments/ActionManager/Actions/EndsWithAction.cs +++ b/Experiments/ExternalActionManager/TelegramBotBase.Experiments/ActionManager/Actions/EndsWithAction.cs @@ -26,12 +26,4 @@ namespace TelegramBotBase.Experiments.ActionManager.Actions } - public static class EndsWithAction_Extensions - { - public static void AddEndsWithAction(this ExternalActionManager manager, string value, Func action) - { - manager.Add(new EndsWithAction(value, action)); - } - } - } diff --git a/Experiments/ExternalActionManager/TelegramBotBase.Experiments/ActionManager/Actions/GuidAction.Extensions.cs b/Experiments/ExternalActionManager/TelegramBotBase.Experiments/ActionManager/Actions/GuidAction.Extensions.cs new file mode 100644 index 0000000..3f7f2b7 --- /dev/null +++ b/Experiments/ExternalActionManager/TelegramBotBase.Experiments/ActionManager/Actions/GuidAction.Extensions.cs @@ -0,0 +1,13 @@ +using TelegramBotBase.Base; + +namespace TelegramBotBase.Experiments.ActionManager.Actions +{ + public static class GuidAction_Extensions + { + + public static void AddGuidAction(this ExternalActionManager manager, string method, Func action) + { + manager.Add(new GuidAction(method, action)); + } + } +} diff --git a/Experiments/ExternalActionManager/TelegramBotBase.Experiments/ActionManager/Actions/GuidAction.cs b/Experiments/ExternalActionManager/TelegramBotBase.Experiments/ActionManager/Actions/GuidAction.cs index cd24c21..1cd3987 100644 --- a/Experiments/ExternalActionManager/TelegramBotBase.Experiments/ActionManager/Actions/GuidAction.cs +++ b/Experiments/ExternalActionManager/TelegramBotBase.Experiments/ActionManager/Actions/GuidAction.cs @@ -82,13 +82,4 @@ namespace TelegramBotBase.Experiments.ActionManager.Actions public static CallbackData GetCallback(string method, Guid guid) => new CallbackData(method, guid.ToString()); } - - public static class GuidAction_Extensions - { - - public static void AddGuidAction(this ExternalActionManager manager, string method, Func action) - { - manager.Add(new GuidAction(method, action)); - } - } } diff --git a/Experiments/ExternalActionManager/TelegramBotBase.Experiments/ActionManager/Actions/StartWithAction.Extensions.cs b/Experiments/ExternalActionManager/TelegramBotBase.Experiments/ActionManager/Actions/StartWithAction.Extensions.cs new file mode 100644 index 0000000..b126bff --- /dev/null +++ b/Experiments/ExternalActionManager/TelegramBotBase.Experiments/ActionManager/Actions/StartWithAction.Extensions.cs @@ -0,0 +1,13 @@ +using TelegramBotBase.Base; + +namespace TelegramBotBase.Experiments.ActionManager.Actions +{ + public static class StartWithAction_Extensions + { + public static void AddStartsWithAction(this ExternalActionManager manager, string value, Func action) + { + manager.Add(new StartWithAction(value, action)); + } + } + +} diff --git a/Experiments/ExternalActionManager/TelegramBotBase.Experiments/ActionManager/Actions/StartWithAction.cs b/Experiments/ExternalActionManager/TelegramBotBase.Experiments/ActionManager/Actions/StartWithAction.cs index 6b7415e..0cf888f 100644 --- a/Experiments/ExternalActionManager/TelegramBotBase.Experiments/ActionManager/Actions/StartWithAction.cs +++ b/Experiments/ExternalActionManager/TelegramBotBase.Experiments/ActionManager/Actions/StartWithAction.cs @@ -26,12 +26,4 @@ namespace TelegramBotBase.Experiments.ActionManager.Actions } - public static class StartWithAction_Extensions - { - public static void AddStartsWithAction(this ExternalActionManager manager, string value, Func action) - { - manager.Add(new StartWithAction(value, action)); - } - } - } diff --git a/Experiments/ExternalActionManager/TelegramBotBase.Experiments/ActionManager/Navigation/EndsWithNavigation.Extensions.cs b/Experiments/ExternalActionManager/TelegramBotBase.Experiments/ActionManager/Navigation/EndsWithNavigation.Extensions.cs new file mode 100644 index 0000000..2f79624 --- /dev/null +++ b/Experiments/ExternalActionManager/TelegramBotBase.Experiments/ActionManager/Navigation/EndsWithNavigation.Extensions.cs @@ -0,0 +1,63 @@ +using System.Linq.Expressions; +using TelegramBotBase.Form; + +namespace TelegramBotBase.Experiments.ActionManager.Navigation +{ + public static class EndsWithNavigation_Extensions + { + public static void AddEndsWithNavigation(this ExternalActionManager manager, string method, Expression> propertySelector) + where TForm : FormBase + { + if (!typeof(FormBase).IsAssignableFrom(typeof(TForm))) + { + throw new ArgumentException($"{nameof(TForm)} argument must be a {nameof(FormBase)} type"); + } + + var newValue = Expression.Parameter(propertySelector.Body.Type); + + var assign = Expression.Lambda>(Expression.Assign(propertySelector.Body, newValue), propertySelector.Parameters[0], newValue); + + var setter = assign.Compile(true); + + manager.Add(new EndsWithNavigation(method, setter)); + } + public static void AddEndsWithNavigation(this ExternalActionManager manager, string value, Action setProperty) + where TForm : FormBase + { + if (!typeof(FormBase).IsAssignableFrom(typeof(TForm))) + { + throw new ArgumentException($"{nameof(TForm)} argument must be a {nameof(FormBase)} type"); + } + + manager.Add(new EndsWithNavigation(value, setProperty)); + } + + public static void AddEndsWithNavigation(this ExternalActionManager manager, Type formType, string value, Expression> propertySelector) + { + if (!typeof(FormBase).IsAssignableFrom(formType)) + { + throw new ArgumentException($"{nameof(formType)} argument must be a {nameof(FormBase)} type"); + } + + var newValue = Expression.Parameter(propertySelector.Body.Type); + + var assign = Expression.Lambda>(Expression.Assign(propertySelector.Body, newValue), propertySelector.Parameters[0], newValue); + + var setter = assign.Compile(true); + + manager.Add(new EndsWithNavigation(formType, value, setter)); + } + + public static void AddEndsWithNavigation(this ExternalActionManager manager, Type formType, string value, Action setProperty) + { + if (!typeof(FormBase).IsAssignableFrom(formType)) + { + throw new ArgumentException($"{nameof(formType)} argument must be a {nameof(FormBase)} type"); + } + + manager.Add(new EndsWithNavigation(formType, value, setProperty)); + } + + } + +} diff --git a/Experiments/ExternalActionManager/TelegramBotBase.Experiments/ActionManager/Navigation/EndsWithNavigation.cs b/Experiments/ExternalActionManager/TelegramBotBase.Experiments/ActionManager/Navigation/EndsWithNavigation.cs index 486dd98..acd47ce 100644 --- a/Experiments/ExternalActionManager/TelegramBotBase.Experiments/ActionManager/Navigation/EndsWithNavigation.cs +++ b/Experiments/ExternalActionManager/TelegramBotBase.Experiments/ActionManager/Navigation/EndsWithNavigation.cs @@ -1,5 +1,4 @@ -using System.Linq.Expressions; -using TelegramBotBase.Base; +using TelegramBotBase.Base; using TelegramBotBase.Form; namespace TelegramBotBase.Experiments.ActionManager.Navigation @@ -75,61 +74,4 @@ namespace TelegramBotBase.Experiments.ActionManager.Navigation } - public static class EndsWithNavigation_Extensions - { - public static void AddEndsWithNavigation(this ExternalActionManager manager, string method, Expression> propertySelector) - where TForm : FormBase - { - if (!typeof(FormBase).IsAssignableFrom(typeof(TForm))) - { - throw new ArgumentException($"{nameof(TForm)} argument must be a {nameof(FormBase)} type"); - } - - var newValue = Expression.Parameter(propertySelector.Body.Type); - - var assign = Expression.Lambda>(Expression.Assign(propertySelector.Body, newValue), propertySelector.Parameters[0], newValue); - - var setter = assign.Compile(true); - - manager.Add(new EndsWithNavigation(method, setter)); - } - public static void AddEndsWithNavigation(this ExternalActionManager manager, string value, Action setProperty) - where TForm : FormBase - { - if (!typeof(FormBase).IsAssignableFrom(typeof(TForm))) - { - throw new ArgumentException($"{nameof(TForm)} argument must be a {nameof(FormBase)} type"); - } - - manager.Add(new EndsWithNavigation(value, setProperty)); - } - - public static void AddEndsWithNavigation(this ExternalActionManager manager, Type formType, string value, Expression> propertySelector) - { - if (!typeof(FormBase).IsAssignableFrom(formType)) - { - throw new ArgumentException($"{nameof(formType)} argument must be a {nameof(FormBase)} type"); - } - - var newValue = Expression.Parameter(propertySelector.Body.Type); - - var assign = Expression.Lambda>(Expression.Assign(propertySelector.Body, newValue), propertySelector.Parameters[0], newValue); - - var setter = assign.Compile(true); - - manager.Add(new EndsWithNavigation(formType, value, setter)); - } - - public static void AddEndsWithNavigation(this ExternalActionManager manager, Type formType, string value, Action setProperty) - { - if (!typeof(FormBase).IsAssignableFrom(formType)) - { - throw new ArgumentException($"{nameof(formType)} argument must be a {nameof(FormBase)} type"); - } - - manager.Add(new EndsWithNavigation(formType, value, setProperty)); - } - - } - } diff --git a/Experiments/ExternalActionManager/TelegramBotBase.Experiments/ActionManager/Navigation/GuidNavigation.Extensions.cs b/Experiments/ExternalActionManager/TelegramBotBase.Experiments/ActionManager/Navigation/GuidNavigation.Extensions.cs new file mode 100644 index 0000000..b6e03c7 --- /dev/null +++ b/Experiments/ExternalActionManager/TelegramBotBase.Experiments/ActionManager/Navigation/GuidNavigation.Extensions.cs @@ -0,0 +1,63 @@ +using System.Linq.Expressions; +using TelegramBotBase.Form; + +namespace TelegramBotBase.Experiments.ActionManager.Navigation +{ + public static class GuidNavigation_Extensions + { + + public static void AddGuidNavigation(this ExternalActionManager manager, string method, Expression> propertySelector) + where TForm : FormBase + { + if (!typeof(FormBase).IsAssignableFrom(typeof(TForm))) + { + throw new ArgumentException($"{nameof(TForm)} argument must be a {nameof(FormBase)} type"); + } + + var newValue = Expression.Parameter(propertySelector.Body.Type); + + var assign = Expression.Lambda>(Expression.Assign(propertySelector.Body, newValue), propertySelector.Parameters[0], newValue); + + var setter = assign.Compile(true); + + manager.Add(new GuidNavigation(method, setter)); + } + + public static void AddGuidNavigation(this ExternalActionManager manager, string method, Action action) + where TForm : FormBase + { + if (!typeof(FormBase).IsAssignableFrom(typeof(TForm))) + { + throw new ArgumentException($"{nameof(TForm)} argument must be a {nameof(FormBase)} type"); + } + + manager.Add(new GuidNavigation(method, action)); + } + + public static void AddGuidNavigation(this ExternalActionManager manager, Type formType, string value, Expression> propertySelector) + { + if (!typeof(FormBase).IsAssignableFrom(formType)) + { + throw new ArgumentException($"{nameof(formType)} argument must be a {nameof(FormBase)} type"); + } + + var newValue = Expression.Parameter(propertySelector.Body.Type); + + var assign = Expression.Lambda>(Expression.Assign(propertySelector.Body, newValue), propertySelector.Parameters[0], newValue); + + var setter = assign.Compile(true); + + manager.Add(new GuidNavigation(formType, value, setter)); + } + + public static void AddGuidNavigation(this ExternalActionManager manager, Type formType, string method, Action action) + { + if (!typeof(FormBase).IsAssignableFrom(formType)) + { + throw new ArgumentException($"{nameof(formType)} argument must be a {nameof(FormBase)} type"); + } + + manager.Add(new GuidNavigation(formType, method, action)); + } + } +} diff --git a/Experiments/ExternalActionManager/TelegramBotBase.Experiments/ActionManager/Navigation/GuidNavigation.cs b/Experiments/ExternalActionManager/TelegramBotBase.Experiments/ActionManager/Navigation/GuidNavigation.cs index 230c719..0d361a3 100644 --- a/Experiments/ExternalActionManager/TelegramBotBase.Experiments/ActionManager/Navigation/GuidNavigation.cs +++ b/Experiments/ExternalActionManager/TelegramBotBase.Experiments/ActionManager/Navigation/GuidNavigation.cs @@ -1,5 +1,4 @@ -using System.Linq.Expressions; -using TelegramBotBase.Base; +using TelegramBotBase.Base; using TelegramBotBase.Form; namespace TelegramBotBase.Experiments.ActionManager.Navigation @@ -107,62 +106,4 @@ namespace TelegramBotBase.Experiments.ActionManager.Navigation public static CallbackData GetCallback(string method, Guid guid) => new CallbackData(method, guid.ToString()); } - - public static class GuidNavigation_Extensions - { - - public static void AddGuidNavigation(this ExternalActionManager manager, string method, Expression> propertySelector) - where TForm : FormBase - { - if (!typeof(FormBase).IsAssignableFrom(typeof(TForm))) - { - throw new ArgumentException($"{nameof(TForm)} argument must be a {nameof(FormBase)} type"); - } - - var newValue = Expression.Parameter(propertySelector.Body.Type); - - var assign = Expression.Lambda>(Expression.Assign(propertySelector.Body, newValue), propertySelector.Parameters[0], newValue); - - var setter = assign.Compile(true); - - manager.Add(new GuidNavigation(method, setter)); - } - - public static void AddGuidNavigation(this ExternalActionManager manager, string method, Action action) - where TForm : FormBase - { - if (!typeof(FormBase).IsAssignableFrom(typeof(TForm))) - { - throw new ArgumentException($"{nameof(TForm)} argument must be a {nameof(FormBase)} type"); - } - - manager.Add(new GuidNavigation(method, action)); - } - - public static void AddGuidNavigation(this ExternalActionManager manager, Type formType, string value, Expression> propertySelector) - { - if (!typeof(FormBase).IsAssignableFrom(formType)) - { - throw new ArgumentException($"{nameof(formType)} argument must be a {nameof(FormBase)} type"); - } - - var newValue = Expression.Parameter(propertySelector.Body.Type); - - var assign = Expression.Lambda>(Expression.Assign(propertySelector.Body, newValue), propertySelector.Parameters[0], newValue); - - var setter = assign.Compile(true); - - manager.Add(new GuidNavigation(formType, value, setter)); - } - - public static void AddGuidNavigation(this ExternalActionManager manager, Type formType, string method, Action action) - { - if (!typeof(FormBase).IsAssignableFrom(formType)) - { - throw new ArgumentException($"{nameof(formType)} argument must be a {nameof(FormBase)} type"); - } - - manager.Add(new GuidNavigation(formType, method, action)); - } - } } diff --git a/Experiments/ExternalActionManager/TelegramBotBase.Experiments/ActionManager/Navigation/StartWithNavigation.Extensions.cs b/Experiments/ExternalActionManager/TelegramBotBase.Experiments/ActionManager/Navigation/StartWithNavigation.Extensions.cs new file mode 100644 index 0000000..22beb57 --- /dev/null +++ b/Experiments/ExternalActionManager/TelegramBotBase.Experiments/ActionManager/Navigation/StartWithNavigation.Extensions.cs @@ -0,0 +1,63 @@ +using System.Linq.Expressions; +using TelegramBotBase.Form; + +namespace TelegramBotBase.Experiments.ActionManager.Navigation +{ + public static class StartWithNavigation_Extensions + { + public static void AddStartsWithNavigation(this ExternalActionManager manager, string method, Expression> propertySelector) + where TForm : FormBase + { + if (!typeof(FormBase).IsAssignableFrom(typeof(TForm))) + { + throw new ArgumentException($"{nameof(TForm)} argument must be a {nameof(FormBase)} type"); + } + + var newValue = Expression.Parameter(propertySelector.Body.Type); + + var assign = Expression.Lambda>(Expression.Assign(propertySelector.Body, newValue), propertySelector.Parameters[0], newValue); + + var setter = assign.Compile(true); + + manager.Add(new StartWithNavigation(method, setter)); + } + public static void AddStartsWithNavigation(this ExternalActionManager manager, string value, Action setProperty) + where TForm : FormBase + { + if (!typeof(FormBase).IsAssignableFrom(typeof(TForm))) + { + throw new ArgumentException($"{nameof(TForm)} argument must be a {nameof(FormBase)} type"); + } + + manager.Add(new StartWithNavigation(value, setProperty)); + } + + public static void AddStartsWithNavigation(this ExternalActionManager manager, Type formType, string value, Expression> propertySelector) + { + if (!typeof(FormBase).IsAssignableFrom(formType)) + { + throw new ArgumentException($"{nameof(formType)} argument must be a {nameof(FormBase)} type"); + } + + var newValue = Expression.Parameter(propertySelector.Body.Type); + + var assign = Expression.Lambda>(Expression.Assign(propertySelector.Body, newValue), propertySelector.Parameters[0], newValue); + + var setter = assign.Compile(true); + + manager.Add(new StartWithNavigation(formType, value, setter)); + } + + public static void AddStartsWithNavigation(this ExternalActionManager manager, Type formType, string value, Action setProperty) + { + if (!typeof(FormBase).IsAssignableFrom(formType)) + { + throw new ArgumentException($"{nameof(formType)} argument must be a {nameof(FormBase)} type"); + } + + manager.Add(new StartWithNavigation(formType, value, setProperty)); + } + + } + +} diff --git a/Experiments/ExternalActionManager/TelegramBotBase.Experiments/ActionManager/Navigation/StartWithNavigation.cs b/Experiments/ExternalActionManager/TelegramBotBase.Experiments/ActionManager/Navigation/StartWithNavigation.cs index da73619..df9794f 100644 --- a/Experiments/ExternalActionManager/TelegramBotBase.Experiments/ActionManager/Navigation/StartWithNavigation.cs +++ b/Experiments/ExternalActionManager/TelegramBotBase.Experiments/ActionManager/Navigation/StartWithNavigation.cs @@ -1,5 +1,4 @@ -using System.Linq.Expressions; -using TelegramBotBase.Base; +using TelegramBotBase.Base; using TelegramBotBase.Form; namespace TelegramBotBase.Experiments.ActionManager.Navigation @@ -72,61 +71,4 @@ namespace TelegramBotBase.Experiments.ActionManager.Navigation } - public static class StartWithNavigation_Extensions - { - public static void AddStartsWithNavigation(this ExternalActionManager manager, string method, Expression> propertySelector) - where TForm : FormBase - { - if (!typeof(FormBase).IsAssignableFrom(typeof(TForm))) - { - throw new ArgumentException($"{nameof(TForm)} argument must be a {nameof(FormBase)} type"); - } - - var newValue = Expression.Parameter(propertySelector.Body.Type); - - var assign = Expression.Lambda>(Expression.Assign(propertySelector.Body, newValue), propertySelector.Parameters[0], newValue); - - var setter = assign.Compile(true); - - manager.Add(new StartWithNavigation(method, setter)); - } - public static void AddStartsWithNavigation(this ExternalActionManager manager, string value, Action setProperty) - where TForm : FormBase - { - if (!typeof(FormBase).IsAssignableFrom(typeof(TForm))) - { - throw new ArgumentException($"{nameof(TForm)} argument must be a {nameof(FormBase)} type"); - } - - manager.Add(new StartWithNavigation(value, setProperty)); - } - - public static void AddStartsWithNavigation(this ExternalActionManager manager, Type formType, string value, Expression> propertySelector) - { - if (!typeof(FormBase).IsAssignableFrom(formType)) - { - throw new ArgumentException($"{nameof(formType)} argument must be a {nameof(FormBase)} type"); - } - - var newValue = Expression.Parameter(propertySelector.Body.Type); - - var assign = Expression.Lambda>(Expression.Assign(propertySelector.Body, newValue), propertySelector.Parameters[0], newValue); - - var setter = assign.Compile(true); - - manager.Add(new StartWithNavigation(formType, value, setter)); - } - - public static void AddStartsWithNavigation(this ExternalActionManager manager, Type formType, string value, Action setProperty) - { - if (!typeof(FormBase).IsAssignableFrom(formType)) - { - throw new ArgumentException($"{nameof(formType)} argument must be a {nameof(FormBase)} type"); - } - - manager.Add(new StartWithNavigation(formType, value, setProperty)); - } - - } - }