Adding short non generic version
This commit is contained in:
parent
aee7562424
commit
fc1e8e84c6
@ -152,6 +152,22 @@ namespace DemoBot.ActionManager.Actions
|
|||||||
manager.Add(new GuidAction<TForm>(method, action));
|
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)
|
public static void AddGuidAction(this ExternalActionManager manager, Type formType, string method, Action<FormBase, Guid> action)
|
||||||
{
|
{
|
||||||
if (!typeof(FormBase).IsAssignableFrom(formType))
|
if (!typeof(FormBase).IsAssignableFrom(formType))
|
||||||
|
|||||||
@ -129,6 +129,22 @@ namespace DemoBot.ActionManager.Actions
|
|||||||
manager.Add(new StartWithAction<TForm>(value, setProperty));
|
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)
|
public static void AddStartsWithAction(this ExternalActionManager manager, Type formType, string value, Action<FormBase, String> setProperty)
|
||||||
{
|
{
|
||||||
if (!typeof(FormBase).IsAssignableFrom(formType))
|
if (!typeof(FormBase).IsAssignableFrom(formType))
|
||||||
|
|||||||
@ -81,17 +81,8 @@ namespace DemoBot
|
|||||||
//Waiting for input starting with 'a_'
|
//Waiting for input starting with 'a_'
|
||||||
config.AddStartsWithAction<HiddenForm>("a_", a => a.value);
|
config.AddStartsWithAction<HiddenForm>("a_", a => a.value);
|
||||||
|
|
||||||
|
//Waiting for input starting with 't_' (Non generic version)
|
||||||
//Waiting for input starting with 't_'
|
config.AddStartsWithAction(typeof(HiddenForm), "t_", a => ((HiddenForm)a).value);
|
||||||
config.AddStartsWithAction(typeof(HiddenForm), "t_", (a, b) =>
|
|
||||||
{
|
|
||||||
var hf = a as HiddenForm;
|
|
||||||
if (hf == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
hf.value = b;
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
//Deserialize input and waiting for the method property to has value 'tickets'
|
//Deserialize input and waiting for the method property to has value 'tickets'
|
||||||
config.AddGuidAction<HiddenTicketForm>("tickets", a => a.ticketId);
|
config.AddGuidAction<HiddenTicketForm>("tickets", a => a.ticketId);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user