34 lines
2.0 KiB
Python
34 lines
2.0 KiB
Python
all_types = ["System.Action", "System.Threading.Tasks.Task", "YarnTask", "IEnumerator", "Coroutine", "Awaitable", "UniTask"]
|
|
|
|
doc_template = '/// <inheritdoc cref="IActionRegistration.AddCommandHandler(string, Delegate)"/>'
|
|
imp_template = "public static void AddCommandHandler(this IActionRegistration registration, string commandName, System.Func<{0}> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);"
|
|
imp_numeric_template = "public static void AddCommandHandler<{1}>(this IActionRegistration registration, string commandName, System.Func<{1}, {0}> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);"
|
|
|
|
# System.Action has a slightly different signature so needs a tweaked template
|
|
imp_action_template = "public static void AddCommandHandler(this IActionRegistration registration, string commandName, System.Action handler) => registration.AddCommandHandler(commandName, (Delegate)handler);"
|
|
imp_action_numeric_template = "public static void AddCommandHandler<{1}>(this IActionRegistration registration, string commandName, System.Action<{1}> handler) => registration.AddCommandHandler(commandName, (Delegate)handler);"
|
|
|
|
def gyb(count, types):
|
|
for type in types:
|
|
print(f"// These registrations for {type} were generated by action-gyb.py")
|
|
|
|
# generating the registration for the 0 parameter form
|
|
print(doc_template)
|
|
|
|
# true' if True else 'false'
|
|
template = imp_template if type != "System.Action" else imp_action_template
|
|
print(template.format(type))
|
|
|
|
# generating the registration for the 1->count parameter forms
|
|
for i in range(count):
|
|
print(doc_template)
|
|
|
|
# generating the <T1, T2> etc type values
|
|
r = ["T" + str(x) for x in range(1, i + 2)]
|
|
s = ", ".join(r)
|
|
template = imp_numeric_template if type != "System.Action" else imp_action_numeric_template
|
|
print(template.format(type, s))
|
|
print()
|
|
|
|
gyb(16, all_types)
|