Player data initial
This commit is contained in:
@@ -12,7 +12,7 @@ namespace TOOHUCardAPI.Controllers
|
||||
public class MethodBasedController : ControllerBase
|
||||
{
|
||||
public delegate Task<object> EndpointHandler(string requestBody);
|
||||
private static Dictionary<Type, MethodMap> MethodMapByType;
|
||||
private static Dictionary<Type, MethodMap> MethodMapByType = new Dictionary<Type, MethodMap>();
|
||||
|
||||
protected Task<object> InvokeEndpointHandlerForMethod<T>(object _this, string method, string body)
|
||||
{
|
||||
@@ -20,7 +20,7 @@ namespace TOOHUCardAPI.Controllers
|
||||
if (registeredEndpointHandlers.ContainsKey(method))
|
||||
{
|
||||
return ((EndpointHandler) registeredEndpointHandlers[method]
|
||||
.CreateDelegate(typeof(EndpointHandler), _this)).Invoke(body);
|
||||
.CreateDelegate(typeof(EndpointHandler), _this))(body);
|
||||
}
|
||||
throw new MissingEndpointHandlerException(method);
|
||||
}
|
||||
@@ -29,15 +29,14 @@ namespace TOOHUCardAPI.Controllers
|
||||
{
|
||||
if (!MethodMapByType.ContainsKey(typeof(T)))
|
||||
{
|
||||
RegisterEndpointHandlers<T>();
|
||||
MethodMapByType[typeof(T)] = RegisterEndpointHandlers<T>();
|
||||
}
|
||||
|
||||
return MethodMapByType[typeof(T)];
|
||||
}
|
||||
|
||||
private static MethodMap RegisterEndpointHandlers<T>()
|
||||
{
|
||||
MethodInfo[] methods = typeof(T).GetMethods();
|
||||
MethodInfo[] methods = typeof(T).GetMethods(BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
return methods
|
||||
.Aggregate(new MethodMap(), (handlers, m) =>
|
||||
{
|
||||
@@ -51,4 +50,11 @@ namespace TOOHUCardAPI.Controllers
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public class MissingEndpointHandlerException : Exception
|
||||
{
|
||||
public MissingEndpointHandlerException(string method) : base($"Handler for [{method}] is either missing or incorrectly setup.")
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user