diff options
author | Ignacio Etcheverry <neikeq@users.noreply.github.com> | 2018-09-12 22:08:54 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-12 22:08:54 +0200 |
commit | 8704b7787624da98cece35c1b8b8e51bde709488 (patch) | |
tree | 398ab2ee1e88e3b853c6157458362dced14d64da /modules/mono/glue/Managed/Files/DebuggingUtils.cs | |
parent | 4cd3dd821932660a7d89d90da7626fa46c07ac39 (diff) | |
parent | 995a40e8efa9f7a868a6706e30c476305e16180b (diff) |
Merge pull request #22007 from neikeq/<name_of_your_new_branch>
Move modules/mono/glue/cs_files to modules/mono/glue/Managed/Files
Diffstat (limited to 'modules/mono/glue/Managed/Files/DebuggingUtils.cs')
-rw-r--r-- | modules/mono/glue/Managed/Files/DebuggingUtils.cs | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/modules/mono/glue/Managed/Files/DebuggingUtils.cs b/modules/mono/glue/Managed/Files/DebuggingUtils.cs new file mode 100644 index 0000000000..b27816084e --- /dev/null +++ b/modules/mono/glue/Managed/Files/DebuggingUtils.cs @@ -0,0 +1,83 @@ +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 + sb.Append(type); + + 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(); + + if (methodBase == null) + { + methodDecl = string.Empty; + return; + } + + var sb = new StringBuilder(); + + if (methodBase is MethodInfo) + sb.AppendTypeName(((MethodInfo)methodBase).ReturnType); + + sb.Append(methodBase.DeclaringType.FullName); + sb.Append("."); + sb.Append(methodBase.Name); + + if (methodBase.IsGenericMethod) + { + Type[] genericParams = methodBase.GetGenericArguments(); + + sb.Append("<"); + + for (int j = 0; j < genericParams.Length; j++) + { + if (j > 0) + sb.Append(", "); + + sb.AppendTypeName(genericParams[j]); + } + + sb.Append(">"); + } + + sb.Append("("); + + bool varArgs = (methodBase.CallingConvention & CallingConventions.VarArgs) != 0; + + ParameterInfo[] parameter = methodBase.GetParameters(); + + for (int i = 0; i < parameter.Length; i++) + { + if (i > 0) + sb.Append(", "); + + if (i == parameter.Length - 1 && varArgs) + sb.Append("params "); + + sb.AppendTypeName(parameter[i].ParameterType); + } + + sb.Append(")"); + + methodDecl = sb.ToString(); + } + } +} |