2018-01-09 16:19:03 +00:00
|
|
|
using System;
|
|
|
|
using System.Diagnostics;
|
|
|
|
using System.Reflection;
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
namespace Godot
|
|
|
|
{
|
|
|
|
internal static class DebuggingUtils
|
|
|
|
{
|
|
|
|
internal static void AppendTypeName(this StringBuilder sb, Type type)
|
|
|
|
{
|
|
|
|
if (type.IsPrimitive)
|
|
|
|
sb.Append(type.Name);
|
|
|
|
else if (type == typeof(void))
|
|
|
|
sb.Append("void");
|
|
|
|
else
|
2018-04-08 03:28:24 +00:00
|
|
|
sb.Append(type);
|
2018-01-09 16:19:03 +00:00
|
|
|
|
|
|
|
sb.Append(" ");
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void GetStackFrameInfo(StackFrame frame, out string fileName, out int fileLineNumber, out string methodDecl)
|
|
|
|
{
|
|
|
|
fileName = frame.GetFileName();
|
|
|
|
fileLineNumber = frame.GetFileLineNumber();
|
|
|
|
|
|
|
|
MethodBase methodBase = frame.GetMethod();
|
|
|
|
|
2018-01-12 18:23:11 +00:00
|
|
|
if (methodBase == null)
|
|
|
|
{
|
|
|
|
methodDecl = string.Empty;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-04-08 03:30:43 +00:00
|
|
|
var sb = new StringBuilder();
|
2018-01-09 16:19:03 +00:00
|
|
|
|
2018-01-18 11:43:23 +00:00
|
|
|
if (methodBase is MethodInfo)
|
|
|
|
sb.AppendTypeName(((MethodInfo)methodBase).ReturnType);
|
2018-01-09 16:19:03 +00:00
|
|
|
|
|
|
|
sb.Append(methodBase.DeclaringType.FullName);
|
|
|
|
sb.Append(".");
|
|
|
|
sb.Append(methodBase.Name);
|
|
|
|
|
|
|
|
if (methodBase.IsGenericMethod)
|
|
|
|
{
|
|
|
|
Type[] genericParams = methodBase.GetGenericArguments();
|
|
|
|
|
|
|
|
sb.Append("<");
|
|
|
|
|
2018-04-16 22:33:42 +00:00
|
|
|
for (int j = 0; j < genericParams.Length; j++)
|
2018-01-09 16:19:03 +00:00
|
|
|
{
|
|
|
|
if (j > 0)
|
|
|
|
sb.Append(", ");
|
|
|
|
|
|
|
|
sb.AppendTypeName(genericParams[j]);
|
|
|
|
}
|
|
|
|
|
|
|
|
sb.Append(">");
|
|
|
|
}
|
|
|
|
|
|
|
|
sb.Append("(");
|
|
|
|
|
|
|
|
bool varArgs = (methodBase.CallingConvention & CallingConventions.VarArgs) != 0;
|
|
|
|
|
|
|
|
ParameterInfo[] parameter = methodBase.GetParameters();
|
|
|
|
|
2018-04-16 22:33:42 +00:00
|
|
|
for (int i = 0; i < parameter.Length; i++)
|
2018-01-09 16:19:03 +00:00
|
|
|
{
|
|
|
|
if (i > 0)
|
|
|
|
sb.Append(", ");
|
|
|
|
|
|
|
|
if (i == parameter.Length - 1 && varArgs)
|
|
|
|
sb.Append("params ");
|
|
|
|
|
|
|
|
sb.AppendTypeName(parameter[i].ParameterType);
|
|
|
|
}
|
|
|
|
|
|
|
|
sb.Append(")");
|
|
|
|
|
|
|
|
methodDecl = sb.ToString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|