namespacify everything

This commit is contained in:
2024-04-06 14:42:10 +03:00
parent 68b735b59c
commit 6430cc9b4d
42 changed files with 10066 additions and 10107 deletions

View File

@@ -1,78 +1,77 @@
using System;
using System.Reflection;
namespace Game
namespace Game;
internal struct ConsoleCommand
{
internal struct ConsoleCommand
public string name { get; }
private readonly MethodInfo[] methods;
public ConsoleCommand(string name, MethodInfo[] method)
{
public string name { get; }
this.name = name;
methods = method;
}
private readonly MethodInfo[] methods;
public ConsoleCommand(string name, MethodInfo[] method)
public void Invoke()
{
foreach (MethodInfo method in methods)
{
this.name = name;
methods = method;
var methodParameters = method.GetParameters();
if (methodParameters.Length == 0)
method.Invoke(null, null);
else if (methodParameters.Length == 1 && methodParameters[0].ParameterType == typeof(string[]))
method.Invoke(null, new object[] { Array.Empty<string>() });
else
continue;
return;
}
public void Invoke()
throw new Exception("Unexpected number of parameters.");
}
public void Invoke(string[] parameters)
{
MethodInfo match = null;
foreach (MethodInfo method in methods)
{
foreach (MethodInfo method in methods)
var methodParameters = method.GetParameters();
if (methodParameters.Length == 1 && methodParameters[0].ParameterType == typeof(string[]))
{
var methodParameters = method.GetParameters();
if (methodParameters.Length == 0)
method.Invoke(null, null);
else if (methodParameters.Length == 1 && methodParameters[0].ParameterType == typeof(string[]))
method.Invoke(null, new object[] { Array.Empty<string>() });
else
continue;
return;
match = method;
continue;
}
throw new Exception("Unexpected number of parameters.");
}
if (methodParameters.Length != parameters.Length)
continue;
public void Invoke(string[] parameters)
{
MethodInfo match = null;
foreach (MethodInfo method in methods)
{
var methodParameters = method.GetParameters();
if (methodParameters.Length == 1 && methodParameters[0].ParameterType == typeof(string[]))
{
match = method;
// TODO: try to parse string parameters to needed types first,
// may require finding the exact match first instead of first matching one.
for (int i = 0; i < methodParameters.Length; i++)
//if (methodParameters[i].ParameterType != parameters[i].GetType())
if (methodParameters[i].ParameterType != typeof(string))
continue;
}
if (match != null)
// Prefer exact number of parameters over string[] match
if (methodParameters.Length != parameters.Length)
continue;
// TODO: try to parse string parameters to needed types first,
// may require finding the exact match first instead of first matching one.
for (int i = 0; i < methodParameters.Length; i++)
//if (methodParameters[i].ParameterType != parameters[i].GetType())
if (methodParameters[i].ParameterType != typeof(string))
continue;
if (match != null)
// Prefer exact number of parameters over string[] match
if (methodParameters.Length != parameters.Length)
continue;
match = method;
}
if (match != null)
{
if (match.GetParameters().Length == 1 && match.GetParameters()[0].ParameterType == typeof(string[]))
match.Invoke(null, new object[] { parameters });
else
match.Invoke(null, parameters);
return;
}
throw new Exception("Unexpected number of parameters.");
match = method;
}
if (match != null)
{
if (match.GetParameters().Length == 1 && match.GetParameters()[0].ParameterType == typeof(string[]))
match.Invoke(null, new object[] { parameters });
else
match.Invoke(null, parameters);
return;
}
throw new Exception("Unexpected number of parameters.");
}
}