Adding short non generic version

This commit is contained in:
Florian Zevedei
2024-01-22 03:58:00 +01:00
parent aee7562424
commit fc1e8e84c6
3 changed files with 34 additions and 11 deletions
@@ -152,6 +152,22 @@ namespace DemoBot.ActionManager.Actions
manager.Add(new GuidAction<TForm>(method, action));
}
public static void AddGuidAction(this ExternalActionManager manager, Type formType, string value, Expression<Func<FormBase, Guid>> 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<Action<FormBase, Guid>>(Expression.Assign(propertySelector.Body, newValue), propertySelector.Parameters[0], newValue);
var setter = assign.Compile(true);
manager.Add(new GuidAction(formType, value, setter));
}
public static void AddGuidAction(this ExternalActionManager manager, Type formType, string method, Action<FormBase, Guid> action)
{
if (!typeof(FormBase).IsAssignableFrom(formType))
@@ -129,6 +129,22 @@ namespace DemoBot.ActionManager.Actions
manager.Add(new StartWithAction<TForm>(value, setProperty));
}
public static void AddStartsWithAction(this ExternalActionManager manager, Type formType, string value, Expression<Func<FormBase, String>> 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<Action<FormBase, String>>(Expression.Assign(propertySelector.Body, newValue), propertySelector.Parameters[0], newValue);
var setter = assign.Compile(true);
manager.Add(new StartWithAction(formType, value, setter));
}
public static void AddStartsWithAction(this ExternalActionManager manager, Type formType, string value, Action<FormBase, String> setProperty)
{
if (!typeof(FormBase).IsAssignableFrom(formType))